diff --git a/config/config.go b/config/config.go index b2ce6ca..b96da8e 100644 --- a/config/config.go +++ b/config/config.go @@ -4,14 +4,14 @@ package config import ( "database/sql" - "encoding/json" "fmt" - "io/ioutil" "log" "regexp" "github.com/jmoiron/sqlx" 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 @@ -64,7 +64,7 @@ type Config struct { Hosts []string } Your struct { - MaxLength int + MaxLength int Replacements []Replacement } LeftPad struct { @@ -91,12 +91,12 @@ type Config struct { Chance float64 } Reaction struct { - GeneralChance float64 - HarrassChance float64 + GeneralChance float64 + HarrassChance float64 NegativeHarrassmentMultiplier int - HarrassList []string - PositiveReactions []string - NegativeReactions []string + HarrassList []string + PositiveReactions []string + NegativeReactions []string } } @@ -113,24 +113,24 @@ func init() { } type Replacement struct { - This string - That string + This string + That string Frequency float64 } // Readconfig loads the config data out of a JSON file located in cfile func Readconfig(version, cfile string) *Config { fmt.Printf("Using %s as config file.\n", cfile) - file, e := ioutil.ReadFile(cfile) - if e != nil { - panic("Couldn't read config file!") + L := lua.NewState() + if err := L.DoFile(cfile); err != nil { + panic(err) } var c Config - err := json.Unmarshal(file, &c) - if err != nil { + if err := gluamapper.Map(L.GetGlobal("config").(*lua.LTable), &c); err != nil { panic(err) } + c.Version = version if c.Type == "" { diff --git a/example_config.json b/example_config.json deleted file mode 100644 index d4ad7c1..0000000 --- a/example_config.json +++ /dev/null @@ -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": "" - }, - "Nick": "CatBaseTest", - "FullName": "CatBase", - "CommandChar": ["!", "¡"], - "RatePerSec": 10.0, - "LogLength": 50, - "Admins": [""], - "HttpAddr": "127.0.0.1:1337", - - "Untappd": { - "Token": "", - "Freq": 3600, - "Channels": [] - }, - - "TwitterConsumerKey": "", - "TwitterConsumerSecret": "", - "TwitterUserKey": "", - "TwitterUserSecret": "", - - "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"] - } -} diff --git a/example_config.lua b/example_config.lua new file mode 100644 index 0000000..969ac2e --- /dev/null +++ b/example_config.lua @@ -0,0 +1,109 @@ +config = { + Channels = { + "#CatBaseTest" + }, + TwitterConsumerSecret = "", + 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 = "" + }, + 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 = "", + MainChannel = "#CatBaseTest", + TwitterUserSecret = "", + 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 = "" + }, + TwitterConsumerKey = "", + Babbler = { + DefaultUsers = { + "seabass" + } + }, + Type = "slack", + Admins = { + "" + }, + Stats = { + Sightings = { + "user" + }, + DBPath = "stats.db" + }, + HttpAddr = "127.0.0.1:1337" +} \ No newline at end of file