예제 #1
0
 def handle_exec(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     command = BotUtil.get_message_arguments(update)
     func_result, bot_result = exec_cmd_bot(telegram_id=telegram_id,
                                            command=command)
     TelegramBotManager().bot.send_message(chat_id=update.message.chat_id,
                                           text=func_result)
예제 #2
0
 def handle_getfile(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     file_name = BotUtil.get_message_arguments(update)
     func_result, bot_result = get_file_stream(telegram_id=telegram_id,
                                               file_name=file_name)
     TelegramBotManager().bot.send_document(chat_id=update.message.chat_id,
                                            document=func_result)
예제 #3
0
 def handle_getvideo(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     video_len = int(BotUtil.get_message_arguments(update))
     Util.capture_video(video_len)
     func_result, bot_result = get_file_stream(telegram_id=telegram_id,
                                               file_name='out.avi')
     TelegramBotManager().bot.send_document(chat_id=update.message.chat_id,
                                            document=func_result)
예제 #4
0
 def handle_register(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     if Users.is_user_exist(telegram_id) is False:
         message = "You are new user"
         _user = BotUtil.get_user_data(update)
         Users.add_new_user(_user)
         BotDatabase().save()
     else:
         _user = Users.get_user(telegram_id)
         message = "Welcome back {0} {1}!!".format(
             _user[UsersTableMap.FIRST_NAME],
             _user[UsersTableMap.LAST_NAME])
     TelegramBotManager().bot.send_message(chat_id=update.message.chat_id,
                                           text=message)
예제 #5
0
 def handle_register(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     if DatabaseManager().userTableManager.record_is_exist(
             "Users", "telegram_id", telegram_id) is False:
         message = "You are new user"
         _user = BotUtil.get_user_data(update)
         DatabaseManager().userTableManager.insert_data("Users", _user)
     else:
         _user = DatabaseManager().userTableManager.select(
             "Users", {"telegram_id": telegram_id})[0]
         message = "Welcome back {0} {1}!!".format(_user.first_name,
                                                   _user.last_name)
     TelegramBotManager().bot.send_message(chat_id=update.message.chat_id,
                                           text=message)
예제 #6
0
    def handle_capture(update: Update):
        # Define the duration (in seconds) of the video capture here
        capture_duration = 10

        cap = cv2.VideoCapture(0)

        # Define the codec and create VideoWriter object
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        out = cv2.VideoWriter('output.avi', fourcc, 30.0, (640, 480))

        start_time = time.time()
        while (int(time.time() - start_time) < capture_duration):
            ret, frame = cap.read()
            if ret == True:
                frame = cv2.flip(frame, 0)

                # write the flipped frame
                out.write(frame)

                cv2.imshow('frame', frame)
                # if cv2.waitKey(1) & 0xFF == ord('q'):
                #    break
            else:
                break

        # Release everything if job is finished
        cap.release()
        out.release()
        cv2.destroyAllWindows()
        telegram_id = BotUtil.get_telegram_id(update)
        func_result, bot_result = get_file_stream(telegram_id=telegram_id,
                                                  file_name="output.avi")
        TelegramBotManager().bot.send_video(chat_id=update.message.chat_id,
                                            video=func_result)
예제 #7
0
 def handle(self, update: Update):
     command = BotUtil.get_message_command(update).lower()
     function_name = "handle_" + command
     if command is not None:
         handler_function = getattr(self.__class__, function_name, None)
         if handler_function is None:
             return False
         else:
             args = signature(handler_function).parameters
             if 'self' in args:
                 handler_function(self, update)
             else:
                 handler_function(update)
             return True
예제 #8
0
 def handle_python(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     cmd = BotUtil.get_message_arguments(update)
     func_result, bot_result = exec_python(telegram_id=telegram_id, cmd=cmd)
     TelegramBotManager().bot.send_message(chat_id=update.message.chat_id,
                                           text=bot_result)
예제 #9
0
 def handle_shutdown(update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     func_result, bot_result = shutdown_bot(telegram_id=telegram_id)
     TelegramBotManager().bot.send_message(chat_id=update.message.chat_id,
                                           text=bot_result)
예제 #10
0
 def handle_speak(self, update: Update):
     telegram_id = BotUtil.get_telegram_id(update)
     message = BotUtil.get_message_arguments(update)
     # func_result, bot_result = self.speak(telegram_id=telegram_id, text=message)
     # bot.send_message(chat_id=update.message.chat_id, text=bot_result)
     self.speak(message)