mirror of https://github.com/velour/catbase.git
Compare commits
2 Commits
e1250dd25e
...
2045fc4591
Author | SHA1 | Date |
---|---|---|
Chris Sexton | 2045fc4591 | |
Chris Sexton | f2a6d779d3 |
7
main.go
7
main.go
|
@ -4,6 +4,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -77,10 +78,12 @@ func main() {
|
||||||
"Database file to load. (Defaults to catbase.db)")
|
"Database file to load. (Defaults to catbase.db)")
|
||||||
flag.Parse() // parses the logging flags.
|
flag.Parse() // parses the logging flags.
|
||||||
|
|
||||||
log.Logger = log.With().Caller().Stack().Logger()
|
var output io.Writer = os.Stdout
|
||||||
if *prettyLog {
|
if *prettyLog {
|
||||||
log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
output = zerolog.ConsoleWriter{Out: output}
|
||||||
}
|
}
|
||||||
|
log.Logger = log.Output(output).With().Caller().Stack().Logger()
|
||||||
|
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
if *debug {
|
if *debug {
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
|
|
|
@ -53,14 +53,6 @@ func (p *GoalsPlugin) mkDB() {
|
||||||
|
|
||||||
func (p *GoalsPlugin) registerCmds() {
|
func (p *GoalsPlugin) registerCmds() {
|
||||||
p.handlers = bot.HandlerTable{
|
p.handlers = bot.HandlerTable{
|
||||||
{Kind: bot.Message, IsCmd: true,
|
|
||||||
Regex: regexp.MustCompile(`(?i)^register (?P<type>competition|goal) (?P<what>[[:punct:][:alnum:]]+) (?P<amount>[[:digit:]]+)?`),
|
|
||||||
HelpText: "Register with `%s` for yourself",
|
|
||||||
Handler: func(r bot.Request) bool {
|
|
||||||
amount, _ := strconv.Atoi(r.Values["amount"])
|
|
||||||
p.register(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Msg.User.Name, amount)
|
|
||||||
return true
|
|
||||||
}},
|
|
||||||
{Kind: bot.Message, IsCmd: true,
|
{Kind: bot.Message, IsCmd: true,
|
||||||
Regex: regexp.MustCompile(`(?i)^register (?P<type>competition|goal) for (?P<who>[[:punct:][:alnum:]]+) (?P<what>[[:punct:][:alnum:]]+) (?P<amount>[[:digit:]]+)?`),
|
Regex: regexp.MustCompile(`(?i)^register (?P<type>competition|goal) for (?P<who>[[:punct:][:alnum:]]+) (?P<what>[[:punct:][:alnum:]]+) (?P<amount>[[:digit:]]+)?`),
|
||||||
HelpText: "Register with `%s` for other people",
|
HelpText: "Register with `%s` for other people",
|
||||||
|
@ -70,10 +62,11 @@ func (p *GoalsPlugin) registerCmds() {
|
||||||
return true
|
return true
|
||||||
}},
|
}},
|
||||||
{Kind: bot.Message, IsCmd: true,
|
{Kind: bot.Message, IsCmd: true,
|
||||||
Regex: regexp.MustCompile(`(?i)^deregister (?P<type>competition|goal) (?P<what>[[:punct:][:alnum:]]+)`),
|
Regex: regexp.MustCompile(`(?i)^register (?P<type>competition|goal) (?P<what>[[:punct:][:alnum:]]+) (?P<amount>[[:digit:]]+)?`),
|
||||||
HelpText: "Deregister with `%s` for yourself",
|
HelpText: "Register with `%s` for yourself",
|
||||||
Handler: func(r bot.Request) bool {
|
Handler: func(r bot.Request) bool {
|
||||||
p.deregister(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Msg.User.Name)
|
amount, _ := strconv.Atoi(r.Values["amount"])
|
||||||
|
p.register(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Msg.User.Name, amount)
|
||||||
return true
|
return true
|
||||||
}},
|
}},
|
||||||
{Kind: bot.Message, IsCmd: true,
|
{Kind: bot.Message, IsCmd: true,
|
||||||
|
@ -84,10 +77,10 @@ func (p *GoalsPlugin) registerCmds() {
|
||||||
return true
|
return true
|
||||||
}},
|
}},
|
||||||
{Kind: bot.Message, IsCmd: true,
|
{Kind: bot.Message, IsCmd: true,
|
||||||
Regex: regexp.MustCompile(`(?i)^check (?P<type>competition|goal) (?P<what>[[:punct:][:alnum:]]+)`),
|
Regex: regexp.MustCompile(`(?i)^deregister (?P<type>competition|goal) (?P<what>[[:punct:][:alnum:]]+)`),
|
||||||
HelpText: "Check with `%s` for yourself",
|
HelpText: "Deregister with `%s` for yourself",
|
||||||
Handler: func(r bot.Request) bool {
|
Handler: func(r bot.Request) bool {
|
||||||
p.check(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Msg.User.Name)
|
p.deregister(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Msg.User.Name)
|
||||||
return true
|
return true
|
||||||
}},
|
}},
|
||||||
{Kind: bot.Message, IsCmd: true,
|
{Kind: bot.Message, IsCmd: true,
|
||||||
|
@ -97,6 +90,13 @@ func (p *GoalsPlugin) registerCmds() {
|
||||||
p.check(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Values["who"])
|
p.check(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Values["who"])
|
||||||
return true
|
return true
|
||||||
}},
|
}},
|
||||||
|
{Kind: bot.Message, IsCmd: true,
|
||||||
|
Regex: regexp.MustCompile(`(?i)^check (?P<type>competition|goal) (?P<what>[[:punct:][:alnum:]]+)`),
|
||||||
|
HelpText: "Check with `%s` for yourself",
|
||||||
|
Handler: func(r bot.Request) bool {
|
||||||
|
p.check(r.Conn, r.Msg.Channel, r.Values["type"], r.Values["what"], r.Msg.User.Name)
|
||||||
|
return true
|
||||||
|
}},
|
||||||
}
|
}
|
||||||
p.b.RegisterTable(p, p.handlers)
|
p.b.RegisterTable(p, p.handlers)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue