From 29d68e3d4ebd32a72c28a4b740b658d6eab350ab 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 | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 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..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..df1f680d --- /dev/null +++ b/plugins/re_botcmd_fullmatch.py @@ -0,0 +1,30 @@ +from errbot import BotPlugin, botcmd + + +class Re_botcmd_fullmatch(BotPlugin): + """ + Checks whether all re_botcmd regexes are fullmatches or not and warns the + admins. + """ + + def activate(self): + """ + Triggers on plugin activation + + You should delete it if you're not using it to override any default behaviour + """ + super(Re_botcmd_fullmatch, self).activate() + + 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))