Ejemplo n.º 1
0
 async def bot_check_user_message(self, message_text, from_id, dialog_entity_id, dialog_entity_type):
     bot_check_message = message_text.replace(',', ' ')
     bot_check_message = self.adapt_command(bot_check_message)
     if self.is_active_for_user(dialog_entity_id, False) and bot_check_message.startswith(MainHelper().get_config_value('chat_bot', 'bot_ignore_prefix')):
         return False
     if self.is_active_for_user(dialog_entity_id, False) and bot_check_message.startswith(MainHelper().get_config_value('chat_bot', 'bot_end_prefix')):
         bot_message = bot_check_message.replace(MainHelper().get_config_value('chat_bot', 'bot_end_prefix'), '', 1).strip()
         if not bot_message:
             bot_message = MainHelper().get_config_value('chat_bot', 'bot_empty_goodbuy')
         print('Bot command:')
         self.tg_client.sprint('<<< ' + bot_message.replace('\n', ' \\n '))
         await self.bot_command(bot_message, from_id, dialog_entity_id, dialog_entity_type)
         self.stop_chat_with_user(dialog_entity_id)
         return True
     elif self.is_active_for_user(dialog_entity_id, False) or ((self.tg_client.selected_user_activity == dialog_entity_id) and (bot_check_message.startswith(MainHelper().get_config_value('chat_bot', 'bot_start_prefix')))):
         if not self.is_active_for_user(dialog_entity_id, False):
             bot_message = bot_check_message.replace(MainHelper().get_config_value('chat_bot', 'bot_start_prefix'), '', 1).strip()
         else:
             bot_message = message_text.strip()
         if not bot_message:
             bot_message = MainHelper().get_config_value('chat_bot', 'bot_empty_greet')
         print('Bot command:')
         self.tg_client.sprint('<<< ' + message_text.replace('\n', ' \\n '))
         await self.bot_command(bot_message, from_id, dialog_entity_id, dialog_entity_type)
         return True
     return False
Ejemplo n.º 2
0
 async def send_version_message_to_all_bot_users(self):
     sent_count = 0
     try:
         version_messages = self.get_version_messages()
         new_ver = MainHelper().get_config_float_value(
             'main', 'actual_version')
         new_ver_title = MainHelper().get_config_value(
             'main', 'new_version_title')
         new_ver_help = MainHelper().get_config_value(
             'main', 'new_version_help')
         result_title = new_ver_title.replace(
             '[actual_version]', "{0:0.2f}".format(new_ver)).replace(
                 '[bot_name]',
                 MainHelper().get_config_value('tg_bot', 'bot_username'))
         result_title = result_title + '\n' + new_ver_help
         chats = self.tg_client.entity_controller.get_all_bot_users_chats()
         if chats and len(chats) > 0:
             for chat in chats:
                 user_last_version = self.tg_client.entity_controller.get_user_bot_last_version(
                     chat.user_id)
                 if not user_last_version:
                     user_last_version = 0.0
                 user_last_version = float(user_last_version)
                 result_user_message = []
                 for version_message in version_messages:
                     if version_message['version'] > user_last_version:
                         version_message_text = 'Список изменений версии {0:0.2f}:\n'.format(
                             version_message['version'])
                         version_message_text = version_message_text + version_message[
                             'message']
                         result_user_message.append(version_message_text)
                 if len(result_user_message) > 0:
                     result_user_message = result_title + '\n--------\n' + (
                         "\n--------\n".join(result_user_message)).strip()
                     self.tg_client.entity_controller.save_user_bot_last_version(
                         chat.user_id, new_ver)
                     await self.send_message(chat, result_user_message)
                     sent_count = sent_count + 1
     except:
         traceback.print_exc()
     return sent_count