From 348e451d77f8ce6e4c73d3b440fdbb2a9c9a871e Mon Sep 17 00:00:00 2001 From: vylion Date: Tue, 25 Sep 2018 23:37:20 +0200 Subject: [PATCH] Velasco 3.1 - Added a "print" marker for the end of chat loading - Added some code for future possible video compatibility in a panic when normal Animation support didn't work --- chatlog.py | 4 ++++ markov.py | 1 + velasco.py | 27 ++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/chatlog.py b/chatlog.py index 2947a2a..03b03e0 100644 --- a/chatlog.py +++ b/chatlog.py @@ -59,6 +59,10 @@ class Chatlog(object): self.gen.add_text(STICKER_TAG + ' ' + file_id + ' ' + TAIL) self.count += 1 + def add_video(self, file_id): + self.gen.add_text(VIDEO_TAG + ' ' + file_id + ' ' + TAIL) + self.count += 1 + def add_animation(self, file_id): self.gen.add_text(ANIM_TAG + ' ' + file_id + ' ' + TAIL) self.count += 1 diff --git a/markov.py b/markov.py index 522a183..1a37d31 100644 --- a/markov.py +++ b/markov.py @@ -7,6 +7,7 @@ HEAD = "\n^MESSAGE_SEPARATOR^" TAIL = "^MESSAGE_SEPARATOR^" STICKER_TAG = "^IS_STICKER^" ANIM_TAG = "^IS_ANIMATION^" +VIDEO_TAG = "^IS_VIDEO^" def trim_and_split(text): words = text.replace('\n', '\n ').split(' ') diff --git a/velasco.py b/velasco.py index fb6c327..a111336 100755 --- a/velasco.py +++ b/velasco.py @@ -95,7 +95,7 @@ def echo(bot, update): update.message.reply_text(text) def error(bot, update, error): - logger.warn('Update "%s" caused error "%s"' % (update, error)) + logger.warning('Update "%s" caused error "%s"' % (update, error)) def get_chatname(chat): if chat.title is not None: @@ -121,10 +121,15 @@ def read(bot, update): if update.message.text is not None: chatlog.add_msg(update.message.text) elif update.message.sticker is not None: + #print("I received a sticker") chatlog.add_sticker(update.message.sticker.file_id) elif update.message.animation is not None: + #print("I received an animation") chatlog.add_animation(update.message.animation.file_id) - + elif update.message.video is not None: + #print("I received a video") + chatlog.add_video(update.message.video.file_id) + # print("Read a message of id "update.message.message_id) if chatlog.get_count()%chatlog.freq == 1: chatlog.restart_replyables(update.message.message_id) else: @@ -204,6 +209,18 @@ def send_message(bot, update, msg, reply_id=None): else: bot.sendAnimation(update.message.chat_id, words[1]) + elif words[0] == VIDEO_TAG: + if reply_id is not None: + try: + update.message.reply_animation(words[1]) + except: + update.message.reply_video(words[1]) + else: + try: + bot.sendAnimation(update.message.chat_id, words[1]) + except: + bot.sendVideo(update.message.chat_id, words[1]) + else: if reply_id is not None: bot.sendMessage(update.message.chat.id, msg, reply_to_message_id=reply_id) @@ -356,13 +373,17 @@ def main(): # on noncommand i.e message - echo the message on Telegram # dp.add_handler(MessageHandler(Filters.text, echo)) - dp.add_handler(MessageHandler((Filters.text | Filters.sticker), read)) + dp.add_handler(MessageHandler((Filters.text | Filters.sticker | Filters.animation), read)) # log all errors dp.add_error_handler(error) wake(updater.bot) + print("-----") + print("Finished loading.") + print("-----") + # Start the Bot updater.start_polling()