Skip to content

Commit

Permalink
fix: request rearchival by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tyzbit committed Feb 6, 2023
1 parent bc33809 commit 2d7ca58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 8 additions & 2 deletions bot/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -41,6 +42,7 @@ var (
ReplyToOriginalMessage: false,
UseEmbed: true,
AutoArchive: true,
SkipLookup: true,
RetryAttempts: 4,
}

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 2d7ca58

Please sign in to comment.