respect chat for last_hashtag and /delete command
This commit is contained in:
parent
fbb78e4316
commit
a9d5967996
1 changed files with 28 additions and 26 deletions
14
delojza.py
14
delojza.py
|
@ -235,8 +235,8 @@ class DelojzaBot:
|
||||||
def get_hashtags(self, message):
|
def get_hashtags(self, message):
|
||||||
hashtags = self.extract_hashtags(message)
|
hashtags = self.extract_hashtags(message)
|
||||||
if len(hashtags) == 0 and self.last_hashtags is not None:
|
if len(hashtags) == 0 and self.last_hashtags is not None:
|
||||||
user, ts, hashtags = self.last_hashtags
|
user, chat, ts, hashtags = self.last_hashtags
|
||||||
if user == message.from_user and ts > datetime.now() - timedelta(hours=1):
|
if user == message.from_user and chat == message.chat and ts > datetime.now() - timedelta(hours=1):
|
||||||
hashtags = self.last_hashtags[1]
|
hashtags = self.last_hashtags[1]
|
||||||
return hashtags
|
return hashtags
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ class DelojzaBot:
|
||||||
self.handle_tg_message(update.message.reply_to_message, bot, hashtags)
|
self.handle_tg_message(update.message.reply_to_message, bot, hashtags)
|
||||||
self.handle_urls(update.message.reply_to_message, hashtags)
|
self.handle_urls(update.message.reply_to_message, hashtags)
|
||||||
else:
|
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
|
# noinspection PyBroadException
|
||||||
def handle(self, urls, message, hashtags, download_fn, filename=None):
|
def handle(self, urls, message, hashtags, download_fn, filename=None):
|
||||||
|
@ -284,7 +284,7 @@ class DelojzaBot:
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
response = self.tumblr_client.create_photo(self.tumblr_name, state="published", data=filename)
|
response = self.tumblr_client.create_photo(self.tumblr_name, state="published", data=filename)
|
||||||
tumblr_ids.append(response['id'])
|
tumblr_ids.append(response['id'])
|
||||||
self.last_downloaded = filenames, hashtags, tumblr_ids
|
self.last_downloaded = message.chat, filenames, hashtags, tumblr_ids
|
||||||
return filenames
|
return filenames
|
||||||
except:
|
except:
|
||||||
exc_type, exc_value, __ = sys.exc_info()
|
exc_type, exc_value, __ = sys.exc_info()
|
||||||
|
@ -406,7 +406,8 @@ class DelojzaBot:
|
||||||
|
|
||||||
def tg_delete(self, _, update):
|
def tg_delete(self, _, update):
|
||||||
if self.last_downloaded is not None:
|
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:
|
for file in files:
|
||||||
update.message.reply_text("Removing \"{}\"!".format(file[len(self.out_dir) + 1:]))
|
update.message.reply_text("Removing \"{}\"!".format(file[len(self.out_dir) + 1:]))
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
@ -426,7 +427,8 @@ class DelojzaBot:
|
||||||
if self.tumblr_client:
|
if self.tumblr_client:
|
||||||
self.tumblr_client.delete_post(self.tumblr_name, tumblr_id)
|
self.tumblr_client.delete_post(self.tumblr_name, tumblr_id)
|
||||||
self.last_downloaded = None
|
self.last_downloaded = None
|
||||||
else:
|
return
|
||||||
|
|
||||||
update.message.reply_text("Nothing to remove!")
|
update.message.reply_text("Nothing to remove!")
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
|
|
Loading…
Reference in a new issue