add list command functionality

This commit is contained in:
Dawid Wysokiński 2020-05-30 11:07:02 +02:00
parent fa7dda85e4
commit 6865a2d113
1 changed files with 16 additions and 0 deletions

View File

@ -76,6 +76,7 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
case DeleteCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleDeleteCommand(m, args...)
case ListCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleListCommand(m)
case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
}
@ -85,6 +86,21 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
s.sendHelpMessage(m.Author.Mention(), m.ChannelID)
}
func (s *Session) handleListCommand(m *discordgo.MessageCreate) {
tribes, _, err := s.cfg.TribeRepository.Fetch(context.Background(), &models.TribeFilter{
ServerID: []string{m.GuildID},
})
if err != nil {
return
}
msg := m.Author.Mention() + " ```ID w bazie - Świat - ID plemienia \n\n"
for _, tribe := range tribes {
msg += fmt.Sprintf(">>> %d - %s - %d\n", tribe.ID, tribe.World, tribe.TribeID)
}
msg += "```"
s.sendMessage(m.ChannelID, msg)
}
func (s *Session) handleAddCommand(m *discordgo.MessageCreate, args ...string) {
argsLength := len(args)
if argsLength > 2 {