Compare commits

..

No commits in common. "4a024e98f2c74c187fb28718da1fedb0af4f7be3" and "33bf5eaff2f828bf499452a36a75e749066fb22a" have entirely different histories.

9 changed files with 21 additions and 38 deletions

View File

@ -21,7 +21,9 @@ func (c *Coin) Flip() bool {
} }
func NewCoinHandler(s string) *CoinHandler { func NewCoinHandler(s string) *CoinHandler {
return &CoinHandler{Name: s} h := new(CoinHandler)
h.Name = s
return h
} }
func (h *CoinHandler) SetConfig(config bot.Config) { func (h *CoinHandler) SetConfig(config bot.Config) {

View File

@ -85,7 +85,9 @@ func (r *Roll) RollDice() {
} }
func NewRollHandler(s string) *RollHandler { func NewRollHandler(s string) *RollHandler {
return &RollHandler{Name: s} h := new(RollHandler)
h.Name = s
return h
} }
func (h *RollHandler) SetConfig(config bot.Config) { func (h *RollHandler) SetConfig(config bot.Config) {

View File

@ -15,7 +15,9 @@ type (
) )
func NewPingHandler(s string) *PingHandler { func NewPingHandler(s string) *PingHandler {
return &PingHandler{Name: s} h := new(PingHandler)
h.Name = s
return h
} }
func (h *PingHandler) SetConfig(config bot.Config) { func (h *PingHandler) SetConfig(config bot.Config) {

View File

@ -75,7 +75,9 @@ func (g *Gun) IsEmpty() bool {
} }
func NewRouletteHandler(s string) *RouletteHandler { func NewRouletteHandler(s string) *RouletteHandler {
return &RouletteHandler{Name: s} h := new(RouletteHandler)
h.Name = s
return h
} }
func (h *RouletteHandler) SetConfig(config bot.Config) { func (h *RouletteHandler) SetConfig(config bot.Config) {

View File

@ -18,7 +18,9 @@ type (
) )
func NewTimeHandler(s string) *TimeHandler { func NewTimeHandler(s string) *TimeHandler {
return &TimeHandler{Name: s} h := new(TimeHandler)
h.Name = s
return h
} }
func (h *TimeHandler) SetConfig(config bot.Config) { func (h *TimeHandler) SetConfig(config bot.Config) {

View File

@ -21,7 +21,9 @@ type (
) )
func NewVersionHandler(s string) *VersionHandler { func NewVersionHandler(s string) *VersionHandler {
return &VersionHandler{Name: s} h := new(VersionHandler)
h.Name = s
return h
} }
func (h *VersionHandler) SetConfig(config bot.Config) { func (h *VersionHandler) SetConfig(config bot.Config) {

View File

@ -17,7 +17,9 @@ type WeatherHandler struct {
} }
func NewWeatherHandler(s string) *WeatherHandler { func NewWeatherHandler(s string) *WeatherHandler {
return &WeatherHandler{Name: s} h := new(WeatherHandler)
h.Name = s
return h
} }
func (h *WeatherHandler) SetConfig(config bot.Config) { func (h *WeatherHandler) SetConfig(config bot.Config) {

View File

@ -53,9 +53,6 @@ func BuildURI(rawuri, rawpath string) string {
func HasCommand(s, prefix, cmd string) bool { func HasCommand(s, prefix, cmd string) bool {
s = strings.TrimSpace(s) s = strings.TrimSpace(s)
args := strings.Split(s, " ")
s = args[0]
// a command cannot be less than two characters e.g. !x // a command cannot be less than two characters e.g. !x
if len(s) < 2 { if len(s) < 2 {
return false return false

View File

@ -1,28 +0,0 @@
package lib
import "testing"
func TestHasCommand(t *testing.T) {
tables := []struct {
s string
prefix string
cmd string
r bool
}{
{"!command x y", "!", "command", true},
{"#command x y", "#", "command", true},
{"command x y", "!", "comamnd", false},
{"", "", "", false},
{"!", "!", "", false},
{"! x y", "!", "", false},
}
for _, table := range tables {
r := HasCommand(table.s, table.prefix, table.cmd)
if r != table.r {
t.Errorf("HasCommand(%q, %q, %q), got: %t, want: %t",
table.s, table.prefix, table.cmd, r, table.r,
)
}
}
}