From 4dca0f47d5a733f1231336e2ff137cfbc94bf2c8 Mon Sep 17 00:00:00 2001 From: Kichiyaki Date: Sun, 19 Jul 2020 15:12:52 +0200 Subject: [PATCH] the observations command is fully translatable --- discord/admin_commands.go | 60 +++++++++++++++++++++++------ discord/discord.go | 2 +- message/translations/active.en.json | 4 ++ 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/discord/admin_commands.go b/discord/admin_commands.go index d66331f..a2f659e 100644 --- a/discord/admin_commands.go +++ b/discord/admin_commands.go @@ -663,7 +663,7 @@ func (s *Session) handleUnObserveCommand(ctx commandCtx, m *discordgo.MessageCre })) } -func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ...string) { +func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.MessageCreate, args ...string) { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has { return } @@ -674,22 +674,41 @@ func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ... return } else if argsLength < 1 { s.SendMessage(m.ChannelID, - fmt.Sprintf(`%s %s [id grupy]`, - m.Author.Mention(), - ObservationsCommand.WithPrefix(s.cfg.CommandPrefix))) + m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "help.observations", + DefaultMessage: message.FallbackMsg("help.observations", + "**{{.Command}}** [group id from {{.GroupsCommand}}] shows a list of observed tribes by this group."), + TemplateData: map[string]interface{}{ + "Command": ObservationsCommand.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 ID grupy powinno być liczbą całkowitą większą od 0.`, - m.Author.Mention())) + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "observations.invalidGroupID", + DefaultMessage: message.FallbackMsg("observations.invalidGroupID", + "{{.Mention}} The group ID must be a number greater than 0."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } group, err := s.cfg.GroupRepository.GetByID(context.Background(), groupID) if err != nil || group.ServerID != m.GuildID { - s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie znaleziono grupy.`) + s.SendMessage(m.ChannelID, + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "observations.groupNotFound", + DefaultMessage: message.FallbackMsg("observations.groupNotFound", "{{.Mention}} Group not found."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } observations, _, err := s.cfg.ObservationRepository.Fetch(context.Background(), &models.ObservationFilter{ @@ -697,7 +716,15 @@ func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ... Order: []string{"id ASC"}, }) if err != nil { - s.SendMessage(m.ChannelID, m.Author.Mention()+` Wystąpił błąd wewnętrzny, prosimy spróbować później.`) + s.SendMessage(m.ChannelID, + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "internalServerError", + DefaultMessage: message.FallbackMsg("internalServerError", + "{{.Mention}} Internal server error occurred, please try again later."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } @@ -722,7 +749,15 @@ func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ... ID: tribeIDs, }) if err != nil { - s.SendMessage(m.ChannelID, m.Author.Mention()+` Wystąpił błąd wewnętrzny, prosimy spróbować później.`) + s.SendMessage(m.ChannelID, + ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "internalServerError", + DefaultMessage: message.FallbackMsg("internalServerError", + "{{.Mention}} Internal server error occurred, please try again later."), + TemplateData: map[string]interface{}{ + "Mention": m.Author.Mention(), + }, + })) return } for _, tribe := range list.Items { @@ -759,9 +794,12 @@ func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ... } } s.SendEmbed(m.ChannelID, NewEmbed(). - SetTitle("Lista obserwowanych plemion\nIndeks | ID - Serwer - Plemię"). + SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ + MessageID: "observations.title", + DefaultMessage: message.FallbackMsg("observations.title", + "Observed tribes\nIndex | ID - Server - Tribe"), + })). SetFields(msg.ToMessageEmbedFields()). - SetFooter("Strona 1 z 1"). MessageEmbed) } diff --git a/discord/discord.go b/discord/discord.go index 21421cb..a1e70c1 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -122,7 +122,7 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre case UnObserveCommand.WithPrefix(s.cfg.CommandPrefix): s.handleUnObserveCommand(ctx, m, args...) case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleObservationsCommand(m, args...) + s.handleObservationsCommand(ctx, m, args...) case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): s.handleConqueredVillagesCommand(ctx, m, args...) case UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): diff --git a/message/translations/active.en.json b/message/translations/active.en.json index bd60ddb..be7e69f 100644 --- a/message/translations/active.en.json +++ b/message/translations/active.en.json @@ -72,6 +72,10 @@ "unObserve.groupNotFound": "{{.Mention}} Group not found.", "unObserve.success": "{{.Mention}} Deleted.", + "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", + "api.defaultError": "{{.Mention}} There was an error fetching data from the API, please try again later.", "pagination.labelDisplayedPage": "Page: {{.Page}} from {{.MaxPage}}",