From c576888da53df4412530de3b9bd88acf42097f7f Mon Sep 17 00:00:00 2001
From: git-sid <25916907+git-sid@users.noreply.github.com>
Date: Thu, 13 Sep 2018 17:24:19 +0200
Subject: [PATCH 1/6] small fix
---
active_bots/mastodonbot.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/active_bots/mastodonbot.py b/active_bots/mastodonbot.py
index 5127eab..adfac48 100755
--- a/active_bots/mastodonbot.py
+++ b/active_bots/mastodonbot.py
@@ -29,7 +29,7 @@ class MastodonBot(Bot):
logger.error("Unknown Mastodon API Error.", exc_info=True)
return mentions
for status in notifications:
- if user.get_seen_toot() == None:
+ if user.get_seen_toot() is None:
user.init_seen_toot(m.instance()['uri'])
if (status['type'] == 'mention' and
status['status']['id'] > user.get_seen_toot()):
From c2ed73bafc772826fbe63a2d0e1e6211ae87ffa4 Mon Sep 17 00:00:00 2001
From: git-sid <25916907+git-sid@users.noreply.github.com>
Date: Thu, 13 Sep 2018 17:33:33 +0200
Subject: [PATCH 2/6] Make code more pep8 compliant
---
active_bots/mastodonbot.py | 5 +++--
active_bots/telegrambot.py | 3 ++-
frontend.py | 3 ++-
report.py | 1 +
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/active_bots/mastodonbot.py b/active_bots/mastodonbot.py
index adfac48..5cf9cbc 100755
--- a/active_bots/mastodonbot.py
+++ b/active_bots/mastodonbot.py
@@ -21,7 +21,7 @@ class MastodonBot(Bot):
try:
m = Mastodon(*user.get_masto_credentials())
except TypeError:
- #logger.error("No Mastodon Credentials in database.", exc_info=True)
+ # logger.error("No Mastodon Credentials in database.", exc_info=True)
return mentions
try:
notifications = m.notifications()
@@ -71,4 +71,5 @@ class MastodonBot(Bot):
try:
m.toot(text)
except Exception:
- logger.error('Error tooting: ' + user.get_city() + ': ' + report.id, exc_info=True)
+ logger.error('Error tooting: ' + user.get_city() + ': ' +
+ report.id, exc_info=True)
diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py
index e916943..dc8d921 100644
--- a/active_bots/telegrambot.py
+++ b/active_bots/telegrambot.py
@@ -34,7 +34,8 @@ class TelegramBot(Bot):
# TODO: /help message should be set in frontend
else:
reports.append(Report(update.message.sender.username, self,
- update.message.text, None, update.message.date))
+ update.message.text, None,
+ update.message.date))
return reports
def post(self, user, report):
diff --git a/frontend.py b/frontend.py
index 7b71ee6..45a1981 100755
--- a/frontend.py
+++ b/frontend.py
@@ -123,7 +123,7 @@ def unsubscribe(token):
user = db.by_city(city)
user.remove_subscriber(email)
return city_page(city, info="You successfully unsubscribed " + email +
- " from the mail notifications.")
+ " from the mail notifications.")
@get('/settings')
@@ -145,6 +145,7 @@ def update_mail_md(user):
user.set_mail_md(request.forms['mail_md'])
return user.state()
+
@post('/settings/goodlist')
@view('template/settings.tpl')
def update_trigger_patterns(user):
diff --git a/report.py b/report.py
index 5cf2c13..dc27003 100644
--- a/report.py
+++ b/report.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
+
class Report(object):
"""
A ticketfrei report object.
From 72d6798022a8b05cfbffc8509b1ea658efb06385 Mon Sep 17 00:00:00 2001
From: git-sid <25916907+git-sid@users.noreply.github.com>
Date: Thu, 13 Sep 2018 19:54:51 +0200
Subject: [PATCH 3/6] WIP: #31 fix: blacklist -> blocklist.
Replace all relevant instances of "blacklist" with blocklist.
Untested due to OS restricitions. Please check before merge.
---
README.md | 6 +++---
frontend.py | 4 ++--
static/bot.html | 10 +++++-----
static/js/functions.js | 2 +-
template/settings.tpl | 10 +++++-----
user.py | 2 +-
6 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index da364b7..fcc2933 100644
--- a/README.md
+++ b/README.md
@@ -50,16 +50,16 @@ to check if something was retweeted in the last hour or something.
To this date, we have never heard of this happening though.
-### blacklisting
+### blockisting
-You also need to edit the goodlist and the blacklist. You can do this on the
+You also need to edit the goodlist and the blocklist. You can do this on the
website, in the settings of your bot.
Just add the words to the goodlist, which you want to require. A report is only
spread if it contains at least one of them. If you want to RT everything, just
add a ```*```.
-There is also a blacklist, which you can use to automatically sort out
+There is also a blocklist, which you can use to automatically sort out
malicious messages. Be careful though, our filter can't read the intention with
which a word was used. Maybe you wanted it there.
diff --git a/frontend.py b/frontend.py
index 45a1981..ca8264a 100755
--- a/frontend.py
+++ b/frontend.py
@@ -153,10 +153,10 @@ def update_trigger_patterns(user):
return user.state()
-@post('/settings/blacklist')
+@post('/settings/blocklist')
@view('template/settings.tpl')
def update_badwords(user):
- user.set_badwords(request.forms['blacklist'])
+ user.set_badwords(request.forms['blocklist'])
return user.state()
diff --git a/static/bot.html b/static/bot.html
index 9d11d2f..b2e2bf6 100644
--- a/static/bot.html
+++ b/static/bot.html
@@ -83,16 +83,16 @@
-
+
These words are not allowed in reports.
If you encounter spam, you can add more here - the bot will ignore reports which use such words.
-
+
-
diff --git a/static/js/functions.js b/static/js/functions.js
index ef1fa5c..4630ae0 100644
--- a/static/js/functions.js
+++ b/static/js/functions.js
@@ -36,4 +36,4 @@ document.getElementById("enablebutton").innerHTML = enableButton();
document.getElementById("goodlist").innerHTML = listformat(getCookie("goodlist"));
-document.getElementById("blacklist").innerHTML = listformat(getCookie("blacklist"));
\ No newline at end of file
+document.getElementById("blocklist").innerHTML = listformat(getCookie("blocklist"));
\ No newline at end of file
diff --git a/template/settings.tpl b/template/settings.tpl
index acc2b5e..234128d 100644
--- a/template/settings.tpl
+++ b/template/settings.tpl
@@ -140,15 +140,15 @@
-
Edit the blacklist
+
Edit the blocklist
These words are not allowed in reports. If you encounter spam, you can
add more here - the bot will ignore reports which use such words.
-
-
+
diff --git a/user.py b/user.py
index 2e1a550..4487f4e 100644
--- a/user.py
+++ b/user.py
@@ -253,7 +253,7 @@ schlitz
# - markdown
# - mail_md
# - goodlist
- # - blacklist
+ # - blocklist
# - logged in with twitter?
# - logged in with mastodon?
# - enabled?
From 1703eb3802f4f0224667558a29a931a9e5cf3f2a Mon Sep 17 00:00:00 2001
From: git-sid <25916907+git-sid@users.noreply.github.com>
Date: Fri, 14 Sep 2018 12:45:49 +0200
Subject: [PATCH 4/6] Make code even more PEP8 compliant
It could be made even more compliant, but that would actually decrease
readability imo.
---
active_bots/__init__.py | 1 -
active_bots/mailbot.py | 5 +++--
active_bots/mastodonbot.py | 4 ++--
active_bots/telegrambot.py | 12 +++++++++---
active_bots/twitterDMs.py | 6 +++---
active_bots/twitterbot.py | 4 ++--
db.py | 23 +++++++++++------------
sendmail.py | 2 +-
user.py | 7 +++----
9 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/active_bots/__init__.py b/active_bots/__init__.py
index eedb95f..fb28c7f 100644
--- a/active_bots/__init__.py
+++ b/active_bots/__init__.py
@@ -12,4 +12,3 @@ for loader, name, is_pkg in pkgutil.walk_packages(__path__):
globals()[name] = value
__all__.append(name)
-
diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py
index f51fb26..12945b8 100644
--- a/active_bots/mailbot.py
+++ b/active_bots/mailbot.py
@@ -18,7 +18,8 @@ class Mailbot(Bot):
# returns a list of Report objects
def crawl(self, user):
reports = []
- mails = mailbox.mbox('/var/mail/test') # todo: adjust to actual mailbox
+ # todo: adjust to actual mailbox
+ mails = mailbox.mbox('/var/mail/test')
for msg in mails:
if get_date_from_header(msg['Date']) > user.get_seen_mail():
reports.append(make_report(msg, user))
@@ -31,7 +32,7 @@ class Mailbot(Bot):
rec = rec[0]
unsubscribe_text = "\n_______\nYou don't want to receive those messages? Unsubscribe with this link: "
body = report.text + unsubscribe_text + config['web']['host'] + "/city/mail/unsubscribe/" \
- + db.mail_subscription_token(rec, user.get_city())
+ + db.mail_subscription_token(rec, user.get_city())
if report.author != rec:
try:
sendmail.sendmail(rec, "Ticketfrei " + user.get_city() +
diff --git a/active_bots/mastodonbot.py b/active_bots/mastodonbot.py
index 5cf9cbc..6e74f3e 100755
--- a/active_bots/mastodonbot.py
+++ b/active_bots/mastodonbot.py
@@ -38,8 +38,8 @@ class MastodonBot(Bot):
# add mention to mentions
text = re.sub(r'<[^>]*>', '', status['status']['content'])
text = re.sub(
- "(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
- "", text)
+ "(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
+ "", text)
if status['status']['visibility'] == 'public':
mentions.append(Report(status['account']['acct'],
self,
diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py
index dc8d921..fe3beed 100644
--- a/active_bots/telegrambot.py
+++ b/active_bots/telegrambot.py
@@ -23,14 +23,20 @@ class TelegramBot(Bot):
user.save_seen_tg(update.update_id)
if update.message.text.lower() == "/start":
user.add_telegram_subscribers(update.message.sender.id)
- tb.send_message(update.message.sender.id, "You are now subscribed to report notifications.")
+ tb.send_message(
+ update.message.sender.id,
+ "You are now subscribed to report notifications.")
# TODO: /start message should be set in frontend
elif update.message.text.lower() == "/stop":
user.remove_telegram_subscribers(update.message.sender.id)
- tb.send_message(update.message.sender.id, "You are now unsubscribed from report notifications.")
+ tb.send_message(
+ update.message.sender.id,
+ "You are now unsubscribed from report notifications.")
# TODO: /stop message should be set in frontend
elif update.message.text.lower() == "/help":
- tb.send_message(update.message.sender.id, "Send reports here to share them with other users. Use /start and /stop to get reports or not.")
+ tb.send_message(
+ update.message.sender.id,
+ "Send reports here to share them with other users. Use /start and /stop to get reports or not.")
# TODO: /help message should be set in frontend
else:
reports.append(Report(update.message.sender.username, self,
diff --git a/active_bots/twitterDMs.py b/active_bots/twitterDMs.py
index 50d2810..237d7a1 100644
--- a/active_bots/twitterDMs.py
+++ b/active_bots/twitterDMs.py
@@ -33,14 +33,14 @@ class TwitterBot(Bot):
return reports # no twitter account for this user.
last_dm = user.get_seen_dm()
try:
- if last_dm == None:
+ if last_dm is None:
mentions = api.direct_messages()
else:
mentions = api.mentions_timeline(since_id=last_dm[0])
for status in mentions:
text = re.sub(
- "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
- "", status.text)
+ "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
+ "", status.text)
reports.append(report.Report(status.author.screen_name,
"twitterDM",
text,
diff --git a/active_bots/twitterbot.py b/active_bots/twitterbot.py
index bf127a2..336737b 100755
--- a/active_bots/twitterbot.py
+++ b/active_bots/twitterbot.py
@@ -48,8 +48,8 @@ class TwitterBot(Bot):
user.set_last_twitter_request(time())
for status in mentions:
text = re.sub(
- "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
- "", status.text)
+ "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
+ "", status.text)
reports.append(report.Report(status.author.screen_name,
self,
text,
diff --git a/db.py b/db.py
index 7eb938b..8528938 100644
--- a/db.py
+++ b/db.py
@@ -162,7 +162,7 @@ class DB(object):
masto_link TEXT,
twit_link TEXT,
FOREIGN KEY(user_id) REFERENCES user(id),
- UNIQUE(user_id, city) ON CONFLICT IGNORE
+ UNIQUE(user_id, city) ON CONFLICT IGNORE
);
CREATE TABLE IF NOT EXISTS secret (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
@@ -198,11 +198,11 @@ class DB(object):
:return:
"""
return jwt.encode({
- 'email': email,
- 'passhash': scrypt_mcf(
- password.encode('utf-8')
- ).decode('ascii')
- }, self.secret).decode('ascii')
+ 'email': email,
+ 'passhash': scrypt_mcf(
+ password.encode('utf-8')
+ ).decode('ascii')
+ }, self.secret).decode('ascii')
def mail_subscription_token(self, email, city):
"""
@@ -223,7 +223,6 @@ class DB(object):
json = jwt.decode(token, self.secret)
return json['email'], json['city']
-
def confirm(self, token, city):
from user import User
try:
@@ -262,10 +261,10 @@ u\d\d?"""
(uid, json['email']))
self.execute("""INSERT INTO telegram_accounts (user_id, apikey,
active) VALUES(?, ?, ?);""", (uid, "", 1))
- self.execute("INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?,?);",
- (uid, 0))
- self.execute("INSERT INTO seen_mail (user_id, mail_date) VALUES (?,?);",
- (uid, 0))
+ self.execute(
+ "INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?,?);", (uid, 0))
+ self.execute(
+ "INSERT INTO seen_mail (user_id, mail_date) VALUES (?,?);", (uid, 0))
self.commit()
user = User(uid)
user.set_city(city)
@@ -290,7 +289,7 @@ u\d\d?"""
return User(uid)
def user_facing_properties(self, city):
- self.execute("""SELECT city, markdown, mail_md, masto_link, twit_link
+ self.execute("""SELECT city, markdown, mail_md, masto_link, twit_link
FROM cities
WHERE city=?;""", (city, ))
try:
diff --git a/sendmail.py b/sendmail.py
index e7e1f67..d739d78 100755
--- a/sendmail.py
+++ b/sendmail.py
@@ -34,7 +34,7 @@ class Mailer(object):
try:
context = ssl.create_default_context()
self.s.starttls(context=context)
- except:
+ except BaseException: # TODO: Amend specific exception
logger.error('StartTLS failed.', exc_info=True)
self.s.login(config["mail"]["user"], config["mail"]["passphrase"])
diff --git a/user.py b/user.py
index 4487f4e..9064ec9 100644
--- a/user.py
+++ b/user.py
@@ -80,7 +80,7 @@ fag
faggot
nigger
neger
-schlitz
+schlitz
"""
db.execute("SELECT words FROM badwords WHERE user_id=?;",
(self.uid, ))
@@ -345,8 +345,8 @@ schlitz
return db.cur.fetchone()[0]
def set_city(self, city):
- masto_link = "https://example.mastodon.social/@" + city # get masto_link
- twit_link = "https://example.twitter.com/" + city # get twit_link
+ masto_link = "https://example.mastodon.social/@" + city # get masto_link
+ twit_link = "https://example.twitter.com/" + city # get twit_link
mailinglist = city + "@" + config['web']['host']
markdown = """# Wie funktioniert Ticketfrei?
@@ -461,4 +461,3 @@ unsubscribe-link mitgeschickt.
masto_link, twit_link) VALUES(?,?,?,?,?,?)""",
(self.uid, city, markdown, mail_md, masto_link, twit_link))
db.commit()
-
From e9ac7286d9e2398add1149d7e8b103d8ce882e66 Mon Sep 17 00:00:00 2001
From: b3yond
Date: Sat, 15 Sep 2018 18:47:43 +0200
Subject: [PATCH 5/6] peak readability
---
active_bots/mailbot.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py
index 12945b8..2a88ba1 100644
--- a/active_bots/mailbot.py
+++ b/active_bots/mailbot.py
@@ -32,7 +32,7 @@ class Mailbot(Bot):
rec = rec[0]
unsubscribe_text = "\n_______\nYou don't want to receive those messages? Unsubscribe with this link: "
body = report.text + unsubscribe_text + config['web']['host'] + "/city/mail/unsubscribe/" \
- + db.mail_subscription_token(rec, user.get_city())
+ + db.mail_subscription_token(rec, user.get_city())
if report.author != rec:
try:
sendmail.sendmail(rec, "Ticketfrei " + user.get_city() +
From 1a793657afa4851267e7210c2922187cbd442f40 Mon Sep 17 00:00:00 2001
From: b3yond
Date: Sat, 15 Sep 2018 18:50:37 +0200
Subject: [PATCH 6/6] right of = should be right of =
---
active_bots/twitterDMs.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/active_bots/twitterDMs.py b/active_bots/twitterDMs.py
index 237d7a1..36b2562 100644
--- a/active_bots/twitterDMs.py
+++ b/active_bots/twitterDMs.py
@@ -39,8 +39,8 @@ class TwitterBot(Bot):
mentions = api.mentions_timeline(since_id=last_dm[0])
for status in mentions:
text = re.sub(
- "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
- "", status.text)
+ "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
+ "", status.text)
reports.append(report.Report(status.author.screen_name,
"twitterDM",
text,