diff --git a/Makefile b/Makefile index 96ceb6c..92a8228 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: ensure_env format build install +all: ensure_env format build install test format: ./.venv/bin/python -m pip install black @@ -15,4 +15,7 @@ install: ./.venv/bin/python -m pip install -e . run: - python -m ragnar.run \ No newline at end of file + python -m ragnar.run + +test: + ./.venv/bin/python -m unittest ragnar.tests \ No newline at end of file diff --git a/src/ragnar/bot.py b/src/ragnar/bot.py index 32e7bed..f899a42 100644 --- a/src/ragnar/bot.py +++ b/src/ragnar/bot.py @@ -2,6 +2,7 @@ from ragnar.api import Api import time import random from ragnar.cache import method_cache +import re class Bot: @@ -23,7 +24,15 @@ class Bot: self.name ) self.auth = None - self.triggers = ["$", "crypto", "hacker", "recovery"] + + self.triggers = [ + "$", + "crypto", + "hacker", + "recovery", + {"regex": "\([+,(,0-9,),-]{7,}"}, + "money", + ] self.api = Api(username=self.username, password=self.password) @@ -39,12 +48,23 @@ class Bot: raise Exception("Login error") print("Authentication succesful for {}.".format(self.username)) - @method_cache + def clean_rant_text(self, rant_text): + return rant_text.replace(" ", "").lower() + + # @method_cache def is_sus_rant(self, rant_id, rant_text): - clean_text = rant_text.replace(" ", "").lower() + clean_text = self.clean_rant_text(rant_text) for trigger in self.triggers: - if trigger in clean_text: + if type(trigger) == dict: + if trigger.get("regex"): + regex = trigger["regex"] + if re.search(regex, clean_text): + print("Regex trigger {} matched!".format(regex)) + return True + elif trigger in clean_text: + print("Trigger {} matched!".format(trigger)) return True + return False def is_flagged_as_sus(self, rant_id, num_comments): if not num_comments: