diff --git a/bot/bot.go b/bot/bot.go index 76757e1..bd92002 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -99,8 +99,9 @@ func (bot *ArchiverBot) MessageCreate(s *discordgo.Session, m *discordgo.Message // This function will be called every time a new react is created on any message // that the authenticated bot has access to. func (bot *ArchiverBot) MessageReactionAdd(s *discordgo.Session, r *discordgo.MessageReactionAdd) { + ServerConfig := bot.getServerConfig(r.GuildID) if r.MessageReaction.Emoji.Name == "🏛️" { - err := bot.handleArchiveRequest(s, r, false) + err := bot.handleArchiveRequest(s, r, ServerConfig.SkipLookup) if err != nil { log.Errorf("problem handling archive request: %v", err) } @@ -111,7 +112,7 @@ func (bot *ArchiverBot) MessageReactionAdd(s *discordgo.Session, r *discordgo.Me log.Warnf("Error getting reactions for message id: %s, channel: %s", r.MessageID, r.ChannelID) } if r.MessageReaction.Emoji.Name == "🔁" && len(users) > 0 { - err := bot.handleArchiveRequest(s, r, true) + err := bot.handleArchiveRequest(s, r, ServerConfig.SkipLookup) if err != nil { log.Errorf("problem handling archive request: %v", err) } diff --git a/bot/servers.go b/bot/servers.go index 2e27664..c2f9474 100644 --- a/bot/servers.go +++ b/bot/servers.go @@ -21,11 +21,12 @@ type ServerRegistration struct { type ServerConfig struct { DiscordId string `gorm:"primaryKey" pretty:"Server ID"` Name string `pretty:"Server Name"` - ArchiveEnabled bool `pretty:"ArchiveEvent Enabled"` + ArchiveEnabled bool `pretty:"Bot functionality enabled (switch)"` ReplyToOriginalMessage bool `pretty:"Reply to original message (embed must be off) (replyto)"` UseEmbed bool `pretty:"Use embed to reply (embed)"` AutoArchive bool `pretty:"Automatically try archiving a page if it is not found (archive)"` - RetryAttempts uint `pretty:"Number of attempts the bot should make to archive a URL. Max 10"` + SkipLookup bool `pretty:"Skip straight to submitting the URL for immediate archival (skip)"` + RetryAttempts uint `pretty:"Number of attempts the bot should make to archive a URL - Max 10 (retry)"` } const ( @@ -41,6 +42,7 @@ var ( ReplyToOriginalMessage: false, UseEmbed: true, AutoArchive: true, + SkipLookup: true, RetryAttempts: 4, } @@ -159,6 +161,10 @@ func (bot *ArchiverBot) setServerConfig(s *discordgo.Session, m *discordgo.Messa if valueIsStringBoolean { tx = bot.DB.Model(&ServerConfig{}).Where(&ServerConfig{DiscordId: guild.ID}).Update("use_embed", value == "on") } + case "skip": + if valueIsStringBoolean { + tx = bot.DB.Model(&ServerConfig{}).Where(&ServerConfig{DiscordId: guild.ID}).Update("skip_lookup", value == "on") + } case "archive": if valueIsStringBoolean { tx = bot.DB.Model(&ServerConfig{}).Where(&ServerConfig{DiscordId: guild.ID}).Update("auto_archive", value == "on") diff --git a/go.sum b/go.sum index 427d89b..4fc87c9 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/tyzbit/go-archive v0.0.0-20230206195843-20514a4efc44 h1:eFnPPxL7hFNDJ github.com/tyzbit/go-archive v0.0.0-20230206195843-20514a4efc44/go.mod h1:D8vNUS0ZU4ILov2Igxw1h+Kj7aeyapjUU1ruPLEx9gw= github.com/tyzbit/go-archive v0.0.0-20230206214528-8c7d3d901b0f h1:hH1l6N+2Cgr3/Lh31zifSJW1yHGi5VPojTmAHujq+X4= github.com/tyzbit/go-archive v0.0.0-20230206214528-8c7d3d901b0f/go.mod h1:D8vNUS0ZU4ILov2Igxw1h+Kj7aeyapjUU1ruPLEx9gw= +github.com/tyzbit/go-archive v0.0.0-20230206220046-c25482a1430d h1:AyuV30tBZ5KXOIel0P6YPRamMSkPC0JosTSRE0x0UpA= +github.com/tyzbit/go-archive v0.0.0-20230206220046-c25482a1430d/go.mod h1:D8vNUS0ZU4ILov2Igxw1h+Kj7aeyapjUU1ruPLEx9gw= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=