From b21f1023ef20522c3c5f4af801829c89cfb234be Mon Sep 17 00:00:00 2001 From: Schallaven Date: Sun, 15 Jul 2018 14:29:23 -0400 Subject: [PATCH] Replaces large if statement by 'any' and code lists --- Cinnabot/plugins/CommunityRegistration.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Cinnabot/plugins/CommunityRegistration.py b/Cinnabot/plugins/CommunityRegistration.py index d879bcf..a127d5b 100644 --- a/Cinnabot/plugins/CommunityRegistration.py +++ b/Cinnabot/plugins/CommunityRegistration.py @@ -16,6 +16,17 @@ ] } +# Checked vs individual words declared here as two lists; one word of each list has to be present +codelist1 = ["code", "codigo", u"c\ufffddigo", "community"] +codelist2 = ["denregistrement", "enregistrement", "registration", "registro"] +codewords_whitelist = [(item1, item2) for item1 in codelist1 for item2 in codelist2 if item1 is not item2] +# Some special cases, which cannot be easily generalized +codewords_whitelist.append(("community", "code")) +print(codewords_whitelist) + +# Checked vs the whole message line; one item has to be present +codeterms_whitelist = [ "reg code", "reg. code" ] + class CommunityRegistrationPlugin(BasePlugin): def __init__(self, bot, plugin_name): BasePlugin.__init__(self, bot, plugin_name) @@ -99,7 +110,7 @@ def process_channel_message(self, source, target, msg): if current_word != "": words_lower.append(current_word) - if (("denregistrement" in words_lower or "enregistrement" in words_lower) and "code" in words_lower) or ("registro" in words_lower and (u'c\ufffddigo' in words_lower or 'codigo' in words_lower)) or ("registration" in words_lower and "code" in words_lower) or ("community" in words_lower and "code" in words_lower) or ("registration" in words_lower and "community" in words_lower) or ("reg code" in msg.lower()) or ("reg. code" in msg.lower()): + if any(term in msg.lower() for term in codeterms_whitelist) or any((word[0] in words_lower and word[1] in words_lower) for word in codewords_whitelist): from_nickname = source.split("!")[0] if from_nickname in self._bot._nick_to_username_map and self._bot._nick_to_username_map[from_nickname] in self.ignore_users: return