refactor main, and fix bugs from initial manual run
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
55f9725af1
commit
fed49ba3cb
6 changed files with 66 additions and 35 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
|
@ -42,11 +43,18 @@ var (
|
|||
i *discordgo.InteractionCreate,
|
||||
) {
|
||||
"confessional": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
state.PublishEvent(state.ConfessionsChannelLinkEvent{
|
||||
if err := state.PublishEvent(state.ConfessionsChannelLinkEvent{
|
||||
GuildID: i.GuildID,
|
||||
ChannelID: i.ChannelID,
|
||||
Created: time.Now(),
|
||||
})
|
||||
}); err != nil {
|
||||
logging.Error(fmt.Sprintf(
|
||||
"failed to publish confession channel link: %s",
|
||||
err.Error(),
|
||||
))
|
||||
} else {
|
||||
logging.Info("published confession channel link")
|
||||
}
|
||||
},
|
||||
|
||||
// handle a confession
|
||||
|
|
@ -68,6 +76,10 @@ func handleCommand(s *discordgo.Session, e *discordgo.InteractionCreate) {
|
|||
} else {
|
||||
logging.Debug("no handler for command: %s", name)
|
||||
}
|
||||
|
||||
s.InteractionRespond(e.Interaction, &discordgo.InteractionResponse{
|
||||
// TODO: Some silent ACK
|
||||
})
|
||||
}
|
||||
|
||||
func registerCommands(s *discordgo.Session) {
|
||||
|
|
@ -79,12 +91,12 @@ func registerCommands(s *discordgo.Session) {
|
|||
)
|
||||
|
||||
if err != nil {
|
||||
logging.Error(
|
||||
"Failed to register commands for guild",
|
||||
guild.ID, ": ", err.Error(),
|
||||
)
|
||||
logging.Error(fmt.Sprintf(
|
||||
"Failed to register commands for guild %s: %s",
|
||||
guild.ID, err.Error(),
|
||||
))
|
||||
} else {
|
||||
logging.Info("Registered commands for guild ", guild.ID)
|
||||
logging.Info(fmt.Sprintf("Registered commands for guild %s", guild.ID))
|
||||
registeredCommands[guild.ID] = cmds
|
||||
}
|
||||
}
|
||||
|
|
@ -98,15 +110,15 @@ func deregisterCommands(s *discordgo.Session) {
|
|||
guild,
|
||||
cmd.ID,
|
||||
); err != nil {
|
||||
logging.Error(
|
||||
"Failed to delete", cmd.Name, "command (id:", cmd.ID,
|
||||
") from guild ", guild,
|
||||
)
|
||||
logging.Error(fmt.Sprintf(
|
||||
"Failed to delete %s command (id: %s) from guild %s",
|
||||
cmd.Name, cmd.ID, guild,
|
||||
))
|
||||
} else {
|
||||
logging.Info(
|
||||
"Deregistered command ", cmd.Name,"(id:", cmd.ID,
|
||||
") from guild ", guild,
|
||||
)
|
||||
logging.Info(fmt.Sprintf(
|
||||
"Deregistered command %s (id: %s) from guild %s",
|
||||
cmd.Name, cmd.ID, guild,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue