2020-06-27 16:48:33 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-05-06 12:42:37 +00:00
|
|
|
"github.com/tribalwarshelp/shared/tw/twmodel"
|
|
|
|
"github.com/tribalwarshelp/shared/tw/twurlbuilder"
|
2020-06-27 16:48:33 +00:00
|
|
|
"math"
|
|
|
|
"strconv"
|
2021-01-08 19:15:11 +00:00
|
|
|
"strings"
|
2020-06-27 16:48:33 +00:00
|
|
|
|
2020-07-19 10:16:02 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/message"
|
|
|
|
|
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
2020-06-27 16:48:33 +00:00
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2021-02-06 09:36:13 +00:00
|
|
|
"github.com/dustin/go-humanize"
|
2020-06-27 16:48:33 +00:00
|
|
|
"github.com/tribalwarshelp/golang-sdk/sdk"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-07-18 10:21:02 +00:00
|
|
|
cmdHelp command = "help"
|
|
|
|
cmdTribe command = "tribe"
|
|
|
|
cmdTopODA command = "topoda"
|
|
|
|
cmdTopODD command = "topodd"
|
|
|
|
cmdTopODS command = "topods"
|
|
|
|
cmdTopOD command = "topod"
|
|
|
|
cmdTopPoints command = "toppoints"
|
|
|
|
cmdAuthor command = "author"
|
2020-06-27 16:48:33 +00:00
|
|
|
)
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrHelp struct {
|
2021-07-18 06:53:12 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrHelp{}
|
2021-07-18 06:53:12 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrHelp) cmd() command {
|
|
|
|
return cmdHelp
|
2021-07-18 06:53:12 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrHelp) requireAdmPermissions() bool {
|
2021-07-18 06:53:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrHelp) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:53:12 +00:00
|
|
|
commandsForAll := fmt.Sprintf(`
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
`,
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpTribeTopODA,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdTribe.WithPrefix(hndlr.cfg.CommandPrefix) + " " + cmdTopODA.String(),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpTribeTopODD,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdTribe.WithPrefix(hndlr.cfg.CommandPrefix) + " " + cmdTopODD.String(),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpTribeTopODS,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdTribe.WithPrefix(hndlr.cfg.CommandPrefix) + " " + cmdTopODS.String(),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpTribeTopOD,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdTribe.WithPrefix(hndlr.cfg.CommandPrefix) + " " + cmdTopOD.String(),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpTribeTopPoints,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdTribe.WithPrefix(hndlr.cfg.CommandPrefix) + " " + cmdTopPoints.String(),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpAuthor,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdAuthor.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
|
|
|
commandsForGuildAdmins := fmt.Sprintf(`
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
`,
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpAddGroup,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdAddGroup.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpGroups,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDeleteGroup,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdDeleteGroup.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpShowEnnobledBarbs,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdShowEnnobledBarbarians.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpObserve,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdObserve.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpGroups,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdObservations.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDeleteObservation,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdDeleteObservation.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"ObservationsCommand": cmdObservations.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpConqueredVillages,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdConqueredVillages.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDisableConqueredVillages,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdDisableConqueredVillages.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
|
|
|
commandsForGuildAdmins2 := fmt.Sprintf(`
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
- %s
|
|
|
|
`,
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpLostVillages,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdLostVillages.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDisableLostVillages,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdDisableLostVillages.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpShowInternals,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdShowInternals.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpChangageLanguage,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdChangeLanguage.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
"Languages": getAvailableLanguages(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpCoordsTranslation,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdCoordsTranslation.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDisableCoordsTranslation,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdDisableCoordsTranslation.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:53:12 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
|
|
|
forAdmins := ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpForAdmins,
|
|
|
|
})
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendEmbed(m.ChannelID, NewEmbed().
|
2021-07-18 06:53:12 +00:00
|
|
|
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpTitle,
|
|
|
|
})).
|
|
|
|
SetURL("https://dcbot.tribalwarshelp.com/").
|
|
|
|
SetDescription(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDescription,
|
|
|
|
})).
|
|
|
|
AddField(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpForAllUsers,
|
|
|
|
}), commandsForAll).
|
|
|
|
AddField(forAdmins, commandsForGuildAdmins).
|
|
|
|
AddField(forAdmins+" 2", commandsForGuildAdmins2))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrAuthor struct {
|
2021-07-18 06:53:12 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrAuthor{}
|
2021-07-18 06:53:12 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrAuthor) cmd() command {
|
|
|
|
return cmdAuthor
|
2021-07-18 06:53:12 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrAuthor) requireAdmPermissions() bool {
|
2021-07-18 06:53:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrAuthor) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:53:12 +00:00
|
|
|
fmt.Sprintf("%s Discord: Kichiyaki#2064 | https://dwysokinski.me/#contact.",
|
|
|
|
m.Author.Mention()))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrTribe struct {
|
2021-07-18 06:53:12 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrTribe{}
|
2021-07-18 06:53:12 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrTribe) cmd() command {
|
|
|
|
return cmdTribe
|
2021-07-18 06:53:12 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrTribe) requireAdmPermissions() bool {
|
2021-07-18 06:53:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrTribe) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:53:12 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength < 3 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
command := command(args[0])
|
2021-07-18 06:53:12 +00:00
|
|
|
server := args[1]
|
|
|
|
page, err := strconv.Atoi(args[2])
|
|
|
|
if err != nil || page <= 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:53:12 +00:00
|
|
|
MessageID: message.TribeInvalidPage,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var ids []int
|
|
|
|
var tags []string
|
|
|
|
for _, arg := range args[3:argsLength] {
|
|
|
|
trimmed := strings.TrimSpace(arg)
|
|
|
|
if trimmed == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
id, err := strconv.Atoi(trimmed)
|
|
|
|
if err != nil || id <= 0 {
|
|
|
|
tags = append(tags, trimmed)
|
|
|
|
} else {
|
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(ids) == 0 && len(tags) == 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:53:12 +00:00
|
|
|
MessageID: message.TribeNoTribeID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
exists := true
|
|
|
|
limit := 10
|
|
|
|
offset := (page - 1) * limit
|
|
|
|
filter := &twmodel.PlayerFilter{
|
|
|
|
Exists: &exists,
|
|
|
|
TribeFilter: &twmodel.TribeFilter{
|
|
|
|
Or: &twmodel.TribeFilterOr{
|
|
|
|
ID: ids,
|
|
|
|
Tag: tags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
title := ""
|
|
|
|
sort := ""
|
|
|
|
switch command {
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopODA:
|
2021-07-18 06:53:12 +00:00
|
|
|
filter.RankAttGTE = 1
|
|
|
|
sort = "rankAtt ASC"
|
|
|
|
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.TribeTitleOrderedByODA,
|
|
|
|
})
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopODD:
|
2021-07-18 06:53:12 +00:00
|
|
|
filter.RankDefGTE = 1
|
|
|
|
sort = "rankDef ASC"
|
|
|
|
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.TribeTitleOrderedByODD,
|
|
|
|
})
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopODS:
|
2021-07-18 06:53:12 +00:00
|
|
|
filter.RankSupGTE = 1
|
|
|
|
sort = "rankSup ASC"
|
|
|
|
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.TribeTitleOrderedByODS,
|
|
|
|
})
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopOD:
|
2021-07-18 06:53:12 +00:00
|
|
|
filter.RankTotalGTE = 1
|
|
|
|
sort = "rankTotal ASC"
|
|
|
|
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.TribeTitleOrderedByOD,
|
|
|
|
})
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopPoints:
|
2021-07-18 06:53:12 +00:00
|
|
|
sort = "rank ASC"
|
|
|
|
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.TribeTitleOrderedByPoints,
|
|
|
|
})
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
playerList, err := hndlr.cfg.API.Player.Browse(server,
|
2021-07-18 06:53:12 +00:00
|
|
|
limit,
|
|
|
|
offset,
|
|
|
|
[]string{sort},
|
|
|
|
filter,
|
|
|
|
&sdk.PlayerInclude{
|
|
|
|
Tribe: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:53:12 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ApiDefaultError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if playerList == nil || playerList.Total == 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:53:12 +00:00
|
|
|
MessageID: message.TribeTribesNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
totalPages := int(math.Ceil(float64(playerList.Total) / float64(limit)))
|
|
|
|
if page > totalPages {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:53:12 +00:00
|
|
|
MessageID: message.TribeExceededMaximumNumberOfPages,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
"Page": page,
|
|
|
|
"MaxPage": totalPages,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
code := twmodel.VersionCodeFromServerKey(server)
|
2021-07-18 07:52:13 +00:00
|
|
|
version, err := hndlr.cfg.API.Version.Read(code)
|
2021-07-18 06:53:12 +00:00
|
|
|
if err != nil || version == nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:53:12 +00:00
|
|
|
MessageID: message.InternalServerError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
bldr := &MessageEmbedFieldBuilder{}
|
2021-07-18 08:07:49 +00:00
|
|
|
bldr.SetName(title)
|
2021-07-18 06:53:12 +00:00
|
|
|
for i, player := range playerList.Items {
|
|
|
|
if player == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
rank := 0
|
|
|
|
score := 0
|
|
|
|
switch command {
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopODA:
|
2021-07-18 06:53:12 +00:00
|
|
|
rank = player.RankAtt
|
|
|
|
score = player.ScoreAtt
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopODD:
|
2021-07-18 06:53:12 +00:00
|
|
|
rank = player.RankDef
|
|
|
|
score = player.ScoreDef
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopODS:
|
2021-07-18 06:53:12 +00:00
|
|
|
rank = player.RankSup
|
|
|
|
score = player.ScoreSup
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopOD:
|
2021-07-18 06:53:12 +00:00
|
|
|
rank = player.RankTotal
|
|
|
|
score = player.ScoreTotal
|
2021-07-18 10:21:02 +00:00
|
|
|
case cmdTopPoints:
|
2021-07-18 06:53:12 +00:00
|
|
|
rank = player.Rank
|
|
|
|
score = player.Points
|
|
|
|
}
|
|
|
|
|
|
|
|
tribeTag := "-"
|
|
|
|
tribeURL := "-"
|
|
|
|
if player.Tribe != nil {
|
|
|
|
tribeTag = player.Tribe.Tag
|
|
|
|
tribeURL = twurlbuilder.BuildTribeURL(server, version.Host, player.Tribe.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
bldr.Append(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.TribeMessageLine,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Index": offset + i + 1,
|
|
|
|
"PlayerName": player.Name,
|
|
|
|
"PlayerURL": twurlbuilder.BuildPlayerURL(server, version.Host, player.ID),
|
|
|
|
"TribeTag": tribeTag,
|
|
|
|
"TribeURL": tribeURL,
|
|
|
|
"Rank": rank,
|
|
|
|
"Score": humanize.Comma(int64(score)),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendEmbed(m.ChannelID, NewEmbed().
|
2021-07-18 06:53:12 +00:00
|
|
|
SetTitle(title).
|
|
|
|
SetFields(bldr.ToMessageEmbedFields()).
|
|
|
|
SetFooter(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.PaginationLabelDisplayedPage,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Page": page,
|
|
|
|
"MaxPage": totalPages,
|
|
|
|
},
|
|
|
|
})))
|
|
|
|
}
|