mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Fix active command matching
This commit is contained in:
parent
b805641ea4
commit
f06c6dd767
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@ github/
|
||||
gitlab/
|
||||
rss/
|
||||
factorial/
|
||||
dictionary/
|
||||
|
@ -43,6 +43,7 @@ func (pc *ParsedCommand) parseCommandSyntax(command maubot.Command) error {
|
||||
argumentEncountered := false
|
||||
|
||||
regexBuilder.WriteString("^!")
|
||||
swBuilder.WriteRune('!')
|
||||
words := strings.Split(command.Syntax, " ")
|
||||
for i, word := range words {
|
||||
argument, ok := command.Arguments[word]
|
||||
@ -50,8 +51,10 @@ func (pc *ParsedCommand) parseCommandSyntax(command maubot.Command) error {
|
||||
if ok && len(word) > 0 /*&& word[0] == '$'*/ {
|
||||
argumentEncountered = true
|
||||
regex := argument.Matches
|
||||
if argument.Required {
|
||||
if !argument.Required {
|
||||
regex = fmt.Sprintf("(?:%s)?", regex)
|
||||
} else {
|
||||
regex = fmt.Sprintf("(%s)", regex)
|
||||
}
|
||||
pc.Arguments = append(pc.Arguments, word)
|
||||
regexBuilder.WriteString(regex)
|
||||
|
@ -104,11 +104,11 @@ func (client *Client) GetEvent(roomID, eventID string) *maubot.Event {
|
||||
func (client *Client) TriggerCommand(command *ParsedCommand, evt *maubot.Event) maubot.CommandHandlerResult {
|
||||
handlers, ok := client.handlers[command.Name]
|
||||
if !ok {
|
||||
log.Warnf("Command %s triggered by %s doesn't have any handlers.\n", command.Name, evt.Sender)
|
||||
log.Warnf("Command `%s` triggered by %s doesn't have any handlers.\n", command.Name, evt.Sender)
|
||||
return maubot.Continue
|
||||
}
|
||||
|
||||
log.Debugf("Command %s on client %s triggered by %s\n", command.Name, client.UserID, evt.Sender)
|
||||
log.Debugf("Command `%s` on client %s triggered by %s\n", command.Name, client.UserID, evt.Sender)
|
||||
for _, handler := range handlers {
|
||||
result := handler(evt)
|
||||
if result == maubot.StopCommandPropagation {
|
||||
|
Loading…
Reference in New Issue
Block a user