Different apps might need different message matching behavior to make sure we don't waste time with this initial filtering step.
We assume there are four different kinds of commonly expected behavior for which we provide an implementation.
SimpleStaticMessageMatcher
A SimpleStaticMessageMatcher
assumes that all prefixes defined in the Application are already resolved (therefore static) and will not change while the app is running. Knowing this we can just iterate over the limited set of prefixes on every message event to check for one of the prefixes.
TransientDynamicMessageMatcher
The TransientDynamicMessageMatcher
is able to resolve dynamic prefixes which might be asynchronous or depend on some other outside data. It will resolve all possible prefixes that are defined in the application using the incoming message. On resolution, the message content will be checked for possible matches.
CachedDynamicMessageMatcher
The CachedDynamicMessageMatcher
works almost exactly like the TransientDynamicMessageMatcher
with the key difference that the resolved prefix is saved in a cache for later reference.
When a message passes, a resync of the cache will be scheduled asynchronously using the prefix and the message. (This process will not be awaited and can happen in the background). This way the cache will stay up to date while still having good lookup times for prefixes. Because we're dealing with dynamic prefixes which, depending on the size of the app, could be too many to just iterate over, we'll use a Trie will be used to figure out the prefix used in a given message.
GuildScopedMessageMatcher
A GuildScopedMessageMatcher
works very similarly to the CachedDynamicMessageMatcher
. Here we assume that every guild only has one prefix assigned to it. That way we can cache prefixes in a guildId
- prefix
map to look up prefixes. Similar to the other implementation we'll also sync the prefix cache for a prefix on every message.
To force a resync (After a guild prefix update maybe) we provide a public method on the matcher to force an update for a given guild.
Note that you'll also be able to provide your own implementation to best fit your needs.