mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-13 09:03:10 +01:00
Ignore multiple spaces in commands
This commit is contained in:
parent
9dfd9c88b2
commit
bb883e1262
1 changed files with 10 additions and 2 deletions
12
commands.go
12
commands.go
|
@ -78,6 +78,14 @@ func (ce *CommandEvent) Reply(msg string, args ...interface{}) {
|
||||||
// Handle handles messages to the bridge
|
// Handle handles messages to the bridge
|
||||||
func (handler *CommandHandler) Handle(roomID id.RoomID, user *User, message string) {
|
func (handler *CommandHandler) Handle(roomID id.RoomID, user *User, message string) {
|
||||||
args := strings.Split(message, " ")
|
args := strings.Split(message, " ")
|
||||||
|
ptr := 0
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
if args[i] != "" {
|
||||||
|
args[ptr] = args[i]
|
||||||
|
ptr++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args = args[:ptr]
|
||||||
ce := &CommandEvent{
|
ce := &CommandEvent{
|
||||||
Bot: handler.bridge.Bot,
|
Bot: handler.bridge.Bot,
|
||||||
Bridge: handler.bridge,
|
Bridge: handler.bridge,
|
||||||
|
@ -601,7 +609,7 @@ func (handler *CommandHandler) CommandList(ce *CommandEvent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pages := int(math.Ceil(float64(len(result)) / float64(max)))
|
pages := int(math.Ceil(float64(len(result)) / float64(max)))
|
||||||
if (page - 1) * max >= len(result) {
|
if (page-1)*max >= len(result) {
|
||||||
if pages == 1 {
|
if pages == 1 {
|
||||||
ce.Reply("There is only 1 page of %s", strings.ToLower(typeName))
|
ce.Reply("There is only 1 page of %s", strings.ToLower(typeName))
|
||||||
} else {
|
} else {
|
||||||
|
@ -609,7 +617,7 @@ func (handler *CommandHandler) CommandList(ce *CommandEvent) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastIndex := page*max
|
lastIndex := page * max
|
||||||
if lastIndex > len(result) {
|
if lastIndex > len(result) {
|
||||||
lastIndex = len(result)
|
lastIndex = len(result)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue