Added unit test and regex
Some checks failed
Build Ragnar anti spam bot / Build (push) Failing after 1m1s
Some checks failed
Build Ragnar anti spam bot / Build (push) Failing after 1m1s
This commit is contained in:
parent
c48bf54dc1
commit
42eca170a6
5
Makefile
5
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
|
||||
@ -16,3 +16,6 @@ install:
|
||||
|
||||
run:
|
||||
python -m ragnar.run
|
||||
|
||||
test:
|
||||
./.venv/bin/python -m unittest ragnar.tests
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user