Skip to content

Commit

Permalink
feat(responses): add archive.is link
Browse files Browse the repository at this point in the history
  • Loading branch information
tyzbit committed Aug 5, 2024
1 parent f4a4aef commit b6ad78c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion bot/discord_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ func (bot *ArchiverBot) archiveInteraction(i *discordgo.InteractionCreate, newSn

for _, message := range messagesToSend {
if message == nil {
log.Errorf("empty message")
log.Errorf("empty message, not trying to send")
message = &discordgo.MessageSend{
Content: "Error handling interaction",
}
}
err := bot.sendArchiveCommandResponse(i.Interaction, message)
if err != nil {
Expand Down
21 changes: 15 additions & 6 deletions bot/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (
)

const (
archiveDomain string = "web.archive.org"
archiveRoot string = "https://" + archiveDomain + "/web"
originalURLSearch string = ".*(http.*)"
waybackPrefix string = "http(s)?://web.archive.org"
archiveDomain string = "web.archive.org"
archiveRoot string = "https://" + archiveDomain + "/web"
archivePhTimeGateAPI string = "https://archive.is/timegate"
originalURLSearch string = ".*(http.*)"
waybackPrefix string = "http(s)?://web.archive.org"
)

// buildMessageResponse takes a Discord session an original message and
Expand Down Expand Up @@ -178,7 +179,9 @@ func (bot *ArchiverBot) buildInteractionResponse(i *discordgo.InteractionCreate,
newSnapshot = command.BoolValue()
}
}
} else if commandData.Name == globals.ArchiveMessage || commandData.Name == globals.ArchiveMessageNewSnapshot {
} else if commandData.Name == globals.ArchiveMessage ||
commandData.Name == globals.ArchiveMessageNewSnapshot ||
commandData.Name == globals.ArchiveMessagePrivate {
for _, message := range commandData.Resolved.Messages {
urlGroup, urlErrs := bot.extractMessageUrls(message.Content)
messageUrls = append(messageUrls, urlGroup...)
Expand Down Expand Up @@ -448,6 +451,12 @@ func (bot *ArchiverBot) buildArchiveReply(archivedLinks []string, messageUrls []
Name: "Total Number of Snapshots",
Value: fmt.Sprintf("[%s](%s/%s0000000000*/%s)",
fmt.Sprint(snapshotCount), archiveRoot, fmt.Sprint(time.Now().Year()), originalUrl),
Inline: true,
},
{
Name: "Alternate links",
Value: fmt.Sprintf("[%s](%s/%s)", "archive.is", archivePhTimeGateAPI, originalUrl),
Inline: true,
},
}
}
Expand All @@ -457,7 +466,7 @@ func (bot *ArchiverBot) buildArchiveReply(archivedLinks []string, messageUrls []
embed.Footer = &discordgo.MessageEmbedFooter{
Text: "⚙️ Customize this message with /settings\n" +
"NOTICE: Reacting with 🏛️ being deprecated September 1, 2024," +
" run `/help` for more.",
" run `/help` for more.\n",
}

embed.URL = originalUrl
Expand Down

0 comments on commit b6ad78c

Please sign in to comment.