Bot for checking for spam in telegram groups
-
Put hamspam.db in go-telegram-antispam directory
-
Run bot by docker compose
echo "TOKEN=<YOUR_TELEGRAM_BOT_TOKEN>" > .env
docker compose up -d
import sqlite3
import uuid
import os
con = sqlite3.connect("spam.db")
cur = con.cursor()
sel = cur.execute("SELECT * FROM messages")
learn_spam_dir = 'ex/learn/spam/'
test_spam_dir = 'ex/test/spam/'
learn_ham_dir = 'ex/learn/ham/'
test_ham_dir = 'ex/test/ham/'
for d in [learn_spam_dir, learn_ham_dir, test_spam_dir, test_ham_dir]:
if not os.path.exists(d):
os.makedirs(d)
# 60% for training, 40% for testing
learn_test_ratio = .6
rows = sel.fetchall()
for i, row in enumerate(rows):
path = test_spam_dir if i > (len(rows) * learn_test_ratio) \
else learn_spam_dir
with open(path + uuid.uuid4().urn[9:], 'w') as f:
f.write(row[0])
Ham messages can be downloaded from telegram chat history.