dice: clean up

This commit is contained in:
Chris Sexton 2017-12-19 13:38:02 -05:00
parent 132fdd29be
commit 6bc72b93d1
1 changed files with 24 additions and 35 deletions

View File

@ -12,8 +12,6 @@ import (
import (
"fmt"
"math/rand"
"strconv"
"strings"
)
// This is a dice plugin to serve as an example and quick copy/paste for new plugins.
@ -39,22 +37,15 @@ func rollDie(sides int) int {
// This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *DicePlugin) Message(message msg.Message) bool {
channel := message.Channel
parts := strings.Fields(message.Body)
if len(parts) == 1 && message.Command {
var dice []string
dice = strings.Split(parts[0], "d")
if len(dice) == 2 {
// We actually have a die roll.
nDice, err := strconv.Atoi(dice[0])
if err != nil {
if !message.Command {
return false
}
sides, err := strconv.Atoi(dice[1])
if err != nil {
channel := message.Channel
nDice := 0
sides := 0
if n, err := fmt.Sscanf(message.Body, "%dd%d", &nDice, &sides); n != 2 || err != nil {
return false
}
@ -76,9 +67,7 @@ func (p *DicePlugin) Message(message msg.Message) bool {
p.Bot.SendMessage(channel, rolls)
return true
}
}
return false
}
// Help responds to help requests. Every plugin must implement a help function.