From 9d77cbbd7040abc4d3c45eb44f191812974b3a84 Mon Sep 17 00:00:00 2001 From: Kichiyaki Date: Thu, 18 Jun 2020 15:54:31 +0200 Subject: [PATCH] rename discord commands: delete -> unobserve, list -> observations --- discord/commands.go | 22 +++++++++++++--------- discord/discord.go | 8 ++++---- models/observation.go | 2 +- server/repository/server_pg_repo.go | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/discord/commands.go b/discord/commands.go index 03db915..6c7c3cf 100644 --- a/discord/commands.go +++ b/discord/commands.go @@ -6,6 +6,8 @@ import ( "math" "strconv" + "log" + shared_models "github.com/tribalwarshelp/shared/models" "github.com/bwmarrin/discordgo" @@ -23,8 +25,8 @@ type Command string const ( HelpCommand Command = "help" ObserveCommand Command = "observe" - ListCommand Command = "list" - DeleteCommand Command = "delete" + ObservationsCommand Command = "observations" + UnObserveCommand Command = "unobserve" LostVillagesCommand Command = "lostvillages" ConqueredVillagesCommand Command = "conqueredvillages" TribeCommand Command = "tribe" @@ -71,9 +73,9 @@ func (s *Session) handleHelpCommand(m *discordgo.MessageCreate) { - %s - ustawia kanał na którym będą wyświetlać się informacje o podbitych wioskach `, ObserveCommand.WithPrefix(s.cfg.CommandPrefix), - ListCommand.WithPrefix(s.cfg.CommandPrefix), - DeleteCommand.WithPrefix(s.cfg.CommandPrefix), - ListCommand.WithPrefix(s.cfg.CommandPrefix), + ObservationsCommand.WithPrefix(s.cfg.CommandPrefix), + UnObserveCommand.WithPrefix(s.cfg.CommandPrefix), + ObservationsCommand.WithPrefix(s.cfg.CommandPrefix), LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix)) @@ -306,6 +308,7 @@ func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...strin } err = s.cfg.ServerRepository.Store(context.Background(), dcServer) if err != nil { + log.Print(err) s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`) return } @@ -321,6 +324,7 @@ func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...strin ServerID: dcServer.ID, }) if err != nil { + log.Print(err) s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`) return } @@ -328,7 +332,7 @@ func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...strin s.SendMessage(m.ChannelID, m.Author.Mention()+` Dodano.`) } -func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string) { +func (s *Session) handleUnObserveCommand(m *discordgo.MessageCreate, args ...string) { if m.GuildID == "" { return } @@ -344,7 +348,7 @@ func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string s.SendMessage(m.ChannelID, fmt.Sprintf(`%s %s [id z tw!list]`, m.Author.Mention(), - DeleteCommand.WithPrefix(s.cfg.CommandPrefix))) + UnObserveCommand.WithPrefix(s.cfg.CommandPrefix))) return } @@ -353,7 +357,7 @@ func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string s.SendMessage(m.ChannelID, fmt.Sprintf(`%s %s [id z tw!list]`, m.Author.Mention(), - DeleteCommand.WithPrefix(s.cfg.CommandPrefix))) + UnObserveCommand.WithPrefix(s.cfg.CommandPrefix))) return } @@ -365,7 +369,7 @@ func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string s.SendMessage(m.ChannelID, m.Author.Mention()+` Usunięto.`) } -func (s *Session) handleListCommand(m *discordgo.MessageCreate) { +func (s *Session) handleObservationsCommand(m *discordgo.MessageCreate) { if m.GuildID == "" { return } diff --git a/discord/discord.go b/discord/discord.go index fd544c5..9f68539 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -81,10 +81,10 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre s.handleHelpCommand(m) case ObserveCommand.WithPrefix(s.cfg.CommandPrefix): s.handleObserveCommand(m, args...) - case DeleteCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleDeleteCommand(m, args...) - case ListCommand.WithPrefix(s.cfg.CommandPrefix): - s.handleListCommand(m) + case UnObserveCommand.WithPrefix(s.cfg.CommandPrefix): + s.handleUnObserveCommand(m, args...) + case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix): + s.handleObservationsCommand(m) case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix): s.handleLostVillagesCommand(m) case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): diff --git a/models/observation.go b/models/observation.go index d4308c8..e650b61 100644 --- a/models/observation.go +++ b/models/observation.go @@ -3,7 +3,7 @@ package models type Observation struct { ID int `json:"id" gqlgen:"id"` World string `pg:"unique:group_1" json:"world" gqlgen:"world"` - TribeID int `pg:"unique:group_1" json:"TribeID" gqlgen:"TribeID"` + TribeID int `pg:"unique:group_1" json:"tribeID" gqlgen:"tribeID"` ServerID string `pg:"on_delete:CASCADE,unique:group_1" json:"serverID" gqlgen:"serverID"` Server *Server `json:"server,omitempty" gqlgen:"server"` } diff --git a/server/repository/server_pg_repo.go b/server/repository/server_pg_repo.go index 5fe81db..2116847 100644 --- a/server/repository/server_pg_repo.go +++ b/server/repository/server_pg_repo.go @@ -30,7 +30,7 @@ func (repo *pgRepo) Store(ctx context.Context, server *models.Server) error { Where("id = ?id"). Returning("*"). Context(ctx). - Relation("Tribes"). + Relation("Observations"). SelectOrInsert(); err != nil { return err }