Fix out of bounds error in user commands (the most stupid bug possible)

This commit is contained in:
Alex 2020-04-05 12:31:35 +02:00
parent ad8461491b
commit 4d909fffd8

View file

@ -225,6 +225,10 @@ func handleTxnEvent(e *mxlib.Event) error {
func handleSystemMessage(mxid string, msg string) { func handleSystemMessage(mxid string, msg string) {
cmd := strings.Fields(msg) cmd := strings.Fields(msg)
if len(cmd) == 0 {
return
}
switch cmd[0] { switch cmd[0] {
case "help": case "help":
ezbrSystemSend(mxid, "Welcome to Easybridge! Here is a list of available commands:") ezbrSystemSend(mxid, "Welcome to Easybridge! Here is a list of available commands:")
@ -246,6 +250,11 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSendf(mxid, "No account currently configured") ezbrSystemSendf(mxid, "No account currently configured")
} }
case "join": case "join":
if len(cmd) != 2 {
ezbrSystemSendf(mxid, "Usage: %s <protocol or account> <room id>", cmd[0])
return
}
account := findAccount(mxid, cmd[1]) account := findAccount(mxid, cmd[1])
if account != nil { if account != nil {
err := account.Conn.Join(connector.RoomID(cmd[2])) err := account.Conn.Join(connector.RoomID(cmd[2]))
@ -256,6 +265,11 @@ func handleSystemMessage(mxid string, msg string) {
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", "talk": case "query", "talk":
if len(cmd) != 2 {
ezbrSystemSendf(mxid, "Usage: %s <protocol or account> <user id>", cmd[0])
return
}
account := findAccount(mxid, cmd[1]) account := findAccount(mxid, cmd[1])
if account != nil { if account != nil {
quser := connector.UserID(cmd[2]) quser := connector.UserID(cmd[2])
@ -278,6 +292,11 @@ func handleSystemMessage(mxid string, msg string) {
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 "search": case "search":
if len(cmd) < 2 {
ezbrSystemSendf(mxid, "Usage: %s <protocol or account> <name>", cmd[0])
return
}
account := findAccount(mxid, cmd[1]) account := findAccount(mxid, cmd[1])
if account != nil { if account != nil {
rep, err := account.Conn.SearchForUsers(strings.Join(cmd[2:], " ")) rep, err := account.Conn.SearchForUsers(strings.Join(cmd[2:], " "))