Merge pull request #77 from velour/lua_config

config: change to lua
This commit is contained in:
Chris Sexton 2017-09-07 00:34:11 -04:00 committed by GitHub
commit 87487a518e
3 changed files with 124 additions and 101 deletions

View File

@ -4,14 +4,14 @@ package config
import ( import (
"database/sql" "database/sql"
"encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"regexp" "regexp"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
sqlite3 "github.com/mattn/go-sqlite3" sqlite3 "github.com/mattn/go-sqlite3"
"github.com/yuin/gluamapper"
lua "github.com/yuin/gopher-lua"
) )
// Config stores any system-wide startup information that cannot be easily configured via // Config stores any system-wide startup information that cannot be easily configured via
@ -121,16 +121,16 @@ type Replacement struct {
// Readconfig loads the config data out of a JSON file located in cfile // Readconfig loads the config data out of a JSON file located in cfile
func Readconfig(version, cfile string) *Config { func Readconfig(version, cfile string) *Config {
fmt.Printf("Using %s as config file.\n", cfile) fmt.Printf("Using %s as config file.\n", cfile)
file, e := ioutil.ReadFile(cfile) L := lua.NewState()
if e != nil { if err := L.DoFile(cfile); err != nil {
panic("Couldn't read config file!") panic(err)
} }
var c Config var c Config
err := json.Unmarshal(file, &c) if err := gluamapper.Map(L.GetGlobal("config").(*lua.LTable), &c); err != nil {
if err != nil {
panic(err) panic(err)
} }
c.Version = version c.Version = version
if c.Type == "" { if c.Type == "" {

View File

@ -1,86 +0,0 @@
{
"DB": {
"File": "catbase.db",
"Server": "127.0.0.1"
},
"Channels": ["#CatBaseTest"],
"MainChannel": "#CatBaseTest",
"Plugins": [],
"Type": "slack",
"Irc": {
"Server": "ircserver:6697",
"Pass": "CatBaseTest:test"
},
"Slack": {
"Token": "<your slack token>"
},
"Nick": "CatBaseTest",
"FullName": "CatBase",
"CommandChar": ["!", "¡"],
"RatePerSec": 10.0,
"LogLength": 50,
"Admins": ["<Admin Nick>"],
"HttpAddr": "127.0.0.1:1337",
"Untappd": {
"Token": "<Your Token>",
"Freq": 3600,
"Channels": []
},
"TwitterConsumerKey": "<Consumer Key>",
"TwitterConsumerSecret": "<Consumer Secret>",
"TwitterUserKey": "<User Key>",
"TwitterUserSecret": "<User Secret>",
"WelcomeMsgs": [
"Real men use screen, %s.",
"Joins upset the hivemind's OCD, %s.",
"Joins upset the hivemind's CDO, %s.",
"%s, I WILL CUT YOU!"
],
"Bad": {
"Msgs": [],
"Nicks": [],
"Hosts": []
},
"Your": {
"MaxLength": 140,
"Replacements": [
{ "This": "this", "That": "that", "Frequency": 1.0 },
]
},
"LeftPad": {
"MaxLen": 50,
"Who": "person"
},
"Factoid": {
"QuoteChance": 0.99,
"QuoteTime": 1,
"StartupFact": "speed test",
"MinLen": 5
},
"Babbler": {
"DefaultUsers": [
"seabass"
]
},
"Reminder": {
"MaxBatchAdd" : 10
},
"Stats": {
"DBPath": "stats.db",
"Sightings": ["user"]
},
"Emojify": {
"Chance": 0.02
},
"Reaction" : {
"GeneralChance": 0.01,
"HarrassChance": 0.05,
"NegativeHarrassmentMultiplier": 2,
"HarrassList": ["msherms"],
"PositiveReactions": ["+1", "authorized", "aw_yea","joy"],
"NegativeReactions": ["bullshit","fake","tableflip","vomit"]
}
}

109
example_config.lua Normal file
View File

@ -0,0 +1,109 @@
config = {
Channels = {
"#CatBaseTest"
},
TwitterConsumerSecret = "<Consumer Secret>",
Reminder = {
MaxBatchAdd = 10
},
Nick = "CatBaseTest",
LeftPad = {
Who = "person",
MaxLen = 50
},
Factoid = {
StartupFact = "speed test",
QuoteTime = 1,
QuoteChance = 0.99,
MinLen = 5
},
CommandChar = {
"!",
"¡"
},
FullName = "CatBase",
Your = {
MaxLength = 140,
DuckingChance = 0.5,
FuckingChance = 0.15,
YourChance = 0.4
},
Emojify = {
Chance = 0.02
},
DB = {
File = "catbase.db",
Server = "127.0.0.1"
},
Plugins = {
},
Untappd = {
Freq = 3600,
Channels = {
},
Token = "<Your Token>"
},
LogLength = 50,
RatePerSec = 10,
Reaction = {
HarrassChance = 0.05,
GeneralChance = 0.01,
NegativeHarrassmentMultiplier = 2,
HarrassList = {
"msherms"
},
NegativeReactions = {
"bullshit",
"fake",
"tableflip",
"vomit"
},
PositiveReactions = {
"+1",
"authorized",
"aw_yea",
"joy"
}
},
TwitterUserKey = "<User Key>",
MainChannel = "#CatBaseTest",
TwitterUserSecret = "<User Secret>",
WelcomeMsgs = {
"Real men use screen, %s.",
"Joins upset the hivemind's OCD, %s.",
"Joins upset the hivemind's CDO, %s.",
"%s, I WILL CUT YOU!"
},
Bad = {
Msgs = {
},
Hosts = {
},
Nicks = {
}
},
Irc = {
Server = "ircserver:6697",
Pass = "CatBaseTest:test"
},
Slack = {
Token = "<your slack token>"
},
TwitterConsumerKey = "<Consumer Key>",
Babbler = {
DefaultUsers = {
"seabass"
}
},
Type = "slack",
Admins = {
"<Admin Nick>"
},
Stats = {
Sightings = {
"user"
},
DBPath = "stats.db"
},
HttpAddr = "127.0.0.1:1337"
}