Compare commits

..

3 Commits

9 changed files with 38 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

28
lib/common_test.go Normal file
View File

@ -0,0 +1,28 @@
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,
)
}
}
}