From 9828a6cba9d834fe3014ca6f4da4c0d3b2e3af13 Mon Sep 17 00:00:00 2001 From: Kichiyaki Date: Sun, 19 Jul 2020 14:22:41 +0200 Subject: [PATCH] the lostvillages, conqueredvillages, unobservelostvillages, unobserveconqueredvillages commands are fully translatable --- discord/admin_commands.go | 169 +++++++++++++++++++++------- discord/discord.go | 10 +- message/translations/active.en.json | 19 ++++ 3 files changed, 155 insertions(+), 43 deletions(-) diff --git a/discord/admin_commands.go b/discord/admin_commands.go index de68b5c..ff6614b 100644 --- a/discord/admin_commands.go +++ b/discord/admin_commands.go @@ -128,7 +128,7 @@ func (s *Session) handleDeleteGroupCommand(ctx commandCtx, m *discordgo.MessageC })) } -func (s *Session) handleGroupsCommand(m *discordgo.MessageCreate) { +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 } @@ -147,17 +147,22 @@ func (s *Session) handleGroupsCommand(m *discordgo.MessageCreate) { } if msg == "" { - msg = "Brak dodanych grup" + msg = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "groups.noGroupsAdded", + DefaultMessage: message.FallbackMsg("groups.noGroupsAdded", "No groups added"), + }) } s.SendEmbed(m.ChannelID, NewEmbed(). - SetTitle("Lista grup"). - AddField("Indeks | ID", msg). - SetFooter("Strona 1 z 1"). + SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "groups.title", + DefaultMessage: message.FallbackMsg("groups.title", "Group list"), + })). + AddField("Index | ID", msg). MessageEmbed) } -func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate, args ...string) { +func (s *Session) handleConqueredVillagesCommand(ctx commandCtx, m *discordgo.MessageCreate, args ...string) { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has { return } @@ -168,16 +173,27 @@ func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate, arg return } else if argsLength < 1 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s %s [id grupy]", - m.Author.Mention(), - ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) + m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + 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."), + TemplateData: map[string]interface{}{ + "Command": ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix), + "GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix), + }, + })) return } groupID, err := strconv.Atoi(args[0]) if err != nil { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Niepoprawne ID grupy (powinna to być liczba całkowita większa od 1).", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "conqueredVillages.invalidID", + DefaultMessage: message.FallbackMsg("conqueredVillages.invalidID", "{{.Mention}} The group ID must be a number greater than 0."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -187,18 +203,29 @@ func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate, arg }) if err != nil || len(groups) == 0 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s nie znaleziono grupy.", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "conqueredVillages.groupNotFound", + DefaultMessage: message.FallbackMsg("conqueredVillages.groupNotFound", "{{.Mention}} Group not found."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } groups[0].ConqueredVillagesChannelID = m.ChannelID go s.cfg.GroupRepository.Update(context.Background(), groups[0]) s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o podbitych wioskach (Grupa: %d).", - m.Author.Mention(), groupID)) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "conqueredVillages.success", + DefaultMessage: message.FallbackMsg("conqueredVillages.success", "{{.Mention}} Channel changed successfully."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) } -func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCreate, args ...string) { +func (s *Session) handleUnObserveConqueredVillagesCommand(ctx commandCtx, m *discordgo.MessageCreate, args ...string) { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has { return } @@ -209,16 +236,27 @@ func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCr return } else if argsLength < 1 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s %s [id grupy]", - m.Author.Mention(), - UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) + m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "help.unobserveconqueredvillages", + DefaultMessage: message.FallbackMsg("help.unobserveconqueredvillages", "**{{.Command}}** [group id from {{.GroupsCommand}}] - disable notifications about conquered villages."), + TemplateData: map[string]interface{}{ + "Command": UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix), + "GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix), + }, + })) return } groupID, err := strconv.Atoi(args[0]) if err != nil { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Niepoprawne ID grupy (powinna to być liczba całkowita większa od 1).", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "unObserveConqueredVillages.invalidID", + DefaultMessage: message.FallbackMsg("unObserveConqueredVillages.invalidID", "{{.Mention}} The group ID must be a number greater than 0."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -228,7 +266,13 @@ func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCr }) if err != nil || len(groups) == 0 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s nie znaleziono grupy.", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "unObserveConqueredVillages.groupNotFound", + DefaultMessage: message.FallbackMsg("unObserveConqueredVillages.groupNotFound", "{{.Mention}} Group not found."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -237,10 +281,16 @@ func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCr go s.cfg.GroupRepository.Update(context.Background(), groups[0]) } s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Informacje o podbitych wioskach grupy %d nie będą się już pojawiały.", m.Author.Mention(), groupID)) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "unObserveConqueredVillages.success", + DefaultMessage: message.FallbackMsg("unObserveConqueredVillages.success", "{{.Mention}} Notifications about conquered villages will no longer show up."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) } -func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate, args ...string) { +func (s *Session) handleLostVillagesCommand(ctx commandCtx, m *discordgo.MessageCreate, args ...string) { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has { return } @@ -251,16 +301,27 @@ func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate, args ... return } else if argsLength < 1 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s %s [id grupy]", - m.Author.Mention(), - LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) + m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "help.lostvillages", + DefaultMessage: message.FallbackMsg("help.lostvillages", "**{{.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{}{ + "Command": LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), + "GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix), + }, + })) return } groupID, err := strconv.Atoi(args[0]) if err != nil { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Niepoprawne ID grupy", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "lostVillages.invalidID", + DefaultMessage: message.FallbackMsg("lostVillages.invalidID", "{{.Mention}} The group ID must be a number greater than 0."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -270,19 +331,30 @@ func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate, args ... }) if err != nil || len(groups) == 0 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Nie znaleziono grupy.", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "lostVillages.groupNotFound", + DefaultMessage: message.FallbackMsg("lostVillages.groupNotFound", "{{.Mention}} Group not found."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } + groups[0].LostVillagesChannelID = m.ChannelID go s.cfg.GroupRepository.Update(context.Background(), groups[0]) s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o straconych wioskach (Grupa: %d).", - m.Author.Mention(), - groupID)) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "lostVillages.success", + DefaultMessage: message.FallbackMsg("lostVillages.success", "{{.Mention}} Channel changed successfully."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) } -func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate, args ...string) { +func (s *Session) handleUnObserveLostVillagesCommand(ctx commandCtx, m *discordgo.MessageCreate, args ...string) { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has { return } @@ -293,16 +365,27 @@ func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate, return } else if argsLength < 1 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s %s [id grupy]", - m.Author.Mention(), - UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) + m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "help.unobservelostvillages", + DefaultMessage: message.FallbackMsg("help.unobservelostvillages", "**{{.Command}}** [group id from {{.GroupsCommand}}] - disable notifications about lost villages."), + TemplateData: map[string]interface{}{ + "Command": UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), + "GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix), + }, + })) return } groupID, err := strconv.Atoi(args[0]) if err != nil { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Niepoprawne ID grupy", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "unObserveLostVillages.invalidID", + DefaultMessage: message.FallbackMsg("unObserveLostVillages.invalidID", "{{.Mention}} The group ID must be a number greater than 0."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -312,7 +395,13 @@ func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate, }) if err != nil || len(groups) == 0 { s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Nie znaleziono grupy.", m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "unObserveLostVillages.groupNotFound", + DefaultMessage: message.FallbackMsg("unObserveLostVillages.groupNotFound", "{{.Mention}} Group not found."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -322,9 +411,13 @@ func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate, } s.SendMessage(m.ChannelID, - fmt.Sprintf("%s Informacje o straconych wioskach grupy %d nie będą się już pojawiały.", - m.Author.Mention(), - groupID)) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "unObserveLostVillages.success", + DefaultMessage: message.FallbackMsg("unObserveLostVillages.success", "{{.Mention}} Notifications about lost villages will no longer show up."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) } func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...string) { diff --git a/discord/discord.go b/discord/discord.go index 73891fe..d2c6374 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -113,7 +113,7 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre case DeleteGroupCommand.WithPrefix(s.cfg.CommandPrefix): s.handleDeleteGroupCommand(ctx, m, args...) case GroupsCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleGroupsCommand(m) + s.handleGroupsCommand(ctx, m) case ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix): s.handleShowEnnobledBarbariansCommand(m, args...) @@ -124,13 +124,13 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix): s.handleObservationsCommand(m, args...) case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleConqueredVillagesCommand(m, args...) + s.handleConqueredVillagesCommand(ctx, m, args...) case UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleUnObserveConqueredVillagesCommand(m, args...) + s.handleUnObserveConqueredVillagesCommand(ctx, m, args...) case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleLostVillagesCommand(m, args...) + s.handleLostVillagesCommand(ctx, m, args...) case UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleUnObserveLostVillagesCommand(m, args...) + s.handleUnObserveLostVillagesCommand(ctx, m, args...) } } diff --git a/message/translations/active.en.json b/message/translations/active.en.json index 881310d..c21da87 100644 --- a/message/translations/active.en.json +++ b/message/translations/active.en.json @@ -39,6 +39,25 @@ "deleteGroup.invalidID": "{{.Mention}} The group ID must be a number greater than 0.", "deleteGroup.success": "{{.Mention}} The group has been deleted.", + "groups.noGroupsAdded": "No groups added.", + "groups.title": "Group list", + + "conqueredVillages.invalidID": "{{.Mention}} The group ID must be a number greater than 0.", + "conqueredVillages.groupNotFound": "{{.Mention}} Group not found.", + "conqueredVillages.success": "{{.Mention}} Channel changed successfully.", + + "unObserveConqueredVillages.invalidID": "{{.Mention}} The group ID must be a number greater than 0.", + "unObserveConqueredVillages.groupNotFound": "{{.Mention}} Group not found.", + "unObserveConqueredVillages.success": "{{.Mention}} Notifications about conquered villages will no longer show up.", + + "lostVillages.invalidID": "{{.Mention}} The group ID must be a number greater than 0.", + "lostVillages.groupNotFound": "{{.Mention}} Group not found.", + "lostVillages.success": "{{.Mention}} Channel changed successfully.", + + "unObserveLostVillages.invalidID": "{{.Mention}} The group ID must be a number greater than 0.", + "unObserveLostVillages.groupNotFound": "{{.Mention}} Group not found.", + "unObserveLostVillages.success": "{{.Mention}} Notifications about lost villages will no longer show up.", + "api.defaultError": "{{.Mention}} There was an error fetching data from the API, please try again later.", "pagination.labelDisplayedPage": "Page: {{.Page}} from {{.MaxPage}}",