Reworded to cringe/based; auto-create wordlist.db

master
Thor 3 years ago
parent b471628ab1
commit b179a0fc5c
  1. 14
      README.md
  2. 6
      bogofilter.py
  3. 36
      cringebot.py

@ -57,17 +57,17 @@ journalctl -t cringebot -f
The bot will respond to each of your messages with a categorisation direct message. To adjust it, you can respond to this direct message with:
```
learn spam
learn ham
learn cringe
learn based
unlearn spam
unlearn ham
unlearn cringe
unlearn based
relearn spam
relearn ham
relearn cringe
relearn based
```
Use `learn` on messages the bot is unsure about, `unlearn` to weaken the categorisation, and `relearn` to nudge a clear categorisation one way or another. When a message is learned or relearned as spam, it's scheduled for deletion `max_age` minutes after it was posted. When it's learned or relearned as ham, or unlearned as spam, it's removed from the deletion schedule.
Use `learn` on messages the bot is unsure about, `unlearn` to weaken the categorisation, and `relearn` to nudge a clear categorisation one way or another. When a message is learned or relearned as cringe, it's scheduled for deletion `max_age` minutes after it was posted. When it's learned or relearned as based, or unlearned as cringe, it's removed from the deletion schedule.
## Maintainer

@ -2,13 +2,16 @@ import subprocess
from email.utils import format_datetime
from datetime import datetime
import quopri
import os
DB_DIR = "."
DB_PATH = os.path.join(DB_DIR, "wordlist.db")
MAX_HAM = 0.07
MIN_SPAM = 0.25
MIN_DEV = 2 * (MIN_SPAM - MAX_HAM) * 0.375
ROBS = 0.0178
ROBX = (MAX_HAM + MIN_SPAM) / 2
LOAD_COMMAND = ["bogoutil", "-l", DB_PATH]
COMMAND = ["bogofilter", "-T", "-c", "/dev/null", "-d", DB_DIR, "-o", "{},{}".format(MIN_SPAM, MAX_HAM), "-m", "{},{},{}".format(MIN_DEV, ROBS, ROBX)]
@ -76,6 +79,9 @@ def run(text, actions = [CLASSIFY], category = UNSURE):
for action in actions:
args.extend(ACTIONS[action])
if not os.path.exists(DB_PATH):
subprocess.run(LOAD_COMMAND, input = b'')
cp = subprocess.run(COMMAND + args, capture_output = True, encoding = "utf-8", input = text)
arr = cp.stdout.strip().split(" ")
if len(arr) == 2:

@ -115,39 +115,39 @@ class CringeBotClient(BotClient):
token = tokens.popleft()
if token == "learn":
token = tokens.popleft()
if token == "spam":
if token == "cringe":
bogofilter.run(target_mail_text, [bogofilter.LEARN_SPAM])
self.track_status(target_status)
self.respond(status, "Learned as spam")
self.respond(status, "Learned as cringe")
break
elif token == "ham":
elif token == "based":
bogofilter.run(target_mail_text, [bogofilter.LEARN_HAM])
self.expire_status(target_timeslot_key, target_status_id)
self.respond(status, "Learned as ham")
self.respond(status, "Learned as based")
break
elif token == "unlearn":
token = tokens.popleft()
if token == "spam":
if token == "cringe":
bogofilter.run(target_mail_text, [bogofilter.UNLEARN_SPAM])
self.expire_status(target_timeslot_key, target_status_id)
self.respond(status, "Unlearned as spam")
self.respond(status, "Unlearned as cringe")
break
elif token == "ham":
bogofilter.run(target_mail_text, [bogofilter.UNLEARN_SPAM])
elif token == "based":
bogofilter.run(target_mail_text, [bogofilter.UNLEARN_HAM])
self.expire_status(target_timeslot_key, target_status_id)
self.respond(status, "Unlearned as spam")
self.respond(status, "Unlearned as cringe")
break
elif token == "relearn":
token = tokens.popleft()
if token == "spam":
if token == "cringe":
bogofilter.run(target_mail_text, [bogofilter.UNLEARN_HAM, bogofilter.LEARN_SPAM])
self.track_status(target_status)
self.respond(status, "Relearned as spam")
self.respond(status, "Relearned as cringe")
break
elif token == "ham":
elif token == "based":
bogofilter.run(target_mail_text, [bogofilter.UNLEARN_SPAM, bogofilter.LEARN_HAM])
self.expire_status(target_timeslot_key, target_status_id)
self.respond(status, "Relearned as as ham")
self.respond(status, "Relearned as as based")
break
except IndexError:
self.respond(status, "Invalid command")
@ -162,15 +162,15 @@ class CringeBotClient(BotClient):
result = bogofilter.run(mail_text, [bogofilter.CLASSIFY, bogofilter.REGISTER])
bogo_report = "Bogofilter: Category={}, Score={}".format(result.category, "{:.4f}".format(result.score))
if result.category == bogofilter.SPAM:
self.log("SPAM: Tracking status with ID {} as spam".format(status["id"]))
self.respond(status, "Categorised as spam\n{}".format(bogo_report))
self.log("CRINGE: Tracking status with ID {} as cringe".format(status["id"]))
self.respond(status, "Categorised as cringe\n{}".format(bogo_report))
self.track_status(status)
elif result.category == bogofilter.UNSURE:
self.log("UNSURE: Not tracking status with ID {} as spam".format(status["id"]))
self.log("UNSURE: Not tracking status with ID {} as cringe".format(status["id"]))
self.respond(status, "Categorised as unsure\n{}".format(bogo_report))
else:
self.log("HAM: Not tracking status with ID {} as spam".format(status["id"]))
self.respond(status, "Categorised as ham\n{}".format(bogo_report))
self.log("BASED: Not tracking status with ID {} as cringe".format(status["id"]))
self.respond(status, "Categorised as based\n{}".format(bogo_report))
self.log()
self.log(preview_text)

Loading…
Cancel
Save