cog
cog copied to clipboard
Cache command prefix regex
We build regular expressions to strip the command prefix from command text in a number of places, often for each message we receive. Since this pattern does not change during the runtime of Cog, we should compile the necessary patterns during initialization of the processes that they're relevant for. These patterns are not identical in every place they're used so we can't do that globally, but we could cache in each adapter for example.
A good example of this pattern exists in the Cog.Adapters.HipChat.Connection Genserver:
https://github.com/operable/cog/blob/master/lib/cog/adapters/hipchat/connection.ex#L17