diff --git a/bot.py b/bot.py index b47b23b..d1294d2 100644 --- a/bot.py +++ b/bot.py @@ -63,26 +63,39 @@ class Core(TasksHandlerMixin): def handle_state_search(self): self.send_message('πŸ€– Поиски собСсСдника ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ°ΡŽΡ‚ΡΡ') - def send_message(self, text, chat_id=None, reply_markup=None, remove_keyboard=True, method='send_message', **kwargs): - if text is None and not kwargs: + def send_message(self, text, chat_id=None, reply_markup=None, remove_keyboard=True): + if text is None: return if reply_markup is None and remove_keyboard: reply_markup = ReplyKeyboardRemove() body = { 'chat_id': chat_id or self.chat_id, + 'text': text, } - if text: - body['text'] = text if reply_markup: body['reply_markup'] = reply_markup.to_json() - body.update(kwargs) + set_task( + 'botalka_mailbox', + { + 'project': 'roulette-bot', + 'name': 'telegram-bot', + 'method': 'send_message', + 'body': body, + }, + 1, + ) + + def send(self, chat_id, method, **kwargs): set_task( 'botalka_mailbox', { 'project': 'roulette-bot', 'name': 'telegram-bot', 'method': method, - 'body': body, + 'body': { + 'chat_id': chat_id, + **kwargs, + }, }, 1, ) @@ -100,15 +113,15 @@ class Core(TasksHandlerMixin): current_dialog = mongo.get_current_dialog(self.chat_id) chat_to_send = current_dialog['chat_id_2'] if current_dialog['chat_id_1'] == self.chat_id else current_dialog['chat_id_1'] if self.message.photo: - self.send_message(None, chat_to_send, method='send_photo', photo=self.message.photo[-1].file_id) + self.send(chat_to_send, 'send_photo', photo=self.message.photo[-1].file_id) if self.message.sticker: - self.send_message(None, chat_to_send, method='send_data', data=self.message.sticker.file_id, data_type='sticker') + self.send(chat_to_send, 'send_data', data=self.message.sticker.file_id, data_type='sticker') if self.message.voice: - self.send_message(None, chat_to_send, method='send_voice', voice=self.message.voice.file_id) + self.send(chat_to_send, 'send_voice', voice=self.message.voice.file_id) if self.message.video_note: - self.send_message(None, chat_to_send, method='send_video_note', data=self.message.video_note.file_id) + self.send(chat_to_send, 'send_video_note', data=self.message.video_note.file_id) if self.message.animation: - self.send_message(None, chat_to_send, method='send_animation', animation=self.message.animation.file_id) + self.send(chat_to_send, 'send_animation', animation=self.message.animation.file_id) self.send_message(self.message_text, chat_to_send) def start_new_dialog(self, chat_ids):