Added logging and rant_history
All checks were successful
Build Ragnar anti spam bot / Build (push) Successful in 1m2s
All checks were successful
Build Ragnar anti spam bot / Build (push) Successful in 1m2s
This commit is contained in:
parent
dba78e616c
commit
ac851d76c3
@ -2,10 +2,10 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO, # Adjust as needed
|
level=logging.DEBUG,
|
||||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.StreamHandler(sys.stdout), # Log to stdout
|
logging.StreamHandler(sys.stdout),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class Api:
|
|||||||
|
|
||||||
@method_cache
|
@method_cache
|
||||||
def login(self):
|
def login(self):
|
||||||
print("New login, cache miss?")
|
log.info("Logged in as {}".format(self.username))
|
||||||
rawdata = requests.post(
|
rawdata = requests.post(
|
||||||
self.base_url + "users/auth-token",
|
self.base_url + "users/auth-token",
|
||||||
data={"username": self.username, "password": self.password, "app": 3},
|
data={"username": self.username, "password": self.password, "app": 3},
|
||||||
|
@ -11,7 +11,7 @@ class Bot:
|
|||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.name = self.username.split("@")[0]
|
self.name = self.username.split("@")[0]
|
||||||
|
self.rant_history = []
|
||||||
names = {
|
names = {
|
||||||
"no-spam": "anna",
|
"no-spam": "anna",
|
||||||
"no-spam1": "ira",
|
"no-spam1": "ira",
|
||||||
@ -49,7 +49,7 @@ class Bot:
|
|||||||
def clean_rant_text(self, rant_text):
|
def clean_rant_text(self, rant_text):
|
||||||
return rant_text.replace(" ", "").lower()
|
return rant_text.replace(" ", "").lower()
|
||||||
|
|
||||||
# @method_cache
|
@method_cache
|
||||||
def is_sus_rant(self, rant_id, rant_text):
|
def is_sus_rant(self, rant_id, rant_text):
|
||||||
clean_text = self.clean_rant_text(rant_text)
|
clean_text = self.clean_rant_text(rant_text)
|
||||||
for trigger in self.triggers:
|
for trigger in self.triggers:
|
||||||
@ -93,16 +93,21 @@ class Bot:
|
|||||||
self.rsleepii()
|
self.rsleepii()
|
||||||
rants = self.api.get_rants("recent", 5, 0)
|
rants = self.api.get_rants("recent", 5, 0)
|
||||||
for rant in rants:
|
for rant in rants:
|
||||||
|
if rant['id'] in self.rant_history:
|
||||||
|
log.debug("{}: Already checked rant {}.".format(self.name,rant['id']))
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
self.rant_history.append(rant['id'])
|
||||||
if not self.is_user_sus(rant["user_username"]):
|
if not self.is_user_sus(rant["user_username"]):
|
||||||
log.info("User {} is trusted.".format(rant["user_username"]))
|
log.info("{}: User {} is trusted.".format(self.name, rant["user_username"]))
|
||||||
continue
|
continue
|
||||||
if not self.is_sus_rant(rant["id"], rant["text"]):
|
if not self.is_sus_rant(rant["id"], rant["text"]):
|
||||||
log.info("Rant by {} is not sus.".format(rant["user_username"]))
|
log.info("{}: Rant by {} is not sus.".format(self.name, rant["user_username"]))
|
||||||
continue
|
continue
|
||||||
if self.is_flagged_as_sus(rant["id"], rant.get("num_comments")):
|
if self.is_flagged_as_sus(rant["id"], rant.get("num_comments")):
|
||||||
continue
|
continue
|
||||||
log.warning("Rant is not {} flagged as sus yet.".format(rant["user_username"]))
|
log.warning("{}: Rant is not {} flagged as sus yet.".format(self.name,rant["user_username"]))
|
||||||
log.warning("Flagging rant by {} as sus.".format(rant["user_username"]))
|
log.warning("{}: Flagging rant by {} as sus.".format(self.name, rant["user_username"]))
|
||||||
self.mark_as_sus(rant)
|
self.mark_as_sus(rant)
|
||||||
self.down_vote_rant(rant)
|
self.down_vote_rant(rant)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ def parse_args():
|
|||||||
|
|
||||||
|
|
||||||
def bot_task(username, password):
|
def bot_task(username, password):
|
||||||
log.info("Created new but task. Username: {}".format(username))
|
log.info("Created new bot runniner. Username: {}".format(username))
|
||||||
time.sleep(random.randint(1, 20))
|
time.sleep(random.randint(1, 20))
|
||||||
bot = Bot(username=username, password=password)
|
bot = Bot(username=username, password=password)
|
||||||
bot.login()
|
bot.login()
|
||||||
|
Loading…
Reference in New Issue
Block a user