the lostvillages, conqueredvillages, unobservelostvillages, unobserveconqueredvillages commands are fully translatable

This commit is contained in:
Dawid Wysokiński 2020-07-19 14:22:41 +02:00 committed by Kichiyaki
parent 7e53a6f745
commit 9828a6cba9
3 changed files with 155 additions and 43 deletions

View File

@ -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 { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return return
} }
@ -147,17 +147,22 @@ func (s *Session) handleGroupsCommand(m *discordgo.MessageCreate) {
} }
if msg == "" { 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(). s.SendEmbed(m.ChannelID, NewEmbed().
SetTitle("Lista grup"). SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
AddField("Indeks | ID", msg). MessageID: "groups.title",
SetFooter("Strona 1 z 1"). DefaultMessage: message.FallbackMsg("groups.title", "Group list"),
})).
AddField("Index | ID", msg).
MessageEmbed) 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 { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return return
} }
@ -168,16 +173,27 @@ func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate, arg
return return
} else if argsLength < 1 { } else if argsLength < 1 {
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf("%s %s [id grupy]", m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), MessageID: "help.conqueredvillages",
ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) 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 return
} }
groupID, err := strconv.Atoi(args[0]) groupID, err := strconv.Atoi(args[0])
if err != nil { if err != nil {
s.SendMessage(m.ChannelID, 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 return
} }
@ -187,18 +203,29 @@ func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate, arg
}) })
if err != nil || len(groups) == 0 { if err != nil || len(groups) == 0 {
s.SendMessage(m.ChannelID, 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 return
} }
groups[0].ConqueredVillagesChannelID = m.ChannelID groups[0].ConqueredVillagesChannelID = m.ChannelID
go s.cfg.GroupRepository.Update(context.Background(), groups[0]) go s.cfg.GroupRepository.Update(context.Background(), groups[0])
s.SendMessage(m.ChannelID, 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).", ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), groupID)) 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 { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return return
} }
@ -209,16 +236,27 @@ func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCr
return return
} else if argsLength < 1 { } else if argsLength < 1 {
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf("%s %s [id grupy]", m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), MessageID: "help.unobserveconqueredvillages",
UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) 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 return
} }
groupID, err := strconv.Atoi(args[0]) groupID, err := strconv.Atoi(args[0])
if err != nil { if err != nil {
s.SendMessage(m.ChannelID, 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 return
} }
@ -228,7 +266,13 @@ func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCr
}) })
if err != nil || len(groups) == 0 { if err != nil || len(groups) == 0 {
s.SendMessage(m.ChannelID, 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 return
} }
@ -237,10 +281,16 @@ func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCr
go s.cfg.GroupRepository.Update(context.Background(), groups[0]) go s.cfg.GroupRepository.Update(context.Background(), groups[0])
} }
s.SendMessage(m.ChannelID, 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 { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return return
} }
@ -251,16 +301,27 @@ func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate, args ...
return return
} else if argsLength < 1 { } else if argsLength < 1 {
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf("%s %s [id grupy]", m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), MessageID: "help.lostvillages",
LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) 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 return
} }
groupID, err := strconv.Atoi(args[0]) groupID, err := strconv.Atoi(args[0])
if err != nil { if err != nil {
s.SendMessage(m.ChannelID, 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 return
} }
@ -270,19 +331,30 @@ func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate, args ...
}) })
if err != nil || len(groups) == 0 { if err != nil || len(groups) == 0 {
s.SendMessage(m.ChannelID, 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 return
} }
groups[0].LostVillagesChannelID = m.ChannelID groups[0].LostVillagesChannelID = m.ChannelID
go s.cfg.GroupRepository.Update(context.Background(), groups[0]) go s.cfg.GroupRepository.Update(context.Background(), groups[0])
s.SendMessage(m.ChannelID, 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).", ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), MessageID: "lostVillages.success",
groupID)) 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 { if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return return
} }
@ -293,16 +365,27 @@ func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate,
return return
} else if argsLength < 1 { } else if argsLength < 1 {
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf("%s %s [id grupy]", m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), MessageID: "help.unobservelostvillages",
UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix))) 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 return
} }
groupID, err := strconv.Atoi(args[0]) groupID, err := strconv.Atoi(args[0])
if err != nil { if err != nil {
s.SendMessage(m.ChannelID, 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 return
} }
@ -312,7 +395,13 @@ func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate,
}) })
if err != nil || len(groups) == 0 { if err != nil || len(groups) == 0 {
s.SendMessage(m.ChannelID, 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 return
} }
@ -322,9 +411,13 @@ func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate,
} }
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf("%s Informacje o straconych wioskach grupy %d nie będą się już pojawiały.", ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
m.Author.Mention(), MessageID: "unObserveLostVillages.success",
groupID)) 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) { func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...string) {

View File

@ -113,7 +113,7 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
case DeleteGroupCommand.WithPrefix(s.cfg.CommandPrefix): case DeleteGroupCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleDeleteGroupCommand(ctx, m, args...) s.handleDeleteGroupCommand(ctx, m, args...)
case GroupsCommand.WithPrefix(s.cfg.CommandPrefix): case GroupsCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleGroupsCommand(m) s.handleGroupsCommand(ctx, m)
case ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix): case ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleShowEnnobledBarbariansCommand(m, args...) s.handleShowEnnobledBarbariansCommand(m, args...)
@ -124,13 +124,13 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix): case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleObservationsCommand(m, args...) s.handleObservationsCommand(m, args...)
case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleConqueredVillagesCommand(m, args...) s.handleConqueredVillagesCommand(ctx, m, args...)
case UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleUnObserveConqueredVillagesCommand(m, args...) s.handleUnObserveConqueredVillagesCommand(ctx, m, args...)
case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleLostVillagesCommand(m, args...) s.handleLostVillagesCommand(ctx, m, args...)
case UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleUnObserveLostVillagesCommand(m, args...) s.handleUnObserveLostVillagesCommand(ctx, m, args...)
} }
} }

View File

@ -39,6 +39,25 @@
"deleteGroup.invalidID": "{{.Mention}} The group ID must be a number greater than 0.", "deleteGroup.invalidID": "{{.Mention}} The group ID must be a number greater than 0.",
"deleteGroup.success": "{{.Mention}} The group has been deleted.", "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.", "api.defaultError": "{{.Mention}} There was an error fetching data from the API, please try again later.",
"pagination.labelDisplayedPage": "Page: {{.Page}} from {{.MaxPage}}", "pagination.labelDisplayedPage": "Page: {{.Page}} from {{.MaxPage}}",