Compare commits
	
		
			3 Commits
		
	
	
		
			33bf5eaff2
			...
			4a024e98f2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						4a024e98f2
	
				 | 
					
					
						|||
| 
						
						
							
						
						9b33684d60
	
				 | 
					
					
						|||
| 
						
						
							
						
						cd46fcb60d
	
				 | 
					
					
						
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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
									
								
							
							
						
						
									
										28
									
								
								lib/common_test.go
									
									
									
									
									
										Normal 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,
 | 
			
		||||
			)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user