Skip to content

Commit

Permalink
Merge pull request #17 from wneessen/ledger
Browse files Browse the repository at this point in the history
Emissary ledger slash command
  • Loading branch information
wneessen authored Oct 1, 2022
2 parents f5fcc8d + 3a0d0d0 commit 9734dc5
Show file tree
Hide file tree
Showing 27 changed files with 318 additions and 65 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
81 changes: 46 additions & 35 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
ApiURLSoTUserOverview = "https://www.seaofthieves.com/api/profilev2/overview"
ApiURLSoTEventHub = "https://www.seaofthieves.com/event-hub"
ApiURLRTTradeRoutes = "https://maps.seaofthieves.rarethief.com/js/trade_routes.js"
ApiURLSoTLedger = "https://www.seaofthieves.com/api/ledger/friends"
AssetsBaseURL = "https://github.com/wneessen/arrgo/raw/main/assets"
)

Expand Down Expand Up @@ -119,14 +120,12 @@ func (b *Bot) Run() error {
signal.Notify(sc)

// Timer events
var rn int
rn = int(b.Config.Timer.FHSpam)
rn, err = crypto.RandNum(int(b.Config.Timer.FHSpam))
rd, err := crypto.RandDuration(b.Config.Timer.FHSpam, "m")
if err != nil {
ll.Warn().Msgf("failed to generate random number for FH timer: %s", err)
rn = int(b.Config.Timer.FHSpam)
rd = time.Minute * time.Duration(b.Config.Timer.FHSpam)
}
fht := time.NewTicker(time.Duration(int64(rn)+b.Config.Timer.FHSpam) * time.Minute)
fht := time.NewTicker(rd)
defer fht.Stop()
trt := time.NewTicker(b.Config.Timer.TRUpdate)
defer trt.Stop()
Expand All @@ -137,18 +136,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 All @@ -168,33 +169,43 @@ func (b *Bot) Run() error {
return nil
}
case <-fht.C:
if err := b.ScheduledEventSoTFlameheart(); err != nil {
ll.Error().Msgf("failed to process scheuled flameheart event: %s", err)
}
go func() {
if err := b.ScheduledEventSoTFlameheart(); err != nil {
ll.Error().Msgf("failed to process scheuled flameheart event: %s", err)
}
}()

// Reset the duration
rn, err = crypto.RandNum(int(b.Config.Timer.FHSpam))
rd, err := crypto.RandDuration(b.Config.Timer.FHSpam, "m")
if err != nil {
ll.Warn().Msgf("failed to generate random number for FH timer: %s", err)
rn = int(b.Config.Timer.FHSpam)
rd = time.Minute * time.Duration(b.Config.Timer.FHSpam)
}
fht.Reset(time.Duration(int64(rn)+b.Config.Timer.FHSpam) * time.Minute)
fht.Reset(rd)
case <-trt.C:
if err := b.ScheduledEventUpdateTradeRoutes(); err != nil {
ll.Error().Msgf("failed to process scheuled traderoute update event: %s", err)
}
go func() {
if err := b.ScheduledEventUpdateTradeRoutes(); err != nil {
ll.Error().Msgf("failed to process scheuled traderoute update event: %s", err)
}
}()
case <-ust.C:
if err := b.ScheduledEventUpdateUserStats(); err != nil {
ll.Error().Msgf("failed to process scheuled traderoute update event: %s", err)
}
go func() {
if err := b.ScheduledEventUpdateUserStats(); err != nil {
ll.Error().Msgf("failed to process scheuled traderoute update event: %s", err)
}
}()
case <-rct.C:
if err := b.ScheduledEventCheckRATCookies(); err != nil {
ll.Error().Msgf("failed to process scheuled RAT cookie check event: %s", err)
}
go func() {
if err := b.ScheduledEventCheckRATCookies(); err != nil {
ll.Error().Msgf("failed to process scheuled RAT cookie check event: %s", err)
}
}()
case <-ddt.C:
if err := b.ScheduledEventUpdateDailyDeeds(); err != nil {
ll.Error().Msgf("failed to process scheuled daily deeds update event: %s", err)
}
go func() {
if err := b.ScheduledEventUpdateDailyDeeds(); err != nil {
ll.Error().Msgf("failed to process scheuled daily deeds update event: %s", err)
}
}()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions bot/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
IconShip = "⛵"
IconVomit = "🤮"
IconDistance = "📐"
IconGauge = "🌡️"
)

// changeIcon returns either an increase or decrease icon based on the provided value
Expand Down
2 changes: 1 addition & 1 deletion bot/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewHTTPClient() (*HTTPClient, error) {
}
hc := &http.Client{
Transport: t,
Timeout: 10 * time.Second,
Timeout: 20 * time.Second,
Jar: cj,
}

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
Loading

0 comments on commit 9734dc5

Please sign in to comment.