simplify interface
This commit is contained in:
parent
a5f0a4660d
commit
e432b6c4d2
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdRegex = regexp.MustCompile("[[:space:]]*!(?P<Command>[a-zA-Z]+)[[:space:]]+(?P<Arg>[a-zA-Z]+)")
|
var cmdRegex = regexp.MustCompile("[[:space:]]*@esbot[[:space:]]+(?P<Verb>[a-zA-ZñÑ]+)")
|
||||||
|
|
||||||
type EventProcessor interface {
|
type EventProcessor interface {
|
||||||
ProcessEvents(events []*RawEvent) error
|
ProcessEvents(events []*RawEvent) error
|
||||||
|
@ -61,16 +61,8 @@ func (p *processor) ProcessEvents(events []*RawEvent) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
match := cmdRegex.FindStringSubmatch(e.Content.Body)
|
match := cmdRegex.FindStringSubmatch(e.Content.Body)
|
||||||
cmd := match[1]
|
if err := p.handleVerb(e, match[1]); err != nil {
|
||||||
arg := match[2]
|
return err
|
||||||
|
|
||||||
switch cmd {
|
|
||||||
case "verb":
|
|
||||||
if err := p.handleVerb(e, cmd, arg); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
p.logger.Debug().Str("command", cmd).Str("arg", arg).Msg("unrecognized command")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.processed[e.Id] = true
|
p.processed[e.Id] = true
|
||||||
|
@ -94,8 +86,8 @@ func (p *processor) acceptInvite(e *RawEvent) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) handleVerb(e *RawEvent, _, arg string) error {
|
func (p *processor) handleVerb(e *RawEvent, q string) error {
|
||||||
verb := lang.GetVerb(strings.ToLower(arg))
|
verb := lang.GetVerb(strings.ToLower(q))
|
||||||
var sb sendBody
|
var sb sendBody
|
||||||
if verb != nil {
|
if verb != nil {
|
||||||
sb = sendBody{
|
sb = sendBody{
|
||||||
|
|
Loading…
Reference in New Issue