irc-osric is now complete, all that's left is bugfixes.

This commit is contained in:
Elliott Pardee 2015-02-28 06:46:44 -05:00
parent f74aec6baa
commit 666125b50f
3 changed files with 78 additions and 9 deletions

View File

@ -15,9 +15,8 @@ TODO:
* ~~Dictionary for abbreviations (hp, ap, algn, xp)~~
* ~~Dice System~~
* ~~Voting System~~
* Save Progress Midway
* Character System
* ~~Character System~~
* ~~Importing Characters~~
* ~~Reading (printing) Character Info~~
* Writing Character Info
* Exporting Characters
* ~~Writing Character Info~~
* ~~Exporting Characters~~

25
bot.go
View File

@ -48,6 +48,7 @@ var dict = map[string]string{
}
var argmap = map[string]int{
".set": 4,
".print": 3,
".vote": 1,
".d": 1,
@ -129,6 +130,30 @@ func (b *Bot) Command(nick string, msg string) {
fmt.Println("[cmd] import " + args[0])
}
case ".set":
if nick == dunmas {
if len(args) == 5 {
if setChar(args[0], args[1], args[2], args[3], args[4]) {
fmt.Println("[cmd] set")
}
} else {
if setChar(args[0], args[1], "nil", args[2], args[3]) {
fmt.Println("[cmd] set")
}
}
} else if stringInSlice(nick, admins) && stringInSlice(modeopt[0], rulemod) {
if len(args) == 5 {
if setChar(args[0], args[1], args[2], args[3], args[4]) {
fmt.Println("[cmd] set")
b.Say(nick + " used override, it's super effective!")
}
} else {
if setChar(args[0], args[1], "nil", args[2], args[3]) {
fmt.Println("[cmd] set")
b.Say(nick + " used override, it's super effective!")
}
}
}
case ".print":
if len(args) == 4 {
b.Say(args[0] + "[" + args[3] + "] = " + printChar(args[0], args[1], args[2], args[3]))

View File

@ -4,7 +4,9 @@ package main
import (
"github.com/antonholmquist/jason"
"io/ioutil"
"os"
"strconv"
"strings"
)
var charmap map[string]*jason.Object
@ -25,12 +27,10 @@ func importChar(nick string) bool {
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 _, err := os.Stat("json/" + nick + ".json"); os.IsNotExist(err) {
return "does not exist"
}
if scat == "nil" {
test, _ := charmap[nick].GetString(cat, item)
@ -58,3 +58,48 @@ func printChar(nick string, cat string, scat string, item string) string {
return "does not exist"
}
}
func setChar(nick string, cat string, scat string, item string, value string) bool {
file, err := ioutil.ReadFile("json/" + nick + ".json")
if err != nil {
return false
}
lines := strings.Split(string(file), "\n")
for i, l := range lines {
if strings.Contains(l, item) {
if scat == "nil" {
test, _ := charmap[nick].GetString(cat, item)
if len(test) == 0 {
lines[i] = "\"" + item + "\": " + value + ","
} else {
lines[i] = "\"" + item + "\": \"" + value + "\","
}
} else {
test, _ := charmap[nick].GetString(cat, scat, item)
if len(test) == 0 {
lines[i] = "\"" + item + "\": " + value + ","
} else {
lines[i] = "\"" + item + "\": \"" + value + "\","
}
}
}
}
oput := strings.Join(lines, "\n")
err = ioutil.WriteFile("json/"+nick+".json", []byte(oput), 0644)
if err != nil {
return false
}
if !importChar(nick) {
return false
}
return true
}