mirror of
https://github.com/Unkn0wnCat/matrix-veles.git
synced 2025-05-31 09:46:39 +02:00
Initial commit
This commit is contained in:
commit
b81af24e50
21 changed files with 2283 additions and 0 deletions
59
internal/bot/commandParser.go
Normal file
59
internal/bot/commandParser.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright © 2022 Kevin Kandlbinder.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package bot
|
||||
|
||||
import (
|
||||
"log"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// handleCommand takes a command, parses it and executes any actions it implies
|
||||
func handleCommand(command string, sender id.UserID, id id.RoomID, client *mautrix.Client) {
|
||||
myUsername, _, err := client.UserID.Parse()
|
||||
if err != nil {
|
||||
log.Panicln("Invalid user id in client")
|
||||
}
|
||||
|
||||
command = strings.TrimPrefix(command, "!") // Remove !
|
||||
command = strings.TrimPrefix(command, "@") // Remove @
|
||||
command = strings.TrimPrefix(command, myUsername) // Remove our own username
|
||||
command = strings.TrimPrefix(command, ":") // Remove : (as in "@soccerbot:")
|
||||
command = strings.TrimSpace(command)
|
||||
|
||||
// TODO: Remove this, it is debug!
|
||||
log.Println(command)
|
||||
|
||||
// Is this a help command?
|
||||
if strings.HasPrefix(command, "help") {
|
||||
commandHelp(sender, id, client)
|
||||
return
|
||||
}
|
||||
|
||||
// No match :( - display help
|
||||
commandHelp(sender, id, client)
|
||||
return
|
||||
}
|
||||
|
||||
func commandHelp(_ id.UserID, id id.RoomID, client *mautrix.Client) {
|
||||
// TODO: Improve help message
|
||||
|
||||
// Ignore errors as we can't do anything about them, the user will probably retry
|
||||
_, _ = client.SendNotice(id, "matrix-veles help\n\n!veles-bot help - shows this help")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue