add new command showennobledbarbs [group ID]
This commit is contained in:
parent
d4c518749e
commit
92717b6f0a
|
@ -48,7 +48,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)
|
||||
|
@ -146,8 +146,10 @@ func (h *handler) checkLastEnnoblements() {
|
|||
if group.ConqueredVillagesChannelID != "" {
|
||||
msg := &discord.EmbedMessage{}
|
||||
for _, ennoblement := range ennoblements.getConqueredVillagesByTribe(observation.TribeID) {
|
||||
if !isPlayerTribeNil(ennoblement.OldOwner) &&
|
||||
group.Observations.Contains(observation.Server, ennoblement.OldOwner.Tribe.ID) {
|
||||
isBarbarian := isPlayerNil(ennoblement.OldOwner) || ennoblement.OldOwner.ID == 0
|
||||
if (!isPlayerTribeNil(ennoblement.OldOwner) &&
|
||||
group.Observations.Contains(observation.Server, ennoblement.OldOwner.Tribe.ID)) ||
|
||||
(!group.ShowEnnobledBarbarians && isBarbarian) {
|
||||
continue
|
||||
}
|
||||
newMsgDataConfig := newMessageConfig{
|
||||
|
|
|
@ -20,6 +20,7 @@ const (
|
|||
AddGroupCommand Command = "addgroup"
|
||||
DeleteGroupCommand Command = "deletegroup"
|
||||
GroupsCommand Command = "groups"
|
||||
ShowEnnobledBarbariansCommand Command = "showennobledbarbs"
|
||||
ObserveCommand Command = "observe"
|
||||
ObservationsCommand Command = "observations"
|
||||
UnObserveCommand Command = "unobserve"
|
||||
|
@ -53,7 +54,8 @@ func (s *Session) handleAddGroupCommand(m *discordgo.MessageCreate) {
|
|||
}
|
||||
|
||||
group := &models.Group{
|
||||
ServerID: m.GuildID,
|
||||
ServerID: m.GuildID,
|
||||
ShowEnnobledBarbarians: true,
|
||||
}
|
||||
if err := s.cfg.GroupRepository.Store(context.Background(), group); err != nil {
|
||||
s.SendMessage(m.ChannelID,
|
||||
|
@ -111,6 +113,7 @@ func (s *Session) handleGroupsCommand(m *discordgo.MessageCreate) {
|
|||
|
||||
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &models.GroupFilter{
|
||||
ServerID: []string{m.GuildID},
|
||||
Order: []string{"id ASC"},
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -475,6 +478,7 @@ func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ...
|
|||
}
|
||||
observations, _, err := s.cfg.ObservationRepository.Fetch(context.Background(), &models.ObservationFilter{
|
||||
GroupID: []int{groupID},
|
||||
Order: []string{"id ASC"},
|
||||
})
|
||||
if err != nil {
|
||||
s.SendMessage(m.ChannelID, m.Author.Mention()+` Wystąpił błąd wewnętrzny, prosimy spróbować później.`)
|
||||
|
@ -540,3 +544,52 @@ func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate, args ...
|
|||
SetFooter("Strona 1 z 1").
|
||||
MessageEmbed)
|
||||
}
|
||||
|
||||
func (s *Session) handleShowEnnobledBarbariansCommand(m *discordgo.MessageCreate, args ...string) {
|
||||
if m.GuildID == "" {
|
||||
return
|
||||
}
|
||||
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,
|
||||
fmt.Sprintf(`%s %s [id grupy]`,
|
||||
m.Author.Mention(),
|
||||
ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix)))
|
||||
return
|
||||
}
|
||||
|
||||
groupID, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
s.SendMessage(m.ChannelID,
|
||||
fmt.Sprintf(`%s ID grupy powinno być liczbą całkowitą większą od 0.`,
|
||||
m.Author.Mention()))
|
||||
return
|
||||
}
|
||||
group, err := s.cfg.GroupRepository.GetByID(context.Background(), groupID)
|
||||
if err != nil || group.ServerID != m.GuildID {
|
||||
s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie znaleziono grupy.`)
|
||||
return
|
||||
}
|
||||
|
||||
oldValue := group.ShowEnnobledBarbarians
|
||||
group.ShowEnnobledBarbarians = !oldValue
|
||||
if err := s.cfg.GroupRepository.Update(context.Background(), group); err != nil {
|
||||
s.SendMessage(m.ChannelID, m.Author.Mention()+` Wewnętrzny błąd serwera.`)
|
||||
return
|
||||
}
|
||||
|
||||
if oldValue {
|
||||
s.SendMessage(m.ChannelID,
|
||||
m.Author.Mention()+` Informacje o podbitych wioskach barbarzyńskich nie będą się już pojawiały.`)
|
||||
} else {
|
||||
s.SendMessage(m.ChannelID,
|
||||
m.Author.Mention()+` Włączono wyświetlanie informacji o podbitych wioskach barbarzyńskich.`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,6 +93,8 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
|
|||
case GroupsCommand.WithPrefix(s.cfg.CommandPrefix):
|
||||
s.handleGroupsCommand(m)
|
||||
|
||||
case ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix):
|
||||
s.handleShowEnnobledBarbariansCommand(m, args...)
|
||||
case ObserveCommand.WithPrefix(s.cfg.CommandPrefix):
|
||||
s.handleObserveCommand(m, args...)
|
||||
case UnObserveCommand.WithPrefix(s.cfg.CommandPrefix):
|
||||
|
|
|
@ -50,6 +50,7 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
|
|||
- **%s** - tworzy nową grupę
|
||||
- **%s** - lista grup
|
||||
- **%s** [id grupy z %s] - usuwa grupę
|
||||
- **%s** [id grupy z %s] - włącza/wyłącza wyświetlanie powiadomień o podbitych wioskach barbarzyńskich
|
||||
- **%s** [id grupy z %s] [świat] [id plemienia] - dodaje plemię z danego świata do obserwowanych
|
||||
- **%s** [id grupy z %s] - wyświetla wszystkie obserwowane plemiona
|
||||
- **%s** [id grupy z %s] [id z %s] - usuwa plemię z obserwowanych
|
||||
|
@ -62,6 +63,8 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
|
|||
GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
DeleteGroupCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
ShowEnnobledBarbariansCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
ObserveCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
GroupsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
|
||||
|
@ -88,7 +91,7 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
|
|||
}
|
||||
|
||||
func (s *Session) handleAuthorCommand(m *discordgo.MessageCreate) {
|
||||
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Discord: Kichiyaki#2064.", m.Author.Mention()))
|
||||
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Discord: Kichiyaki#2064 | https://dawid-wysokinski.pl/#contact.", m.Author.Mention()))
|
||||
}
|
||||
|
||||
func (s *Session) handleTribeCommand(m *discordgo.MessageCreate, args ...string) {
|
||||
|
|
|
@ -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"`
|
||||
ServerID string `pg:"on_delete:CASCADE,use_zero" json:"serverID" gqlgen:"serverID"`
|
||||
ShowEnnobledBarbarians bool `pg:",use_zero"`
|
||||
Server *Server `json:"server,omitempty" gqlgen:"server"`
|
||||
Observations Observations `json:"observation,omitempty" gqlgen:"observation"`
|
||||
}
|
||||
|
|
Reference in New Issue