Refactor, rename query command to talk
This commit is contained in:
parent
6d33fa5d93
commit
a8e87e378e
1 changed files with 15 additions and 20 deletions
|
@ -204,7 +204,7 @@ func handleSystemMessage(mxid string, msg string) {
|
||||||
ezbrSystemSend(mxid, "- list: list accounts")
|
ezbrSystemSend(mxid, "- list: list accounts")
|
||||||
ezbrSystemSend(mxid, "- accounts: list accounts")
|
ezbrSystemSend(mxid, "- accounts: list accounts")
|
||||||
ezbrSystemSend(mxid, "- join <protocol or account> <room id>: join public chat room")
|
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":
|
case "list", "account", "accounts":
|
||||||
one := false
|
one := false
|
||||||
if accts, ok := registeredAccounts[mxid]; ok {
|
if accts, ok := registeredAccounts[mxid]; ok {
|
||||||
|
@ -217,15 +217,7 @@ func handleSystemMessage(mxid string, msg string) {
|
||||||
ezbrSystemSendf(mxid, "No account currently configured")
|
ezbrSystemSendf(mxid, "No account currently configured")
|
||||||
}
|
}
|
||||||
case "join":
|
case "join":
|
||||||
var account *Account
|
account := findAccount(mxid, cmd[1])
|
||||||
if accts, ok := registeredAccounts[mxid]; ok {
|
|
||||||
for name, acct := range accts {
|
|
||||||
if name == cmd[1] || acct.Protocol == cmd[1] {
|
|
||||||
account = acct
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if account != nil {
|
if account != nil {
|
||||||
err := account.Conn.Join(connector.RoomID(cmd[2]))
|
err := account.Conn.Join(connector.RoomID(cmd[2]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -234,16 +226,8 @@ func handleSystemMessage(mxid string, msg string) {
|
||||||
} else {
|
} else {
|
||||||
ezbrSystemSendf(mxid, "No account with name or using protocol %s", cmd[1])
|
ezbrSystemSendf(mxid, "No account with name or using protocol %s", cmd[1])
|
||||||
}
|
}
|
||||||
case "query":
|
case "talk":
|
||||||
var account *Account
|
account := findAccount(mxid, cmd[1])
|
||||||
if accts, ok := registeredAccounts[mxid]; ok {
|
|
||||||
for name, acct := range accts {
|
|
||||||
if name == cmd[1] || acct.Protocol == cmd[1] {
|
|
||||||
account = acct
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if account != nil {
|
if account != nil {
|
||||||
quser := connector.UserID(cmd[2])
|
quser := connector.UserID(cmd[2])
|
||||||
err := account.Conn.Invite(quser, connector.RoomID(""))
|
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!")
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue