diff --git a/delojza.py b/delojza.py index dca4157..4b3821e 100755 --- a/delojza.py +++ b/delojza.py @@ -235,8 +235,8 @@ class DelojzaBot: def get_hashtags(self, message): hashtags = self.extract_hashtags(message) if len(hashtags) == 0 and self.last_hashtags is not None: - user, ts, hashtags = self.last_hashtags - if user == message.from_user and ts > datetime.now() - timedelta(hours=1): + user, chat, ts, hashtags = self.last_hashtags + if user == message.from_user and chat == message.chat and ts > datetime.now() - timedelta(hours=1): hashtags = self.last_hashtags[1] return hashtags @@ -247,7 +247,7 @@ class DelojzaBot: self.handle_tg_message(update.message.reply_to_message, bot, hashtags) self.handle_urls(update.message.reply_to_message, hashtags) else: - self.last_hashtags = (update.message.from_user, datetime.now(), hashtags) + self.last_hashtags = update.message.from_user, update.message.chat, datetime.now(), hashtags # noinspection PyBroadException def handle(self, urls, message, hashtags, download_fn, filename=None): @@ -284,7 +284,7 @@ class DelojzaBot: for filename in filenames: response = self.tumblr_client.create_photo(self.tumblr_name, state="published", data=filename) tumblr_ids.append(response['id']) - self.last_downloaded = filenames, hashtags, tumblr_ids + self.last_downloaded = message.chat, filenames, hashtags, tumblr_ids return filenames except: exc_type, exc_value, __ = sys.exc_info() @@ -406,28 +406,30 @@ class DelojzaBot: def tg_delete(self, _, update): if self.last_downloaded is not None: - files, hashtags, tumblr_ids = self.last_downloaded - for file in files: - update.message.reply_text("Removing \"{}\"!".format(file[len(self.out_dir) + 1:])) - os.remove(file) - parent_dir = os.path.dirname(file) - while True: - if len(os.listdir(parent_dir)) == 0: - update.message.reply_text("Removing directory \"{}\" as it's empty..." - .format(parent_dir[len(self.out_dir) + 1:])) - os.rmdir(parent_dir) - parent_dir = os.path.dirname(parent_dir) - if parent_dir == self.out_dir: - break - if len(tumblr_ids) > 0: - plural = "s (all {} of them)".format(len(tumblr_ids)) if len(tumblr_ids) > 1 else "" - update.message.reply_text("Also deleting tumblr post{}!".format(plural)) - for tumblr_id in tumblr_ids: - if self.tumblr_client: - self.tumblr_client.delete_post(self.tumblr_name, tumblr_id) - self.last_downloaded = None - else: - update.message.reply_text("Nothing to remove!") + chat, files, hashtags, tumblr_ids = self.last_downloaded + if chat == update.message.chat: + for file in files: + update.message.reply_text("Removing \"{}\"!".format(file[len(self.out_dir) + 1:])) + os.remove(file) + parent_dir = os.path.dirname(file) + while True: + if len(os.listdir(parent_dir)) == 0: + update.message.reply_text("Removing directory \"{}\" as it's empty..." + .format(parent_dir[len(self.out_dir) + 1:])) + os.rmdir(parent_dir) + parent_dir = os.path.dirname(parent_dir) + if parent_dir == self.out_dir: + break + if len(tumblr_ids) > 0: + plural = "s (all {} of them)".format(len(tumblr_ids)) if len(tumblr_ids) > 1 else "" + update.message.reply_text("Also deleting tumblr post{}!".format(plural)) + for tumblr_id in tumblr_ids: + if self.tumblr_client: + self.tumblr_client.delete_post(self.tumblr_name, tumblr_id) + self.last_downloaded = None + return + + update.message.reply_text("Nothing to remove!") # noinspection PyMethodMayBeStatic def tg_version(self, _, update):