rolling dice is a bit cleaner

This commit is contained in:
Elliott Pardee 2015-02-10 09:24:36 -05:00
parent f02caacbb5
commit 267ad38fb1

18
bot.go
View File

@ -3,11 +3,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/thoj/go-ircevent" "github.com/thoj/go-ircevent"
"math/rand"
"os" "os"
"strconv"
"strings" "strings"
"time" "time"
"math/rand"
"strconv"
) )
type Bot struct { type Bot struct {
@ -51,7 +51,7 @@ var dict = map[string]string{
var argmap = map[string]int{ var argmap = map[string]int{
".set": 4, ".set": 4,
".print": 3, ".print": 3,
".roll": 1, ".d": 1,
".mode": 1, ".mode": 1,
".rmmode": 1, ".rmmode": 1,
".dm": 1, ".dm": 1,
@ -71,7 +71,7 @@ func fillCharmap(nick string, cat string, item string, val string) {
func roll(amount int, side int) int { func roll(amount int, side int) int {
var numbers = make([]int, amount) var numbers = make([]int, amount)
var finaln = 0; var finaln = 0
for i := 0; i < amount; i++ { for i := 0; i < amount; i++ {
number := rand.Intn(side) + 1 number := rand.Intn(side) + 1
@ -92,17 +92,17 @@ func roll(amount int, side int) int {
// TODO: Create functions related to character import/export. // TODO: Create functions related to character import/export.
func (b *Bot) Command(nick string, msg string) { func (b *Bot) Command(nick string, msg string) {
var args = make([]string, len(strings.Split(msg, " ")) -1) var args = make([]string, len(strings.Split(msg, " "))-1)
var command = "" var command = ""
if stringInSlice(modeopt[2], rulemod) { if stringInSlice(modeopt[2], rulemod) {
b.Log(nick + ": " + msg, initLog) b.Log(nick+": "+msg, initLog)
initLog = false initLog = false
} }
for i, j := range strings.Split(msg, " ") { for i, j := range strings.Split(msg, " ") {
if j != " " && i != 0 { if j != " " && i != 0 {
args[i - 1] = strings.Split(msg, " ")[i] args[i-1] = strings.Split(msg, " ")[i]
} }
} }
@ -138,7 +138,7 @@ func (b *Bot) Command(nick string, msg string) {
} }
break break
case ".roll": case ".d":
amount, _ := strconv.Atoi(strings.Split(args[0], "d")[0]) amount, _ := strconv.Atoi(strings.Split(args[0], "d")[0])
side, _ := strconv.Atoi(strings.Split(args[0], "d")[1]) side, _ := strconv.Atoi(strings.Split(args[0], "d")[1])
@ -220,7 +220,7 @@ func (b *Bot) Log(line string, initLog bool) {
func (b *Bot) Say(msg string) { func (b *Bot) Say(msg string) {
if stringInSlice(modeopt[2], rulemod) { if stringInSlice(modeopt[2], rulemod) {
b.Log("bot: " + msg, initLog) b.Log("bot: "+msg, initLog)
} }
b.Conn.Privmsg(b.Channel, msg) b.Conn.Privmsg(b.Channel, msg)