From 6d10fae743ec1014b6be9920284a0250d0608701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sat, 18 May 2019 14:28:23 +0200 Subject: [PATCH] protected chats & tags --- delojza.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/delojza.py b/delojza.py index 4b3821e..32bbd35 100755 --- a/delojza.py +++ b/delojza.py @@ -11,6 +11,7 @@ from configparser import ConfigParser from datetime import datetime, timedelta from glob import glob from operator import itemgetter +from random import choice import acoustid import filetype @@ -41,6 +42,7 @@ def datestr(date): class DelojzaBot: def __init__(self, tg_api_key, out_dir, tmp_dir=None, + protected_chats=None, protected_tags=None, acoustid_key=None, tumblr_name=None, tumblr_keys=None, markov=None): self.logger = logging.getLogger("delojza") @@ -74,6 +76,9 @@ class DelojzaBot: self.tumblr_name = tumblr_name self.tumblr_client = pytumblr.TumblrRestClient(*tumblr_keys) + self.protected_chats = protected_chats or [] + self.protected_tags = protected_tags or [] + self.last_downloaded = None self.last_hashtags = None @@ -256,6 +261,13 @@ class DelojzaBot: self.logger.info("Ignoring %s due to no hashtag present..." % urls) return + if any(hashtag in self.protected_tags for hashtag in hashtags): + if message.chat.title not in self.protected_chats: + self.logger.info("Ignoring {} in chat {} due to protected hashtags: {}..." + .format(urls, message.chat.title, hashtags)) + message.reply_text(choice(["No.", "Nein", "Nope", ":(", "Error: Cannot.", "Fail."])) + return + self.last_hashtags = None self.logger.info("Downloading %s under '%s'" % (urls, "/".join(hashtags))) @@ -503,6 +515,8 @@ if __name__ == '__main__': delojza = DelojzaBot(config.get('delojza', 'tg_api_key'), config.get('delojza', 'OUT_DIR', fallback=os.path.join(_DIR_, "out")), tmp_dir=config.get('delojza', 'tmp_dir', fallback=tempfile.gettempdir()), + protected_chats=config.get('delojza', 'protected_chats').split(";"), + protected_tags=config.get('delojza', 'protected_tags').split(";"), acoustid_key=config.get('delojza', 'acoustid_api_key'), tumblr_name=config.get('tumblr', 'blog_name'), tumblr_keys=(config.get('tumblr', 'consumer_key'),