diff --git a/bot/handler/coin.go b/bot/handler/coin.go index 439e375..37322f3 100644 --- a/bot/handler/coin.go +++ b/bot/handler/coin.go @@ -1,8 +1,6 @@ package handler import ( - "strings" - "git.kill0.net/chill9/beepboop/bot" "git.kill0.net/chill9/beepboop/lib" "github.com/bwmarrin/discordgo" @@ -13,6 +11,7 @@ type ( CoinHandler struct { config bot.Config + Name string } ) @@ -21,8 +20,10 @@ func (c *Coin) Flip() bool { return bool(*c) } -func NewCoinHandler() *CoinHandler { - return new(CoinHandler) +func NewCoinHandler(s string) *CoinHandler { + h := new(CoinHandler) + h.Name = s + return h } func (h *CoinHandler) SetConfig(config bot.Config) { @@ -39,7 +40,7 @@ func (h *CoinHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) { return } - if !strings.HasPrefix(m.Content, "!coin") { + if !lib.HasCommand(m.Content, h.config.Prefix, h.Name) { return } diff --git a/bot/handler/dice.go b/bot/handler/dice.go index 2e37198..59ce739 100644 --- a/bot/handler/dice.go +++ b/bot/handler/dice.go @@ -28,6 +28,7 @@ type ( RollHandler struct { config bot.Config + Name string } ) @@ -83,8 +84,10 @@ func (r *Roll) RollDice() { } } -func NewRollHandler() *RollHandler { - return new(RollHandler) +func NewRollHandler(s string) *RollHandler { + h := new(RollHandler) + h.Name = s + return h } func (h *RollHandler) SetConfig(config bot.Config) { @@ -102,7 +105,7 @@ func (h *RollHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) { return } - if !strings.HasPrefix(m.Content, "!roll") { + if !lib.HasCommand(m.Content, h.config.Prefix, h.Name) { return } diff --git a/bot/handler/ping.go b/bot/handler/ping.go index da20bac..a34e4d1 100644 --- a/bot/handler/ping.go +++ b/bot/handler/ping.go @@ -1,9 +1,8 @@ package handler import ( - "strings" - "git.kill0.net/chill9/beepboop/bot" + "git.kill0.net/chill9/beepboop/lib" "github.com/bwmarrin/discordgo" log "github.com/sirupsen/logrus" ) @@ -11,11 +10,14 @@ import ( type ( PingHandler struct { config bot.Config + Name string } ) -func NewPingHandler() *PingHandler { - return new(PingHandler) +func NewPingHandler(s string) *PingHandler { + h := new(PingHandler) + h.Name = s + return h } func (h *PingHandler) SetConfig(config bot.Config) { @@ -27,7 +29,7 @@ func (h *PingHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) { return } - if !strings.HasPrefix(m.Content, "!ping") { + if !lib.HasCommand(m.Content, h.config.Prefix, h.Name) { return } diff --git a/bot/handler/roulette.go b/bot/handler/roulette.go index 4015462..3edc094 100644 --- a/bot/handler/roulette.go +++ b/bot/handler/roulette.go @@ -24,6 +24,7 @@ type ( RouletteHandler struct { config bot.Config + Name string } ) @@ -73,8 +74,10 @@ func (g *Gun) IsEmpty() bool { return true } -func NewRouletteHandler() *RouletteHandler { - return new(RouletteHandler) +func NewRouletteHandler(s string) *RouletteHandler { + h := new(RouletteHandler) + h.Name = s + return h } func (h *RouletteHandler) SetConfig(config bot.Config) { diff --git a/bot/handler/time.go b/bot/handler/time.go index e2d87d4..9f59f76 100644 --- a/bot/handler/time.go +++ b/bot/handler/time.go @@ -13,11 +13,14 @@ import ( type ( TimeHandler struct { config bot.Config + Name string } ) -func NewTimeHandler() *TimeHandler { - return new(TimeHandler) +func NewTimeHandler(s string) *TimeHandler { + h := new(TimeHandler) + h.Name = s + return h } func (h *TimeHandler) SetConfig(config bot.Config) { diff --git a/bot/handler/weather.go b/bot/handler/weather.go index 6ddedf4..9cd6f89 100644 --- a/bot/handler/weather.go +++ b/bot/handler/weather.go @@ -24,6 +24,7 @@ var ( type ( WeatherHandler struct { Config bot.Config + Name string } Temperature float32 @@ -66,8 +67,10 @@ func (t *Temperature) Celcius() float32 { return float32(*t) - 273.15 } -func NewWeatherHandler() *WeatherHandler { - return new(WeatherHandler) +func NewWeatherHandler(s string) *WeatherHandler { + h := new(WeatherHandler) + h.Name = s + return h } func (h *WeatherHandler) SetConfig(config bot.Config) { diff --git a/cmd/bb/main.go b/cmd/bb/main.go index 8742940..77ba6d6 100644 --- a/cmd/bb/main.go +++ b/cmd/bb/main.go @@ -24,14 +24,15 @@ var ( C bot.Config handlers []bot.MessageCreateHandler = []bot.MessageCreateHandler{ - handler.NewCoinHandler(), - handler.NewPingHandler(), - handler.NewRollHandler(), - handler.NewRouletteHandler(), - handler.NewTimeHandler(), + handler.NewCoinHandler("coin"), + handler.NewPingHandler("ping"), + handler.NewRollHandler("roll"), + handler.NewRouletteHandler("roulette"), + handler.NewTimeHandler("time"), handler.NewVersionHandler("version"), - handler.NewWeatherHandler(), + handler.NewWeatherHandler("weather"), handler.NewReactionHandler(), + handler.NewDealHandler("deal"), } )