Skip to content

Commit

Permalink
feat: add discord /missing proper command
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed May 4, 2024
1 parent 9c30c2d commit d9ce580
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
23 changes: 18 additions & 5 deletions pkg/reporters/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
statePkg "main/pkg/state"
templatesPkg "main/pkg/templates"
types "main/pkg/types"
"main/pkg/utils"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -199,16 +200,28 @@ func (reporter *Reporter) Send(report *types.Report) error {
}

func (reporter *Reporter) BotRespond(s *discordgo.Session, i *discordgo.InteractionCreate, text string) {
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
chunks := utils.SplitStringIntoChunks(text, 2000)

Check failure on line 203 in pkg/reporters/discord/discord.go

View workflow job for this annotation

GitHub Actions / lint

Magic number: 2000, in <argument> detected (mnd)
firstChunk, rest := chunks[0], chunks[1:]

if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: text,
Content: firstChunk,
},
})

if err != nil {
}); err != nil {
reporter.Logger.Error().Err(err).Msg("Error sending response")
}

for index, chunk := range rest {
if _, err := s.FollowupMessageCreate(i.Interaction, false, &discordgo.WebhookParams{
Content: chunk,
}); err != nil {
reporter.Logger.Error().
Int("chunk", index).
Err(err).
Msg("Error sending followup message")
}
}
}

func (reporter *Reporter) SerializeDate(date time.Time) string {
Expand Down
9 changes: 1 addition & 8 deletions pkg/reporters/discord/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ func (reporter *Reporter) GetHelpCommand() *Command {
return
}

if err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: template,
},
}); err != nil {
reporter.Logger.Error().Err(err).Msg("Error sending help")
}
reporter.BotRespond(s, i, template)
},
}
}
13 changes: 1 addition & 12 deletions pkg/reporters/discord/missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,7 @@ func (reporter *Reporter) GetMissingCommand() *Command {
return
}

chunks := utils.SplitStringIntoChunks(template, 2000)

for _, chunk := range chunks {
if err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: chunk,
},
}); err != nil {
reporter.Logger.Error().Err(err).Msg("Error sending missing")
}
}
reporter.BotRespond(s, i, template)
},
}
}
9 changes: 1 addition & 8 deletions pkg/reporters/discord/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ func (reporter *Reporter) GetParamsCommand() *Command {
return
}

if err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: template,
},
}); err != nil {
reporter.Logger.Error().Err(err).Msg("Error sending params")
}
reporter.BotRespond(s, i, template)
},
}
}

0 comments on commit d9ce580

Please sign in to comment.