fixing some bugs with voting

This commit is contained in:
Elliott Pardee 2015-06-09 08:19:08 -04:00
parent c97c06409d
commit bd783ea199

21
bot.go
View File

@ -92,6 +92,11 @@ func vote(nick string) {
func choose() (string, int) { func choose() (string, int) {
nmap := sortMapByValue(votemap) nmap := sortMapByValue(votemap)
for i, _ := range votemap {
votemap[i] = 0
}
return nmap[0].Key, nmap[0].Value return nmap[0].Key, nmap[0].Value
} }
@ -147,7 +152,7 @@ func (b *Bot) Command(nick string, msg string) {
break break
case ".vote": case ".vote":
if stringInSlice(modeopt[3], rulemod) { if stringInSlice(modeopt[2], rulemod) {
vote(args[0]) vote(args[0])
fmt.Println("[cmd] vote - " + args[0]) fmt.Println("[cmd] vote - " + args[0])
} else { } else {
@ -200,12 +205,12 @@ func (b *Bot) Command(nick string, msg string) {
case ".choose": case ".choose":
var val = 0 var val = 0
if stringInSlice(modeopt[3], rulemod) { if stringInSlice(modeopt[2], rulemod) {
dunmas, val = choose() dunmas, val = choose()
fmt.Println("[cmd] choosing " + dunmas + " as dm") fmt.Println("[cmd] choosing " + dunmas + " as dm")
b.Say("the dm is now " + dunmas + " after " + strconv.Itoa(val) + " vote(s)") b.Say("the dm is now " + dunmas + " after " + strconv.Itoa(val) + " vote(s)")
if removeItemInSlice(modeopt[3], rulemod) { if removeItemInSlice(modeopt[2], rulemod) {
b.Say("voting is now disabled") b.Say("voting is now disabled")
} }
} }
@ -217,8 +222,8 @@ func (b *Bot) Command(nick string, msg string) {
fmt.Println("[cmd] resetdm") fmt.Println("[cmd] resetdm")
b.Say("dm has been reset") b.Say("dm has been reset")
if stringInSlice(modeopt[3], rulemod) { if !stringInSlice(modeopt[2], rulemod) {
rulemod = append(rulemod, modeopt[3]) rulemod = append(rulemod, modeopt[2])
b.Say("voting is now enabled") b.Say("voting is now enabled")
} }
} else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) && len(dunmas) > 0 { } else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) && len(dunmas) > 0 {
@ -227,8 +232,8 @@ func (b *Bot) Command(nick string, msg string) {
b.Say("dm has been reset") b.Say("dm has been reset")
b.Say(nick + " used override, it's super effective!") b.Say(nick + " used override, it's super effective!")
if stringInSlice(modeopt[3], rulemod) { if !stringInSlice(modeopt[2], rulemod) {
rulemod = append(rulemod, modeopt[3]) rulemod = append(rulemod, modeopt[2])
b.Say("voting is now enabled") b.Say("voting is now enabled")
} }
} }
@ -268,7 +273,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[1], rulemod) {
b.Log("bot: "+msg, initLog) b.Log("bot: "+msg, initLog)
} }