Part 1 of Characters, importing and reading
This commit is contained in:
parent
b537551405
commit
0580748b9c
10
README.md
10
README.md
@ -3,7 +3,7 @@ irc-osric
|
|||||||
|
|
||||||
[![Build Status](https://travis-ci.org/vypr/irc-osric.svg?branch=master)](https://travis-ci.org/vypr/irc-osric)
|
[![Build Status](https://travis-ci.org/vypr/irc-osric.svg?branch=master)](https://travis-ci.org/vypr/irc-osric)
|
||||||
|
|
||||||
Run with `go run bot.go smap.go slices.go`.
|
Run with `./run.sh`.
|
||||||
|
|
||||||
Goal: Create an IRC bot that can effectively maintain an active OSRIC session.
|
Goal: Create an IRC bot that can effectively maintain an active OSRIC session.
|
||||||
|
|
||||||
@ -12,10 +12,12 @@ TODO:
|
|||||||
* ~~Logging~~
|
* ~~Logging~~
|
||||||
* ~~Stat Manipulation~~
|
* ~~Stat Manipulation~~
|
||||||
* ~~Permission System~~
|
* ~~Permission System~~
|
||||||
* ~~Character System~~
|
|
||||||
* ~~Dictionary for abbreviations (hp, ap, algn, xp)~~
|
* ~~Dictionary for abbreviations (hp, ap, algn, xp)~~
|
||||||
* ~~Dice System~~
|
* ~~Dice System~~
|
||||||
* ~~Voting System~~
|
* ~~Voting System~~
|
||||||
* Import/Export Character
|
|
||||||
* Save Progress Midway
|
* Save Progress Midway
|
||||||
* Battle System
|
* Character System
|
||||||
|
* ~~Importing Characters~~
|
||||||
|
* ~~Reading (printing) Character Info~~
|
||||||
|
* Writing Character Info
|
||||||
|
* Exporting Characters
|
||||||
|
50
bot.go
50
bot.go
@ -26,8 +26,6 @@ var (
|
|||||||
modeopt = []string{"adminoverride", "saves", "logging", "voting"}
|
modeopt = []string{"adminoverride", "saves", "logging", "voting"}
|
||||||
initLog = true
|
initLog = true
|
||||||
|
|
||||||
charmap = make(map[string]map[string]map[string]string)
|
|
||||||
monsmap = make(map[string]string)
|
|
||||||
votemap = make(map[string]int)
|
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"
|
||||||
@ -50,28 +48,18 @@ var dict = map[string]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var argmap = map[string]int{
|
var argmap = map[string]int{
|
||||||
".set": 4,
|
|
||||||
".print": 3,
|
".print": 3,
|
||||||
".vote": 1,
|
".vote": 1,
|
||||||
".d": 1,
|
".d": 1,
|
||||||
".mode": 1,
|
".mode": 1,
|
||||||
".rmmode": 1,
|
".rmmode": 1,
|
||||||
".dm": 1,
|
".dm": 1,
|
||||||
|
".import": 1,
|
||||||
".choose": 0,
|
".choose": 0,
|
||||||
".resetdm": 0,
|
".resetdm": 0,
|
||||||
".quit": 0,
|
".quit": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillCharmap(nick string, cat string, item string, val string) {
|
|
||||||
charmap = map[string]map[string]map[string]string{
|
|
||||||
nick: map[string]map[string]string{
|
|
||||||
cat: map[string]string{
|
|
||||||
item: val,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
@ -135,23 +123,19 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case ".set":
|
case ".import":
|
||||||
if nick == dunmas {
|
if importChar(args[0]) {
|
||||||
fillCharmap(args[0], args[1], args[2], args[3])
|
b.Say("importing " + args[0] + " successful")
|
||||||
fmt.Println("[cmd] set - " + args[0] + "'s " + args[2] + "in " + args[1] + " is set to " + args[3])
|
fmt.Println("[cmd] import " + args[0])
|
||||||
} else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) {
|
|
||||||
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])
|
|
||||||
b.Say(nick + " used override, it's super effective!")
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
|
|
||||||
case ".print":
|
case ".print":
|
||||||
if len(charmap[args[0]][args[1]][args[2]]) == 0 {
|
if len(args) == 4 {
|
||||||
b.Say("there is no setting for " + args[0] + "'s " + args[2])
|
b.Say(args[0] + "[" + args[3] + "] = " + printChar(args[0], args[1], args[2], args[3]))
|
||||||
|
fmt.Println("[cmd] print")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("[cmd] print - " + args[0] + "'s " + args[2] + " in " + args[1])
|
b.Say(args[0] + "[" + args[2] + "] = " + printChar(args[0], args[1], "nil", args[2]))
|
||||||
b.Say(args[0] + "'s " + args[2] + " is set to " + charmap[args[0]][args[1]][args[2]])
|
fmt.Println("[cmd] print")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -221,15 +205,25 @@ func (b *Bot) Command(nick string, msg string) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case ".resetdm":
|
case ".resetdm":
|
||||||
if nick == dunmas {
|
if nick == dunmas && len(dunmas) > 0 {
|
||||||
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) {
|
|
||||||
|
if stringInSlice(modeopt[3], rulemod) {
|
||||||
|
rulemod = append(rulemod, modeopt[3])
|
||||||
|
b.Say("voting is now enabled")
|
||||||
|
}
|
||||||
|
} else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) && len(dunmas) > 0 {
|
||||||
dunmas = ""
|
dunmas = ""
|
||||||
fmt.Println("[cmd] resetdm")
|
fmt.Println("[cmd] resetdm")
|
||||||
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) {
|
||||||
|
rulemod = append(rulemod, modeopt[3])
|
||||||
|
b.Say("voting is now enabled")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
|
60
character.go
Normal file
60
character.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// characters and moar by vypr
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/antonholmquist/jason"
|
||||||
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
var charmap map[string]*jason.Object
|
||||||
|
|
||||||
|
func importChar(nick string) bool {
|
||||||
|
file, err := ioutil.ReadFile("json/" + nick + ".json")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
char, _ := jason.NewObjectFromBytes(file)
|
||||||
|
|
||||||
|
charmap = map[string]*jason.Object{
|
||||||
|
nick: char,
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportChar(nick string) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
func printChar(nick string, cat string, scat string, item string) string {
|
||||||
|
// TODO: Checking if nick exists, to prevent crashing the bot.
|
||||||
|
|
||||||
|
if scat == "nil" {
|
||||||
|
test, _ := charmap[nick].GetString(cat, item)
|
||||||
|
|
||||||
|
if len(test) == 0 {
|
||||||
|
val, _ := charmap[nick].GetInt64(cat, item)
|
||||||
|
return strconv.FormatInt(val, 10)
|
||||||
|
} else {
|
||||||
|
val, _ := charmap[nick].GetString(cat, item)
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
return "does not exist"
|
||||||
|
} else {
|
||||||
|
test, _ := charmap[nick].GetString(cat, scat, item)
|
||||||
|
|
||||||
|
if len(test) == 0 {
|
||||||
|
val, _ := charmap[nick].GetInt64(cat, scat, item)
|
||||||
|
return strconv.FormatInt(val, 10)
|
||||||
|
} else {
|
||||||
|
val, _ := charmap[nick].GetString(cat, scat, item)
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
return "does not exist"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user