move message ids to constants (help command), cron doesn't make an http request when the slice of servers is empty

This commit is contained in:
Dawid Wysokiński 2020-10-14 05:45:31 +02:00
parent f14f311daa
commit 5bd650a83f
7 changed files with 93 additions and 60 deletions

View File

@ -35,6 +35,10 @@ type handler struct {
func (h *handler) loadEnnoblements(servers []string) (map[string]ennoblements, error) { func (h *handler) loadEnnoblements(servers []string) (map[string]ennoblements, error) {
m := make(map[string]ennoblements) m := make(map[string]ennoblements)
if len(servers) == 0 {
return m, nil
}
query := "" query := ""
for _, w := range servers { for _, w := range servers {
@ -87,7 +91,7 @@ func (h *handler) loadLangVersions(servers []string) ([]*shared_models.LangVersi
languageTags := []shared_models.LanguageTag{} languageTags := []shared_models.LanguageTag{}
cache := make(map[shared_models.LanguageTag]bool) cache := make(map[shared_models.LanguageTag]bool)
for _, server := range servers { for _, server := range servers {
languageTag := utils.LanguageTagFromWorldName(server) languageTag := utils.LanguageTagFromServerKey(server)
if languageTag.IsValid() && !cache[languageTag] { if languageTag.IsValid() && !cache[languageTag] {
cache[languageTag] = true cache[languageTag] = true
languageTags = append(languageTags, languageTag) languageTags = append(languageTags, languageTag)
@ -140,7 +144,7 @@ func (h *handler) checkEnnoblements() {
conqueredVillagesMsg := &discord.EmbedMessage{} conqueredVillagesMsg := &discord.EmbedMessage{}
for _, observation := range group.Observations { for _, observation := range group.Observations {
ennoblements, ok := ennoblementsByServerKey[observation.Server] ennoblements, ok := ennoblementsByServerKey[observation.Server]
langVersion := utils.FindLangVersionByTag(langVersions, utils.LanguageTagFromWorldName(observation.Server)) langVersion := utils.FindLangVersionByTag(langVersions, utils.LanguageTagFromServerKey(observation.Server))
if ok && langVersion != nil && langVersion.Host != "" { if ok && langVersion != nil && langVersion.Host != "" {
if group.LostVillagesChannelID != "" { if group.LostVillagesChannelID != "" {
for _, ennoblement := range ennoblements.getLostVillagesByTribe(observation.TribeID) { for _, ennoblement := range ennoblements.getLostVillagesByTribe(observation.TribeID) {

View File

@ -96,7 +96,7 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) {
coords := extractAllCoordsFromMessage(m.Content) coords := extractAllCoordsFromMessage(m.Content)
coordsLen := len(coords) coordsLen := len(coords)
if coordsLen > 0 { if coordsLen > 0 {
langVersion, err := s.cfg.API.LangVersions.Read(utils.LanguageTagFromWorldName(ctx.server.CoordsTranslation)) langVersion, err := s.cfg.API.LangVersions.Read(utils.LanguageTagFromServerKey(ctx.server.CoordsTranslation))
if err != nil || langVersion == nil { if err != nil || langVersion == nil {
return return
} }

View File

@ -754,7 +754,7 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
langTags := []shared_models.LanguageTag{} langTags := []shared_models.LanguageTag{}
for _, observation := range observations { for _, observation := range observations {
tribeIDsByServer[observation.Server] = append(tribeIDsByServer[observation.Server], observation.TribeID) tribeIDsByServer[observation.Server] = append(tribeIDsByServer[observation.Server], observation.TribeID)
currentLangTag := utils.LanguageTagFromWorldName(observation.Server) currentLangTag := utils.LanguageTagFromServerKey(observation.Server)
unique := true unique := true
for _, langTag := range langTags { for _, langTag := range langTags {
if langTag == currentLangTag { if langTag == currentLangTag {
@ -804,7 +804,7 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
if observation.Tribe != nil { if observation.Tribe != nil {
tag = observation.Tribe.Tag tag = observation.Tribe.Tag
} }
lv := utils.FindLangVersionByTag(langVersionList.Items, utils.LanguageTagFromWorldName(observation.Server)) lv := utils.FindLangVersionByTag(langVersionList.Items, utils.LanguageTagFromServerKey(observation.Server))
tribeURL := "" tribeURL := ""
if lv != nil { if lv != nil {
tribeURL = utils.FormatTribeURL(observation.Server, lv.Host, observation.TribeID) tribeURL = utils.FormatTribeURL(observation.Server, lv.Host, observation.TribeID)

View File

@ -37,48 +37,48 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
- %s - %s
`, `,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topoda", MessageID: message.HelpTribeTopODA,
DefaultMessage: message.FallbackMsg("help.tribe.topoda", DefaultMessage: message.FallbackMsg(message.HelpTribeTopODA,
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODA."), "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODA."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopODACommand.String(), "Command": tribeCMDWithPrefix + " " + TopODACommand.String(),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topodd", MessageID: message.HelpTribeTopODD,
DefaultMessage: message.FallbackMsg("help.tribe.topodd", DefaultMessage: message.FallbackMsg(message.HelpTribeTopODD,
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODD."), "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODD."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopODDCommand.String(), "Command": tribeCMDWithPrefix + " " + TopODDCommand.String(),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topods", MessageID: message.HelpTribeTopODS,
DefaultMessage: message.FallbackMsg("help.tribe.topods", DefaultMessage: message.FallbackMsg(message.HelpTribeTopODS,
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODS."), "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by ODS."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopODSCommand.String(), "Command": tribeCMDWithPrefix + " " + TopODSCommand.String(),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.topod", MessageID: message.HelpTribeTopOD,
DefaultMessage: message.FallbackMsg("help.tribe.topod", DefaultMessage: message.FallbackMsg(message.HelpTribeTopOD,
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by OD."), "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by OD."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopODCommand.String(), "Command": tribeCMDWithPrefix + " " + TopODCommand.String(),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.tribe.toppoints", MessageID: message.HelpTribeTopPoints,
DefaultMessage: message.FallbackMsg("help.tribe.toppoints", DefaultMessage: message.FallbackMsg(message.HelpTribeTopPoints,
"**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by points."), "**{{.Command}}** [server] [page] [id1] [id2] [id3] [n id] - generates a player list from selected tribes ordered by points."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": tribeCMDWithPrefix + " " + TopPointsCommand.String(), "Command": tribeCMDWithPrefix + " " + TopPointsCommand.String(),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.author", MessageID: message.HelpAuthor,
DefaultMessage: message.FallbackMsg("help.author", DefaultMessage: message.FallbackMsg(message.HelpAuthor,
"**{{.Command}}** - shows how to get in touch with the author."), "**{{.Command}}** - shows how to get in touch with the author."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": AuthorCommand.WithPrefix(s.cfg.CommandPrefix), "Command": AuthorCommand.WithPrefix(s.cfg.CommandPrefix),
@ -98,24 +98,24 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
- %s - %s
`, `,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.addgroup", MessageID: message.HelpAddGroup,
DefaultMessage: message.FallbackMsg("help.addgroup", DefaultMessage: message.FallbackMsg(message.HelpAddGroup,
"**{{.Command}}** - adds a new observation group."), "**{{.Command}}** - adds a new observation group."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": AddGroupCommand.WithPrefix(s.cfg.CommandPrefix), "Command": AddGroupCommand.WithPrefix(s.cfg.CommandPrefix),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.groups", MessageID: message.HelpGroups,
DefaultMessage: message.FallbackMsg("help.groups", DefaultMessage: message.FallbackMsg(message.HelpGroups,
"**{{.Command}}** - shows you a list of groups created by this server."), "**{{.Command}}** - shows you a list of groups created by this server."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": GroupsCommand.WithPrefix(s.cfg.CommandPrefix), "Command": GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.deletegroup", MessageID: message.HelpDeleteGroup,
DefaultMessage: message.FallbackMsg("help.deletegroup", DefaultMessage: message.FallbackMsg(message.HelpDeleteGroup,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - deletes an observation group."), "**{{.Command}}** [group id from {{.GroupsCommand}}] - deletes an observation group."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": DeleteGroupCommand.WithPrefix(s.cfg.CommandPrefix), "Command": DeleteGroupCommand.WithPrefix(s.cfg.CommandPrefix),
@ -123,8 +123,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.showennobledbarbs", MessageID: message.HelpShowEnnobledBarbs,
DefaultMessage: message.FallbackMsg("help.showennobledbarbs", DefaultMessage: message.FallbackMsg(message.HelpShowEnnobledBarbs,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about ennobling barbarian villages."), "**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about ennobling barbarian villages."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix), "Command": ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix),
@ -132,8 +132,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.observe", MessageID: message.HelpObserve,
DefaultMessage: message.FallbackMsg("help.observe", DefaultMessage: message.FallbackMsg(message.HelpObserve,
"**{{.Command}}** [group id from {{.GroupsCommand}}] [server] [tribe id] - adds a tribe to the observation group."), "**{{.Command}}** [group id from {{.GroupsCommand}}] [server] [tribe id] - adds a tribe to the observation group."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": ObserveCommand.WithPrefix(s.cfg.CommandPrefix), "Command": ObserveCommand.WithPrefix(s.cfg.CommandPrefix),
@ -141,8 +141,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.observations", MessageID: message.HelpGroups,
DefaultMessage: message.FallbackMsg("help.observations", DefaultMessage: message.FallbackMsg(message.HelpGroups,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of observed tribes by this group."), "**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of observed tribes by this group."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": ObservationsCommand.WithPrefix(s.cfg.CommandPrefix), "Command": ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
@ -150,8 +150,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.deleteobservation", MessageID: message.HelpDeleteObservation,
DefaultMessage: message.FallbackMsg("help.deleteobservation", DefaultMessage: message.FallbackMsg(message.HelpDeleteObservation,
"**{{.Command}}** [group id from {{.GroupsCommand}}] [id from {{.ObservationsCommand}}] - removes a tribe from the observation group."), "**{{.Command}}** [group id from {{.GroupsCommand}}] [id from {{.ObservationsCommand}}] - removes a tribe from the observation group."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": DeleteObservationCommand.WithPrefix(s.cfg.CommandPrefix), "Command": DeleteObservationCommand.WithPrefix(s.cfg.CommandPrefix),
@ -160,8 +160,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.conqueredvillages", MessageID: message.HelpConqueredVillages,
DefaultMessage: message.FallbackMsg("help.conqueredvillages", DefaultMessage: message.FallbackMsg(message.HelpConqueredVillages,
"**{{.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."), "**{{.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."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix), "Command": ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
@ -169,8 +169,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.disableconqueredvillages", MessageID: message.HelpDisableConqueredVillages,
DefaultMessage: message.FallbackMsg("help.disableconqueredvillages", DefaultMessage: message.FallbackMsg(message.HelpDisableConqueredVillages,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - disables notifications about conquered villages."), "**{{.Command}}** [group id from {{.GroupsCommand}}] - disables notifications about conquered villages."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": DisableConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix), "Command": DisableConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
@ -188,8 +188,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
- %s - %s
`, `,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.lostvillages", MessageID: message.HelpLostVillages,
DefaultMessage: message.FallbackMsg("help.lostvillages", DefaultMessage: message.FallbackMsg(message.HelpLostVillages,
"**{{.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."), "**{{.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."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), "Command": LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
@ -197,8 +197,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.disablelostvillages", MessageID: message.HelpDisableLostVillages,
DefaultMessage: message.FallbackMsg("help.disablelostvillages", DefaultMessage: message.FallbackMsg(message.HelpDisableLostVillages,
"**{{.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."), "**{{.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."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": DisableLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), "Command": DisableLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
@ -206,8 +206,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.showinternals", MessageID: message.HelpShowInternals,
DefaultMessage: message.FallbackMsg("help.showinternals", DefaultMessage: message.FallbackMsg(message.HelpShowInternals,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about in-group/in-tribe conquering."), "**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about in-group/in-tribe conquering."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": ShowInternalsCommand.WithPrefix(s.cfg.CommandPrefix), "Command": ShowInternalsCommand.WithPrefix(s.cfg.CommandPrefix),
@ -215,8 +215,8 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.changelanguage", MessageID: message.HelpChangageLanguage,
DefaultMessage: message.FallbackMsg("help.changelanguage", DefaultMessage: message.FallbackMsg(message.HelpChangageLanguage,
"**{{.Command}}** [{{.Languages}}] - changes language."), "**{{.Command}}** [{{.Languages}}] - changes language."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": ChangeLanguageCommand.WithPrefix(s.cfg.CommandPrefix), "Command": ChangeLanguageCommand.WithPrefix(s.cfg.CommandPrefix),
@ -224,16 +224,16 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.coordstranslation", MessageID: message.HelpCoordsTranslation,
DefaultMessage: message.FallbackMsg("help.coordstranslation", DefaultMessage: message.FallbackMsg(message.HelpCoordsTranslation,
"**{{.Command}}** [server] - enables coords translation feature."), "**{{.Command}}** [server] - enables coords translation feature."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": CoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix), "Command": CoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix),
}, },
}), }),
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.disablecoordstranslation", MessageID: message.HelpDisableCoordsTranslation,
DefaultMessage: message.FallbackMsg("help.disablecoordstranslation", DefaultMessage: message.FallbackMsg(message.HelpDisableCoordsTranslation,
"**{{.Command}}** - disables coords translation feature."), "**{{.Command}}** - disables coords translation feature."),
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Command": DisableCoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix), "Command": DisableCoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix),
@ -242,23 +242,23 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
) )
forAdmins := ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ forAdmins := ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.forAdmins", MessageID: message.HelpForAdmins,
DefaultMessage: message.FallbackMsg("help.forAdmins", "For admins"), DefaultMessage: message.FallbackMsg(message.HelpForAdmins, "For admins"),
}) })
s.SendEmbed(m.ChannelID, NewEmbed(). s.SendEmbed(m.ChannelID, NewEmbed().
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.title", MessageID: message.HelpTitle,
DefaultMessage: message.FallbackMsg("help.title", "Help"), DefaultMessage: message.FallbackMsg(message.HelpTitle, "Help"),
})). })).
SetURL("https://dcbot.tribalwarshelp.com/"). SetURL("https://dcbot.tribalwarshelp.com/").
SetDescription(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ SetDescription(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.description", MessageID: message.HelpDescription,
DefaultMessage: message.FallbackMsg("help.description", "Commands offered by bot"), DefaultMessage: message.FallbackMsg(message.HelpDescription, "Commands offered by bot"),
})). })).
AddField(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ AddField(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.forAllUsers", MessageID: message.HelpForAllUsers,
DefaultMessage: message.FallbackMsg("help.forAllUsers", "For all server members."), DefaultMessage: message.FallbackMsg(message.HelpForAllUsers, "For all server members."),
}), commandsForAll). }), commandsForAll).
AddField(forAdmins, commandsForGuildAdmins). AddField(forAdmins, commandsForGuildAdmins).
AddField(forAdmins+" 2", commandsForGuildAdmins2). AddField(forAdmins+" 2", commandsForGuildAdmins2).
@ -399,7 +399,7 @@ func (s *Session) handleTribeCommand(ctx commandCtx, m *discordgo.MessageCreate,
return return
} }
langTag := utils.LanguageTagFromWorldName(world) langTag := utils.LanguageTagFromServerKey(world)
langVersion, err := s.cfg.API.LangVersions.Read(langTag) langVersion, err := s.cfg.API.LangVersions.Read(langTag)
if err != nil || langVersion == nil { if err != nil || langVersion == nil {
s.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ s.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{

29
message/ids.go Normal file
View File

@ -0,0 +1,29 @@
package message
const (
HelpForAdmins = "help.forAdmins"
HelpTitle = "help.title"
HelpDescription = "help.description"
HelpForAllUsers = "help.forAllUsers"
HelpTribeTopODA = "help.tribe.topoda"
HelpTribeTopODD = "help.tribe.topodd"
HelpTribeTopODS = "help.tribe.topods"
HelpTribeTopOD = "help.tribe.topod"
HelpTribeTopPoints = "help.tribe.toppoints"
HelpAuthor = "help.author"
HelpAddGroup = "help.addgroup"
HelpGroups = "help.groups"
HelpDeleteGroup = "help.deletegroup"
HelpShowEnnobledBarbs = "help.showennobledbarbs"
HelpObserve = "help.observe"
HelpObservations = "help.observations"
HelpDeleteObservation = "help.deleteobservation"
HelpConqueredVillages = "help.conqueredvillages"
HelpDisableConqueredVillages = "help.disableconqueredvillages"
HelpLostVillages = "help.lostvillages"
HelpDisableLostVillages = "help.disablelostvillages"
HelpShowInternals = "help.showinternals"
HelpChangageLanguage = "help.changelanguage"
HelpCoordsTranslation = "help.coordstranslation"
HelpDisableCoordsTranslation = "help.disablecoordstranslation"
)

View File

@ -11,7 +11,7 @@
"help.tribe.toppoints": "**{{.Command}}** [serwer] [strona] [id1] [id2] [id3] [n id] - Generuje listę graczy z wybranych plemion i sortuje po punktach.", "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.author": "**{{.Command}}** - pokazuje możliwe formy kontaktu z autorem.",
"help.addgroup": "**{{.Command}}** - dodaje nową grupę obserwacyjną.", "help.addgroup": "**{{.Command}}** - dodaje nową grupę obserwacyjną.",
"help.groups": "**{{.Command}}** - pokazuje listę grup dodanych przez administrację tego serwera Discord..", "help.groups": "**{{.Command}}** - pokazuje listę grup dodanych przez administrację tego serwera Discord.",
"help.deletegroup": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - usuwa grupę obserwacyjną.", "help.deletegroup": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - usuwa grupę obserwacyjną.",
"help.showennobledbarbs": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - włącza/wyłącza informacje o podbitych wioskach barbarzyńskich.", "help.showennobledbarbs": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - włącza/wyłącza informacje o podbitych wioskach barbarzyńskich.",
"help.observe": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] [serwer] [id plemienia] - dodaje plemię do grupy.", "help.observe": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] [serwer] [id plemienia] - dodaje plemię do grupy.",

View File

@ -4,9 +4,9 @@ import (
"github.com/tribalwarshelp/shared/models" "github.com/tribalwarshelp/shared/models"
) )
func LanguageTagFromWorldName(world string) models.LanguageTag { func LanguageTagFromServerKey(key string) models.LanguageTag {
if len(world) < 2 { if len(key) < 2 {
return "" return ""
} }
return models.LanguageTag(world[0:2]) return models.LanguageTag(key[0:2])
} }