Skip to content

Commit

Permalink
chore: updated dependencies and updated code to reflect updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed Mar 31, 2024
1 parent d7fa053 commit a15a10b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 34 deletions.
5 changes: 3 additions & 2 deletions bot/commands/cmd_debugreload.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func (cm *CommandManager) commandDebugReload(

cm.Discord.S.ApplicationCommandBulkOverwrite(cm.Discord.S.State.User.ID, "", discordCommands)

cm.Discord.S.InteractionResponseEdit(cm.Discord.S.State.User.ID, interaction.Interaction, &discordgo.WebhookEdit{
Content: "Reload commands succeeded. This can take an hour to take effect.",
content := "Reload commands succeeded. This can take an hour to take effect."
cm.Discord.S.InteractionResponseEdit(interaction.Interaction, &discordgo.WebhookEdit{
Content: &content,
})

return
Expand Down
10 changes: 5 additions & 5 deletions bot/commands/cmd_konesyntees.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ func (cm *CommandManager) commandKonesyntees(

cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: "Processing your konesyntees",
},
})

response, err := gonesyntees.Request(text, gonesyntees.Voice(voice), speed)

if err != nil {
cm.Discord.S.FollowupMessageCreate(cm.Discord.S.State.User.ID, interaction.Interaction, false, &discordgo.WebhookParams{
cm.Discord.S.FollowupMessageCreate(interaction.Interaction, false, &discordgo.WebhookParams{
Content: fmt.Sprintf("Error in sending request: %s", err.Error()),
})
return
}

audio, err := http.Get(response.MP3Url)
if err != nil {
cm.Discord.S.FollowupMessageCreate(cm.Discord.S.State.User.ID, interaction.Interaction, false, &discordgo.WebhookParams{
cm.Discord.S.FollowupMessageCreate(interaction.Interaction, false, &discordgo.WebhookParams{
Content: fmt.Sprintf("Error in getting response URL: %s", err.Error()),
})
return
}

cm.Discord.S.InteractionResponseDelete(cm.Discord.S.State.User.ID, interaction.Interaction)
cm.Discord.S.InteractionResponseDelete(interaction.Interaction)
cm.Discord.ChannelFileSend(interaction.ChannelID, "konesyntees.mp3", audio.Body)
return
}
Expand All @@ -72,7 +72,7 @@ func parseVoiceParams(text string) (string, int, int, error) {
voice := 0

for i := 0; i < len(params); i++ {
if strings.HasPrefix(params[i], "--") == false {
if !strings.HasPrefix(params[i], "--") {
break
}

Expand Down
28 changes: 15 additions & 13 deletions bot/commands/command_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ func (cm *CommandManager) OnMessage(message discordgo.Message) (err error) {
}

func (cm *CommandManager) TryFindAndFireCommand(interaction *discordgo.InteractionCreate) {
zap.L().Info("User attempting command", zap.Any("user", interaction.Member.User.ID), zap.Any("command", interaction.Data.Name))
zap.L().Info("User attempting command", zap.Any("user", interaction.Member.User.ID), zap.Any("command", interaction.ApplicationCommandData().Name))
for _, command := range cm.Commands {
if strings.TrimLeft(command.Name, "/") == interaction.Data.Name {
if strings.TrimLeft(command.Name, "/") == interaction.ApplicationCommandData().Name {
if hasPermissions(command.Settings.Roles, interaction.Member.Roles) {
args := make(map[string]*discordgo.ApplicationCommandInteractionDataOption)
for _, option := range interaction.Data.Options {
for _, option := range interaction.ApplicationCommandData().Options {
args[option.Name] = option
}
command.Function(interaction, args, command.Settings)
} else {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: "You're not authorized for this!",
},
})
time.Sleep(time.Second * 5)
cm.Discord.S.InteractionResponseDelete(cm.Discord.S.State.User.ID, interaction.Interaction)
cm.Discord.S.InteractionResponseDelete(interaction.Interaction)
}
break
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func pcd(since time.Duration, cooldown time.Duration) (result string) {
func (cm *CommandManager) replyDirectly(interaction *discordgo.InteractionCreate, response string) {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: response,
},
})
Expand All @@ -146,7 +146,7 @@ func (cm *CommandManager) replyDirectly(interaction *discordgo.InteractionCreate
func (cm *CommandManager) replyDirectlyEmbed(interaction *discordgo.InteractionCreate, response string, embed *discordgo.MessageEmbed) {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: response,
Embeds: []*discordgo.MessageEmbed{embed},
},
Expand All @@ -157,21 +157,23 @@ func (cm *CommandManager) replyDirectlyEmbed(interaction *discordgo.InteractionC
func (cm *CommandManager) sendThinkingResponse(interaction *discordgo.InteractionCreate) {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: "",
},
})
}

func (cm *CommandManager) editOriginalResponse(interaction *discordgo.InteractionCreate, response string) {
cm.Discord.S.InteractionResponseEdit(cm.Discord.S.State.User.ID, interaction.Interaction, &discordgo.WebhookEdit{
Content: response,
cm.Discord.S.InteractionResponseEdit(interaction.Interaction, &discordgo.WebhookEdit{
Content: &response,
})
}

func (cm *CommandManager) editOriginalResponseWithEmbed(interaction *discordgo.InteractionCreate, embed *discordgo.MessageEmbed) {
cm.Discord.S.InteractionResponseEdit(cm.Discord.S.State.User.ID, interaction.Interaction, &discordgo.WebhookEdit{
Content: "",
Embeds: []*discordgo.MessageEmbed{embed},
content := ""
embeds := []*discordgo.MessageEmbed{embed}
cm.Discord.S.InteractionResponseEdit(interaction.Interaction, &discordgo.WebhookEdit{
Content: &content,
Embeds: &embeds,
})
}
7 changes: 3 additions & 4 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discord

import (
"math/rand"
"time"

"github.com/bwmarrin/discordgo"
"github.com/robfig/cron"
Expand Down Expand Up @@ -59,11 +60,11 @@ func (s *Session) GetCurrentChannelMessageFrequency(channelID string) (freq floa
return 0.0, nil
}

start, err := messages[0].Timestamp.Parse()
start, err := time.Parse(time.RFC3339, messages[0].Timestamp.Format(time.RFC3339))
if err != nil {
return
}
end, err := messages[len(messages)-1].Timestamp.Parse()
end, err := time.Parse(time.RFC3339, messages[len(messages)-1].Timestamp.Format(time.RFC3339))
if err != nil {
return
}
Expand Down Expand Up @@ -96,8 +97,6 @@ func (s *Session) cacheUsernames() {
}
s.UserIndex[name] = *u
}

return
}

func must(err error) {
Expand Down
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ replace gopkg.in/russross/blackfriday.v2 => github.com/russross/blackfriday/v2 v

require (
github.com/Bios-Marcel/discordemojimap v1.0.1
github.com/bwmarrin/discordgo v0.23.3-0.20210515023446-8dc42757bea5
github.com/bwmarrin/discordgo v0.27.1
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/google/go-github/v28 v28.1.1
github.com/google/go-querystring v1.1.0 // indirect
github.com/joho/godotenv v1.4.0
github.com/joho/godotenv v1.5.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kristoisberg/gonesyntees v0.0.0-20190527174556-0595a02f9399
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/robfig/cron v1.2.0
github.com/stretchr/testify v1.7.1
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/stretchr/testify v1.9.0
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/xmlpath.v2 v2.0.0-20150820204837-860cbeca3ebc
gopkg.in/yaml.v2 v2.2.8 // indirect
)

0 comments on commit a15a10b

Please sign in to comment.