Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Action:
- def __init__(self, uid, message):
- self.uid = uid
- self.message = message
- def send_message(self):
- message_text = self.message.html_text
- bot.send_message(self.uid, message_text, parse_mode='HTML')
- return text
- def send_photo(self):
- file_id = self.message.photo[-1].file_id
- bot.send_photo(self.uid, file_id, caption=self.message.html_caption),
- return file_id
- def send_video(self):
- file_id = self.message.video.file_id
- bot.send_video(self.uid, file_id, caption=self.message.html_caption, parse_mode="HTML")
- return file_id
- def send_document(self):
- file_id = self.message.document.file_id
- bot.send_document(self.uid, file_id, caption=self.message.html_caption, parse_mode="HTML")
- return file_id
- def send_animation(self):
- file_id = self.message.animation.file_id
- bot.send_animation(self.uid, file_id, caption=self.message.html_caption, parse_mode="HTML")
- return file_id
- def action_dispatcher(content_type, message):
- uid = message.from_user.id
- action = Action(uid, message)
- callbacks_list = {
- 'text': action.send_message(),
- 'photo': action.send_photo(),
- 'video': action.send_video(),
- 'document': action.send_document(),
- 'animation': action.send_animation()
- }
- return callbacks_list.get(content_type)
- def get_broadcast_keyboard():
- markup = types.ReplyKeyboardMarkup(True)
- markup.row("Добавить кнопку")
- markup.row("Отправить рассылку")
- return markup
- def broadcast(message):
- uid = message.from_user.id
- caption = message.html_caption
- content_type = message.content_type
- mestext = message.html_text
- file_id = action_dispatcher(content_type, message)
- if not file_id:
- bot.send_message(uid, "Неподдерживаемый тип сообщения")
- return
- msg = bot.send_message(uid, "Ок, дальше?", reply_markup=get_broadcast_keyboard())
- bot.register_next_step_handler(msg, ready, content_type, mestext, caption, file_id, {})
Advertisement
Add Comment
Please, Sign In to add comment