Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces large if statement by 'any' and code lists #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Cinnabot/plugins/CommunityRegistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down