Refactor, rename query command to talk

This commit is contained in:
Alex 2020-02-26 16:03:55 +01:00
parent 6d33fa5d93
commit a8e87e378e

View file

@ -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
}