mirror of https://github.com/velour/catbase.git
Config-ize factoid
This commit is contained in:
parent
a63c22c00e
commit
f2f1326a19
|
@ -29,8 +29,6 @@ type Config struct {
|
||||||
Version string
|
Version string
|
||||||
CommandChar string
|
CommandChar string
|
||||||
RatePerSec float64
|
RatePerSec float64
|
||||||
QuoteChance float64
|
|
||||||
QuoteTime int
|
|
||||||
LogLength int
|
LogLength int
|
||||||
Admins []string
|
Admins []string
|
||||||
HttpAddr string
|
HttpAddr string
|
||||||
|
@ -45,7 +43,6 @@ type Config struct {
|
||||||
TwitterConsumerSecret string
|
TwitterConsumerSecret string
|
||||||
TwitterUserKey string
|
TwitterUserKey string
|
||||||
TwitterUserSecret string
|
TwitterUserSecret string
|
||||||
StartupFact string
|
|
||||||
BadMsgs []string
|
BadMsgs []string
|
||||||
Bad struct {
|
Bad struct {
|
||||||
Msgs []string
|
Msgs []string
|
||||||
|
@ -61,6 +58,12 @@ type Config struct {
|
||||||
MaxLen int
|
MaxLen int
|
||||||
Who string
|
Who string
|
||||||
}
|
}
|
||||||
|
Factoid struct {
|
||||||
|
MinLen int
|
||||||
|
QuoteChance float64
|
||||||
|
QuoteTime int
|
||||||
|
StartupFact string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
"FullName": "CatBase",
|
"FullName": "CatBase",
|
||||||
"CommandChar": "!",
|
"CommandChar": "!",
|
||||||
"RatePerSec": 10.0,
|
"RatePerSec": 10.0,
|
||||||
"QuoteChance": 0.99,
|
|
||||||
"QuoteTime": 1,
|
|
||||||
"LogLength": 50,
|
"LogLength": 50,
|
||||||
"Admins": ["<Admin Nick>"],
|
"Admins": ["<Admin Nick>"],
|
||||||
"HttpAddr": "127.0.0.1:1337",
|
"HttpAddr": "127.0.0.1:1337",
|
||||||
|
@ -35,8 +33,6 @@
|
||||||
"TwitterUserKey": "<User Key>",
|
"TwitterUserKey": "<User Key>",
|
||||||
"TwitterUserSecret": "<User Secret>",
|
"TwitterUserSecret": "<User Secret>",
|
||||||
|
|
||||||
"StartupFact": "speed test",
|
|
||||||
|
|
||||||
"WelcomeMsgs": [
|
"WelcomeMsgs": [
|
||||||
"Real men use screen, %s.",
|
"Real men use screen, %s.",
|
||||||
"Joins upset the hivemind's OCD, %s.",
|
"Joins upset the hivemind's OCD, %s.",
|
||||||
|
@ -56,5 +52,11 @@
|
||||||
"LeftPad": {
|
"LeftPad": {
|
||||||
"MaxLen": 50,
|
"MaxLen": 50,
|
||||||
"Who": "person"
|
"Who": "person"
|
||||||
|
},
|
||||||
|
"Factoid": {
|
||||||
|
"QuoteChance": 0.99,
|
||||||
|
"QuoteTime": 1,
|
||||||
|
"StartupFact": "speed test",
|
||||||
|
"MinLen": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ func New(botInst bot.Bot) *FactoidPlugin {
|
||||||
go func(ch string) {
|
go func(ch string) {
|
||||||
// Some random time to start up
|
// Some random time to start up
|
||||||
time.Sleep(time.Duration(15) * time.Second)
|
time.Sleep(time.Duration(15) * time.Second)
|
||||||
if ok, fact := p.findTrigger(p.Bot.Config().StartupFact); ok {
|
if ok, fact := p.findTrigger(p.Bot.Config().Factoid.StartupFact); ok {
|
||||||
p.sayFact(msg.Message{
|
p.sayFact(msg.Message{
|
||||||
Channel: ch,
|
Channel: ch,
|
||||||
Body: "speed test", // BUG: This is defined in the config too
|
Body: "speed test", // BUG: This is defined in the config too
|
||||||
|
@ -355,7 +355,8 @@ func (p *FactoidPlugin) sayFact(message msg.Message, fact factoid) {
|
||||||
// trigger checks the message for its fitness to be a factoid and then hauls
|
// trigger checks the message for its fitness to be a factoid and then hauls
|
||||||
// the message off to sayFact for processing if it is in fact a trigger
|
// the message off to sayFact for processing if it is in fact a trigger
|
||||||
func (p *FactoidPlugin) trigger(message msg.Message) bool {
|
func (p *FactoidPlugin) trigger(message msg.Message) bool {
|
||||||
if len(message.Body) > 4 || message.Command || message.Body == "..." {
|
minLen := p.Bot.Config().Factoid.MinLen
|
||||||
|
if len(message.Body) > minLen || message.Command || message.Body == "..." {
|
||||||
if ok, fact := p.findTrigger(message.Body); ok {
|
if ok, fact := p.findTrigger(message.Body); ok {
|
||||||
p.sayFact(message, *fact)
|
p.sayFact(message, *fact)
|
||||||
return true
|
return true
|
||||||
|
@ -597,7 +598,7 @@ func (p *FactoidPlugin) randomFact() *factoid {
|
||||||
|
|
||||||
// factTimer spits out a fact at a given interval and with given probability
|
// factTimer spits out a fact at a given interval and with given probability
|
||||||
func (p *FactoidPlugin) factTimer(channel string) {
|
func (p *FactoidPlugin) factTimer(channel string) {
|
||||||
duration := time.Duration(p.Bot.Config().QuoteTime) * time.Minute
|
duration := time.Duration(p.Bot.Config().Factoid.QuoteTime) * time.Minute
|
||||||
myLastMsg := time.Now()
|
myLastMsg := time.Now()
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Duration(5) * time.Second)
|
time.Sleep(time.Duration(5) * time.Second)
|
||||||
|
@ -610,7 +611,7 @@ func (p *FactoidPlugin) factTimer(channel string) {
|
||||||
tdelta := time.Since(lastmsg.Time)
|
tdelta := time.Since(lastmsg.Time)
|
||||||
earlier := time.Since(myLastMsg) > tdelta
|
earlier := time.Since(myLastMsg) > tdelta
|
||||||
chance := rand.Float64()
|
chance := rand.Float64()
|
||||||
success := chance < p.Bot.Config().QuoteChance
|
success := chance < p.Bot.Config().Factoid.QuoteChance
|
||||||
|
|
||||||
if success && tdelta > duration && earlier {
|
if success && tdelta > duration && earlier {
|
||||||
fact := p.randomFact()
|
fact := p.randomFact()
|
||||||
|
|
|
@ -168,8 +168,8 @@ func (p *RememberPlugin) quoteTimer(channel string) {
|
||||||
for {
|
for {
|
||||||
// this pisses me off: You can't multiply int * time.Duration so it
|
// this pisses me off: You can't multiply int * time.Duration so it
|
||||||
// has to look ugly as shit.
|
// has to look ugly as shit.
|
||||||
time.Sleep(time.Duration(p.Bot.Config().QuoteTime) * time.Minute)
|
time.Sleep(time.Duration(p.Bot.Config().Factoid.QuoteTime) * time.Minute)
|
||||||
chance := 1.0 / p.Bot.Config().QuoteChance
|
chance := 1.0 / p.Bot.Config().Factoid.QuoteChance
|
||||||
if rand.Intn(int(chance)) == 0 {
|
if rand.Intn(int(chance)) == 0 {
|
||||||
msg := p.randQuote()
|
msg := p.randQuote()
|
||||||
p.Bot.SendMessage(channel, msg)
|
p.Bot.SendMessage(channel, msg)
|
||||||
|
|
Loading…
Reference in New Issue