2016-01-17 18:00:44 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
2013-12-10 23:37:07 +00:00
|
|
|
|
2012-08-17 20:38:15 +00:00
|
|
|
package config
|
|
|
|
|
2017-07-25 17:58:04 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
sqlite3 "github.com/mattn/go-sqlite3"
|
2017-08-31 20:25:51 +00:00
|
|
|
"github.com/yuin/gluamapper"
|
|
|
|
lua "github.com/yuin/gopher-lua"
|
2017-07-25 17:58:04 +00:00
|
|
|
)
|
2012-08-17 20:38:15 +00:00
|
|
|
|
|
|
|
// Config stores any system-wide startup information that cannot be easily configured via
|
|
|
|
// the database
|
|
|
|
type Config struct {
|
2017-07-25 17:58:04 +00:00
|
|
|
DBConn *sqlx.DB
|
|
|
|
|
2016-03-10 18:37:07 +00:00
|
|
|
DB struct {
|
|
|
|
File string
|
|
|
|
Name string
|
|
|
|
Server string
|
|
|
|
}
|
|
|
|
Channels []string
|
|
|
|
MainChannel string
|
|
|
|
Plugins []string
|
|
|
|
Type string
|
|
|
|
Irc struct {
|
|
|
|
Server, Pass string
|
|
|
|
}
|
2016-03-11 02:11:52 +00:00
|
|
|
Slack struct {
|
|
|
|
Token string
|
|
|
|
}
|
2016-03-11 17:48:41 +00:00
|
|
|
Nick string
|
|
|
|
FullName string
|
|
|
|
Version string
|
2016-09-27 16:42:00 +00:00
|
|
|
CommandChar []string
|
2016-03-11 17:48:41 +00:00
|
|
|
RatePerSec float64
|
|
|
|
LogLength int
|
|
|
|
Admins []string
|
|
|
|
HttpAddr string
|
|
|
|
Untappd struct {
|
|
|
|
Token string
|
|
|
|
Freq int
|
|
|
|
Channels []string
|
|
|
|
}
|
2016-08-30 19:40:55 +00:00
|
|
|
Twitch struct {
|
2017-09-27 18:39:36 +00:00
|
|
|
Freq int
|
|
|
|
Users map[string][]string //channel -> usernames
|
|
|
|
ClientID string
|
|
|
|
Authorization string
|
2016-08-09 00:44:28 +00:00
|
|
|
}
|
2016-01-15 14:43:31 +00:00
|
|
|
EnforceNicks bool
|
2013-02-21 03:24:51 +00:00
|
|
|
WelcomeMsgs []string
|
|
|
|
TwitterConsumerKey string
|
|
|
|
TwitterConsumerSecret string
|
|
|
|
TwitterUserKey string
|
|
|
|
TwitterUserSecret string
|
2013-03-30 11:12:27 +00:00
|
|
|
BadMsgs []string
|
2013-04-21 16:37:04 +00:00
|
|
|
Bad struct {
|
|
|
|
Msgs []string
|
|
|
|
Nicks []string
|
|
|
|
Hosts []string
|
|
|
|
}
|
2016-03-24 17:49:44 +00:00
|
|
|
Your struct {
|
2017-08-31 20:25:51 +00:00
|
|
|
MaxLength int
|
2017-03-13 17:44:44 +00:00
|
|
|
Replacements []Replacement
|
2016-03-24 17:49:44 +00:00
|
|
|
}
|
2016-04-01 14:37:44 +00:00
|
|
|
LeftPad struct {
|
|
|
|
MaxLen int
|
|
|
|
Who string
|
|
|
|
}
|
2016-04-01 14:45:45 +00:00
|
|
|
Factoid struct {
|
|
|
|
MinLen int
|
|
|
|
QuoteChance float64
|
|
|
|
QuoteTime int
|
|
|
|
StartupFact string
|
|
|
|
}
|
2016-05-11 01:15:52 +00:00
|
|
|
Babbler struct {
|
|
|
|
DefaultUsers []string
|
|
|
|
}
|
2017-05-01 15:54:44 +00:00
|
|
|
Reminder struct {
|
|
|
|
MaxBatchAdd int
|
|
|
|
}
|
2017-06-05 22:37:46 +00:00
|
|
|
Stats struct {
|
|
|
|
DBPath string
|
|
|
|
Sightings []string
|
|
|
|
}
|
2017-07-25 18:44:36 +00:00
|
|
|
Emojify struct {
|
|
|
|
Chance float64
|
|
|
|
}
|
2017-08-30 17:41:58 +00:00
|
|
|
Reaction struct {
|
2017-08-31 20:25:51 +00:00
|
|
|
GeneralChance float64
|
|
|
|
HarrassChance float64
|
2017-08-30 18:44:04 +00:00
|
|
|
NegativeHarrassmentMultiplier int
|
2017-08-31 20:25:51 +00:00
|
|
|
HarrassList []string
|
|
|
|
PositiveReactions []string
|
|
|
|
NegativeReactions []string
|
2017-08-30 17:41:58 +00:00
|
|
|
}
|
2017-09-29 04:58:21 +00:00
|
|
|
Inventory struct {
|
|
|
|
Max int
|
|
|
|
}
|
2017-11-06 19:32:49 +00:00
|
|
|
Sisyphus struct {
|
|
|
|
MinDecrement int
|
2017-11-06 19:40:43 +00:00
|
|
|
MaxDecrement int
|
2017-11-06 19:32:49 +00:00
|
|
|
MinPush int
|
2017-11-06 19:40:43 +00:00
|
|
|
MaxPush int
|
2017-11-06 19:32:49 +00:00
|
|
|
}
|
2012-08-17 21:37:49 +00:00
|
|
|
}
|
2012-08-17 20:38:15 +00:00
|
|
|
|
2017-07-25 17:58:04 +00:00
|
|
|
func init() {
|
|
|
|
regex := func(re, s string) (bool, error) {
|
|
|
|
return regexp.MatchString(re, s)
|
|
|
|
}
|
|
|
|
sql.Register("sqlite3_custom",
|
|
|
|
&sqlite3.SQLiteDriver{
|
|
|
|
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
|
|
|
return conn.RegisterFunc("REGEXP", regex, true)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-13 17:44:44 +00:00
|
|
|
type Replacement struct {
|
2017-08-31 20:25:51 +00:00
|
|
|
This string
|
|
|
|
That string
|
2017-03-13 17:44:44 +00:00
|
|
|
Frequency float64
|
|
|
|
}
|
|
|
|
|
2012-08-17 21:37:49 +00:00
|
|
|
// Readconfig loads the config data out of a JSON file located in cfile
|
2012-08-17 22:56:44 +00:00
|
|
|
func Readconfig(version, cfile string) *Config {
|
2012-08-17 20:38:15 +00:00
|
|
|
fmt.Printf("Using %s as config file.\n", cfile)
|
2017-08-31 20:25:51 +00:00
|
|
|
L := lua.NewState()
|
|
|
|
if err := L.DoFile(cfile); err != nil {
|
|
|
|
panic(err)
|
2012-08-17 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var c Config
|
2017-08-31 20:25:51 +00:00
|
|
|
if err := gluamapper.Map(L.GetGlobal("config").(*lua.LTable), &c); err != nil {
|
2012-08-17 20:38:15 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
2017-08-31 20:25:51 +00:00
|
|
|
|
2012-08-17 22:56:44 +00:00
|
|
|
c.Version = version
|
2012-08-25 04:49:48 +00:00
|
|
|
|
2016-03-10 18:37:07 +00:00
|
|
|
if c.Type == "" {
|
|
|
|
c.Type = "irc"
|
|
|
|
}
|
|
|
|
|
2012-08-25 04:51:16 +00:00
|
|
|
fmt.Printf("godeepintir version %s running.\n", c.Version)
|
2012-08-25 04:49:48 +00:00
|
|
|
|
2017-07-25 17:58:04 +00:00
|
|
|
sqlDB, err := sqlx.Open("sqlite3_custom", c.DB.File)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
c.DBConn = sqlDB
|
|
|
|
|
2012-08-17 20:38:15 +00:00
|
|
|
return &c
|
|
|
|
}
|