Skip to content

Commit

Permalink
v0.1.7: discordgo upgrade and first-run flag
Browse files Browse the repository at this point in the history
- Added firstrun flag so that the "run once at start" tasks are optionally executed
- Upgraded discordgo to 0.2.6 and fixed the breaking changes
  • Loading branch information
wneessen committed Aug 18, 2022
1 parent e148afb commit 466fb78
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ test:
dev:
@/usr/bin/env CGO_ENABLED=0 go run -ldflags="-s -w $(BUILDVER)" $(MODNAME)/cmd/arrgo -c ./arrgo.toml

dev-firstrun:
@/usr/bin/env CGO_ENABLED=0 go run -ldflags="-s -w $(BUILDVER)" $(MODNAME)/cmd/arrgo -c ./arrgo.toml -firstrun

dev-migrate:
@/usr/bin/env CGO_ENABLED=0 go run -ldflags="-s -w $(BUILDVER)" $(MODNAME)/cmd/arrgo -c ./arrgo.toml -migrate

Expand Down
26 changes: 14 additions & 12 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,20 @@ func (b *Bot) Run() error {
ddt := time.NewTicker(b.Config.Timer.DDUpdate)
defer ddt.Stop()

// Perform an update for all scheduled update tasks once
go func() {
if err := b.ScheduledEventUpdateTradeRoutes(); err != nil {
b.Log.Error().Msgf("failed to update trade routes: %s", err)
}
if err := b.ScheduledEventUpdateUserStats(); err != nil {
b.Log.Error().Msgf("failed to update user stats: %s", err)
}
if err := b.ScheduledEventUpdateDailyDeeds(); err != nil {
b.Log.Error().Msgf("failed to update daily deeds: %s", err)
}
}()
// Perform an update for all scheduled update tasks once if first-run flag is set
if b.Config.GetFirstRun() {
go func() {
if err := b.ScheduledEventUpdateTradeRoutes(); err != nil {
b.Log.Error().Msgf("failed to update trade routes: %s", err)
}
if err := b.ScheduledEventUpdateUserStats(); err != nil {
b.Log.Error().Msgf("failed to update user stats: %s", err)
}
if err := b.ScheduledEventUpdateDailyDeeds(); err != nil {
b.Log.Error().Msgf("failed to update daily deeds: %s", err)
}
}()
}

// Wait here until CTRL-C or other term signal is received.
ll.Info().Msg("bot successfully initialized and connected. Press CTRL-C to exit.")
Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (b *Bot) SlashCmdSoTCompare(s *discordgo.Session, i *discordgo.InteractionC
}
}

if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions bot/sc_handler_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (b *Bot) configFlameheart(s *discordgo.Session, i *discordgo.InteractionCre
}

// Edit the deferred message
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return fmt.Errorf("failed to edit /config flameheart-spam request: %w", err)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func (b *Bot) overrideAnnounceChannel(s *discordgo.Session, i *discordgo.Interac
Description: fmt.Sprintf("The annoucment channel for this server has been set to: <#%s>", ch),
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return fmt.Errorf("failed to edit /override annouce-channel request: %w", err)
}

Expand Down Expand Up @@ -149,7 +149,7 @@ func (b *Bot) configAnnounceSoTPlaySummary(s *discordgo.Session, i *discordgo.In
}

// Edit the deferred message
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return fmt.Errorf("failed to edit /config announce-sot-summary request: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_rarethief_traderoutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (b *Bot) SlashCmdSoTTradeRoutes(s *discordgo.Session, i *discordgo.Interact
},
}

if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions bot/sc_handler_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (b *Bot) SlashCmdRegister(s *discordgo.Session, i *discordgo.InteractionCre
Description: "You are already registered with ArrGo. Thanks for double checking...",
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return fmt.Errorf("failed to edit /register request: %w", err)
}
return nil
Expand Down Expand Up @@ -52,7 +52,7 @@ func (b *Bot) SlashCmdRegister(s *discordgo.Session, i *discordgo.InteractionCre
Description: "You have successfully registered your account and are now able to use the full feature set",
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return fmt.Errorf("failed to edit /register request: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_sot_achievement.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (b *Bot) SlashCmdSoTAchievement(s *discordgo.Session, i *discordgo.Interact
Type: discordgo.EmbedTypeImage,
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_sot_dailydeeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (b *Bot) SlashCmdSoTDailyDeeds(s *discordgo.Session, i *discordgo.Interacti
}
}

if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_sot_flameheart.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (b *Bot) SlashCmdSoTFlameheart(s *discordgo.Session, i *discordgo.Interacti
}

// Edit the deferred message
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_sot_season.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (b *Bot) SlashCmdSoTSeasonProgress(s *discordgo.Session, i *discordgo.Inter
}
}

if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions bot/sc_handler_sot_setrat.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *Bot) SlashCmdSetRAT(s *discordgo.Session, i *discordgo.InteractionCreat
"command to register your user with the bot",
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -87,7 +87,7 @@ func (b *Bot) SlashCmdSetRAT(s *discordgo.Session, i *discordgo.InteractionCreat
Description: "Thank you for storing/updating your Sea of Thieves authentication cookie.",
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions bot/sc_handler_sot_userstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (b *Bot) SlashCmdSoTOverview(s *discordgo.Session, i *discordgo.Interaction
},
}

if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -153,7 +153,7 @@ func (b *Bot) SlashCmdSoTBalance(s *discordgo.Session, i *discordgo.InteractionC
e[0].Description = fmt.Sprintf("**Current Title:** %s", ub.Title)
}

if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (b *Bot) SlashCmdTime(s *discordgo.Session, i *discordgo.InteractionCreate)
Description: fmt.Sprintf("The current bot time is: <t:%d>", time.Now().Unix()),
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_uptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (b *Bot) SlashCmdUptime(s *discordgo.Session, i *discordgo.InteractionCreat
"which means I've been running for %s now!", b.StartTimeUnix(), td.String()),
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion bot/sc_handler_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (b *Bot) SlashCmdVersion(s *discordgo.Session, i *discordgo.InteractionCrea
"Nice to meet you!", Version),
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e}); err != nil {
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions bot/slashcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (b *Bot) SlashCommandHandler(s *discordgo.Session, i *discordgo.Interaction
Data: &discordgo.InteractionResponseData{Content: ""},
}
if _, ok := el[i.ApplicationCommandData().Name]; ok {
r.Data.Flags = uint64(discordgo.MessageFlagsEphemeral)
r.Data.Flags = discordgo.MessageFlagsEphemeral
}
err := s.InteractionRespond(i.Interaction, r)
if err != nil {
Expand All @@ -357,7 +357,7 @@ func (b *Bot) SlashCommandHandler(s *discordgo.Session, i *discordgo.Interaction
Title: "Oh no! Something went wrong!",
},
}
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: e})
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e})
}
}
}
8 changes: 7 additions & 1 deletion cmd/arrgo/arrgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CLIFlags struct {
r bool // Remove slash commands
m bool // Run in SQL migration mode
d bool // Run in SQL downgrade mode
f bool // First run
}

func main() {
Expand All @@ -29,7 +30,9 @@ func main() {
flag.StringVar(&cf.c, "c", cf.c, "Path to config file")
flag.BoolVar(&cf.r, "r", cf.r, "Remove slash commands")
flag.BoolVar(&cf.m, "migrate", false, "Execute SQL migrations before starting the bot")
flag.BoolVar(&cf.d, "downgrade", false, "Execute SQL downgrade migrations before starting the bot")
flag.BoolVar(&cf.d, "downgrade", false, "Execute SQL downgrade migrations before "+
"starting the bot")
flag.BoolVar(&cf.f, "firstrun", false, "Execute first-run tasks during startup")
flag.Parse()

// Read/Parse config
Expand All @@ -42,6 +45,9 @@ func main() {
_, _ = fmt.Fprintf(os.Stderr, "could not read config: %s. Aborting", err)
os.Exit(1)
}
if cf.f {
c.SetFirstRun()
}

// Initialize zerolog
zerolog.SetGlobalLevel(zerolog.InfoLevel)
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Config struct {
}
confPath string
confFile string
firstRun bool
}

// WithConfFile overrides the default config file path/name
Expand Down Expand Up @@ -94,3 +95,13 @@ func New(ol ...CfgOpt) (Config, error) {
func (c *Config) ConfFilePath() string {
return c.confFile
}

// SetFirstRun sets the fristRun flag in the config to true
func (c *Config) SetFirstRun() {
c.firstRun = true
}

// GetFirstRun returns the state of the firstRun flag in the config
func (c *Config) GetFirstRun() bool {
return c.firstRun
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/wneessen/arrgo
go 1.18

require (
github.com/bwmarrin/discordgo v0.25.0
github.com/bwmarrin/discordgo v0.26.0
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/kkyr/fig v0.3.0
github.com/lib/pq v1.10.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx2
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/bwmarrin/discordgo v0.25.0 h1:NXhdfHRNxtwso6FPdzW2i3uBvvU7UIQTghmV2T4nqAs=
github.com/bwmarrin/discordgo v0.25.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/bwmarrin/discordgo v0.26.0 h1:/AdFmxHXSHInYAZ7K0O3VEIXlVjGpztk/nuCr9o+JCs=
github.com/bwmarrin/discordgo v0.26.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down

0 comments on commit 466fb78

Please sign in to comment.