message ids from all commands related to the observations are moved to constants

This commit is contained in:
Dawid Wysokiński 2020-10-17 07:58:10 +02:00
parent cc1d6f29ac
commit f80fb95efa
6 changed files with 67 additions and 45 deletions

View File

@ -22,6 +22,17 @@ func getAvailableLanguages() string {
return strings.Join(langTags, " | ")
}
func isValidLanguageTag(lang string) bool {
valid := false
for _, langTag := range message.LanguageTags() {
if langTag.String() == lang {
valid = true
break
}
}
return valid
}
func FormatLink(text string, url string) string {
if url == "" {
return text

View File

@ -693,7 +693,7 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: message.HelpObservations,
DefaultMessage: message.FallbackMsg(message.HelpObservations,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of observed tribes by this group."),
"**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of monitored tribes added to this group."),
TemplateData: map[string]interface{}{
"Command": ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
"GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
@ -706,8 +706,8 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
if err != nil {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "observations.invalidGroupID",
DefaultMessage: message.FallbackMsg("observations.invalidGroupID",
MessageID: message.ObservationsInvalidGroupID,
DefaultMessage: message.FallbackMsg(message.ObservationsInvalidGroupID,
"{{.Mention}} The group ID must be a number greater than 0."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -719,8 +719,8 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
if err != nil || group.ServerID != m.GuildID {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "observations.groupNotFound",
DefaultMessage: message.FallbackMsg("observations.groupNotFound", "{{.Mention}} Group not found."),
MessageID: message.ObservationsGroupNotFound,
DefaultMessage: message.FallbackMsg(message.ObservationsGroupNotFound, "{{.Mention}} Group not found."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
},
@ -811,9 +811,9 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
}
s.SendEmbed(m.ChannelID, NewEmbed().
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "observations.title",
DefaultMessage: message.FallbackMsg("observations.title",
"Observed tribes\nIndex | ID - Server - Tribe"),
MessageID: message.ObservationsTitle,
DefaultMessage: message.FallbackMsg(message.ObservationsTitle,
"monitored tribes\nIndex | ID - Server - Tribe"),
})).
SetFields(msg.ToMessageEmbedFields()).
MessageEmbed)
@ -831,8 +831,8 @@ func (s *Session) handleShowEnnobledBarbariansCommand(ctx commandCtx, m *discord
} else if argsLength < 1 {
s.SendMessage(m.ChannelID,
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.showennobledbarbs",
DefaultMessage: message.FallbackMsg("help.showennobledbarbs",
MessageID: message.HelpShowEnnobledBarbs,
DefaultMessage: message.FallbackMsg(message.HelpShowEnnobledBarbs,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about ennobling barbarian villages."),
TemplateData: map[string]interface{}{
"Command": ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix),
@ -846,8 +846,8 @@ func (s *Session) handleShowEnnobledBarbariansCommand(ctx commandCtx, m *discord
if err != nil || groupID <= 0 {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showEnnobledBarbs.invalidGroupID",
DefaultMessage: message.FallbackMsg("showEnnobledBarbs.invalidGroupID",
MessageID: message.ShowEnnobledBarbsInvalidGroupID,
DefaultMessage: message.FallbackMsg(message.ShowEnnobledBarbsInvalidGroupID,
"{{.Mention}} The group ID must be a number greater than 0."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -859,8 +859,8 @@ func (s *Session) handleShowEnnobledBarbariansCommand(ctx commandCtx, m *discord
if err != nil || group.ServerID != m.GuildID {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showEnnobledBarbs.groupNotFound",
DefaultMessage: message.FallbackMsg("showEnnobledBarbs.groupNotFound", "{{.Mention}} Group not found."),
MessageID: message.ShowEnnobledBarbsGroupNotFound,
DefaultMessage: message.FallbackMsg(message.ShowEnnobledBarbsGroupNotFound, "{{.Mention}} Group not found."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
},
@ -886,8 +886,8 @@ func (s *Session) handleShowEnnobledBarbariansCommand(ctx commandCtx, m *discord
if oldValue {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showEnnobledBarbs.success_1",
DefaultMessage: message.FallbackMsg("showEnnobledBarbs.success_1",
MessageID: message.ShowEnnobledBarbsSuccess1,
DefaultMessage: message.FallbackMsg(message.ShowEnnobledBarbsSuccess1,
"{{.Mention}} Notifications about conquered barbarian villages will no longer show up."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -896,8 +896,8 @@ func (s *Session) handleShowEnnobledBarbariansCommand(ctx commandCtx, m *discord
} else {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showEnnobledBarbs.success_2",
DefaultMessage: message.FallbackMsg("showEnnobledBarbs.success_2",
MessageID: message.ShowEnnobledBarbsSuccess2,
DefaultMessage: message.FallbackMsg(message.ShowEnnobledBarbsSuccess2,
"{{.Mention}} Enabled notifications about conquered barbarian villages."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -918,8 +918,8 @@ func (s *Session) handleChangeLanguageCommand(ctx commandCtx, m *discordgo.Messa
} else if argsLength < 1 {
s.SendMessage(m.ChannelID,
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.changelanguage",
DefaultMessage: message.FallbackMsg("help.changelanguage",
MessageID: message.HelpChangageLanguage,
DefaultMessage: message.FallbackMsg(message.HelpChangageLanguage,
"**{{.Command}}** [{{.Languages}}] - changes language."),
TemplateData: map[string]interface{}{
"Command": ChangeLanguageCommand.WithPrefix(s.cfg.CommandPrefix),
@ -930,18 +930,12 @@ func (s *Session) handleChangeLanguageCommand(ctx commandCtx, m *discordgo.Messa
}
lang := args[0]
valid := false
for _, langTag := range message.LanguageTags() {
if langTag.String() == lang {
valid = true
break
}
}
valid := isValidLanguageTag(lang)
if !valid {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "changeLanguage.languageNotSupported",
DefaultMessage: message.FallbackMsg("changeLanguage.languageNotSupported",
MessageID: message.ChangeLanguageLanguageNotSupported,
DefaultMessage: message.FallbackMsg(message.ChangeLanguageLanguageNotSupported,
"{{.Mention}} Language not supported."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -966,8 +960,8 @@ func (s *Session) handleChangeLanguageCommand(ctx commandCtx, m *discordgo.Messa
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "changeLanguage.success",
DefaultMessage: message.FallbackMsg("changeLanguage.success",
MessageID: message.ChangeLanguageSuccess,
DefaultMessage: message.FallbackMsg(message.ChangeLanguageSuccess,
"{{.Mention}} The language has been changed."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -987,8 +981,8 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
} else if argsLength < 1 {
s.SendMessage(m.ChannelID,
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "help.showinternals",
DefaultMessage: message.FallbackMsg("help.showinternals",
MessageID: message.HelpShowInternals,
DefaultMessage: message.FallbackMsg(message.HelpShowInternals,
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about in-group/in-tribe conquering."),
TemplateData: map[string]interface{}{
"Command": ShowInternalsCommand.WithPrefix(s.cfg.CommandPrefix),
@ -1002,8 +996,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: "showInternals.invalidGroupID",
DefaultMessage: message.FallbackMsg("showInternals.invalidGroupID",
MessageID: message.ShowInternalsInvalidGroupID,
DefaultMessage: message.FallbackMsg(message.ShowInternalsInvalidGroupID,
"{{.Mention}} The group ID must be a number greater than 0."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -1015,8 +1009,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: "showInternals.groupNotFound",
DefaultMessage: message.FallbackMsg("showInternals.groupNotFound", "{{.Mention}} Group not found."),
MessageID: message.ShowInternalsGroupNotFound,
DefaultMessage: message.FallbackMsg(message.ShowInternalsGroupNotFound, "{{.Mention}} Group not found."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
},
@ -1042,8 +1036,8 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
if oldValue {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showInternals.success_1",
DefaultMessage: message.FallbackMsg("showInternals.success_1",
MessageID: message.ShowInternalsSuccess1,
DefaultMessage: message.FallbackMsg(message.ShowInternalsSuccess1,
"{{.Mention}} Notifications about internals will no longer show up."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),
@ -1052,8 +1046,8 @@ func (s *Session) handleShowInternalsCommand(ctx commandCtx, m *discordgo.Messag
} else {
s.SendMessage(m.ChannelID,
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: "showInternals.success_2",
DefaultMessage: message.FallbackMsg("showInternals.success_2",
MessageID: message.ShowInternalsSuccess2,
DefaultMessage: message.FallbackMsg(message.ShowInternalsSuccess2,
"{{.Mention}} Enabled notifications about internals."),
TemplateData: map[string]interface{}{
"Mention": m.Author.Mention(),

View File

@ -143,7 +143,7 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: message.HelpGroups,
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 monitored tribes added to this group."),
TemplateData: map[string]interface{}{
"Command": ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
"GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix),

View File

@ -83,4 +83,21 @@ const (
DeleteObservationInvalidTribeID = "deleteObservation.invalidTribeID"
DeleteObservationGroupNotFound = "deleteObservation.groupNotFound"
DeleteObservationSuccess = "deleteObservation.success"
ObservationsInvalidGroupID = "observations.invalidGroupID"
ObservationsGroupNotFound = "observations.groupNotFound"
ObservationsTitle = "observations.title"
ShowEnnobledBarbsInvalidGroupID = "showEnnobledBarbs.invalidGroupID"
ShowEnnobledBarbsGroupNotFound = "showEnnobledBarbs.groupNotFound"
ShowEnnobledBarbsSuccess1 = "showEnnobledBarbs.success_1"
ShowEnnobledBarbsSuccess2 = "showEnnobledBarbs.success_2"
ChangeLanguageLanguageNotSupported = "changeLanguage.languageNotSupported"
ChangeLanguageSuccess = "changeLanguage.success"
ShowInternalsInvalidGroupID = "showInternals.invalidGroupID"
ShowInternalsGroupNotFound = "showInternals.groupNotFound"
ShowInternalsSuccess1 = "showInternals.success_1"
ShowInternalsSuccess2 = "showInternals.success_2"
)

View File

@ -15,7 +15,7 @@
"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] - adds a tribe to the observation group.",
"help.observations": "**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of observed tribes by this group.",
"help.observations": "**{{.Command}}** [group id from {{.GroupsCommand}}] - shows a list of monitored tribes added to this group.",
"help.deleteobservation": "**{{.Command}}** [group id from {{.GroupsCommand}}] [id from {{.ObservationsCommand}}] - removes a tribe from the observation group.",
"help.conqueredvillages": "**{{.Command}}** [group id from {{.GroupsCommand}}] - changes the channel on which notifications about conquered village will show. **IMPORTANT!** Run this command on the channel you want to display these notifications.",
"help.disableconqueredvillages": "**{{.Command}}** [group id from {{.GroupsCommand}}] - disables notifications about conquered villages.",
@ -79,7 +79,7 @@
"observations.invalidGroupID": "{{.Mention}} The group ID must be a number greater than 0.",
"observations.groupNotFound": "{{.Mention}} Group not found.",
"observations.title": "Observed tribes\nIndex | ID - Server - Tribe",
"observations.title": "monitored tribes\nIndex | ID - Server - Tribe",
"showEnnobledBarbs.invalidGroupID": "{{.Mention}} The group ID must be a number greater than 0.",
"showEnnobledBarbs.groupNotFound": "{{.Mention}} Group not found.",

View File

@ -79,7 +79,7 @@
"observations.invalidGroupID": "{{.Mention}} de groepID moet een hoger dan 0 zijn.",
"observations.groupNotFound": "{{.Mention}} Groep niet gevonden.",
"observations.title": "Observed tribes\nIndex | ID - Server - Stam",
"observations.title": "Monitored tribes\nIndex | ID - Server - Stam",
"showEnnobledBarbs.invalidGroupID": "{{.Mention}} de groepID moet een hoger dan 0 zijn.",
"showEnnobledBarbs.groupNotFound": "{{.Mention}} Groep niet gevonden.",