diff --git a/delojza.py b/delojza.py index a75d37c..6bc850b 100755 --- a/delojza.py +++ b/delojza.py @@ -262,12 +262,34 @@ class DelojzaBot: def tg_handle_hashtag(self, bot, update): hashtags = self.extract_hashtags(update.message) + self.handle_text(update.message.reply_to_message or update.message, hashtags) + if update.message.reply_to_message: 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, update.message.chat, datetime.now(), hashtags + def handle_text(self, message, hashtags): + if len(hashtags) == 0 or hashtags[0] not in ('TEXT', 'TXT'): + return + + info_line = self.sanitize("-".join(re.sub(r'#[\w]+', '', message.text).strip().split()[:7])) + if len(info_line) > 64: + info_line = info_line[:64] + + filename = '{}__{}.txt'.format(datestr(message.date), info_line) + + out_path = os.path.join(self.out_dir, *hashtags[1:] or ['TEXT']) + file_path = os.path.join(out_path, filename) + + mkdir_p(out_path) + + with open(file_path, 'w') as out_file: + out_file.write(message.text) + + message.reply_text("Saved text to \"{}\"...".format(os.path.join(*hashtags[1:], filename))) + # noinspection PyBroadException def handle(self, urls, message, hashtags, download_fn, filetitle=None): try: