Use HasCommand() helper
This commit is contained in:
parent
424b191ebc
commit
af10ef4dc5
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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"),
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user