rename discord commands: delete -> unobserve, list -> observations

This commit is contained in:
Dawid Wysokiński 2020-06-18 15:54:31 +02:00 committed by Kichiyaki
parent f16e93469a
commit 9d77cbbd70
4 changed files with 19 additions and 15 deletions

View File

@ -6,6 +6,8 @@ import (
"math" "math"
"strconv" "strconv"
"log"
shared_models "github.com/tribalwarshelp/shared/models" shared_models "github.com/tribalwarshelp/shared/models"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
@ -23,8 +25,8 @@ type Command string
const ( const (
HelpCommand Command = "help" HelpCommand Command = "help"
ObserveCommand Command = "observe" ObserveCommand Command = "observe"
ListCommand Command = "list" ObservationsCommand Command = "observations"
DeleteCommand Command = "delete" UnObserveCommand Command = "unobserve"
LostVillagesCommand Command = "lostvillages" LostVillagesCommand Command = "lostvillages"
ConqueredVillagesCommand Command = "conqueredvillages" ConqueredVillagesCommand Command = "conqueredvillages"
TribeCommand Command = "tribe" 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 - %s - ustawia kanał na którym będą wyświetlać się informacje o podbitych wioskach
`, `,
ObserveCommand.WithPrefix(s.cfg.CommandPrefix), ObserveCommand.WithPrefix(s.cfg.CommandPrefix),
ListCommand.WithPrefix(s.cfg.CommandPrefix), ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
DeleteCommand.WithPrefix(s.cfg.CommandPrefix), UnObserveCommand.WithPrefix(s.cfg.CommandPrefix),
ListCommand.WithPrefix(s.cfg.CommandPrefix), ObservationsCommand.WithPrefix(s.cfg.CommandPrefix),
LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix), LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix),
ConqueredVillagesCommand.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) err = s.cfg.ServerRepository.Store(context.Background(), dcServer)
if err != nil { if err != nil {
log.Print(err)
s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`) s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`)
return return
} }
@ -321,6 +324,7 @@ func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...strin
ServerID: dcServer.ID, ServerID: dcServer.ID,
}) })
if err != nil { if err != nil {
log.Print(err)
s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`) s.SendMessage(m.ChannelID, m.Author.Mention()+` Nie udało się dodać plemienia do obserwowanych.`)
return return
} }
@ -328,7 +332,7 @@ func (s *Session) handleObserveCommand(m *discordgo.MessageCreate, args ...strin
s.SendMessage(m.ChannelID, m.Author.Mention()+` Dodano.`) 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 == "" { if m.GuildID == "" {
return return
} }
@ -344,7 +348,7 @@ func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf(`%s %s [id z tw!list]`, fmt.Sprintf(`%s %s [id z tw!list]`,
m.Author.Mention(), m.Author.Mention(),
DeleteCommand.WithPrefix(s.cfg.CommandPrefix))) UnObserveCommand.WithPrefix(s.cfg.CommandPrefix)))
return return
} }
@ -353,7 +357,7 @@ func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string
s.SendMessage(m.ChannelID, s.SendMessage(m.ChannelID,
fmt.Sprintf(`%s %s [id z tw!list]`, fmt.Sprintf(`%s %s [id z tw!list]`,
m.Author.Mention(), m.Author.Mention(),
DeleteCommand.WithPrefix(s.cfg.CommandPrefix))) UnObserveCommand.WithPrefix(s.cfg.CommandPrefix)))
return return
} }
@ -365,7 +369,7 @@ func (s *Session) handleDeleteCommand(m *discordgo.MessageCreate, args ...string
s.SendMessage(m.ChannelID, m.Author.Mention()+` Usunięto.`) 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 == "" { if m.GuildID == "" {
return return
} }

View File

@ -81,10 +81,10 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
s.handleHelpCommand(m) s.handleHelpCommand(m)
case ObserveCommand.WithPrefix(s.cfg.CommandPrefix): case ObserveCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleObserveCommand(m, args...) s.handleObserveCommand(m, args...)
case DeleteCommand.WithPrefix(s.cfg.CommandPrefix): case UnObserveCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleDeleteCommand(m, args...) s.handleUnObserveCommand(m, args...)
case ListCommand.WithPrefix(s.cfg.CommandPrefix): case ObservationsCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleListCommand(m) s.handleObservationsCommand(m)
case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case LostVillagesCommand.WithPrefix(s.cfg.CommandPrefix):
s.handleLostVillagesCommand(m) s.handleLostVillagesCommand(m)
case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix): case ConqueredVillagesCommand.WithPrefix(s.cfg.CommandPrefix):

View File

@ -3,7 +3,7 @@ package models
type Observation struct { type Observation struct {
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" 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"` ServerID string `pg:"on_delete:CASCADE,unique:group_1" json:"serverID" gqlgen:"serverID"`
Server *Server `json:"server,omitempty" gqlgen:"server"` Server *Server `json:"server,omitempty" gqlgen:"server"`
} }

View File

@ -30,7 +30,7 @@ func (repo *pgRepo) Store(ctx context.Context, server *models.Server) error {
Where("id = ?id"). Where("id = ?id").
Returning("*"). Returning("*").
Context(ctx). Context(ctx).
Relation("Tribes"). Relation("Observations").
SelectOrInsert(); err != nil { SelectOrInsert(); err != nil {
return err return err
} }