rename struct discord.EmbedMessage -> discord.MessageEmbed | message ids from all commands related to coords translation are moved to constants
This commit is contained in:
parent
f80fb95efa
commit
dc3dd073aa
|
@ -140,8 +140,8 @@ func (h *handler) checkEnnoblements() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
localizer := message.NewLocalizer(group.Server.Lang)
|
localizer := message.NewLocalizer(group.Server.Lang)
|
||||||
lostVillagesMsg := &discord.EmbedMessage{}
|
lostVillagesMsg := &discord.MessageEmbed{}
|
||||||
conqueredVillagesMsg := &discord.EmbedMessage{}
|
conqueredVillagesMsg := &discord.MessageEmbed{}
|
||||||
for _, observation := range group.Observations {
|
for _, observation := range group.Observations {
|
||||||
ennoblements, ok := ennoblementsByServerKey[observation.Server]
|
ennoblements, ok := ennoblementsByServerKey[observation.Server]
|
||||||
langVersion := utils.FindLangVersionByTag(langVersions, utils.LanguageTagFromServerKey(observation.Server))
|
langVersion := utils.FindLangVersionByTag(langVersions, utils.LanguageTagFromServerKey(observation.Server))
|
||||||
|
|
|
@ -26,14 +26,11 @@ func (s *Session) handleCoordsTranslationCommand(ctx commandCtx, m *discordgo.Me
|
||||||
}
|
}
|
||||||
|
|
||||||
argsLength := len(args)
|
argsLength := len(args)
|
||||||
if argsLength > 1 {
|
if argsLength != 1 {
|
||||||
s.sendUnknownCommandError(m.Author.Mention(), m.ChannelID, args[1:argsLength]...)
|
|
||||||
return
|
|
||||||
} else if argsLength < 1 {
|
|
||||||
s.SendMessage(m.ChannelID,
|
s.SendMessage(m.ChannelID,
|
||||||
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||||
MessageID: "help.coordstranslation",
|
MessageID: message.HelpCoordsTranslation,
|
||||||
DefaultMessage: message.FallbackMsg("help.coordstranslation",
|
DefaultMessage: message.FallbackMsg(message.HelpCoordsTranslation,
|
||||||
"**{{.Command}}** [server] - enables coords translation feature."),
|
"**{{.Command}}** [server] - enables coords translation feature."),
|
||||||
TemplateData: map[string]interface{}{
|
TemplateData: map[string]interface{}{
|
||||||
"Command": CoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix),
|
"Command": CoordsTranslationCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||||
|
@ -47,8 +44,8 @@ func (s *Session) handleCoordsTranslationCommand(ctx commandCtx, m *discordgo.Me
|
||||||
if err != nil || server == nil {
|
if err != nil || server == nil {
|
||||||
s.SendMessage(m.ChannelID,
|
s.SendMessage(m.ChannelID,
|
||||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||||
MessageID: "coordsTranslation.serverNotFound",
|
MessageID: message.CoordsTranslationServerNotFound,
|
||||||
DefaultMessage: message.FallbackMsg("coordsTranslation.serverNotFound", "{{.Mention}} Server not found."),
|
DefaultMessage: message.FallbackMsg(message.CoordsTranslationServerNotFound, "{{.Mention}} Server not found."),
|
||||||
TemplateData: map[string]interface{}{
|
TemplateData: map[string]interface{}{
|
||||||
"Mention": m.Author.Mention(),
|
"Mention": m.Author.Mention(),
|
||||||
},
|
},
|
||||||
|
@ -61,8 +58,8 @@ func (s *Session) handleCoordsTranslationCommand(ctx commandCtx, m *discordgo.Me
|
||||||
|
|
||||||
s.SendMessage(m.ChannelID,
|
s.SendMessage(m.ChannelID,
|
||||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||||
MessageID: "coordsTranslation.success",
|
MessageID: message.CoordsTranslationSuccess,
|
||||||
DefaultMessage: message.FallbackMsg("coordsTranslation.success",
|
DefaultMessage: message.FallbackMsg(message.CoordsTranslationSuccess,
|
||||||
"{{.Mention}} Coords translation feature has been enabled."),
|
"{{.Mention}} Coords translation feature has been enabled."),
|
||||||
TemplateData: map[string]interface{}{
|
TemplateData: map[string]interface{}{
|
||||||
"Mention": m.Author.Mention(),
|
"Mention": m.Author.Mention(),
|
||||||
|
@ -80,8 +77,8 @@ func (s *Session) handleDisableCoordsTranslationCommand(ctx commandCtx, m *disco
|
||||||
|
|
||||||
s.SendMessage(m.ChannelID,
|
s.SendMessage(m.ChannelID,
|
||||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||||
MessageID: "disableCoordsTranslation.success",
|
MessageID: message.DisableCoordsTranslationSuccess,
|
||||||
DefaultMessage: message.FallbackMsg("disableCoordsTranslation.success",
|
DefaultMessage: message.FallbackMsg(message.DisableCoordsTranslationSuccess,
|
||||||
"{{.Mention}} Coords translation feature has been disabled."),
|
"{{.Mention}} Coords translation feature has been disabled."),
|
||||||
TemplateData: map[string]interface{}{
|
TemplateData: map[string]interface{}{
|
||||||
"Mention": m.Author.Mention(),
|
"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,
|
list, err := s.cfg.API.Villages.Browse(ctx.server.CoordsTranslation,
|
||||||
&models.VillageFilter{
|
&models.VillageFilter{
|
||||||
XY: coords,
|
XY: coords,
|
||||||
}, &sdk.VillageInclude{
|
},
|
||||||
|
&sdk.VillageInclude{
|
||||||
Player: true,
|
Player: true,
|
||||||
PlayerInclude: sdk.PlayerInclude{
|
PlayerInclude: sdk.PlayerInclude{
|
||||||
Tribe: true,
|
Tribe: true,
|
||||||
|
@ -116,7 +114,7 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &EmbedMessage{}
|
msg := &MessageEmbed{}
|
||||||
for _, village := range list.Items {
|
for _, village := range list.Items {
|
||||||
villageURL := utils.FormatVillageURL(ctx.server.CoordsTranslation, langVersion.Host, village.ID)
|
villageURL := utils.FormatVillageURL(ctx.server.CoordsTranslation, langVersion.Host, village.ID)
|
||||||
playerName := "-"
|
playerName := "-"
|
||||||
|
@ -133,8 +131,8 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Append(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
msg.Append(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||||
MessageID: "coordsTranslation.message",
|
MessageID: message.CoordsTranslationMessage,
|
||||||
DefaultMessage: message.FallbackMsg("coordsTranslation.message",
|
DefaultMessage: message.FallbackMsg(message.CoordsTranslationMessage,
|
||||||
"{{.Village}} owned by {{.Player}} (Tribe: {{.Tribe}})."),
|
"{{.Village}} owned by {{.Player}} (Tribe: {{.Tribe}})."),
|
||||||
TemplateData: map[string]interface{}{
|
TemplateData: map[string]interface{}{
|
||||||
"Village": FormatLink(village.FullName(), villageURL),
|
"Village": FormatLink(village.FullName(), villageURL),
|
||||||
|
@ -146,8 +144,8 @@ func (s *Session) translateCoords(ctx commandCtx, m *discordgo.MessageCreate) {
|
||||||
|
|
||||||
s.SendEmbed(m.ChannelID, NewEmbed().
|
s.SendEmbed(m.ChannelID, NewEmbed().
|
||||||
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||||
MessageID: "coordsTranslation.title",
|
MessageID: message.CoordsTranslationTitle,
|
||||||
DefaultMessage: message.FallbackMsg("coordsTranslation.title", "Villages"),
|
DefaultMessage: message.FallbackMsg(message.CoordsTranslationTitle, "Villages"),
|
||||||
})).
|
})).
|
||||||
SetFields(msg.ToMessageEmbedFields()).
|
SetFields(msg.ToMessageEmbedFields()).
|
||||||
MessageEmbed)
|
MessageEmbed)
|
||||||
|
|
|
@ -79,6 +79,7 @@ func (s *Session) SendEmbed(channelID string, message *discordgo.MessageEmbed) e
|
||||||
if message.Footer != nil {
|
if message.Footer != nil {
|
||||||
baseNumberOfCharacters += len(message.Footer.Text)
|
baseNumberOfCharacters += len(message.Footer.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
splittedFields := [][]*discordgo.MessageEmbedField{}
|
splittedFields := [][]*discordgo.MessageEmbedField{}
|
||||||
characters := baseNumberOfCharacters
|
characters := baseNumberOfCharacters
|
||||||
fromIndex := 0
|
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)
|
guild, err := s.dg.State.Guild(guildID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if guild, err = s.dg.Guild(guildID); err != nil {
|
if guild, err = s.dg.Guild(guildID); err != nil {
|
||||||
|
|
|
@ -252,17 +252,17 @@ func (e *Embed) TruncateFooter() *Embed {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmbedMessage struct {
|
type MessageEmbed struct {
|
||||||
chunks []string
|
chunks []string
|
||||||
index int
|
index int
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *EmbedMessage) IsEmpty() bool {
|
func (msg *MessageEmbed) IsEmpty() bool {
|
||||||
return len(msg.chunks) == 0
|
return len(msg.chunks) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *EmbedMessage) Append(m string) {
|
func (msg *MessageEmbed) Append(m string) {
|
||||||
msg.mutex.Lock()
|
msg.mutex.Lock()
|
||||||
defer msg.mutex.Unlock()
|
defer msg.mutex.Unlock()
|
||||||
for len(msg.chunks) < msg.index+1 {
|
for len(msg.chunks) < msg.index+1 {
|
||||||
|
@ -278,7 +278,7 @@ func (msg *EmbedMessage) Append(m string) {
|
||||||
msg.chunks[msg.index] += m
|
msg.chunks[msg.index] += m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *EmbedMessage) ToMessageEmbedFields() []*discordgo.MessageEmbedField {
|
func (msg *MessageEmbed) ToMessageEmbedFields() []*discordgo.MessageEmbedField {
|
||||||
msg.mutex.Lock()
|
msg.mutex.Lock()
|
||||||
defer msg.mutex.Unlock()
|
defer msg.mutex.Unlock()
|
||||||
fields := []*discordgo.MessageEmbedField{}
|
fields := []*discordgo.MessageEmbedField{}
|
||||||
|
|
|
@ -789,7 +789,7 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
|
||||||
Tag: langTags,
|
Tag: langTags,
|
||||||
})
|
})
|
||||||
|
|
||||||
msg := &EmbedMessage{}
|
msg := &MessageEmbed{}
|
||||||
if len(observations) <= 0 || err != nil || langVersionList == nil || langVersionList.Items == nil {
|
if len(observations) <= 0 || err != nil || langVersionList == nil || langVersionList.Items == nil {
|
||||||
msg.Append("-")
|
msg.Append("-")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -412,7 +412,7 @@ func (s *Session) handleTribeCommand(ctx commandCtx, m *discordgo.MessageCreate,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &EmbedMessage{}
|
msg := &MessageEmbed{}
|
||||||
for i, player := range playerList.Items {
|
for i, player := range playerList.Items {
|
||||||
if player == nil {
|
if player == nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -100,4 +100,11 @@ const (
|
||||||
ShowInternalsGroupNotFound = "showInternals.groupNotFound"
|
ShowInternalsGroupNotFound = "showInternals.groupNotFound"
|
||||||
ShowInternalsSuccess1 = "showInternals.success_1"
|
ShowInternalsSuccess1 = "showInternals.success_1"
|
||||||
ShowInternalsSuccess2 = "showInternals.success_2"
|
ShowInternalsSuccess2 = "showInternals.success_2"
|
||||||
|
|
||||||
|
CoordsTranslationServerNotFound = "coordsTranslation.serverNotFound"
|
||||||
|
CoordsTranslationSuccess = "coordsTranslation.success"
|
||||||
|
CoordsTranslationMessage = "coordsTranslation.message"
|
||||||
|
CoordsTranslationTitle = "coordsTranslation.title"
|
||||||
|
|
||||||
|
DisableCoordsTranslationSuccess = "disableCoordsTranslation.success"
|
||||||
)
|
)
|
||||||
|
|
Reference in New Issue