Skip to content

Commit

Permalink
Implement AmbientMatchCommand plugin config var
Browse files Browse the repository at this point in the history
  • Loading branch information
parsley42 committed Apr 13, 2023
1 parent 10a06b0 commit 583451c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v2.8.0 - POTENTIALLY BREAKING ambient message matching update
In most cases, if someone directs a message to the robot (issues a "command") in a channel, the message should go to the CatchAll if no command matches. Up to now, the default behavior was to match against `MessageMatchers`, even in the case of a command. Starting with v2.8.0, commands will no longer match against message matchers unless `AmbientMatchCommand` is set `true`. For most configurations this shouldn't be an issue, but this could break some configurations. Note that this has no effect in the case of direct messages to the robot, which are always considered commands; all direct messages to the robot can potentially match against `MessageMatchers`.

# v2.7.4 - Longer Memories
Short-term memories really only came in to serious use with the OpenAI plugin, where 7 minutes just wasn't enough for expectations. Now Gopherbot robots have a 14-hour short-term memory.

Expand Down
3 changes: 3 additions & 0 deletions bot/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (w *worker) checkPluginMatchersAndRun(pipelineType pipelineType) (messageMa
}
matchers = plugin.CommandMatchers
case plugMessage:
if w.isCommand && !w.directMsg && !plugin.AmbientMatchCommand {
continue
}
if len(plugin.MessageMatchers) == 0 {
continue
}
Expand Down
8 changes: 7 additions & 1 deletion bot/taskconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ LoadLoop:
val = &intval
case "Disabled":
skip = true
case "AllowDirect", "DirectOnly", "DenyDirect", "AllChannels", "RequireAdmin", "AuthorizeAllCommands", "CatchAll", "MatchUnlisted", "Quiet":
case "AllowDirect", "AmbientMatchCommand", "DirectOnly", "DenyDirect", "AllChannels", "RequireAdmin", "AuthorizeAllCommands", "CatchAll", "MatchUnlisted", "Quiet":
val = &boolval
case "Channels", "ElevatedCommands", "ElevateImmediateCommands", "Users", "AuthorizedCommands", "AdminCommands", "ParameterSets":
val = &sarrval
Expand Down Expand Up @@ -459,6 +459,12 @@ LoadLoop:
} else {
job.Arguments = *(val.(*[]InputMatcher))
}
case "AmbientMatchCommand":
if isPlugin {
plugin.AmbientMatchCommand = *(val.(*bool))
} else {
mismatch = true
}
case "CatchAll":
if isPlugin {
plugin.CatchAll = *(val.(*bool))
Expand Down
1 change: 1 addition & 0 deletions bot/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type Plugin struct {
Help []PluginHelp // All the keyword sets / help texts for this plugin
CommandMatchers []InputMatcher // Input matchers for messages that need to be directed to the 'bot
MessageMatchers []InputMatcher // Input matchers for messages the 'bot hears even when it's not being spoken to
AmbientMatchCommand bool // Whether message matchers should also match when isCommand is true
CatchAll bool // Whenever the robot is spoken to, but no plugin matches, plugins with CatchAll=true get called with command="catchall" and argument=<full text of message to robot>
MatchUnlisted bool // Set to true if ambient messages matches should be checked for users not listed in the UserRoster
*Task
Expand Down
1 change: 1 addition & 0 deletions plugins/samples/hello.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Help:
CommandMatchers:
- Regex: '(?i:hello world)'
Command: "hello"
AmbientMatchCommand: true
MessageMatchers:
- Regex: 'hello robot'
Command: "hello"
Expand Down

0 comments on commit 583451c

Please sign in to comment.