Browse Source

update set/list to config commands

master
David Haukeness 5 years ago
parent
commit
80587d4a1e
No known key found for this signature in database
GPG Key ID: 54F2372DDB7F9462
  1. 33
      commands.go
  2. 11
      handlers.go

33
commands.go

@ -76,19 +76,38 @@ func (b *bot) handleFeedback(m chat1.MsgSummary) { @@ -76,19 +76,38 @@ func (b *bot) handleFeedback(m chat1.MsgSummary) {
}
}
// handleConfigCommand dispatches config calls
func (b *bot) handleConfigCommand(m chat1.MsgSummary) {
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
if args[1] != "config" {
return
}
if len(args) >= 3 {
switch args[2] {
case "set":
b.handleSetCommand(m)
return
case "list":
b.handleListCommand(m)
return
}
}
}
// handleSetCommand processes all settings SET calls
// this should be called from b.handleConfigCommand()
func (b *bot) handleSetCommand(m chat1.MsgSummary) {
b.debug("%s called set command in %s", m.Sender.Username, m.ConvID)
// first normalize the text and extract the arguments
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
if args[1] != "set" {
if args[2] != "set" {
return
}
b.debug("config set called by @%s in %s", m.Sender.Username, m.ConvID)
switch len(args) {
case 4:
if args[2] == "url" {
case 5:
if args[3] == "url" {
// first validate the URL
u, err := url.ParseRequestURI(args[3])
u, err := url.ParseRequestURI(args[4])
if err != nil {
eid := b.logError(err)
b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid)
@ -129,10 +148,12 @@ func (b *bot) handleSetCommand(m chat1.MsgSummary) { @@ -129,10 +148,12 @@ func (b *bot) handleSetCommand(m chat1.MsgSummary) {
}
// handleListCommand lists settings for the conversation
// this should be called from b.handleConfigCommand()
func (b *bot) handleListCommand(m chat1.MsgSummary) {
// first normalize the text and extract the arguments
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
if args[0] != "list" {
if args[2] != "list" {
return
}
b.debug("config list called by @%s in %s", m.Sender.Username, m.ConvID)
}

11
handlers.go

@ -68,14 +68,9 @@ func (b *bot) chatHandler(m chat1.MsgSummary) { @@ -68,14 +68,9 @@ func (b *bot) chatHandler(m chat1.MsgSummary) {
b.handleWelcome(m.ConvID)
return
}
// set commands
if hasCommandPrefix(m.Content.Text.Body, b.cmd(), b.k.Username, "set") {
b.handleSetCommand(m)
return
}
// list commands
if hasCommandPrefix(m.Content.Text.Body, b.cmd(), b.k.Username, "list") {
b.handleSetCommand(m)
// config commands
if hasCommandPrefix(m.Content.Text.Body, b.cmd(), b.k.Username, "config") {
b.handleConfigCommand(m)
return
}
}

Loading…
Cancel
Save