unified command structure
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"samhofi.us/x/keybase/types/chat1"
|
||||
)
|
||||
|
||||
func (b *bot) setupMeeting(convid chat1.ConvIDStr, sender string, words []string, membersType string) {
|
||||
func (b *bot) setupMeeting(convid chat1.ConvIDStr, sender string, args []string, membersType string) {
|
||||
b.debug("command recieved in conversation %s", convid)
|
||||
meeting, err := newJitsiMeeting()
|
||||
if err != nil {
|
||||
@ -21,17 +21,16 @@ func (b *bot) setupMeeting(convid chat1.ConvIDStr, sender string, words []string
|
||||
b.k.SendMessageByConvID(convid, message)
|
||||
}
|
||||
|
||||
func (b *bot) sendFeedback(convid chat1.ConvIDStr, mesgID chat1.MessageID, sender string, words []string) {
|
||||
func (b *bot) sendFeedback(convid chat1.ConvIDStr, mesgID chat1.MessageID, sender string, args []string) {
|
||||
b.debug("feedback recieved in %s", convid)
|
||||
if b.config.FeedbackConvIDStr != "" {
|
||||
feedback := strings.Join(words[2:], " ")
|
||||
feedback := strings.Join(args, " ")
|
||||
fcID := chat1.ConvIDStr(b.config.FeedbackConvIDStr)
|
||||
if _, err := b.k.SendMessageByConvID(fcID, "Feedback from @%s:\n```%s```", sender, feedback); err != nil {
|
||||
b.k.ReplyByConvID(convid, mesgID, "I'm sorry, I was unable to send your feedback because my benevolent overlords have not set a destination for feedback. :sad:")
|
||||
log.Printf("Unable to send feedback: %s", err)
|
||||
} else {
|
||||
b.k.ReplyByConvID(convid, mesgID, "Thanks! Your feedback has been sent to my human overlords!")
|
||||
b.debug("feedback sent")
|
||||
}
|
||||
} else {
|
||||
b.debug("feedback not enabled. set --feedback-convid or BOT_FEEDBACK_CONVID")
|
||||
@ -39,5 +38,5 @@ func (b *bot) sendFeedback(convid chat1.ConvIDStr, mesgID chat1.MessageID, sende
|
||||
}
|
||||
|
||||
func (b *bot) sendWelcome(convid chat1.ConvIDStr) {
|
||||
b.k.SendMessageByConvID(convid, "Hello there!! I'm the Jitsi meeting bot, made by @haukened\nI can start Jitsi meetings right here in this chat!\nI can be activated in 2 ways:\n 1. `@jitsibot meet`\n 2.`!jitsi`\nYou can provide feedback to my humans using:\n 1. `@jitsibot feedback <type anything>`\n 2. `!jitsi feedback <type anything>`\nYou can also join @jitsi_meet to talk about features, enhancements, or talk to live humans! Everyone is welcome!\nI also accept donations to offset hosting costs, just send some XLM to my wallet if you feel like it by typing `+5XLM@jitsibot`")
|
||||
b.k.SendMessageByConvID(convid, "Hello there!! I'm the Jitsi meeting bot, made by @haukened\nI can start Jitsi meetings right here in this chat!\nI can be activated in 2 ways:\n 1. `@jitsibot`\n 2.`!jitsi`\nYou can provide feedback to my humans using:\n 1. `@jitsibot feedback <type anything>`\n 2. `!jitsibot feedback <type anything>`\nYou can also join @jitsi_meet to talk about features, enhancements, or talk to live humans! Everyone is welcome!\nI also accept donations to offset hosting costs, just send some XLM to my wallet if you feel like it by typing `+5XLM@jitsibot`\nIf you ever need to see this message again, ask me for help or say hello to me!")
|
||||
}
|
||||
|
||||
64
handlers.go
64
handlers.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
@ -47,42 +46,37 @@ func (b *bot) chatHandler(m chat1.MsgSummary) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// if the message is @myusername just perform the default function
|
||||
if strings.HasPrefix(m.Content.Text.Body, fmt.Sprintf("@%s", b.k.Username)) {
|
||||
// Determine first if this is a command
|
||||
if strings.HasPrefix(m.Content.Text.Body, "!") || strings.HasPrefix(m.Content.Text.Body, "@") {
|
||||
// determine the root command
|
||||
words := strings.Fields(m.Content.Text.Body)
|
||||
if len(words) > 1 {
|
||||
switch words[1] {
|
||||
case "meet":
|
||||
b.setupMeeting(m.ConvID, m.Sender.Username, words, m.Channel.MembersType)
|
||||
case "feedback":
|
||||
b.sendFeedback(m.ConvID, m.Id, m.Sender.Username, words)
|
||||
case "hello":
|
||||
fallthrough
|
||||
case "help":
|
||||
b.sendWelcome(m.ConvID)
|
||||
}
|
||||
}
|
||||
}
|
||||
// its a command for me, iterate through extended commands
|
||||
if strings.HasPrefix(m.Content.Text.Body, "!") {
|
||||
// break up the message into words
|
||||
words := strings.Fields(m.Content.Text.Body)
|
||||
// strip the ! from the first word, and lowercase to derive the command
|
||||
thisCommand := strings.ToLower(strings.Replace(words[0], "!", "", 1))
|
||||
maybeSubCommand := ""
|
||||
if len(words) > 1 {
|
||||
maybeSubCommand = strings.ToLower(words[1])
|
||||
}
|
||||
// decide if this is askind for extended commands
|
||||
switch thisCommand {
|
||||
command := strings.Replace(words[0], "@", "", 1)
|
||||
command = strings.Replace(command, "!", "", 1)
|
||||
command = strings.ToLower(command)
|
||||
// create the args
|
||||
args := words[1:]
|
||||
nargs := len(args)
|
||||
switch command {
|
||||
case b.k.Username:
|
||||
fallthrough
|
||||
case "jitsi":
|
||||
switch maybeSubCommand {
|
||||
case "feedback":
|
||||
b.sendFeedback(m.ConvID, m.Id, m.Sender.Username, words)
|
||||
case "help":
|
||||
b.sendWelcome(m.ConvID)
|
||||
default:
|
||||
b.setupMeeting(m.ConvID, m.Sender.Username, words, m.Channel.MembersType)
|
||||
if nargs == 0 {
|
||||
b.setupMeeting(m.ConvID, m.Sender.Username, args, m.Channel.MembersType)
|
||||
} else if nargs >= 1 {
|
||||
// pop the subcommand off the front of the list
|
||||
subcommand, args := args[0], args[1:]
|
||||
switch subcommand {
|
||||
case "meet":
|
||||
b.setupMeeting(m.ConvID, m.Sender.Username, args, m.Channel.MembersType)
|
||||
case "feedback":
|
||||
b.sendFeedback(m.ConvID, m.Id, m.Sender.Username, args)
|
||||
case "hello":
|
||||
fallthrough
|
||||
case "help":
|
||||
b.sendWelcome(m.ConvID)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
default:
|
||||
return
|
||||
|
||||
5
main.go
5
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
@ -84,7 +85,7 @@ func (b *bot) registerCommands() {
|
||||
Usage: "",
|
||||
},
|
||||
{
|
||||
Name: "jitsi feedback",
|
||||
Name: fmt.Sprintf("%s feedback", b.k.Username),
|
||||
Description: "Tell us how we're doing!",
|
||||
Usage: "",
|
||||
ExtendedDescription: getFeedbackExtendedDescription(b.config),
|
||||
@ -105,6 +106,8 @@ func (b *bot) run(args []string) error {
|
||||
}
|
||||
|
||||
b.registerHandlers()
|
||||
// clear the commands and advertise the new commands
|
||||
b.k.ClearCommands()
|
||||
b.registerCommands()
|
||||
|
||||
log.Println("Starting...")
|
||||
|
||||
Reference in New Issue
Block a user