kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit 518a00055dca8d72df721ecf8fe52475be7f6a17
parent 9153f2825a66aea5b9461a89bfae26bee52d793e
Author: sin <sin@2f30.org>
Date:   Mon, 12 Aug 2013 12:08:54 +0100

Fix out-of-bound error

If no goal was set let the user know.

Diffstat:
Msrc/games/hangman.go | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/games/hangman.go b/src/games/hangman.go @@ -61,6 +61,9 @@ func hangmanInit(cs *hangmanState) { func hangmanWaitGoal(cs *hangmanState) { cs.ictx.Privmsg(cs.channame, "Hangman is waiting for goal. When ready use hangman <letter|possibleword>.") for msg := range *cs.gchan { + if len(msg.Args) < 2 { + continue + } msg.Args[1] = strings.TrimSpace(msg.Args[1]) if msg.Args[0] == cs.botname { if strings.HasPrefix(msg.Args[1], "setgoal ") { @@ -154,7 +157,11 @@ func cmdHangman(a *irc.Context, gc *chan irc.Message) { for { select { case <-timeout: - a.Privmsg(hc.channame, "Time is up! Goal was -> "+hc.goal) + if hc.goal == "" { + a.Privmsg(hc.channame, "Time is up! No goal was given") + } else { + a.Privmsg(hc.channame, "Time is up! Goal was -> "+hc.goal) + } a.DelIntercept(gc) close(stchan) return