respect chat for last_hashtag and /delete command

This commit is contained in:
Tomáš Mládek 2019-05-16 15:33:38 +02:00
parent fbb78e4316
commit a9d5967996

View file

@ -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,7 +406,8 @@ class DelojzaBot:
def tg_delete(self, _, update):
if self.last_downloaded is not None:
files, hashtags, tumblr_ids = self.last_downloaded
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)
@ -426,7 +427,8 @@ class DelojzaBot:
if self.tumblr_client:
self.tumblr_client.delete_post(self.tumblr_name, tumblr_id)
self.last_downloaded = None
else:
return
update.message.reply_text("Nothing to remove!")
# noinspection PyMethodMayBeStatic