rename struct discord.EmbedMessage -> discord.MessageEmbed | message ids from all commands related to coords translation are moved to constants

This commit is contained in:
Dawid Wysokiński 2020-10-17 08:47:39 +02:00
parent f80fb95efa
commit dc3dd073aa
7 changed files with 33 additions and 27 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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 {

View File

@ -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{}

View File

@ -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 {

View File

@ -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

View File

@ -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"
)