Voting system added, some derp-moment fixes.
This commit is contained in:
parent
6807e7c301
commit
a228501201
@ -14,7 +14,8 @@ TODO:
|
|||||||
* ~~Permission System~~
|
* ~~Permission System~~
|
||||||
* ~~Character System~~
|
* ~~Character System~~
|
||||||
* ~~Dictionary for abbreviations (hp, ap, algn, xp)~~
|
* ~~Dictionary for abbreviations (hp, ap, algn, xp)~~
|
||||||
|
* ~~Dice System~~
|
||||||
|
* ~~Voting System~~
|
||||||
* Import/Export Character
|
* Import/Export Character
|
||||||
* Save Progress Midway
|
* Save Progress Midway
|
||||||
* ~~Dice Rolling~~
|
|
||||||
* Battle System
|
* Battle System
|
||||||
|
57
bot.go
57
bot.go
@ -22,12 +22,13 @@ var (
|
|||||||
dieopt = []string{"4", "6", "8", "10", "12", "20"}
|
dieopt = []string{"4", "6", "8", "10", "12", "20"}
|
||||||
dunmas = ""
|
dunmas = ""
|
||||||
|
|
||||||
rulemod = make([]string, len(modeopt))
|
rulemod = []string{"voting"}
|
||||||
modeopt = []string{"adminoverride", "saves", "logging"}
|
modeopt = []string{"adminoverride", "saves", "logging", "voting"}
|
||||||
initLog = true
|
initLog = true
|
||||||
|
|
||||||
charmap = make(map[string]map[string]map[string]string)
|
charmap = make(map[string]map[string]map[string]string)
|
||||||
monsmap = make(map[string]string)
|
monsmap = make(map[string]string)
|
||||||
|
votemap = make(map[string]int)
|
||||||
|
|
||||||
filename = "log/log_" + time.Now().Local().Format("20060102") + "_" + time.Now().Local().Format("150405") + ".txt"
|
filename = "log/log_" + time.Now().Local().Format("20060102") + "_" + time.Now().Local().Format("150405") + ".txt"
|
||||||
)
|
)
|
||||||
@ -51,10 +52,12 @@ var dict = map[string]string{
|
|||||||
var argmap = map[string]int{
|
var argmap = map[string]int{
|
||||||
".set": 4,
|
".set": 4,
|
||||||
".print": 3,
|
".print": 3,
|
||||||
|
".vote": 1,
|
||||||
".d": 1,
|
".d": 1,
|
||||||
".mode": 1,
|
".mode": 1,
|
||||||
".rmmode": 1,
|
".rmmode": 1,
|
||||||
".dm": 1,
|
".dm": 1,
|
||||||
|
".choose": 0,
|
||||||
".resetdm": 0,
|
".resetdm": 0,
|
||||||
".quit": 0,
|
".quit": 0,
|
||||||
}
|
}
|
||||||
@ -89,6 +92,20 @@ func roll(amount int, side int) int {
|
|||||||
return finaln
|
return finaln
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func vote(nick string) {
|
||||||
|
if _, j := votemap[nick]; j {
|
||||||
|
var tmp = votemap[nick] + 1
|
||||||
|
votemap[nick] = tmp
|
||||||
|
} else {
|
||||||
|
votemap[nick] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func choose() (string, int) {
|
||||||
|
nmap := sortMapByValue(votemap)
|
||||||
|
return nmap[0].Key, nmap[0].Value
|
||||||
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
@ -122,7 +139,7 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
if nick == dunmas {
|
if nick == dunmas {
|
||||||
fillCharmap(args[0], args[1], args[2], args[3])
|
fillCharmap(args[0], args[1], args[2], args[3])
|
||||||
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + "in " + args[1] + " is set to " + args[3])
|
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + "in " + args[1] + " is set to " + args[3])
|
||||||
} else if stringInSlice(nick, admins) && !stringInSlice(modeopt[0], rulemod) {
|
} else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) {
|
||||||
fillCharmap(args[0], args[1], args[2], args[3])
|
fillCharmap(args[0], args[1], args[2], args[3])
|
||||||
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + " in " + args[1] + " is set to " + args[3])
|
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + " in " + args[1] + " is set to " + args[3])
|
||||||
b.Say(nick + " used override, it's super effective!")
|
b.Say(nick + " used override, it's super effective!")
|
||||||
@ -138,6 +155,16 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case ".vote":
|
||||||
|
if stringInSlice(modeopt[3], rulemod) {
|
||||||
|
vote(args[0])
|
||||||
|
fmt.Println("[cmd] vote - " + args[0])
|
||||||
|
} else {
|
||||||
|
b.Say(nick + " - the dm has already been chosen")
|
||||||
|
b.Say(nick + " - have the dm or an admin use .resetdm if necessary")
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
case ".d":
|
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])
|
||||||
@ -149,6 +176,7 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case ".mode":
|
case ".mode":
|
||||||
|
if nick == dunmas || stringInSlice(nick, admins) {
|
||||||
if stringInSlice(args[0], rulemod) {
|
if stringInSlice(args[0], rulemod) {
|
||||||
b.Say(args[0] + " is already set to true")
|
b.Say(args[0] + " is already set to true")
|
||||||
} else if stringInSlice(args[0], modeopt) {
|
} else if stringInSlice(args[0], modeopt) {
|
||||||
@ -156,24 +184,39 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
b.Say(args[0] + " is now enabled")
|
b.Say(args[0] + " is now enabled")
|
||||||
rulemod = append(rulemod, args[0])
|
rulemod = append(rulemod, args[0])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case ".rmmode":
|
case ".rmmode":
|
||||||
|
if nick == dunmas || stringInSlice(nick, admins) {
|
||||||
if removeItemInSlice(args[0], rulemod) {
|
if removeItemInSlice(args[0], rulemod) {
|
||||||
fmt.Println("[cmd] rmmode - " + args[0])
|
fmt.Println("[cmd] rmmode - " + args[0])
|
||||||
b.Say(args[0] + " has been removed from the list of modes")
|
b.Say(args[0] + " has been removed from the list of modes")
|
||||||
} else {
|
} else {
|
||||||
b.Say(args[0] + " isn't in the list of modes")
|
b.Say(args[0] + " isn't in the list of modes")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case ".dm":
|
case ".dm":
|
||||||
if len(dunmas) == 0 {
|
if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) {
|
||||||
dunmas = args[0]
|
dunmas = args[0]
|
||||||
fmt.Println("[cmd] dm - " + dunmas)
|
fmt.Println("[cmd] dm - " + dunmas)
|
||||||
b.Say("dm is now set to " + dunmas)
|
b.Say("dm is now set to " + dunmas)
|
||||||
} else {
|
}
|
||||||
b.Say("dm has already been set, the current DM is " + dunmas)
|
break
|
||||||
|
|
||||||
|
case ".choose":
|
||||||
|
var val = 0
|
||||||
|
|
||||||
|
if stringInSlice(modeopt[3], rulemod) {
|
||||||
|
dunmas, val = choose()
|
||||||
|
fmt.Println("[cmd] choosing " + dunmas + " as dm")
|
||||||
|
b.Say("the dm is now " + dunmas + " after " + strconv.Itoa(val) + " vote(s)")
|
||||||
|
|
||||||
|
if removeItemInSlice(modeopt[3], rulemod) {
|
||||||
|
b.Say("voting is now disabled")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -182,7 +225,7 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
dunmas = ""
|
dunmas = ""
|
||||||
fmt.Println("[cmd] resetdm")
|
fmt.Println("[cmd] resetdm")
|
||||||
b.Say("dm has been reset")
|
b.Say("dm has been reset")
|
||||||
} else if stringInSlice(nick, admins) && !stringInSlice(modeopt[0], rulemod) {
|
} else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) {
|
||||||
dunmas = ""
|
dunmas = ""
|
||||||
fmt.Println("[cmd] resetdm")
|
fmt.Println("[cmd] resetdm")
|
||||||
b.Say("dm has been reset")
|
b.Say("dm has been reset")
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// extra slice functions by vypr
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func stringInSlice(a string, list []string) bool {
|
func stringInSlice(a string, list []string) bool {
|
||||||
|
42
smap.go
Normal file
42
smap.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// map sorting by vypr
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
|
type smap struct {
|
||||||
|
Key string
|
||||||
|
Value int
|
||||||
|
}
|
||||||
|
|
||||||
|
type smapList []smap
|
||||||
|
|
||||||
|
func (s smapList) Swap(i, j int) {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s smapList) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s smapList) Less(i, j int) bool {
|
||||||
|
a, b := s[i].Value, s[j].Value
|
||||||
|
|
||||||
|
if a != b {
|
||||||
|
return a > b
|
||||||
|
} else {
|
||||||
|
return s[j].Value > s[i].Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortMapByValue(m map[string]int) smapList {
|
||||||
|
s := make(smapList, len(m))
|
||||||
|
i := 0
|
||||||
|
|
||||||
|
for k, v := range m {
|
||||||
|
s[i] = smap{k, v}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(s)
|
||||||
|
return s
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user