From b6ad78c4af565bf22068e71f21470f98c84bfc95 Mon Sep 17 00:00:00 2001 From: Tyler Hawkins <3319104+tyzbit@users.noreply.github.com> Date: Mon, 5 Aug 2024 18:39:58 -0400 Subject: [PATCH] feat(responses): add archive.is link --- bot/discord_handlers.go | 5 ++++- bot/responses.go | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bot/discord_handlers.go b/bot/discord_handlers.go index b4b4088..fa592b5 100644 --- a/bot/discord_handlers.go +++ b/bot/discord_handlers.go @@ -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 { diff --git a/bot/responses.go b/bot/responses.go index 1be88ca..c942450 100644 --- a/bot/responses.go +++ b/bot/responses.go @@ -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 @@ -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...) @@ -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, }, } } @@ -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