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