add option to enable showing self-conquers
This commit is contained in:
parent
860499461e
commit
6b0e4c7a06
|
@ -27,12 +27,12 @@ func (e ennoblements) getLostVillagesByTribe(tribeID int) ennoblements {
|
|||
return filtered
|
||||
}
|
||||
|
||||
func (e ennoblements) getConqueredVillagesByTribe(tribeID int) ennoblements {
|
||||
func (e ennoblements) getConqueredVillagesByTribe(tribeID int, showSelfConquers bool) ennoblements {
|
||||
filtered := ennoblements{}
|
||||
for _, ennoblement := range e {
|
||||
if isPlayerTribeNil(ennoblement.NewOwner) ||
|
||||
ennoblement.NewOwner.Tribe.ID != tribeID ||
|
||||
(!isPlayerTribeNil(ennoblement.OldOwner) && ennoblement.OldOwner.Tribe.ID == tribeID) {
|
||||
(!showSelfConquers && !isPlayerTribeNil(ennoblement.OldOwner) && ennoblement.OldOwner.Tribe.ID == tribeID) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, ennoblement)
|
||||
|
|
|
@ -52,7 +52,7 @@ func (h *handler) loadEnnoblements(servers []string) map[string]ennoblements {
|
|||
|
||||
lastEnnoblementAt, ok := h.lastEnnoblementAt[w]
|
||||
if !ok {
|
||||
lastEnnoblementAt = time.Now().Add(-1 * time.Minute)
|
||||
lastEnnoblementAt = time.Now().Add(-60 * time.Minute)
|
||||
}
|
||||
|
||||
m[w] = filterEnnoblements(es, lastEnnoblementAt)
|
||||
|
@ -141,10 +141,11 @@ func (h *handler) checkEnnoblements() {
|
|||
}
|
||||
|
||||
if group.ConqueredVillagesChannelID != "" {
|
||||
for _, ennoblement := range ennoblements.getConqueredVillagesByTribe(observation.TribeID) {
|
||||
for _, ennoblement := range ennoblements.getConqueredVillagesByTribe(observation.TribeID, group.ShowSelfConquers) {
|
||||
isBarbarian := isPlayerNil(ennoblement.OldOwner) || ennoblement.OldOwner.ID == 0
|
||||
if (!isPlayerTribeNil(ennoblement.OldOwner) &&
|
||||
group.Observations.Contains(observation.Server, ennoblement.OldOwner.Tribe.ID)) ||
|
||||
isInTheSameGroup := !isPlayerTribeNil(ennoblement.OldOwner) &&
|
||||
group.Observations.Contains(observation.Server, ennoblement.OldOwner.Tribe.ID)
|
||||
if (!group.ShowSelfConquers && isInTheSameGroup) ||
|
||||
(!group.ShowEnnobledBarbarians && isBarbarian) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ const (
|
|||
ConqueredVillagesCommand Command = "conqueredvillages"
|
||||
DisableConqueredVillagesCommand Command = "disableconqueredvillages"
|
||||
ChangeLanguageCommand Command = "changelanguage"
|
||||
ShowSelfConquersCommand Command = "showselfconquers"
|
||||
)
|
||||
|
||||
func (s *Session) handleAddGroupCommand(ctx commandCtx, m *discordgo.MessageCreate) {
|
||||
|
@ -778,7 +779,7 @@ func (s *Session) handleObservationsCommand(ctx commandCtx, m *discordgo.Message
|
|||
})
|
||||
|
||||
msg := &EmbedMessage{}
|
||||
if len(observations) <= 0 || err != nil || langVersionList != nil {
|
||||
if len(observations) <= 0 || err != nil || langVersionList == nil || langVersionList.Items == nil {
|
||||
msg.Append("-")
|
||||
} else {
|
||||
for i, observation := range observations {
|
||||
|
@ -847,8 +848,8 @@ func (s *Session) handleShowEnnobledBarbariansCommand(ctx commandCtx, m *discord
|
|||
if err != nil || group.ServerID != m.GuildID {
|
||||
s.SendMessage(m.ChannelID,
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "observations.groupNotFound",
|
||||
DefaultMessage: message.FallbackMsg("observations.groupNotFound", "{{.Mention}} Group not found."),
|
||||
MessageID: "showEnnobledBarbs.groupNotFound",
|
||||
DefaultMessage: message.FallbackMsg("showEnnobledBarbs.groupNotFound", "{{.Mention}} Group not found."),
|
||||
TemplateData: map[string]interface{}{
|
||||
"Mention": m.Author.Mention(),
|
||||
},
|
||||
|
@ -961,4 +962,91 @@ func (s *Session) handleChangeLanguageCommand(ctx commandCtx, m *discordgo.Messa
|
|||
"Mention": m.Author.Mention(),
|
||||
},
|
||||
}))
|
||||
|
||||
}
|
||||
func (s *Session) handleShowSelfConquersCommand(ctx commandCtx, m *discordgo.MessageCreate, args ...string) {
|
||||
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
|
||||
return
|
||||
}
|
||||
|
||||
argsLength := len(args)
|
||||
if argsLength > 1 {
|
||||
s.sendUnknownCommandError(m.Author.Mention(), m.ChannelID, args[1:argsLength]...)
|
||||
return
|
||||
} else if argsLength < 1 {
|
||||
s.SendMessage(m.ChannelID,
|
||||
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "help.showselfconquers",
|
||||
DefaultMessage: message.FallbackMsg("help.showselfconquers",
|
||||
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about self-conquers between tribes in one group."),
|
||||
TemplateData: map[string]interface{}{
|
||||
"Command": ShowSelfConquersCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
"GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
},
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
groupID, err := strconv.Atoi(args[0])
|
||||
if err != nil || groupID <= 0 {
|
||||
s.SendMessage(m.ChannelID,
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "showSelfConquers.invalidGroupID",
|
||||
DefaultMessage: message.FallbackMsg("showSelfConquers.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,
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "showSelfConquers.groupNotFound",
|
||||
DefaultMessage: message.FallbackMsg("showSelfConquers.groupNotFound", "{{.Mention}} Group not found."),
|
||||
TemplateData: map[string]interface{}{
|
||||
"Mention": m.Author.Mention(),
|
||||
},
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
oldValue := group.ShowSelfConquers
|
||||
group.ShowSelfConquers = !oldValue
|
||||
if err := s.cfg.GroupRepository.Update(context.Background(), group); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
if oldValue {
|
||||
s.SendMessage(m.ChannelID,
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "showSelfConquers.success_1",
|
||||
DefaultMessage: message.FallbackMsg("showSelfConquers.success_1",
|
||||
"{{.Mention}} Notifications about self-conquers will no longer show up."),
|
||||
TemplateData: map[string]interface{}{
|
||||
"Mention": m.Author.Mention(),
|
||||
},
|
||||
}))
|
||||
} else {
|
||||
s.SendMessage(m.ChannelID,
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "showSelfConquers.success_2",
|
||||
DefaultMessage: message.FallbackMsg("showSelfConquers.success_2",
|
||||
"{{.Mention}} Enabled notifications about self-conquers."),
|
||||
TemplateData: map[string]interface{}{
|
||||
"Mention": m.Author.Mention(),
|
||||
},
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,8 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
|
|||
s.handleLostVillagesCommand(ctx, m, args...)
|
||||
case DisableLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
|
||||
s.handleDisableLostVillagesCommand(ctx, m, args...)
|
||||
case ShowSelfConquersCommand.WithPrefix(s.cfg.CommandPrefix):
|
||||
s.handleShowSelfConquersCommand(ctx, m, args...)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,7 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
|
|||
commandsForGuildAdmins2 := fmt.Sprintf(`
|
||||
- %s
|
||||
- %s
|
||||
- %s
|
||||
- %s
|
||||
`,
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
|
@ -211,6 +212,15 @@ func (s *Session) handleHelpCommand(ctx commandCtx, m *discordgo.MessageCreate)
|
|||
"Languages": getAvailableLanguages(),
|
||||
},
|
||||
}),
|
||||
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "help.showselfconquers",
|
||||
DefaultMessage: message.FallbackMsg("help.showselfconquers",
|
||||
"**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about self-conquers between tribes in one group."),
|
||||
TemplateData: map[string]interface{}{
|
||||
"Command": ShowSelfConquersCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
"GroupsCommand": GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
forAdmins := ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"help.lostvillages": "**{{.Command}}** [group id from {{.GroupsCommand}}] - changes the channel on which notifications about lost village will show. **IMPORTANT!** Run this command on the channel you want to display these notifications.",
|
||||
"help.disablelostvillages": "**{{.Command}}** [group id from {{.GroupsCommand}}] - disable notifications about lost villages.",
|
||||
"help.changelanguage": "**{{.Command}}** [{{.Languages}}] - change language.",
|
||||
"help.showselfconquers": "**{{.Command}}** [group id from {{.GroupsCommand}}] - enables/disables notifications about self-conquers between tribes in one group.",
|
||||
|
||||
"tribe.invalidPage": "{{.Mention}} The page must be a number greater than 0.",
|
||||
"tribe.noTribeID": "{{.Mention}} You haven't entered the tribe ID.",
|
||||
|
@ -85,6 +86,11 @@
|
|||
"changeLanguage.languageNotSupported": "{{.Mention}} Language not supported.",
|
||||
"changeLanguage.success": "{{.Mention}} The language has been changed.",
|
||||
|
||||
"showSelfConquers.invalidGroupID": "{{.Mention}} The group ID must be a number greater than 0.",
|
||||
"showSelfConquers.groupNotFound": "{{.Mention}} Group not found.",
|
||||
"showSelfConquers.success_1": "{{.Mention}} Notifications about self-conquers will no longer show up.",
|
||||
"showSelfConquers.success_2": "{{.Mention}} Enabled notifications about self-conquers.",
|
||||
|
||||
"cron.lostVillages.title": "Lost villages",
|
||||
"cron.conqueredVillages.title": "Conquered villages",
|
||||
"cron.checkEnnoblements.msgLine": "{{.NewOwner}} [{{.NewOwnerTribe}}] has conquered the village {{.Village}} (Old owner: {{.OldOwner}} [{{.OldOwnerTribe}}])",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"help.lostvillages": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - zmienia kanał na którym będą się pojawiać informację o straconych wioskach w danej grupie. **WAŻNE!** Wywołaj tę komendę na kanale na którym chcesz dostawać te powiadomienia.",
|
||||
"help.disablelostvillages": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - wyłącza powiadomienia o straconych wioskach w danej grupie.",
|
||||
"help.changelanguage": "**{{.Command}}** [{{.Languages}}] - zmień język.",
|
||||
"help.showselfconquers": "**{{.Command}}** [id grupy z {{.GroupsCommand}}] - włącza/wyłącza notyfikacje o podbiciach plemion należących do jednej grupy.",
|
||||
|
||||
"tribe.invalidPage": "{{.Mention}} Strona musi być liczbą większą od 0.",
|
||||
"tribe.noTribeID": "{{.Mention}} Nie wprowadziłeś ID plemienia.",
|
||||
|
@ -82,6 +83,11 @@
|
|||
"showEnnobledBarbs.success_1": "{{.Mention}} Powiadomienia o podbitych barbarkach nie będą się już dłużej pokazywały.",
|
||||
"showEnnobledBarbs.success_2": "{{.Mention}} Włączono powiadomienia o podbitych barbarkach.",
|
||||
|
||||
"showSelfConquers.invalidGroupID": "{{.Mention}} ID grupy musi być liczbą większą od 0.",
|
||||
"showSelfConquers.groupNotFound": "{{.Mention}} Grupa nie została znaleziona.",
|
||||
"showSelfConquers.success_1": "{{.Mention}} Powiadomieniach o podbiciach plemion w tej samej grupie nie będą się już pokazywały.",
|
||||
"showSelfConquers.success_2": "{{.Mention}} Włączono powiadomienia o podbiciach plemion w tej samej grupie.",
|
||||
|
||||
"changeLanguage.languageNotSupported": "{{.Mention}} Język nie jest obsługiwany.",
|
||||
"changeLanguage.success": "{{.Mention}} Język został zmieniony.",
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ type Group struct {
|
|||
ConqueredVillagesChannelID string `pg:",use_zero" json:"conqueredVillagesChannelID" gqlgen:"conqueredVillagesChannelID"`
|
||||
LostVillagesChannelID string `pg:",use_zero" json:"lostVillagesChannelID" gqlgen:"lostVillagesChannelID"`
|
||||
ShowEnnobledBarbarians bool `pg:",use_zero"`
|
||||
ShowSelfConquers bool `pg:",use_zero"`
|
||||
ServerID string `pg:"on_delete:CASCADE,use_zero" json:"serverID" gqlgen:"serverID"`
|
||||
Server *Server `json:"server,omitempty" gqlgen:"server"`
|
||||
Observations Observations `json:"observation,omitempty" gqlgen:"observation"`
|
||||
|
|
Reference in New Issue