Groups command should show which options are enabled | update translations

This commit is contained in:
Dawid Wysokiński 2020-08-08 14:02:32 +02:00 committed by Kichiyaki
parent f1d3274e10
commit 82600da64b
7 changed files with 82 additions and 60 deletions

View File

@ -4,6 +4,7 @@ import (
"time"
"github.com/tribalwarshelp/golang-sdk/sdk"
"github.com/tribalwarshelp/shared/mode"
"github.com/tribalwarshelp/dcbot/discord"
"github.com/tribalwarshelp/dcbot/group"
@ -40,6 +41,8 @@ func Attach(c *cron.Cron, cfg Config) {
h.checkBotServers()
h.deleteClosedTribalWarsServers()
h.updateBotStatus()
h.checkEnnoblements()
if mode.Get() == mode.DevelopmentMode {
h.checkEnnoblements()
}
}()
}

View File

@ -192,7 +192,7 @@ func (h *handler) checkEnnoblements() {
discord.
NewEmbed().
SetTitle(title).
SetColor(colorConqueredVillage).
SetColor(colorConqueredVillages).
SetFields(conqueredVillagesMsg.ToMessageEmbedFields()).
SetTimestamp(formatDateOfConquest(time.Now())).
MessageEmbed)
@ -208,7 +208,7 @@ func (h *handler) checkEnnoblements() {
discord.
NewEmbed().
SetTitle(title).
SetColor(colorLostVillage).
SetColor(colorLostVillages).
SetFields(lostVillagesMsg.ToMessageEmbedFields()).
SetTimestamp(formatDateOfConquest(time.Now())).
MessageEmbed)

View File

@ -12,10 +12,10 @@ import (
type messageType string
const (
messageTypeConquer messageType = "conquer"
messageTypeLost messageType = "lost"
colorLostVillage = 0xff0000
colorConqueredVillage = 0x00ff00
messageTypeConquer messageType = "conquer"
messageTypeLost messageType = "lost"
colorLostVillages = 0xff0000
colorConqueredVillages = 0x00ff00
)
type checkEnnoblementsMsg struct {

View File

@ -138,6 +138,13 @@ func (s *Session) handleDeleteGroupCommand(ctx commandCtx, m *discordgo.MessageC
}))
}
func getEmojiForGroupsCommand(val bool) string {
if val {
return ":white_check_mark:"
}
return ":x:"
}
func (s *Session) handleGroupsCommand(ctx commandCtx, m *discordgo.MessageCreate) {
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return
@ -153,7 +160,14 @@ func (s *Session) handleGroupsCommand(ctx commandCtx, m *discordgo.MessageCreate
msg := ""
for i, groups := range groups {
msg += fmt.Sprintf("**%d** | %d\n", i+1, groups.ID)
msg += fmt.Sprintf("**%d** | %d | %s | %s | %s | %s\n", i+1,
groups.ID,
getEmojiForGroupsCommand(groups.ConqueredVillagesChannelID != ""),
getEmojiForGroupsCommand(groups.LostVillagesChannelID != ""),
getEmojiForGroupsCommand(groups.ShowEnnobledBarbarians),
getEmojiForGroupsCommand(groups.ShowInternals),
)
}
if msg == "" {
@ -168,7 +182,10 @@ func (s *Session) handleGroupsCommand(ctx commandCtx, m *discordgo.MessageCreate
MessageID: "groups.title",
DefaultMessage: message.FallbackMsg("groups.title", "Group list"),
})).
AddField("Index | ID", msg).
AddField(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "groups.fieldTitle",
DefaultMessage: message.FallbackMsg("groups.fieldTitle", "Index | ID | Conquer | Loss | Barbarian | Internal"),
}), msg).
MessageEmbed)
}
@ -978,7 +995,7 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.showinternals",
DefaultMessage: message.FallbackMsg("help.showinternals",
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about self-conquers between tribes in one group."),
"**{{.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),
@ -991,8 +1008,8 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
if err != nil || groupID <= 0 {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showSelfConquers.invalidGroupID",
DefaultMessage: message.FallbackMsg("showSelfConquers.invalidGroupID",
MessageID: "showInternals.invalidGroupID",
DefaultMessage: message.FallbackMsg("showInternals.invalidGroupID",
"{{.Mention}} The group ID must be a number greater than 0."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -1004,8 +1021,8 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
if err != nil || group.ServerID != m.GuildID {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showSelfConquers.groupNotFound",
DefaultMessage: message.FallbackMsg("showSelfConquers.groupNotFound", "{{.Mention}} Group not found."),
MessageID: "showInternals.groupNotFound",
DefaultMessage: message.FallbackMsg("showInternals.groupNotFound", "{{.Mention}} Group not found."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
},
@ -1031,9 +1048,9 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
if oldValue {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showSelfConquers.success_1",
DefaultMessage: message.FallbackMsg("showSelfConquers.success_1",
"{{.Mention}} Notifications about self-conquers will no longer show up."),
MessageID: "showInternals.success_1",
DefaultMessage: message.FallbackMsg("showInternals.success_1",
"{{.Mention}} Notifications about internals will no longer show up."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
},
@ -1041,9 +1058,9 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
} else {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showSelfConquers.success_2",
DefaultMessage: message.FallbackMsg("showSelfConquers.success_2",
"{{.Mention}} Enabled notifications about self-conquers."),
MessageID: "showInternals.success_2",
DefaultMessage: message.FallbackMsg("showInternals.success_2",
"{{.Mention}} Enabled notifications about internals."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
},

View File

@ -18,10 +18,10 @@ import (
const (
HelpCommand Command = "help"
TribeCommand Command = "tribe"
TopAttCommand Command = "topatt"
TopDefCommand Command = "topdef"
TopSuppCommand Command = "topsupp"
TopTotalCommand Command = "toptotal"
TopODACommand Command = "topoda"
TopODDCommand Command = "topodd"
TopODSCommand Command = "topods"
TopODCommand Command = "topod"
TopPointsCommand Command = "toppoints"
AuthorCommand Command = "author"
)
@ -37,35 +37,35 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
- %s
`,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topatt",
DefaultMessage: message.FallbackMsg("help.tribe.topatt",
MessageID: "help.tribe.topoda",
DefaultMessage: message.FallbackMsg("help.tribe.topoda",
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODA."),
TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopAttCommand.String(),
"Command": tribeCMDWithPrefix + " " + TopODACommand.String(),
},
}),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topdef",
DefaultMessage: message.FallbackMsg("help.tribe.topdef",
MessageID: "help.tribe.topodd",
DefaultMessage: message.FallbackMsg("help.tribe.topodd",
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODD."),
TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopDefCommand.String(),
"Command": tribeCMDWithPrefix + " " + TopODDCommand.String(),
},
}),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topsupp",
DefaultMessage: message.FallbackMsg("help.tribe.topsupp",
MessageID: "help.tribe.topods",
DefaultMessage: message.FallbackMsg("help.tribe.topods",
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODS."),
TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopSuppCommand.String(),
"Command": tribeCMDWithPrefix + " " + TopODSCommand.String(),
},
}),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.toptotal",
DefaultMessage: message.FallbackMsg("help.tribe.toptotal",
MessageID: "help.tribe.topod",
DefaultMessage: message.FallbackMsg("help.tribe.topod",
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by OD."),
TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopTotalCommand.String(),
"Command": tribeCMDWithPrefix + " " + TopODCommand.String(),
},
}),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
@ -79,7 +79,7 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.author",
DefaultMessage: message.FallbackMsg("help.author",
"**{{.Command}}** - shows how to contact the author."),
"**{{.Command}}** - shows how to get in touch with the author."),
TemplateData: map[string]interface{}{
"Command": AuthorCommand.WithPrefix(s.cfg.CommandPrefix),
},
@ -108,7 +108,7 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.groups",
DefaultMessage: message.FallbackMsg("help.groups",
"**{{.Command}}** - shows you a list of groups created by this guild."),
"**{{.Command}}** - shows you a list of groups created by this server."),
TemplateData: map[string]interface{}{
"Command": GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
},
@ -215,7 +215,7 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.showinternals",
DefaultMessage: message.FallbackMsg("help.showinternals",
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about self-conquers between tribes in one group."),
"**{{.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),
@ -302,28 +302,28 @@ func (s *Session) handleTribeCommand(ctx commandCtx, m *discordgo.MessageCreate,
}
title := ""
switch command {
case TopAttCommand:
case TopODACommand:
filter.RankAttGTE = 1
filter.Sort = "rankAtt ASC"
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "tribe.title.orderedByODA",
DefaultMessage: message.FallbackMsg("tribe.title.orderedByODA", "Ordered by ODA"),
})
case TopDefCommand:
case TopODDCommand:
filter.RankDefGTE = 1
filter.Sort = "rankDef ASC"
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "tribe.title.orderedByODD",
DefaultMessage: message.FallbackMsg("tribe.title.orderedByODD", "Ordered by ODD"),
})
case TopSuppCommand:
case TopODSCommand:
filter.RankSupGTE = 1
filter.Sort = "rankSup ASC"
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "tribe.title.orderedByODS",
DefaultMessage: message.FallbackMsg("tribe.title.orderedByODS", "Ordered by ODS"),
})
case TopTotalCommand:
case TopODCommand:
filter.RankTotalGTE = 1
filter.Sort = "rankTotal ASC"
title = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
@ -404,16 +404,16 @@ func (s *Session) handleTribeCommand(ctx commandCtx, m *discordgo.MessageCreate,
rank := 0
score := 0
switch command {
case TopAttCommand:
case TopODACommand:
rank = player.RankAtt
score = player.ScoreAtt
case TopDefCommand:
case TopODDCommand:
rank = player.RankDef
score = player.ScoreDef
case TopSuppCommand:
case TopODSCommand:
rank = player.RankSup
score = player.ScoreSup
case TopTotalCommand:
case TopODCommand:
rank = player.RankTotal
score = player.ScoreTotal
case TopPointsCommand:

View File

@ -4,14 +4,14 @@
"help.footer": "",
"help.forAllUsers": "For all users",
"help.forAdmins": "For admins",
"help.tribe.topatt": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODA.",
"help.tribe.topdef": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODD.",
"help.tribe.topsupp": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODS.",
"help.tribe.toptotal": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by OD.",
"help.tribe.topoda": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODA.",
"help.tribe.topodd": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODD.",
"help.tribe.topods": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODS.",
"help.tribe.topod": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by OD.",
"help.tribe.toppoints": "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by points.",
"help.author": "**{{.Command}}** - shows how to contact the author.",
"help.author": "**{{.Command}}** - shows how to get in touch with the author.",
"help.addgroup": "**{{.Command}}** - adds a new observation group.",
"help.groups": "**{{.Command}}** - shows you a list of groups created by this guild.",
"help.groups": "**{{.Command}}** - shows you a list of groups created by this server.",
"help.deletegroup": "**{{.Command}}** [group id from {{.GroupsCommand}}] - deletes an observation group.",
"help.showennobledbarbs": "**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about ennobling barbarian villages.",
"help.observe": "**{{.Command}}** [group id from {{.GroupsCommand}}] [server] [tribe id] - command adds a tribe to the observation group.",
@ -22,7 +22,7 @@
"help.lostvillages": "**{{.Command}}** [group id from {{.GroupsCommand}}] - changes the channel on which notifications about lost village will show. **IMPORTANT!** Run this command on the channel you want to display these notifications.",
"help.disablelostvillages": "**{{.Command}}** [group id from {{.GroupsCommand}}] - disable notifications about lost villages.",
"help.changelanguage": "**{{.Command}}** [{{.Languages}}] - change language.",
"help.showinternals": "**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about self-conquers between tribes in one group.",
"help.showinternals": "**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about in-group/in-tribe conquering.",
"tribe.invalidPage": "{{.Mention}} The page must be a number greater than 0.",
"tribe.noTribeID": "{{.Mention}} You haven't entered the tribe ID.",
@ -43,6 +43,7 @@
"groups.noGroupsAdded": "No groups added.",
"groups.title": "Group list",
"groups.fieldTitle": "Index | ID | Conquer | Loss | Barbarian | Internal",
"conqueredVillages.invalidID": "{{.Mention}} The group ID must be a number greater than 0.",
"conqueredVillages.groupNotFound": "{{.Mention}} Group not found.",
@ -88,8 +89,8 @@
"showInternals.invalidGroupID": "{{.Mention}} The group ID must be a number greater than 0.",
"showInternals.groupNotFound": "{{.Mention}} Group not found.",
"showInternals.success_1": "{{.Mention}} Notifications about self-conquers will no longer show up.",
"showInternals.success_2": "{{.Mention}} Enabled notifications about self-conquers.",
"showInternals.success_1": "{{.Mention}} Notifications about internals will no longer show up.",
"showInternals.success_2": "{{.Mention}} Enabled notifications about internals.",
"cron.lostVillages.title": "Lost villages",
"cron.conqueredVillages.title": "Conquered villages",

View File

@ -4,10 +4,10 @@
"help.footer": "",
"help.forAllUsers": "Dla wszystkich",
"help.forAdmins": "Dla adminów",
"help.tribe.topatt": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych w ataku.",
"help.tribe.topdef": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych w obronie.",
"help.tribe.topsupp": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych jako wspierający.",
"help.tribe.toptotal": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych ogólnie.",
"help.tribe.topoda": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych w ataku.",
"help.tribe.topodd": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych w obronie.",
"help.tribe.topods": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych jako wspierający.",
"help.tribe.topod": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - generuje listę graczy z wybranych plemion i sortuje po pokonanych ogólnie.",
"help.tribe.toppoints": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - Generuje listę graczy z wybranych plemion i sortuje po punktach.",
"help.author": "**{{.Command}}** - pokazuje możliwe formy kontaktu z autorem.",
"help.addgroup": "**{{.Command}}** - dodaje nową grupę obserwacyjną.",
@ -43,6 +43,7 @@
"groups.noGroupsAdded": "Brak dodanych grup.",
"groups.title": "Lista grup",
"groups.fieldTitle": "Index | ID | Podbite | Stracone | Barbarki | Wewnętrzne podboje",
"conqueredVillages.invalidID": "{{.Mention}} ID grupy musi być liczbą większą od 0.",
"conqueredVillages.groupNotFound": "{{.Mention}} Grupa nie została znaleziona.",