simplify interface

This commit is contained in:
Rob Watson 2021-02-25 16:41:57 +01:00
parent a5f0a4660d
commit e432b6c4d2
1 changed files with 5 additions and 13 deletions

View File

@ -13,7 +13,7 @@ import (
"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 {
ProcessEvents(events []*RawEvent) error
@ -61,16 +61,8 @@ func (p *processor) ProcessEvents(events []*RawEvent) error {
}
match := cmdRegex.FindStringSubmatch(e.Content.Body)
cmd := match[1]
arg := match[2]
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")
if err := p.handleVerb(e, match[1]); err != nil {
return err
}
p.processed[e.Id] = true
@ -94,8 +86,8 @@ func (p *processor) acceptInvite(e *RawEvent) error {
return nil
}
func (p *processor) handleVerb(e *RawEvent, _, arg string) error {
verb := lang.GetVerb(strings.ToLower(arg))
func (p *processor) handleVerb(e *RawEvent, q string) error {
verb := lang.GetVerb(strings.ToLower(q))
var sb sendBody
if verb != nil {
sb = sendBody{