add three new commands: unobserveconqueredvillages, unobservelostvillages, author

This commit is contained in:
Dawid Wysokiński 2020-06-26 09:47:33 +02:00 committed by Kichiyaki
parent 93bb8b5026
commit 340c1f69e9
5 changed files with 107 additions and 36 deletions

View File

@ -21,18 +21,21 @@ const (
type Command string type Command string
const ( const (
HelpCommand Command = "help" HelpCommand Command = "help"
ObserveCommand Command = "observe" ObserveCommand Command = "observe"
ObservationsCommand Command = "observations" ObservationsCommand Command = "observations"
UnObserveCommand Command = "unobserve" UnObserveCommand Command = "unobserve"
LostVillagesCommand Command = "lostvillages" LostVillagesCommand Command = "lostvillages"
ConqueredVillagesCommand Command = "conqueredvillages" UnObserveLostVillagesCommand Command = "unobservelostvillages"
TribeCommand Command = "tribe" ConqueredVillagesCommand Command = "conqueredvillages"
TopAttCommand Command = "topatt" UnObserveConqueredVillagesCommand Command = "unobserveconqueredvillages"
TopDefCommand Command = "topdef" TribeCommand Command = "tribe"
TopSuppCommand Command = "topsupp" TopAttCommand Command = "topatt"
TopTotalCommand Command = "toptotal" TopDefCommand Command = "topdef"
TopPointsCommand Command = "toppoints" TopSuppCommand Command = "topsupp"
TopTotalCommand Command = "toptotal"
TopPointsCommand Command = "toppoints"
AuthorCommand Command = "author"
) )
func (cmd Command) String() string { func (cmd Command) String() string {
@ -46,11 +49,12 @@ func (cmd Command) WithPrefix(prefix string) string {
func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) { func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
tribeCMDWithPrefix := TribeCommand.WithPrefix(s.cfg.CommandPrefix) tribeCMDWithPrefix := TribeCommand.WithPrefix(s.cfg.CommandPrefix)
commandsForAll := fmt.Sprintf(` commandsForAll := fmt.Sprintf(`
- %s %s [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RA z plemion o podanych id - **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RA z plemion o podanych id
- %s %s [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RO z plemion o podanych id - **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RO z plemion o podanych id
- %s %s [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RW z plemion o podanych id - **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największym RW z plemion o podanych id
- %s %s [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największej liczbie pokonanych z plemion o podanych id - **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największej liczbie pokonanych z plemion o podanych id
- %s %s [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największej liczbie punktów z plemion o podanych id - **%s %s** [serwer] [strona] [id1] [id2] [id3] [n id] - wyświetla graczy o największej liczbie punktów z plemion o podanych id
- **%s** - kontakt z autorem bota
`, `,
tribeCMDWithPrefix, tribeCMDWithPrefix,
TopAttCommand.String(), TopAttCommand.String(),
@ -61,21 +65,28 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
tribeCMDWithPrefix, tribeCMDWithPrefix,
TopTotalCommand.String(), TopTotalCommand.String(),
tribeCMDWithPrefix, tribeCMDWithPrefix,
TopPointsCommand.String()) TopPointsCommand.String(),
AuthorCommand.WithPrefix(s.cfg.CommandPrefix),
)
commandsForGuildAdmins := fmt.Sprintf(` commandsForGuildAdmins := fmt.Sprintf(`
- %s [świat] [id] - dodaje plemię z danego świata do obserwowanych - **%s** [świat] [id] - dodaje plemię z danego świata do obserwowanych
- %s - wyświetla wszystkie obserwowane plemiona - **%s** - wyświetla wszystkie obserwowane plemiona
- %s [id z %s] - usuwa plemię z obserwowanych - **%s** [id z %s] - usuwa plemię z obserwowanych
- %s - ustawia kanał na którym będą wyświetlać się informacje o straconych wioskach - **%s** - ustawia kanał na którym będą wyświetlać się informacje o podbitych wioskach
- %s - ustawia kanał na którym będą wyświetlać się informacje o podbitych wioskach - **%s** - informacje o podbitych wioskach na wybranym kanale nie będą się już pojawiały
- **%s** - ustawia kanał na którym będą wyświetlać się informacje o straconych wioskach
- **%s** - informacje o podbitych wioskach na wybranym kanale nie będą się już pojawiały
`, `,
ObserveCommand.WithPrefix(s.cfg.CommandPrefix), ObserveCommand.WithPrefix(s.cfg.CommandPrefix),
ObservationsCommand.WithPrefix(s.cfg.CommandPrefix), ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
UnObserveCommand.WithPrefix(s.cfg.CommandPrefix), UnObserveCommand.WithPrefix(s.cfg.CommandPrefix),
ObservationsCommand.WithPrefix(s.cfg.CommandPrefix), ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix)) UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
)
s.SendEmbed(m.ChannelID, NewEmbed(). s.SendEmbed(m.ChannelID, NewEmbed().
SetTitle("Pomoc"). SetTitle("Pomoc").
@ -85,6 +96,10 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) {
MessageEmbed) MessageEmbed)
} }
func (s *Session) handleAuthorCommand(m *discordgo.MessageCreate) {
s.SendMessage(m.ChannelID, fmt.Sprintf("%s Discord: Kichiyaki#2064.", m.Author.Mention()))
}
func (s *Session) handleTribeCommand(m *discordgo.MessageCreate, args ...string) { func (s *Session) handleTribeCommand(m *discordgo.MessageCreate, args ...string) {
argsLength := len(args) argsLength := len(args)
if argsLength < 4 { if argsLength < 4 {
@ -230,6 +245,50 @@ func (s *Session) handleTribeCommand(m *discordgo.MessageCreate, args ...string)
MessageEmbed) MessageEmbed)
} }
func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate) {
if m.GuildID == "" {
return
}
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return
}
server := &models.Server{
ID: m.GuildID,
}
err := s.cfg.ServerRepository.Store(context.Background(), server)
if err != nil {
return
}
server.ConqueredVillagesChannelID = m.ChannelID
go s.cfg.ServerRepository.Update(context.Background(), server)
s.SendMessage(m.ChannelID,
fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o podbitych wioskach.", m.Author.Mention()))
}
func (s *Session) handleUnObserveConqueredVillagesCommand(m *discordgo.MessageCreate) {
if m.GuildID == "" {
return
}
if has, err := s.memberHasPermission(m.GuildID, m.Author.ID, discordgo.PermissionAdministrator); err != nil || !has {
return
}
server := &models.Server{
ID: m.GuildID,
}
err := s.cfg.ServerRepository.Store(context.Background(), server)
if err != nil {
return
}
if server.ConqueredVillagesChannelID != "" {
server.ConqueredVillagesChannelID = ""
go s.cfg.ServerRepository.Update(context.Background(), server)
}
s.SendMessage(m.ChannelID,
fmt.Sprintf("%s Informacje o podbitych wioskach nie będą się już pojawiały.", m.Author.Mention()))
}
func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate) { func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate) {
if m.GuildID == "" { if m.GuildID == "" {
return return
@ -251,7 +310,7 @@ func (s *Session) handleLostVillagesCommand(m *discordgo.MessageCreate) {
fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o straconych wioskach.", m.Author.Mention())) fmt.Sprintf("%s Pomyślnie zmieniono kanał na którym będą się wyświetlać informacje o straconych wioskach.", m.Author.Mention()))
} }
func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate) { func (s *Session) handleUnObserveLostVillagesCommand(m *discordgo.MessageCreate) {
if m.GuildID == "" { if m.GuildID == "" {
return return
} }
@ -266,10 +325,12 @@ func (s *Session) handleConqueredVillagesCommand(m *discordgo.MessageCreate) {
if err != nil { if err != nil {
return return
} }
server.ConqueredVillagesChannelID = m.ChannelID if server.LostVillagesChannelID != "" {
go s.cfg.ServerRepository.Update(context.Background(), server) server.LostVillagesChannelID = ""
go s.cfg.ServerRepository.Update(context.Background(), server)
}
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.", m.Author.Mention())) fmt.Sprintf("%s Informacje o straconych wioskach nie będą się już pojawiały.", m.Author.Mention()))
} }
func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...string) { func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...string) {

View File

@ -79,16 +79,22 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
switch splitted[0] { switch splitted[0] {
case HelpCommand.WithPrefix(s.cfg.CommandPrefix): case HelpCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleHelpCommand(m) s.handleHelpCommand(m)
case AuthorCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleAuthorCommand(m)
case ObserveCommand.WithPrefix(s.cfg.CommandPrefix): case ObserveCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleObserveCommand(m, args...) s.handleObserveCommand(m, args...)
case UnObserveCommand.WithPrefix(s.cfg.CommandPrefix): case UnObserveCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleUnObserveCommand(m, args...) s.handleUnObserveCommand(m, args...)
case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix): case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleObservationsCommand(m) s.handleObservationsCommand(m)
case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleLostVillagesCommand(m)
case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleConqueredVillagesCommand(m) s.handleConqueredVillagesCommand(m)
case UnObserveConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleUnObserveConqueredVillagesCommand(m)
case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleLostVillagesCommand(m)
case UnObserveLostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleUnObserveLostVillagesCommand(m)
case TribeCommand.WithPrefix(s.cfg.CommandPrefix): case TribeCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleTribeCommand(m, args...) s.handleTribeCommand(m, args...)
} }

View File

@ -1,10 +1,12 @@
package models package models
type Observation struct { type Observation struct {
tableName struct{} `pg:",alias:observation"`
ID int `json:"id" gqlgen:"id"` ID int `json:"id" gqlgen:"id"`
World string `pg:"unique:group_1" json:"world" gqlgen:"world"` World string `pg:"unique:group_1,use_zero" json:"world" gqlgen:"world"`
TribeID int `pg:"unique:group_1" json:"tribeID" gqlgen:"tribeID"` TribeID int `pg:"unique:group_1,use_zero" json:"tribeID" gqlgen:"tribeID"`
ServerID string `pg:"on_delete:CASCADE,unique:group_1" json:"serverID" gqlgen:"serverID"` ServerID string `pg:"on_delete:CASCADE,unique:group_1,use_zero" json:"serverID" gqlgen:"serverID"`
Server *Server `json:"server,omitempty" gqlgen:"server"` Server *Server `json:"server,omitempty" gqlgen:"server"`
} }

View File

@ -1,9 +1,11 @@
package models package models
type Server struct { type Server struct {
tableName struct{} `pg:",alias:server"`
ID string `pg:",pk" json:"id" gqlgen:"id"` ID string `pg:",pk" json:"id" gqlgen:"id"`
ConqueredVillagesChannelID string `json:"conqueredVillagesChannelID" gqlgen:"conqueredVillagesChannelID"` ConqueredVillagesChannelID string `pg:",use_zero" json:"conqueredVillagesChannelID" gqlgen:"conqueredVillagesChannelID"`
LostVillagesChannelID string `json:"lostVillagesChannelID" gqlgen:"lostVillagesChannelID"` LostVillagesChannelID string `pg:",use_zero" json:"lostVillagesChannelID" gqlgen:"lostVillagesChannelID"`
Observations Observations `json:"observation,omitempty" gqlgen:"observation"` Observations Observations `json:"observation,omitempty" gqlgen:"observation"`
} }

View File

@ -43,7 +43,7 @@ func (repo *pgRepo) Update(ctx context.Context, server *models.Server) error {
WherePK(). WherePK().
Returning("*"). Returning("*").
Context(ctx). Context(ctx).
UpdateNotZero(); err != nil { Update(); err != nil {
return err return err
} }
return nil return nil