2020-05-30 08:35:45 +00:00
|
|
|
package discord
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
shared_models "github.com/tribalwarshelp/shared/models"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"github.com/tribalwarshelp/dcbot/models"
|
|
|
|
"github.com/tribalwarshelp/dcbot/utils"
|
|
|
|
"github.com/tribalwarshelp/golang-sdk/sdk"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-06-18 12:51:31 +00:00
|
|
|
ObservationsPerServer = 10
|
2020-06-06 12:28:45 +00:00
|
|
|
)
|
|
|
|
|
2020-05-30 08:35:45 +00:00
|
|
|
type Command string
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
const (
|
2020-06-26 07:47:33 +00:00
|
|
|
HelpCommand Command = "help"
|
|
|
|
ObserveCommand Command = "observe"
|
|
|
|
ObservationsCommand Command = "observations"
|
|
|
|
UnObserveCommand Command = "unobserve"
|
|
|
|
LostVillagesCommand Command = "lostvillages"
|
|
|
|
UnObserveLostVillagesCommand Command = "unobservelostvillages"
|
|
|
|
ConqueredVillagesCommand Command = "conqueredvillages"
|
|
|
|
UnObserveConqueredVillagesCommand Command = "unobserveconqueredvillages"
|
|
|
|
TribeCommand Command = "tribe"
|
|
|
|
TopAttCommand Command = "topatt"
|
|
|
|
TopDefCommand Command = "topdef"
|
|
|
|
TopSuppCommand Command = "topsupp"
|
|
|
|
TopTotalCommand Command = "toptotal"
|
|
|
|
TopPointsCommand Command = "toppoints"
|
|
|
|
AuthorCommand Command = "author"
|
2020-05-30 08:35:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (cmd Command) String() string {
|
|
|
|
return string(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd Command) WithPrefix(prefix string) string {
|
|
|
|
return prefix + cmd.String()
|
|
|
|
}
|
2020-06-06 12:28:45 +00:00
|
|
|
|
|
|
|
func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
|
|
|
|
tribeCMDWithPrefix := TribeCommand.WithPrefix(s.cfg.CommandPrefix)
|
|
|
|
commandsForAll := fmt.Sprintf(`
|
2020-06-26 07:47:33 +00:00
|
|
|
- **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RA z plemion o podanych id
|
|
|
|
- **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RO z plemion o podanych id
|
|
|
|
- **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RW z plemion o podanych id
|
|
|
|
- **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największej liczbie pokonanych z plemion o podanych id
|
|
|
|
- **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największej liczbie punktów z plemion o podanych id
|
|
|
|
- **%s** - kontakt z autorem bota
|
2020-06-06 12:28:45 +00:00
|
|
|
`,
|
|
|
|
tribeCMDWithPrefix,
|
|
|
|
TopAttCommand.String(),
|
|
|
|
tribeCMDWithPrefix,
|
|
|
|
TopDefCommand.String(),
|
|
|
|
tribeCMDWithPrefix,
|
|
|
|
TopSuppCommand.String(),
|
|
|
|
tribeCMDWithPrefix,
|
|
|
|
TopTotalCommand.String(),
|
|
|
|
tribeCMDWithPrefix,
|
2020-06-26 07:47:33 +00:00
|
|
|
TopPointsCommand.String(),
|
|
|
|
AuthorCommand.WithPrefix(s.cfg.CommandPrefix),
|
|
|
|
)
|
2020-06-06 12:28:45 +00:00
|
|
|
|
|
|
|
commandsForGuildAdmins := fmt.Sprintf(`
|
2020-06-26 07:47:33 +00:00
|
|
|
- **%s** [świat] [id] - dodaje plemię z danego świata do obserwowanych
|
|
|
|
- **%s** - wyświetla wszystkie obserwowane plemiona
|
|
|
|
- **%s** [id z %s] - usuwa plemię z obserwowanych
|
|
|
|
- **%s** - ustawia kanał na którym będą wyświetlać się informacje o podbitych wioskach
|
|
|
|
- **%s** - informacje o podbitych wioskach na wybranym kanale nie będą się już pojawiały
|
|
|
|
- **%s** - ustawia kanał na którym będą wyświetlać się informacje o straconych wioskach
|
|
|
|
- **%s** - informacje o podbitych wioskach na wybranym kanale nie będą się już pojawiały
|
2020-06-06 12:28:45 +00:00
|
|
|
`,
|
2020-06-18 12:51:31 +00:00
|
|
|
ObserveCommand.WithPrefix(s.cfg.CommandPrefix),
|
2020-06-18 13:54:31 +00:00
|
|
|
ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
|
|
|
|
UnObserveCommand.WithPrefix(s.cfg.CommandPrefix),
|
|
|
|
ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
|
2020-06-26 07:47:33 +00:00
|
|
|
ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
|
|
|
|
UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
|
2020-06-06 12:28:45 +00:00
|
|
|
LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
|
2020-06-26 07:47:33 +00:00
|
|
|
UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
|
|
|
|
)
|
2020-06-06 12:28:45 +00:00
|
|
|
|
|
|
|
s.SendEmbed(m.ChannelID, NewEmbed().
|
|
|
|
SetTitle("Pomoc").
|
|
|
|
SetDescription("Komendy oferowane przez bota").
|
|
|
|
AddField("Dla wszystkich", commandsForAll).
|
|
|
|
AddField("Dla adminów", commandsForGuildAdmins).
|
|
|
|
MessageEmbed)
|
|
|
|
}
|
|
|
|
|
2020-06-26 07:47:33 +00:00
|
|
|
func (s *Session) handleAuthorCommand(m *discordgo.MessageCreate) {
|
|
|
|
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Discord: Kichiyaki#2064.", m.Author.Mention()))
|
|
|
|
}
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
func (s *Session) handleTribeCommand(m *discordgo.MessageCreate, args ...string) {
|
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength < 4 {
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s Niepoprawna komenda (sprawdź %s)",
|
|
|
|
m.Author.Mention(),
|
|
|
|
HelpCommand.WithPrefix(s.cfg.CommandPrefix)))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
command := Command(args[0])
|
|
|
|
world := args[1]
|
|
|
|
page, err := strconv.Atoi(args[2])
|
|
|
|
if err != nil || page <= 0 {
|
|
|
|
s.SendMessage(m.ChannelID, fmt.Sprintf("%s 3 argument musi być liczbą większą od 0.", m.Author.Mention()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ids := []int{}
|
|
|
|
for _, arg := range args[3:argsLength] {
|
|
|
|
id, err := strconv.Atoi(arg)
|
2020-06-18 20:46:57 +00:00
|
|
|
if err != nil || id <= 0 {
|
2020-06-06 12:28:45 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
if len(ids) == 0 {
|
|
|
|
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Nie wprowadziłeś ID plemion.", m.Author.Mention()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:01:18 +00:00
|
|
|
exists := true
|
2020-06-06 12:28:45 +00:00
|
|
|
limit := 10
|
|
|
|
offset := (page - 1) * limit
|
|
|
|
filter := &shared_models.PlayerFilter{
|
2020-06-25 14:01:18 +00:00
|
|
|
Exists: &exists,
|
2020-06-06 12:28:45 +00:00
|
|
|
TribeID: ids,
|
|
|
|
Limit: limit,
|
|
|
|
Offset: offset,
|
|
|
|
}
|
|
|
|
title := ""
|
|
|
|
switch command {
|
|
|
|
case TopAttCommand:
|
|
|
|
filter.RankAttGTE = 1
|
|
|
|
filter.Sort = "rankAtt ASC"
|
|
|
|
title = "Top pokonani w ataku"
|
|
|
|
case TopDefCommand:
|
|
|
|
filter.RankDefGTE = 1
|
|
|
|
filter.Sort = "rankDef ASC"
|
|
|
|
title = "Top pokonani w obronie"
|
|
|
|
case TopSuppCommand:
|
|
|
|
filter.RankSupGTE = 1
|
|
|
|
filter.Sort = "rankSup ASC"
|
|
|
|
title = "Top pokonani jako wspierający"
|
|
|
|
case TopTotalCommand:
|
|
|
|
filter.RankTotalGTE = 1
|
|
|
|
filter.Sort = "rankTotal ASC"
|
|
|
|
title = "Top pokonani ogólnie"
|
|
|
|
case TopPointsCommand:
|
|
|
|
filter.Sort = "rank ASC"
|
|
|
|
title = "Najwięcej punktów"
|
|
|
|
default:
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s Nieznana komenda %s (sprawdź %s)",
|
|
|
|
m.Author.Mention(),
|
|
|
|
command.String(),
|
|
|
|
HelpCommand.WithPrefix(s.cfg.CommandPrefix)))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
playersList, err := s.cfg.API.Players.Browse(world, filter, &sdk.PlayerInclude{
|
|
|
|
Tribe: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2020-06-18 20:46:57 +00:00
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s Wystąpił błąd podczas pobierania danych z API, prosimy spróbować później.", m.Author.Mention()))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
2020-06-18 20:46:57 +00:00
|
|
|
if playersList == nil || playersList.Total == 0 {
|
|
|
|
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Nie znaleziono graczy należących do plemion o podanych ID.", m.Author.Mention()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
totalPages := int(math.Ceil(float64(playersList.Total) / float64(limit)))
|
|
|
|
if page > totalPages {
|
|
|
|
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Przekroczyłeś limit stron (%d/%d).", m.Author.Mention(), page, totalPages))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-19 17:45:44 +00:00
|
|
|
langTag := utils.LanguageTagFromWorldName(world)
|
2020-06-18 20:46:57 +00:00
|
|
|
langVersion, err := s.cfg.API.LangVersions.Read(langTag)
|
|
|
|
if err != nil || langVersion == nil {
|
|
|
|
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Nie znaleziono wersji językowej: %s.", m.Author.Mention(), langTag))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := &EmbedMessage{}
|
|
|
|
for i, player := range playersList.Items {
|
2020-06-18 20:46:57 +00:00
|
|
|
if player == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
rank := 0
|
|
|
|
score := 0
|
|
|
|
switch command {
|
|
|
|
case TopAttCommand:
|
|
|
|
rank = player.RankAtt
|
|
|
|
score = player.ScoreAtt
|
|
|
|
case TopDefCommand:
|
|
|
|
rank = player.RankDef
|
|
|
|
score = player.ScoreDef
|
|
|
|
case TopSuppCommand:
|
|
|
|
rank = player.RankSup
|
|
|
|
score = player.ScoreSup
|
|
|
|
case TopTotalCommand:
|
|
|
|
rank = player.RankTotal
|
|
|
|
score = player.ScoreTotal
|
|
|
|
case TopPointsCommand:
|
|
|
|
rank = player.Rank
|
|
|
|
score = player.Points
|
|
|
|
}
|
|
|
|
|
2020-06-18 20:46:57 +00:00
|
|
|
tribeTag := "-"
|
|
|
|
tribeURL := "-"
|
|
|
|
if player.Tribe != nil {
|
|
|
|
tribeTag = player.Tribe.Tag
|
|
|
|
tribeURL = utils.FormatTribeURL(world, langVersion.Host, player.Tribe.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.Append(fmt.Sprintf("**%d**. [``%s``](%s) (Plemię: [``%s``](%s) | Ranking ogólny: **%d** | Wynik: **%d**)\n",
|
2020-06-06 12:28:45 +00:00
|
|
|
offset+i+1,
|
|
|
|
player.Name,
|
|
|
|
utils.FormatPlayerURL(world, langVersion.Host, player.ID),
|
2020-06-18 20:46:57 +00:00
|
|
|
tribeTag,
|
|
|
|
tribeURL,
|
2020-06-06 12:28:45 +00:00
|
|
|
rank,
|
|
|
|
score))
|
|
|
|
}
|
|
|
|
|
|
|
|
s.SendEmbed(m.ChannelID, NewEmbed().
|
|
|
|
SetTitle(title).
|
|
|
|
SetDescription("A oto lista!").
|
|
|
|
SetFields(msg.ToMessageEmbedFields()).
|
|
|
|
SetFooter(fmt.Sprintf("Strona %d z %d", page, totalPages)).
|
|
|
|
MessageEmbed)
|
|
|
|
}
|
|
|
|
|
2020-06-26 07:47:33 +00:00
|
|
|
func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate) {
|
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
server := &models.Server{
|
|
|
|
ID: m.GuildID,
|
|
|
|
}
|
|
|
|
err := s.cfg.ServerRepository.Store(context.Background(), server)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
server.ConqueredVillagesChannelID = m.ChannelID
|
|
|
|
go s.cfg.ServerRepository.Update(context.Background(), server)
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o podbitych wioskach.", m.Author.Mention()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCreate) {
|
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
server := &models.Server{
|
|
|
|
ID: m.GuildID,
|
|
|
|
}
|
|
|
|
err := s.cfg.ServerRepository.Store(context.Background(), server)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if server.ConqueredVillagesChannelID != "" {
|
|
|
|
server.ConqueredVillagesChannelID = ""
|
|
|
|
go s.cfg.ServerRepository.Update(context.Background(), server)
|
|
|
|
}
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s Informacje o podbitych wioskach nie będą się już pojawiały.", m.Author.Mention()))
|
|
|
|
}
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate) {
|
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
server := &models.Server{
|
|
|
|
ID: m.GuildID,
|
|
|
|
}
|
|
|
|
err := s.cfg.ServerRepository.Store(context.Background(), server)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
server.LostVillagesChannelID = m.ChannelID
|
|
|
|
go s.cfg.ServerRepository.Update(context.Background(), server)
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o straconych wioskach.", m.Author.Mention()))
|
|
|
|
}
|
|
|
|
|
2020-06-26 07:47:33 +00:00
|
|
|
func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate) {
|
2020-06-06 12:28:45 +00:00
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
server := &models.Server{
|
|
|
|
ID: m.GuildID,
|
|
|
|
}
|
|
|
|
err := s.cfg.ServerRepository.Store(context.Background(), server)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2020-06-26 07:47:33 +00:00
|
|
|
if server.LostVillagesChannelID != "" {
|
|
|
|
server.LostVillagesChannelID = ""
|
|
|
|
go s.cfg.ServerRepository.Update(context.Background(), server)
|
|
|
|
}
|
2020-06-06 12:28:45 +00:00
|
|
|
s.SendMessage(m.ChannelID,
|
2020-06-26 07:47:33 +00:00
|
|
|
fmt.Sprintf("%s Informacje o straconych wioskach nie będą się już pojawiały.", m.Author.Mention()))
|
2020-06-06 12:28:45 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:51:31 +00:00
|
|
|
func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...string) {
|
2020-06-06 12:28:45 +00:00
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength > 2 {
|
|
|
|
s.sendUnknownCommandError(m.Author.Mention(), m.ChannelID, args[2:argsLength]...)
|
|
|
|
return
|
|
|
|
} else if argsLength < 2 {
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s %s [świat] [id plemienia]",
|
|
|
|
m.Author.Mention(),
|
2020-06-18 12:51:31 +00:00
|
|
|
ObserveCommand.WithPrefix(s.cfg.CommandPrefix)))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
world := args[0]
|
|
|
|
id, err := strconv.Atoi(args[1])
|
|
|
|
if err != nil {
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf("%s %s [świat] [id plemienia]",
|
|
|
|
m.Author.Mention(),
|
2020-06-18 12:51:31 +00:00
|
|
|
ObserveCommand.WithPrefix(s.cfg.CommandPrefix)))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-18 15:52:16 +00:00
|
|
|
server, err := s.cfg.API.Servers.Read(world, nil)
|
2020-06-07 15:49:33 +00:00
|
|
|
if err != nil || server == nil {
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+fmt.Sprintf(` świat %s jest nieobsługiwany.`, world))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if server.Status == shared_models.ServerStatusClosed {
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+fmt.Sprintf(` świat %s jest zamknięty.`, world))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
tribe, err := s.cfg.API.Tribes.Read(world, id)
|
|
|
|
if err != nil || tribe == nil {
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+fmt.Sprintf(` Plemię o ID: %d nie istnieje na świecie %s.`, id, world))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-07 15:49:33 +00:00
|
|
|
dcServer := &models.Server{
|
2020-06-06 12:28:45 +00:00
|
|
|
ID: m.GuildID,
|
|
|
|
}
|
2020-06-07 15:49:33 +00:00
|
|
|
err = s.cfg.ServerRepository.Store(context.Background(), dcServer)
|
2020-06-06 12:28:45 +00:00
|
|
|
if err != nil {
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:51:31 +00:00
|
|
|
if len(dcServer.Observations) >= ObservationsPerServer {
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+fmt.Sprintf(` Osiągnięto limit plemion (%d/%d).`, ObservationsPerServer, ObservationsPerServer))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:51:31 +00:00
|
|
|
err = s.cfg.ObservationRepository.Store(context.Background(), &models.Observation{
|
2020-06-06 12:28:45 +00:00
|
|
|
World: world,
|
|
|
|
TribeID: id,
|
2020-06-07 15:49:33 +00:00
|
|
|
ServerID: dcServer.ID,
|
2020-06-06 12:28:45 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+` Dodano.`)
|
|
|
|
}
|
|
|
|
|
2020-06-18 13:54:31 +00:00
|
|
|
func (s *Session) handleUnObserveCommand(m *discordgo.MessageCreate, args ...string) {
|
2020-06-06 12:28:45 +00:00
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength > 1 {
|
|
|
|
s.sendUnknownCommandError(m.Author.Mention(), m.ChannelID, args[1:argsLength]...)
|
|
|
|
return
|
|
|
|
} else if argsLength < 1 {
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf(`%s %s [id z tw!list]`,
|
|
|
|
m.Author.Mention(),
|
2020-06-18 13:54:31 +00:00
|
|
|
UnObserveCommand.WithPrefix(s.cfg.CommandPrefix)))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
|
|
|
s.SendMessage(m.ChannelID,
|
|
|
|
fmt.Sprintf(`%s %s [id z tw!list]`,
|
|
|
|
m.Author.Mention(),
|
2020-06-18 13:54:31 +00:00
|
|
|
UnObserveCommand.WithPrefix(s.cfg.CommandPrefix)))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:51:31 +00:00
|
|
|
go s.cfg.ObservationRepository.Delete(context.Background(), &models.ObservationFilter{
|
2020-06-06 12:28:45 +00:00
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
ID: []int{id},
|
|
|
|
})
|
|
|
|
|
|
|
|
s.SendMessage(m.ChannelID, m.Author.Mention()+` Usunięto.`)
|
|
|
|
}
|
|
|
|
|
2020-06-18 13:54:31 +00:00
|
|
|
func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate) {
|
2020-06-06 12:28:45 +00:00
|
|
|
if m.GuildID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:51:31 +00:00
|
|
|
observations, _, err := s.cfg.ObservationRepository.Fetch(context.Background(), &models.ObservationFilter{
|
2020-06-06 12:28:45 +00:00
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := ""
|
2020-06-18 12:51:31 +00:00
|
|
|
for i, observation := range observations {
|
|
|
|
msg += fmt.Sprintf("**%d**. %d - %s - %d\n", i+1, observation.ID, observation.World, observation.TribeID)
|
2020-06-06 12:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s.SendEmbed(m.ChannelID, NewEmbed().
|
|
|
|
SetTitle("Lista obserwowanych plemion").
|
|
|
|
AddField("Indeks. ID - świat - ID plemienia", msg).
|
|
|
|
SetFooter("Strona 1 z 1").
|
|
|
|
MessageEmbed)
|
|
|
|
}
|