roles: add help

This commit is contained in:
Chris Sexton 2022-01-03 07:37:35 -05:00
parent d89569cdc6
commit c5a13116fa
1 changed files with 17 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package roles
import ( import (
"fmt" "fmt"
"github.com/velour/catbase/bot/msg"
"regexp" "regexp"
"strings" "strings"
@ -29,6 +30,8 @@ func New(b bot.Bot) *RolesPlugin {
return p return p
} }
var rolesRegexp = regexp.MustCompile(`(?i)^lsroles\s?(?P<offering>.*)`)
func (p *RolesPlugin) Register() { func (p *RolesPlugin) Register() {
p.h = bot.HandlerTable{ p.h = bot.HandlerTable{
{ {
@ -39,17 +42,26 @@ func (p *RolesPlugin) Register() {
}, },
{ {
Kind: bot.Message, IsCmd: true, Kind: bot.Message, IsCmd: true,
Regex: regexp.MustCompile(`(?i)^lsroles\s?(?P<offering>.*)`), Regex: rolesRegexp,
HelpText: "Lists roles with an optional offering set specifier", HelpText: "Lists roles with an optional offering set specifier",
Handler: p.lsRoles, Handler: p.lsRoles,
}, },
{ {
Kind: bot.Message, IsCmd: true, Kind: bot.Help, IsCmd: true,
Regex: regexp.MustCompile(`(?i)^offering (?P<offering>.+)`), Regex: regexp.MustCompile(`.`),
HelpText: "Changes the current offering set", HelpText: "Lists roles with an optional offering set specifier",
Handler: p.setOffering, Handler: p.lsRoles,
}, },
} }
p.b.Register(p, bot.Help, func(c bot.Connector, k bot.Kind, m msg.Message, args ...interface{}) bool {
return p.lsRoles(bot.Request{
Conn: c,
Kind: k,
Msg: m,
Values: bot.ParseValues(rolesRegexp, m.Body),
Args: args,
})
})
p.b.RegisterTable(p, p.h) p.b.RegisterTable(p, p.h)
} }