|
|
|
@ -105,7 +105,7 @@ class Instance: |
|
|
|
|
|
|
|
|
|
def respond(self, status, message): |
|
|
|
|
log_print(self.name, "Responded with: {}".format(message)) |
|
|
|
|
self.api.status_reply(status, "{}\n{}".format(message, config["tag"]), visibility = "direct", untag = True) |
|
|
|
|
self.api.status_reply(status, "{}\n#{}".format(message, config["tag"]), visibility = "direct", untag = True) |
|
|
|
|
|
|
|
|
|
def tracker(self): |
|
|
|
|
my_id = self.api.me()["id"] |
|
|
|
@ -143,8 +143,8 @@ class Instance: |
|
|
|
|
preview.body = md_text |
|
|
|
|
preview_text = preview.format() |
|
|
|
|
|
|
|
|
|
print(preview_text) |
|
|
|
|
print() |
|
|
|
|
log_print(self.name, preview_text) |
|
|
|
|
log_print(self.name) |
|
|
|
|
|
|
|
|
|
category = None |
|
|
|
|
while not category in bogofilter.categories: |
|
|
|
@ -156,7 +156,7 @@ class Instance: |
|
|
|
|
if category == bogofilter.SPAM: |
|
|
|
|
self.track_status(status) |
|
|
|
|
|
|
|
|
|
print() |
|
|
|
|
log_print(self.name) |
|
|
|
|
|
|
|
|
|
self.save_state() |
|
|
|
|
else: |
|
|
|
@ -171,11 +171,11 @@ class Instance: |
|
|
|
|
if target_status_id: |
|
|
|
|
try: |
|
|
|
|
target_status = self.api.status(target_status_id) |
|
|
|
|
target_timeslot_key = encode_time(status["created_at"]) |
|
|
|
|
target_timeslot_key = encode_time(target_status["created_at"]) |
|
|
|
|
target_mail_text = toot_dict_to_mail(target_status).format() |
|
|
|
|
|
|
|
|
|
command = h2t.handle(status["content"]).strip() |
|
|
|
|
log_print("Received command: {}".format(command)) |
|
|
|
|
log_print(self.name, "Received command: {}".format(command)) |
|
|
|
|
if command == "learn spam": |
|
|
|
|
bogofilter.run(target_mail_text, [bogofilter.LEARN_SPAM]) |
|
|
|
|
self.track_status(target_status) |
|
|
|
@ -213,17 +213,20 @@ class Instance: |
|
|
|
|
bogo_report = "Bogofilter: Category={}, Score={}".format(result.category, "{:.4f}".format(result.score)) |
|
|
|
|
if result.category == bogofilter.SPAM: |
|
|
|
|
log_print(self.name, "SPAM: Tracking status with ID {} as spam".format(status["id"])) |
|
|
|
|
self.respond(status, "Tracked as spam\n{}".format(bogo_report)) |
|
|
|
|
self.respond(status, "Categorised as spam\n{}".format(bogo_report)) |
|
|
|
|
self.track_status(status) |
|
|
|
|
time.sleep(1) |
|
|
|
|
elif result.category == bogofilter.UNSURE: |
|
|
|
|
log_print(self.name, "UNSURE: Not tracking status with ID {} as spam".format(status["id"])) |
|
|
|
|
self.respond(status, "Categorised as unsure\n{}".format(bogo_report)) |
|
|
|
|
time.sleep(1) |
|
|
|
|
else: |
|
|
|
|
log_print(self.name, "HAM: Not tracking status with ID {} as spam".format(status["id"])) |
|
|
|
|
self.respond(status, "Tracked as ham\n{}".format(bogo_report)) |
|
|
|
|
self.respond(status, "Categorised as ham\n{}".format(bogo_report)) |
|
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
|
print() |
|
|
|
|
print(mail_text) |
|
|
|
|
|
|
|
|
|
self.track_status(status) |
|
|
|
|
log_print(self.name) |
|
|
|
|
log_print(self.name, mail_text) |
|
|
|
|
|
|
|
|
|
self.save_state() |
|
|
|
|
|
|
|
|
|