diff --git a/plugins/re_botcmd_fullmatch.plug b/plugins/re_botcmd_fullmatch.plug new file mode 100644 index 00000000..6462f6d0 --- /dev/null +++ b/plugins/re_botcmd_fullmatch.plug @@ -0,0 +1,10 @@ +[Core] +name = re_botcmd_fullmatch +module = re_botcmd_fullmatch + +[Documentation] +description = + +[Python] +version = 3 + diff --git a/plugins/re_botcmd_fullmatch.py b/plugins/re_botcmd_fullmatch.py new file mode 100644 index 00000000..c9f167d7 --- /dev/null +++ b/plugins/re_botcmd_fullmatch.py @@ -0,0 +1,24 @@ +from errbot import BotPlugin, botcmd + + +class Re_botcmd_fullmatch(BotPlugin): + """ + Checks whether all re_botcmd regexes are fullmatches or not and warns the + admins. + """ + + @botcmd + def check_regexes(self, msg, args) + if hasattr(self.bot_config, 'RE_BOTCMD_FULLMATCH_IGNORES'): + ignores = self.bot_config.RE_BOTCMD_FULLMATCH_IGNORES + else: + ignores = tuple() + + for name, func in dict(self._bot.re_commands).items(): + pattern = func._err_command_re_pattern.pattern + if not (pattern.startswith('^') and pattern.endswith('$') and + name not in ignores): + self.warn_admins('re_botcmd {} has a pattern `{}` that is not ' + 'a fullmatch. If it is intentional, please ' + 'add it to the `RE_BOTCMD_FULLMATCH_IGNORES` ' + 'config variable.'.format(name, pattern))