update set/list to config commands
This commit is contained in:
39
commands.go
39
commands.go
@ -76,19 +76,38 @@ func (b *bot) handleFeedback(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleSetCommand processes all settings SET calls
|
// handleConfigCommand dispatches config calls
|
||||||
func (b *bot) handleSetCommand(m chat1.MsgSummary) {
|
func (b *bot) handleConfigCommand(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))
|
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
|
||||||
if args[1] != "set" {
|
if args[1] != "config" {
|
||||||
return
|
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) {
|
||||||
|
// first normalize the text and extract the arguments
|
||||||
|
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
|
||||||
|
if args[2] != "set" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.debug("config set called by @%s in %s", m.Sender.Username, m.ConvID)
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 4:
|
case 5:
|
||||||
if args[2] == "url" {
|
if args[3] == "url" {
|
||||||
// first validate the URL
|
// first validate the URL
|
||||||
u, err := url.ParseRequestURI(args[3])
|
u, err := url.ParseRequestURI(args[4])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
eid := b.logError(err)
|
eid := b.logError(err)
|
||||||
b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid)
|
b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid)
|
||||||
@ -129,10 +148,12 @@ func (b *bot) handleSetCommand(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleListCommand lists settings for the conversation
|
// handleListCommand lists settings for the conversation
|
||||||
|
// this should be called from b.handleConfigCommand()
|
||||||
func (b *bot) handleListCommand(m chat1.MsgSummary) {
|
func (b *bot) handleListCommand(m chat1.MsgSummary) {
|
||||||
// first normalize the text and extract the arguments
|
// first normalize the text and extract the arguments
|
||||||
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
|
args := strings.Fields(strings.ToLower(m.Content.Text.Body))
|
||||||
if args[0] != "list" {
|
if args[2] != "list" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
b.debug("config list called by @%s in %s", m.Sender.Username, m.ConvID)
|
||||||
}
|
}
|
||||||
|
|||||||
11
handlers.go
11
handlers.go
@ -68,14 +68,9 @@ func (b *bot) chatHandler(m chat1.MsgSummary) {
|
|||||||
b.handleWelcome(m.ConvID)
|
b.handleWelcome(m.ConvID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// set commands
|
// config commands
|
||||||
if hasCommandPrefix(m.Content.Text.Body, b.cmd(), b.k.Username, "set") {
|
if hasCommandPrefix(m.Content.Text.Body, b.cmd(), b.k.Username, "config") {
|
||||||
b.handleSetCommand(m)
|
b.handleConfigCommand(m)
|
||||||
return
|
|
||||||
}
|
|
||||||
// list commands
|
|
||||||
if hasCommandPrefix(m.Content.Text.Body, b.cmd(), b.k.Username, "list") {
|
|
||||||
b.handleSetCommand(m)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user