add 1hr timeout to hashtags; forget last_hashtag in handle()
This commit is contained in:
parent
f86c5cbc4d
commit
fbb78e4316
1 changed files with 7 additions and 5 deletions
12
delojza.py
12
delojza.py
|
@ -8,7 +8,7 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
|
@ -234,10 +234,10 @@ 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:
|
if len(hashtags) == 0 and self.last_hashtags is not None:
|
||||||
if self.last_hashtags is not None and self.last_hashtags[0] == message.from_user:
|
user, ts, hashtags = self.last_hashtags
|
||||||
|
if user == message.from_user and ts > datetime.now() - timedelta(hours=1):
|
||||||
hashtags = self.last_hashtags[1]
|
hashtags = self.last_hashtags[1]
|
||||||
self.last_hashtags = None
|
|
||||||
return hashtags
|
return hashtags
|
||||||
|
|
||||||
def tg_handle_hashtag(self, bot, update):
|
def tg_handle_hashtag(self, bot, update):
|
||||||
|
@ -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, hashtags)
|
self.last_hashtags = (update.message.from_user, 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):
|
||||||
|
@ -256,6 +256,8 @@ class DelojzaBot:
|
||||||
self.logger.info("Ignoring %s due to no hashtag present..." % urls)
|
self.logger.info("Ignoring %s due to no hashtag present..." % urls)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.last_hashtags = None
|
||||||
|
|
||||||
self.logger.info("Downloading %s under '%s'" % (urls, "/".join(hashtags)))
|
self.logger.info("Downloading %s under '%s'" % (urls, "/".join(hashtags)))
|
||||||
|
|
||||||
out_path = os.path.join(self.out_dir, *hashtags)
|
out_path = os.path.join(self.out_dir, *hashtags)
|
||||||
|
|
Loading…
Reference in a new issue