2020-06-27 16:48:33 +00:00
package discord
import (
"fmt"
"math"
"strconv"
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
shared_models "github.com/tribalwarshelp/shared/models"
"github.com/bwmarrin/discordgo"
"github.com/tribalwarshelp/dcbot/utils"
"github.com/tribalwarshelp/golang-sdk/sdk"
)
const (
HelpCommand Command = "help"
TribeCommand Command = "tribe"
2020-08-08 12:02:32 +00:00
TopODACommand Command = "topoda"
TopODDCommand Command = "topodd"
TopODSCommand Command = "topods"
TopODCommand Command = "topod"
2020-06-27 16:48:33 +00:00
TopPointsCommand Command = "toppoints"
AuthorCommand Command = "author"
)
2020-07-19 10:16:02 +00:00
func ( s * Session ) handleHelpCommand ( ctx commandCtx , m * discordgo . MessageCreate ) {
2020-06-27 16:48:33 +00:00
tribeCMDWithPrefix := TribeCommand . WithPrefix ( s . cfg . CommandPrefix )
commandsForAll := fmt . Sprintf ( `
2020-07-19 10:42:22 +00:00
- % s
- % s
- % s
- % s
- % s
- % s
2020-06-27 16:48:33 +00:00
` ,
2020-07-19 10:42:22 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-08-08 12:02:32 +00:00
MessageID : "help.tribe.topoda" ,
DefaultMessage : message . FallbackMsg ( "help.tribe.topoda" ,
2020-07-19 13:03:53 +00:00
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODA." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-08-08 12:02:32 +00:00
"Command" : tribeCMDWithPrefix + " " + TopODACommand . String ( ) ,
2020-07-19 10:42:22 +00:00
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-08-08 12:02:32 +00:00
MessageID : "help.tribe.topodd" ,
DefaultMessage : message . FallbackMsg ( "help.tribe.topodd" ,
2020-07-19 13:03:53 +00:00
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODD." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-08-08 12:02:32 +00:00
"Command" : tribeCMDWithPrefix + " " + TopODDCommand . String ( ) ,
2020-07-19 10:42:22 +00:00
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-08-08 12:02:32 +00:00
MessageID : "help.tribe.topods" ,
DefaultMessage : message . FallbackMsg ( "help.tribe.topods" ,
2020-07-19 13:03:53 +00:00
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODS." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-08-08 12:02:32 +00:00
"Command" : tribeCMDWithPrefix + " " + TopODSCommand . String ( ) ,
2020-07-19 10:42:22 +00:00
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-08-08 12:02:32 +00:00
MessageID : "help.tribe.topod" ,
DefaultMessage : message . FallbackMsg ( "help.tribe.topod" ,
2020-07-19 13:03:53 +00:00
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by OD." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-08-08 12:02:32 +00:00
"Command" : tribeCMDWithPrefix + " " + TopODCommand . String ( ) ,
2020-07-19 10:42:22 +00:00
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.tribe.toppoints" ,
DefaultMessage : message . FallbackMsg ( "help.tribe.toppoints" ,
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by points." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : tribeCMDWithPrefix + " " + TopPointsCommand . String ( ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.author" ,
DefaultMessage : message . FallbackMsg ( "help.author" ,
2020-08-08 12:02:32 +00:00
"**{{.Command}}** - shows how to get in touch with the author." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : AuthorCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
2020-06-27 16:48:33 +00:00
)
commandsForGuildAdmins := fmt . Sprintf ( `
2020-07-19 10:42:22 +00:00
- % s
- % s
- % s
- % s
- % s
- % s
- % s
- % s
- % s
2020-06-27 16:48:33 +00:00
` ,
2020-07-19 10:42:22 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.addgroup" ,
DefaultMessage : message . FallbackMsg ( "help.addgroup" ,
"**{{.Command}}** - adds a new observation group." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : AddGroupCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.groups" ,
DefaultMessage : message . FallbackMsg ( "help.groups" ,
2020-08-08 12:02:32 +00:00
"**{{.Command}}** - shows you a list of groups created by this server." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.deletegroup" ,
DefaultMessage : message . FallbackMsg ( "help.deletegroup" ,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - deletes an observation group." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : DeleteGroupCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.showennobledbarbs" ,
DefaultMessage : message . FallbackMsg ( "help.showennobledbarbs" ,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about ennobling barbarian villages." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : ShowEnnobledBarbariansCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.observe" ,
DefaultMessage : message . FallbackMsg ( "help.observe" ,
2020-09-03 13:13:49 +00:00
"**{{.Command}}** [group id from {{.GroupsCommand}}] [server] [tribe id] - adds a tribe to the observation group." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : ObserveCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.observations" ,
DefaultMessage : message . FallbackMsg ( "help.observations" ,
2020-09-03 13:13:49 +00:00
"**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of observed tribes by this group." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : ObservationsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 14:56:05 +00:00
MessageID : "help.deleteobservation" ,
DefaultMessage : message . FallbackMsg ( "help.deleteobservation" ,
2020-07-19 13:03:53 +00:00
"**{{.Command}}** [group id from {{.GroupsCommand}}] [id from {{.ObservationsCommand}}] - removes a tribe from the observation group." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-07-19 14:56:05 +00:00
"Command" : DeleteObservationCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
2020-07-19 10:42:22 +00:00
"ObservationsCommand" : ObservationsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.conqueredvillages" ,
DefaultMessage : message . FallbackMsg ( "help.conqueredvillages" ,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - changes the channel on which notifications about conquered village will show. IMPORTANT! Call this command on the channel you want to display these notifications." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : ConqueredVillagesCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 14:56:05 +00:00
MessageID : "help.disableconqueredvillages" ,
DefaultMessage : message . FallbackMsg ( "help.disableconqueredvillages" ,
2020-09-03 13:13:49 +00:00
"**{{.Command}}** [group id from {{.GroupsCommand}}] - disables notifications about conquered villages." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-07-19 14:56:05 +00:00
"Command" : DisableConqueredVillagesCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
2020-07-19 10:42:22 +00:00
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
2020-07-15 10:17:33 +00:00
)
commandsForGuildAdmins2 := fmt . Sprintf ( `
2020-07-19 10:42:22 +00:00
- % s
2020-07-19 15:21:44 +00:00
- % s
2020-07-21 12:01:08 +00:00
- % s
2020-08-09 15:20:23 +00:00
- % s
- % s
2020-07-19 10:42:22 +00:00
- % s
2020-07-15 10:17:33 +00:00
` ,
2020-07-19 10:42:22 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "help.lostvillages" ,
DefaultMessage : message . FallbackMsg ( "help.lostvillages" ,
2020-07-19 15:21:44 +00:00
"**{{.Command}}** [group id from {{.GroupsCommand}}] - changes the channel on which notifications about lost village will show. IMPORTANT! Call this command on the channel you want to display these notifications." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
"Command" : LostVillagesCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 14:56:05 +00:00
MessageID : "help.disablelostvillages" ,
DefaultMessage : message . FallbackMsg ( "help.disablelostvillages" ,
2020-07-19 15:21:44 +00:00
"**{{.Command}}** [group id from {{.GroupsCommand}}] - changes the channel on which notifications about lost village will show. IMPORTANT! Call this command on the channel you want to display these notifications." ) ,
2020-07-19 10:42:22 +00:00
TemplateData : map [ string ] interface { } {
2020-07-19 14:56:05 +00:00
"Command" : DisableLostVillagesCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
2020-07-19 10:42:22 +00:00
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
2020-08-09 15:20:23 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.showinternals" ,
DefaultMessage : message . FallbackMsg ( "help.showinternals" ,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about in-group/in-tribe conquering." ) ,
TemplateData : map [ string ] interface { } {
"Command" : ShowInternalsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"GroupsCommand" : GroupsCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
2020-07-19 15:21:44 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.changelanguage" ,
DefaultMessage : message . FallbackMsg ( "help.changelanguage" ,
2020-09-03 13:13:49 +00:00
"**{{.Command}}** [{{.Languages}}] - changes language." ) ,
2020-07-19 15:21:44 +00:00
TemplateData : map [ string ] interface { } {
"Command" : ChangeLanguageCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
"Languages" : getAvailableLanguages ( ) ,
} ,
} ) ,
2020-07-21 12:01:08 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-08-09 15:20:23 +00:00
MessageID : "help.coordstranslation" ,
DefaultMessage : message . FallbackMsg ( "help.coordstranslation" ,
2020-09-03 13:13:49 +00:00
"**{{.Command}}** [server] - enables coords translation feature." ) ,
2020-07-21 12:01:08 +00:00
TemplateData : map [ string ] interface { } {
2020-08-09 15:20:23 +00:00
"Command" : CoordsTranslationCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
} ,
} ) ,
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.disablecoordstranslation" ,
DefaultMessage : message . FallbackMsg ( "help.disablecoordstranslation" ,
2020-09-03 13:13:49 +00:00
"**{{.Command}}** - disables coords translation feature." ) ,
2020-08-09 15:20:23 +00:00
TemplateData : map [ string ] interface { } {
"Command" : DisableCoordsTranslationCommand . WithPrefix ( s . cfg . CommandPrefix ) ,
2020-07-21 12:01:08 +00:00
} ,
} ) ,
2020-06-27 16:48:33 +00:00
)
2020-07-19 10:16:02 +00:00
forAdmins := ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.forAdmins" ,
DefaultMessage : message . FallbackMsg ( "help.forAdmins" , "For admins" ) ,
} )
2020-06-27 16:48:33 +00:00
s . SendEmbed ( m . ChannelID , NewEmbed ( ) .
2020-07-19 10:16:02 +00:00
SetTitle ( ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.title" ,
DefaultMessage : message . FallbackMsg ( "help.title" , "Help" ) ,
} ) ) .
2020-07-19 14:56:05 +00:00
SetURL ( "https://dcbot.tribalwarshelp.com/" ) .
2020-07-19 10:16:02 +00:00
SetDescription ( ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.description" ,
DefaultMessage : message . FallbackMsg ( "help.description" , "Commands offered by bot" ) ,
} ) ) .
AddField ( ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "help.forAllUsers" ,
2020-09-03 13:13:49 +00:00
DefaultMessage : message . FallbackMsg ( "help.forAllUsers" , "For all server members." ) ,
2020-07-19 10:16:02 +00:00
} ) , commandsForAll ) .
AddField ( forAdmins , commandsForGuildAdmins ) .
AddField ( forAdmins + " 2" , commandsForGuildAdmins2 ) .
2020-06-27 16:48:33 +00:00
MessageEmbed )
}
func ( s * Session ) handleAuthorCommand ( m * discordgo . MessageCreate ) {
2020-07-19 13:03:53 +00:00
s . SendMessage ( m . ChannelID ,
fmt . Sprintf ( "%s Discord: Kichiyaki#2064 | https://dawid-wysokinski.pl/#contact." ,
m . Author . Mention ( ) ) )
2020-06-27 16:48:33 +00:00
}
2020-07-19 11:22:59 +00:00
func ( s * Session ) handleTribeCommand ( ctx commandCtx , m * discordgo . MessageCreate , args ... string ) {
2020-06-27 16:48:33 +00:00
argsLength := len ( args )
2020-07-19 11:22:59 +00:00
if argsLength < 3 {
2020-06-27 16:48:33 +00:00
return
}
command := Command ( args [ 0 ] )
world := args [ 1 ]
page , err := strconv . Atoi ( args [ 2 ] )
if err != nil || page <= 0 {
2020-07-19 11:22:59 +00:00
s . SendMessage ( m . ChannelID , ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "tribe.invalidPage" ,
DefaultMessage : message . FallbackMsg ( "tribe.invalidPage" , "{{.Mention}} The page must be a number greater than 0." ) ,
TemplateData : map [ string ] interface { } {
"Mention" : m . Author . Mention ( ) ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
return
}
ids := [ ] int { }
for _ , arg := range args [ 3 : argsLength ] {
id , err := strconv . Atoi ( arg )
if err != nil || id <= 0 {
continue
}
ids = append ( ids , id )
}
if len ( ids ) == 0 {
2020-07-19 11:22:59 +00:00
s . SendMessage ( m . ChannelID , ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "tribe.noTribeID" ,
DefaultMessage : message . FallbackMsg ( "tribe.noTribeID" , "{{.Mention}} You haven't entered the tribe ID." ) ,
TemplateData : map [ string ] interface { } {
"Mention" : m . Author . Mention ( ) ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
return
}
exists := true
limit := 10
offset := ( page - 1 ) * limit
filter := & shared_models . PlayerFilter {
Exists : & exists ,
TribeID : ids ,
Limit : limit ,
Offset : offset ,
}
title := ""
switch command {
2020-08-08 12:02:32 +00:00
case TopODACommand :
2020-06-27 16:48:33 +00:00
filter . RankAttGTE = 1
filter . Sort = "rankAtt ASC"
2020-07-19 11:22:59 +00:00
title = ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-22 13:46:10 +00:00
MessageID : "tribe.title.orderedByODA" ,
DefaultMessage : message . FallbackMsg ( "tribe.title.orderedByODA" , "Ordered by ODA" ) ,
2020-07-19 11:22:59 +00:00
} )
2020-08-08 12:02:32 +00:00
case TopODDCommand :
2020-06-27 16:48:33 +00:00
filter . RankDefGTE = 1
filter . Sort = "rankDef ASC"
2020-07-19 11:22:59 +00:00
title = ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-22 13:46:10 +00:00
MessageID : "tribe.title.orderedByODD" ,
DefaultMessage : message . FallbackMsg ( "tribe.title.orderedByODD" , "Ordered by ODD" ) ,
2020-07-19 11:22:59 +00:00
} )
2020-08-08 12:02:32 +00:00
case TopODSCommand :
2020-06-27 16:48:33 +00:00
filter . RankSupGTE = 1
filter . Sort = "rankSup ASC"
2020-07-19 11:22:59 +00:00
title = ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-22 13:46:10 +00:00
MessageID : "tribe.title.orderedByODS" ,
DefaultMessage : message . FallbackMsg ( "tribe.title.orderedByODS" , "Ordered by ODS" ) ,
2020-07-19 11:22:59 +00:00
} )
2020-08-08 12:02:32 +00:00
case TopODCommand :
2020-06-27 16:48:33 +00:00
filter . RankTotalGTE = 1
filter . Sort = "rankTotal ASC"
2020-07-19 11:22:59 +00:00
title = ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-22 13:46:10 +00:00
MessageID : "tribe.title.orderedByOD" ,
DefaultMessage : message . FallbackMsg ( "tribe.title.orderedByOD" , "Ordered by OD" ) ,
2020-07-19 11:22:59 +00:00
} )
2020-06-27 16:48:33 +00:00
case TopPointsCommand :
filter . Sort = "rank ASC"
2020-07-19 11:22:59 +00:00
title = ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-22 13:46:10 +00:00
MessageID : "tribe.title.orderedByPoints" ,
DefaultMessage : message . FallbackMsg ( "tribe.title.orderedByPoints" , "Ordered by points" ) ,
2020-07-19 11:22:59 +00:00
} )
2020-06-27 16:48:33 +00:00
default :
return
}
playersList , err := s . cfg . API . Players . Browse ( world , filter , & sdk . PlayerInclude {
Tribe : true ,
} )
if err != nil {
s . SendMessage ( m . ChannelID ,
2020-07-19 11:22:59 +00:00
ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "api.defaultError" ,
DefaultMessage : message . FallbackMsg ( "api.defaultError" ,
"{{.Mention}} There was an error fetching data from the API, please try again later." ) ,
2020-07-19 11:22:59 +00:00
TemplateData : map [ string ] interface { } {
"Mention" : m . Author . Mention ( ) ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
return
}
if playersList == nil || playersList . Total == 0 {
2020-07-19 11:22:59 +00:00
s . SendMessage ( m . ChannelID , ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "tribe.tribesNotFound" ,
DefaultMessage : message . FallbackMsg ( "tribe.tribesNotFound" ,
"{{.Mention}} There was an error fetching data from the API, please try again later." ) ,
2020-07-19 11:22:59 +00:00
TemplateData : map [ string ] interface { } {
"Mention" : m . Author . Mention ( ) ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
return
}
totalPages := int ( math . Ceil ( float64 ( playersList . Total ) / float64 ( limit ) ) )
if page > totalPages {
2020-07-19 11:22:59 +00:00
s . SendMessage ( m . ChannelID , ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "tribe.exceededMaximumNumberOfPages" ,
DefaultMessage : message . FallbackMsg ( "tribe.exceededMaximumNumberOfPages" ,
"{{.Mention}} You have exceeded the maximum number of pages ({{.Page}}/{{.MaxPage}})." ) ,
2020-07-19 11:22:59 +00:00
TemplateData : map [ string ] interface { } {
"Mention" : m . Author . Mention ( ) ,
"Page" : page ,
"MaxPage" : totalPages ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
return
}
langTag := utils . LanguageTagFromWorldName ( world )
langVersion , err := s . cfg . API . LangVersions . Read ( langTag )
if err != nil || langVersion == nil {
2020-07-19 11:22:59 +00:00
s . SendMessage ( m . ChannelID , ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "internalServerError" ,
DefaultMessage : message . FallbackMsg ( "internalServerError" ,
"{{.Mention}} Internal server error occurred, please try again later." ) ,
2020-07-19 11:22:59 +00:00
TemplateData : map [ string ] interface { } {
"Mention" : m . Author . Mention ( ) ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
return
}
msg := & EmbedMessage { }
for i , player := range playersList . Items {
if player == nil {
continue
}
rank := 0
score := 0
switch command {
2020-08-08 12:02:32 +00:00
case TopODACommand :
2020-06-27 16:48:33 +00:00
rank = player . RankAtt
score = player . ScoreAtt
2020-08-08 12:02:32 +00:00
case TopODDCommand :
2020-06-27 16:48:33 +00:00
rank = player . RankDef
score = player . ScoreDef
2020-08-08 12:02:32 +00:00
case TopODSCommand :
2020-06-27 16:48:33 +00:00
rank = player . RankSup
score = player . ScoreSup
2020-08-08 12:02:32 +00:00
case TopODCommand :
2020-06-27 16:48:33 +00:00
rank = player . RankTotal
score = player . ScoreTotal
case TopPointsCommand :
rank = player . Rank
score = player . Points
}
tribeTag := "-"
tribeURL := "-"
if player . Tribe != nil {
tribeTag = player . Tribe . Tag
tribeURL = utils . FormatTribeURL ( world , langVersion . Host , player . Tribe . ID )
}
2020-07-19 11:22:59 +00:00
msg . Append ( ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
2020-07-19 13:03:53 +00:00
MessageID : "tribe.messageLine" ,
DefaultMessage : message . FallbackMsg ( "tribe.messageLine" ,
"**{{.Index}}**. [``{{.PlayerName}}``]({{.PlayerURL}}) (Tribe: [``{{.TribeTag}}``]({{.TribeURL}}) | Rank: **{{.Rank}}** | Score: **{{.Score}}**)\n" ) ,
2020-07-19 11:22:59 +00:00
TemplateData : map [ string ] interface { } {
"Index" : offset + i + 1 ,
"PlayerName" : player . Name ,
"PlayerURL" : utils . FormatPlayerURL ( world , langVersion . Host , player . ID ) ,
"TribeTag" : tribeTag ,
"TribeURL" : tribeURL ,
"Rank" : rank ,
"Score" : score ,
} ,
} ) )
2020-06-27 16:48:33 +00:00
}
s . SendEmbed ( m . ChannelID , NewEmbed ( ) .
SetTitle ( title ) .
SetFields ( msg . ToMessageEmbedFields ( ) ) .
2020-07-19 11:22:59 +00:00
SetFooter ( ctx . localizer . MustLocalize ( & i18n . LocalizeConfig {
MessageID : "pagination.labelDisplayedPage" ,
2020-07-21 09:51:58 +00:00
DefaultMessage : message . FallbackMsg ( "pagination.labelDisplayedPage" , "{{.Page}} of {{.MaxPage}}" ) ,
2020-07-19 11:22:59 +00:00
TemplateData : map [ string ] interface { } {
"Page" : page ,
"MaxPage" : totalPages ,
} ,
} ) ) .
2020-06-27 16:48:33 +00:00
MessageEmbed )
}