From 106d26e616c52769d6c055d36cb91218c33b9afa Mon Sep 17 00:00:00 2001 From: Meet Mangukiya Date: Mon, 27 Nov 2017 19:08:48 +0530 Subject: [PATCH] Re_botcmd_fullmatch: Add re_botcmd_fullmatch Closes https://github.com/coala/corobo/issues/402 --- plugins/re_botcmd_fullmatch.plug | 10 ++++++++++ plugins/re_botcmd_fullmatch.py | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 plugins/re_botcmd_fullmatch.plug create mode 100644 plugins/re_botcmd_fullmatch.py diff --git a/plugins/re_botcmd_fullmatch.plug b/plugins/re_botcmd_fullmatch.plug new file mode 100644 index 00000000..66fb4717 --- /dev/null +++ b/plugins/re_botcmd_fullmatch.plug @@ -0,0 +1,10 @@ +[Core] +name = re_botcmd_fullmatch +module = re_botcmd_fullmatch + +[Documentation] +description = Checks whether all re_botcmd regexes are fullmatches or not and warns the admins. + +[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))