Пример #1
0
def get_tweet_text(bot, update):
    user_peer = update.get_effective_user()
    user = get_registered_user(bot, update)
    if user:
        dispatcher.set_conversation_data(update, "user", user)
        general_message = TextMessage(ReadyText.send_text_twitter)
        btn_list = [
            TemplateMessageButton(text=ButtonText.cancel,
                                  value=ButtonText.cancel,
                                  action=0)
        ]
        template_message = TemplateMessage(general_message=general_message,
                                           btn_list=btn_list)
        kwargs = {
            "message": template_message,
            "update": update,
            "bot": bot,
            "try_times": 1
        }
        bot.send_message(template_message,
                         user_peer,
                         success_callback=success_send_message,
                         failure_callback=failure_send_message,
                         kwargs=kwargs)
        dispatcher.register_conversation_next_step_handler(
            update, common_handlers + [
                MessageHandler(TextFilter(), send_tweet),
                MessageHandler(DefaultFilter(), start_conversation)
            ])
Пример #2
0
def get_tweet_text(bot, update):
    user_peer = update.get_effective_user()
    user_id = user_peer.peer_id
    user = get_user(user_id=user_id)
    if not check_user_registration(update, user_peer, user):
        return 0
    general_message = TextMessage(ReadyMessage.send_text_twitter)
    btn_list = [
        TemplateMessageButton(text=TMessage.cancel,
                              value=TMessage.cancel,
                              action=0)
    ]
    template_message = TemplateMessage(general_message=general_message,
                                       btn_list=btn_list)
    kwargs = {
        "message": template_message,
        "user_peer": user_peer,
        "try_times": 1
    }
    bot.send_message(template_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.register_conversation_next_step_handler(update, [
        CommandHandler("info", info),
        MessageHandler(TextFilter(), send_tweet),
        MessageHandler(DefaultFilter(), start_conversation)
    ])
    def __init__(self, filters, callback):
        super(QuotedMessageHandler, self).__init__(callback=callback)

        if not filters:
            filters = DefaultFilter()

        if isinstance(filters, list) and all(
                isinstance(message_filter, Filter) for message_filter in filters):
            self.filters = filters
        elif isinstance(filters, Filter):
            self.filters = [filters]
        else:
            raise ValueError("filters don't have acceptable format.")
Пример #4
0
def get_search_text(bot, update):
    user_peer = update.get_effective_user()
    user_id = user_peer.peer_id
    user = get_user(user_id=user_id)
    if not check_user_registration(update, user_peer, user):
        return 0
    text_message = TextMessage(ReadyMessage.send_search_text)
    kwargs = {"message": text_message, "user_peer": user_peer, "try_times": 1}
    bot.send_message(text_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.register_conversation_next_step_handler(update, [
        CommandHandler("info", info),
        MessageHandler(TextFilter(), search_tweets),
        MessageHandler(DefaultFilter(), start_conversation)
    ])
Пример #5
0
def registration(bot, update):
    dispatcher.clear_conversation_data(update)
    user_peer = update.get_effective_user()
    auth = get_verify_link()
    dispatcher.set_conversation_data(update, "auth", auth)
    verify_link = auth['auth_url']
    text_message = TextMessage(
        ReadyMessage.send_verify_number.format(verify_link))
    kwargs = {"message": text_message, "user_peer": user_peer, "try_times": 1}
    bot.send_message(text_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.register_conversation_next_step_handler(update, [
        CommandHandler("info", info),
        MessageHandler(TextFilter(), verify),
        MessageHandler(DefaultFilter(), start_conversation)
    ])
Пример #6
0
def main():
    """Start the bot."""
    # Bale Bot Authorization Token
    updater = Updater("TOKEN")

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Bale
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))

    # on noncommand i.e message - echo the message on Bale
    dp.add_handler(MessageHandler(DefaultFilter(), echo))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.run()
Пример #7
0
def get_search_text(bot, update):
    user_peer = update.get_effective_user()
    user = get_registered_user(bot, update)
    if user:
        dispatcher.set_conversation_data(update, "user", user)
        text_message = TextMessage(ReadyText.send_search_text)
        kwargs = {
            "message": text_message,
            "update": update,
            "bot": bot,
            "try_times": 1
        }
        bot.send_message(text_message,
                         user_peer,
                         success_callback=success_send_message,
                         failure_callback=failure_send_message,
                         kwargs=kwargs)
        dispatcher.register_conversation_next_step_handler(
            update, common_handlers + [
                MessageHandler(TextFilter(), search_tweets),
                MessageHandler(DefaultFilter(), start_conversation)
            ])
Пример #8
0
        def decorator(callback_func):
            handler = MessageHandler(DefaultFilter(), callback_func)
            self.add_handler(handler)

            return callback_func
Пример #9
0
        kwargs = {
            "message": message,
            "update": update,
            "bot": bot,
            "try_times": try_times
        }
        bot.respond(update=update,
                    message=message,
                    success_callback=success_send_message,
                    failure_callback=failure_send_message,
                    kwargs=kwargs)
    else:
        my_logger.error(LogMessage.max_fail_retried, extra={"tag": "error"})


@dispatcher.message_handler(filters=[DefaultFilter()])
def start_conversation(bot, update):
    user_peer = update.get_effective_user()
    text_message = TextMessage(Config.main_text_message)
    kwargs = {
        "message": text_message,
        "update": update,
        "bot": bot,
        "try_times": 1
    }
    bot.send_message(text_message,
                     user_peer,
                     success_callback=success_send_message,
                     failure_callback=failure_send_message,
                     kwargs=kwargs)
    dispatcher.finish_conversation(update)
    kwargs = {
        "user_peer": peer,
        "step_name": step,
        "succedent_message": succedent_message,
        "message": message,
        "attempt": 1,
        "bot": bot
    }
    bot.send_message(message=message,
                     peer=peer,
                     success_callback=step_success,
                     failure_callback=step_failure,
                     kwargs=kwargs)


@dispatcher.message_handler(DefaultFilter())
def start(bot, update):
    user_peer = update.get_effective_user()
    money_changer = select_money_changer_by_peer_id(user_peer.peer_id)
    if money_changer and money_changer.access_hash is None:
        update_money_changer_access_hash(money_changer, user_peer.access_hash)
    if money_changer and isinstance(money_changer, MoneyChanger):
        money_changer_panel(bot, update)
    else:
        user_panel(bot, update)


@dispatcher.message_handler(TemplateResponseFilter([BotButtons.help.value]))
def help_me(bot, update):
    user_peer = update.get_effective_user()
    buttons_list = [BotButtons.back_to_main_menu]