diff --git a/cron/handler.go b/cron/handler.go index 7d952ad..b70232c 100644 --- a/cron/handler.go +++ b/cron/handler.go @@ -140,8 +140,8 @@ func (h *handler) checkEnnoblements() { continue } localizer := message.NewLocalizer(group.Server.Lang) - lostVillagesMsg := &discord.EmbedMessage{} - conqueredVillagesMsg := &discord.EmbedMessage{} + lostVillagesMsg := &discord.MessageEmbed{} + conqueredVillagesMsg := &discord.MessageEmbed{} for _, observation := range group.Observations { ennoblements, ok := ennoblementsByServerKey[observation.Server] langVersion := utils.FindLangVersionByTag(langVersions, utils.LanguageTagFromServerKey(observation.Server)) diff --git a/discord/coords_translation.go b/discord/coords_translation.go index c113349..7f1f2b2 100644 --- a/discord/coords_translation.go +++ b/discord/coords_translation.go @@ -26,14 +26,11 @@ func (s *Session) handleCoordsTranslationCommand(ctx commandCtx, m *discordgo.Me } argsLength := len(args) - if argsLength > 1 { - s.sendUnknownCommandError(m.Author.Mention(), m.ChannelID, args[1:argsLength]...) - return - } else if argsLength < 1 { + if argsLength != 1 { s.SendMessage(m.ChannelID, m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ - MessageID: "help.coordstranslation", - DefaultMessage: message.FallbackMsg("help.coordstranslation", + MessageID: message.HelpCoordsTranslation, + DefaultMessage: message.FallbackMsg(message.HelpCoordsTranslation, "**{{.Command}}** [server] - enables coords translation feature."), TemplateData: map[string]interface{}{ "Command": CoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix), @@ -47,8 +44,8 @@ func (s *Session) handleCoordsTranslationCommand(ctx commandCtx, m *discordgo.Me if err != nil || server == nil { s.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ - MessageID: "coordsTranslation.serverNotFound", - DefaultMessage: message.FallbackMsg("coordsTranslation.serverNotFound", "{{.Mention}} Server not found."), + MessageID: message.CoordsTranslationServerNotFound, + DefaultMessage: message.FallbackMsg(message.CoordsTranslationServerNotFound, "{{.Mention}} Server not found."), TemplateData: map[string]interface{}{ "Mention": m.Author.Mention(), }, @@ -61,8 +58,8 @@ func (s *Session) handleCoordsTranslationCommand(ctx commandCtx, m *discordgo.Me s.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ - MessageID: "coordsTranslation.success", - DefaultMessage: message.FallbackMsg("coordsTranslation.success", + MessageID: message.CoordsTranslationSuccess, + DefaultMessage: message.FallbackMsg(message.CoordsTranslationSuccess, "{{.Mention}} Coords translation feature has been enabled."), TemplateData: map[string]interface{}{ "Mention": m.Author.Mention(), @@ -80,8 +77,8 @@ func (s *Session) handleDisableCoordsTranslationCommand(ctx commandCtx, m *disco s.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ - MessageID: "disableCoordsTranslation.success", - DefaultMessage: message.FallbackMsg("disableCoordsTranslation.success", + MessageID: message.DisableCoordsTranslationSuccess, + DefaultMessage: message.FallbackMsg(message.DisableCoordsTranslationSuccess, "{{.Mention}} Coords translation feature has been disabled."), TemplateData: map[string]interface{}{ "Mention": m.Author.Mention(), @@ -106,7 +103,8 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) { list, err := s.cfg.API.Villages.Browse(ctx.server.CoordsTranslation, &models.VillageFilter{ XY: coords, - }, &sdk.VillageInclude{ + }, + &sdk.VillageInclude{ Player: true, PlayerInclude: sdk.PlayerInclude{ Tribe: true, @@ -116,7 +114,7 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) { return } - msg := &EmbedMessage{} + msg := &MessageEmbed{} for _, village := range list.Items { villageURL := utils.FormatVillageURL(ctx.server.CoordsTranslation, langVersion.Host, village.ID) playerName := "-" @@ -133,8 +131,8 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) { } msg.Append(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ - MessageID: "coordsTranslation.message", - DefaultMessage: message.FallbackMsg("coordsTranslation.message", + MessageID: message.CoordsTranslationMessage, + DefaultMessage: message.FallbackMsg(message.CoordsTranslationMessage, "{{.Village}} owned by {{.Player}} (Tribe: {{.Tribe}})."), TemplateData: map[string]interface{}{ "Village": FormatLink(village.FullName(), villageURL), @@ -146,8 +144,8 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) { s.SendEmbed(m.ChannelID, NewEmbed(). SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ - MessageID: "coordsTranslation.title", - DefaultMessage: message.FallbackMsg("coordsTranslation.title", "Villages"), + MessageID: message.CoordsTranslationTitle, + DefaultMessage: message.FallbackMsg(message.CoordsTranslationTitle, "Villages"), })). SetFields(msg.ToMessageEmbedFields()). MessageEmbed) diff --git a/discord/discord.go b/discord/discord.go index 3bb9093..87dbd0c 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -79,6 +79,7 @@ func (s *Session) SendEmbed(channelID string, message *discordgo.MessageEmbed) e if message.Footer != nil { baseNumberOfCharacters += len(message.Footer.Text) } + splittedFields := [][]*discordgo.MessageEmbedField{} characters := baseNumberOfCharacters fromIndex := 0 @@ -199,7 +200,7 @@ func (s *Session) memberHasPermission(guildID string, userID string, permission } } - // check if a user is guild owner + // check if user is a guild owner guild, err := s.dg.State.Guild(guildID) if err != nil { if guild, err = s.dg.Guild(guildID); err != nil { diff --git a/discord/embed.go b/discord/embed.go index ee9ed17..590423e 100644 --- a/discord/embed.go +++ b/discord/embed.go @@ -252,17 +252,17 @@ func (e *Embed) TruncateFooter() *Embed { return e } -type EmbedMessage struct { +type MessageEmbed struct { chunks []string index int mutex sync.Mutex } -func (msg *EmbedMessage) IsEmpty() bool { +func (msg *MessageEmbed) IsEmpty() bool { return len(msg.chunks) == 0 } -func (msg *EmbedMessage) Append(m string) { +func (msg *MessageEmbed) Append(m string) { msg.mutex.Lock() defer msg.mutex.Unlock() for len(msg.chunks) < msg.index+1 { @@ -278,7 +278,7 @@ func (msg *EmbedMessage) Append(m string) { msg.chunks[msg.index] += m } -func (msg *EmbedMessage) ToMessageEmbedFields() []*discordgo.MessageEmbedField { +func (msg *MessageEmbed) ToMessageEmbedFields() []*discordgo.MessageEmbedField { msg.mutex.Lock() defer msg.mutex.Unlock() fields := []*discordgo.MessageEmbedField{} diff --git a/discord/observations.go b/discord/observations.go index 2d399e1..4ebecc7 100644 --- a/discord/observations.go +++ b/discord/observations.go @@ -789,7 +789,7 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message Tag: langTags, }) - msg := &EmbedMessage{} + msg := &MessageEmbed{} if len(observations) <= 0 || err != nil || langVersionList == nil || langVersionList.Items == nil { msg.Append("-") } else { diff --git a/discord/public_commands.go b/discord/public_commands.go index 7eb6ca7..0ab13c4 100644 --- a/discord/public_commands.go +++ b/discord/public_commands.go @@ -412,7 +412,7 @@ func (s *Session) handleTribeCommand(ctx commandCtx, m *discordgo.MessageCreate, return } - msg := &EmbedMessage{} + msg := &MessageEmbed{} for i, player := range playerList.Items { if player == nil { continue diff --git a/message/ids.go b/message/ids.go index 13040ce..1707f64 100644 --- a/message/ids.go +++ b/message/ids.go @@ -100,4 +100,11 @@ const ( ShowInternalsGroupNotFound = "showInternals.groupNotFound" ShowInternalsSuccess1 = "showInternals.success_1" ShowInternalsSuccess2 = "showInternals.success_2" + + CoordsTranslationServerNotFound = "coordsTranslation.serverNotFound" + CoordsTranslationSuccess = "coordsTranslation.success" + CoordsTranslationMessage = "coordsTranslation.message" + CoordsTranslationTitle = "coordsTranslation.title" + + DisableCoordsTranslationSuccess = "disableCoordsTranslation.success" )