aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-26 16:03:55 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-26 16:03:55 +0100
commita8e87e378ea0a232cb06ef65d77fd39009270676 (patch)
treea58792b9eb73f5092744f8593ba2cff2f42d4b5e /appservice
parent6d33fa5d937be3e33fa9cf14d35fc9ab45712750 (diff)
downloadeasybridge-a8e87e378ea0a232cb06ef65d77fd39009270676.tar.gz
easybridge-a8e87e378ea0a232cb06ef65d77fd39009270676.zip
Refactor, rename query command to talk
Diffstat (limited to 'appservice')
-rw-r--r--appservice/server.go35
1 files changed, 15 insertions, 20 deletions
diff --git a/appservice/server.go b/appservice/server.go
index d96f27c..669559d 100644
--- a/appservice/server.go
+++ b/appservice/server.go
@@ -204,7 +204,7 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSend(mxid, "- list: list accounts")
ezbrSystemSend(mxid, "- accounts: list accounts")
ezbrSystemSend(mxid, "- join <protocol or account> <room id>: join public chat room")
- ezbrSystemSend(mxid, "- query <protocol or account> <user id>: open private buffer to contact")
+ ezbrSystemSend(mxid, "- talk <protocol or account> <user id>: open private conversation to contact")
case "list", "account", "accounts":
one := false
if accts, ok := registeredAccounts[mxid]; ok {
@@ -217,15 +217,7 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSendf(mxid, "No account currently configured")
}
case "join":
- var account *Account
- if accts, ok := registeredAccounts[mxid]; ok {
- for name, acct := range accts {
- if name == cmd[1] || acct.Protocol == cmd[1] {
- account = acct
- break
- }
- }
- }
+ account := findAccount(mxid, cmd[1])
if account != nil {
err := account.Conn.Join(connector.RoomID(cmd[2]))
if err != nil {
@@ -234,16 +226,8 @@ func handleSystemMessage(mxid string, msg string) {
} else {
ezbrSystemSendf(mxid, "No account with name or using protocol %s", cmd[1])
}
- case "query":
- var account *Account
- if accts, ok := registeredAccounts[mxid]; ok {
- for name, acct := range accts {
- if name == cmd[1] || acct.Protocol == cmd[1] {
- account = acct
- break
- }
- }
- }
+ case "talk":
+ account := findAccount(mxid, cmd[1])
if account != nil {
quser := connector.UserID(cmd[2])
err := account.Conn.Invite(quser, connector.RoomID(""))
@@ -268,3 +252,14 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSend(mxid, "Unrecognized command. Type `help` if you need some help!")
}
}
+
+func findAccount(mxid string, q string) *Account {
+ if accts, ok := registeredAccounts[mxid]; ok {
+ for name, acct := range accts {
+ if name == q || acct.Protocol == q {
+ return acct
+ }
+ }
+ }
+ return nil
+}