refactor(commands): move registered commands map to dedicated function
This commit is contained in:
@@ -43,14 +43,10 @@ func (h *CommandsHandler) UpdateCommands(
|
||||
return errors.New("User ID is not set in session state")
|
||||
}
|
||||
|
||||
REGISTERED_COMMANDS := map[CommandName]*discordgo.ApplicationCommand{}
|
||||
registeredCommands, err := h.session.ApplicationCommands(APP_ID, GUILD_ID)
|
||||
registeredCommands, err := h.mapRegisteredCommmands(GUILD_ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, rc := range registeredCommands {
|
||||
REGISTERED_COMMANDS[rc.Name] = rc
|
||||
}
|
||||
|
||||
for _, cmd := range REGISTERED_COMMANDS {
|
||||
if _, isHandled := commands[cmd.Name]; !isHandled {
|
||||
@@ -140,3 +136,19 @@ func (h *CommandsHandler) UpdateCommands(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *CommandsHandler) mapRegisteredCommmands(
|
||||
guildID string,
|
||||
) (map[CommandName]*discordgo.ApplicationCommand, error) {
|
||||
cmdMap := map[CommandName]*discordgo.ApplicationCommand{}
|
||||
|
||||
registeredCommands, err := h.session.ApplicationCommands(h.session.State.User.ID, guildID)
|
||||
if err != nil {
|
||||
return cmdMap, err
|
||||
}
|
||||
for _, rc := range registeredCommands {
|
||||
cmdMap[rc.Name] = rc
|
||||
}
|
||||
|
||||
return cmdMap, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user