From a8e87e378ea0a232cb06ef65d77fd39009270676 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 26 Feb 2020 16:03:55 +0100 Subject: Refactor, rename query command to talk --- appservice/server.go | 35 +++++++++++++++-------------------- 1 file 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 : join public chat room") - ezbrSystemSend(mxid, "- query : open private buffer to contact") + ezbrSystemSend(mxid, "- talk : 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 +} -- cgit v1.2.3