Пример #1
0
def remove_exchange(bot, update, args):
    """Remove exchange to exchanges list by which the bot will notify the user"""

    msg = update.message
    try:
        exchange = args[0].replace('-', '_').lower()
        user_exchanges = mq.get_user_settings(
            msg.chat_id)[base_config.EXCHANGES]
        if exchange not in user_exchanges:
            user_exchanges = exchange_convert(user_exchanges)
            msg.reply_text(messages.ALREADY_DISABLED_EXCHANGE_TEXT.format(
                '`' + '`, `'.join(user_exchanges) + '`'),
                           reply_markup=kb_main,
                           parse_mode=messages.MARKDOWN)
            return MAIN_MENU
        mq.remove_from_list(msg.chat_id,
                            list=base_config.EXCHANGES,
                            value=exchange)
        new_user_exchanges = '`' + '`, `'.join(
            exchange_convert(set(user_exchanges) - {exchange})) + '`'
        msg.reply_text(
            messages.REMOVE_EXCHANGE_SUCC_TEXT.format(new_user_exchanges),
            reply_markup=kb_main,
            parse_mode=messages.MARKDOWN)
        return MAIN_MENU
    except (IndexError, ValueError):
        msg.reply_text(messages.REMOVE_EXCHANGE_HELP_TEXT,
                       reply_markup=kb_main,
                       parse_mode=messages.MARKDOWN)
        return MAIN_MENU
Пример #2
0
def add_exchange(bot, update, args):
    """Add exchange to exchanges list by which the bot will notify the user"""

    msg = update.message
    try:
        exchange = args[0].replace('-', '_').lower()
        if exchange not in mq.exchanges:
            exchanges = exchange_convert(mq.exchanges)
            msg.reply_text(messages.UNSUPPORTED_EXCHANGE_TEXT.format(
                '`' + '`, `'.join(exchanges) + '`'),
                           reply_markup=kb_main,
                           parse_mode=messages.MARKDOWN)
            return MAIN_MENU
        user_exchanges = mq.get_user_settings(
            msg.chat_id)[base_config.EXCHANGES]
        if exchange in user_exchanges:
            msg.reply_text(messages.ALREADY_ENABLED_EXCHANGE_TEXT.format(
                '`' + exchange_convert(exchange) + '`'),
                           reply_markup=kb_main,
                           parse_mode=messages.MARKDOWN)
            return MAIN_MENU
        mq.add_to_list(msg.chat_id, list=base_config.EXCHANGES, value=exchange)
        new_user_exchanges = '`' + '`, `'.join(
            exchange_convert(set(user_exchanges + [exchange]))) + '`'
        msg.reply_text(
            messages.ADD_EXCHANGE_SUCC_TEXT.format(new_user_exchanges),
            reply_markup=kb_main,
            parse_mode=messages.MARKDOWN)
        return MAIN_MENU
    except (IndexError, ValueError):
        msg.reply_text(messages.ADD_EXCHANGE_HELP_TEXT,
                       reply_markup=kb_main,
                       parse_mode=messages.MARKDOWN)
        return MAIN_MENU
Пример #3
0
def show_all_exchanges(bot, update):
    """
    Send message to user with all available exchanges
    """
    update.message.reply_text(
        '`' + '`, `'.join(exchange_convert(mq.exchanges)) + '`',
        parse_mode=messages.MARKDOWN)
    return ADD_RM_EX
Пример #4
0
def remove_exchange_dialog(bot, update):
    """Remove exchange from user's list and send message to user about operation's result"""

    msg = update.message
    exchange = msg.text[3:].strip(' \t\n\r').replace('-', '_').lower()
    user_exchanges = mq.get_user_settings(msg.chat_id)[base_config.EXCHANGES]
    if exchange not in user_exchanges:
        user_exchanges = exchange_convert(user_exchanges)
        msg.reply_text(messages.ALREADY_DISABLED_EXCHANGE_TEXT.format(
            '`' + '`, `'.join(user_exchanges) + '`'),
                       parse_mode=messages.MARKDOWN)
        return ADD_RM_EX
    mq.remove_from_list(msg.chat_id,
                        list=base_config.EXCHANGES,
                        value=exchange)
    new_user_exchanges = '`' + '`, `'.join(
        exchange_convert(set(user_exchanges) - {exchange})) + '`'
    msg.reply_text(
        messages.REMOVE_EXCHANGE_SUCC_TEXT.format(new_user_exchanges),
        parse_mode=messages.MARKDOWN)
    return ADD_RM_EX
Пример #5
0
def add_exchange_dialog(bot, update):
    """Add exchange to user's list and send message to user about operation's result """

    msg = update.message
    exchange = msg.text[4:].strip(' \t\n\r').replace('-', '_').lower()
    if exchange not in mq.exchanges:
        msg.reply_text(
            messages.UNSUPPORTED_EXCHANGE_CONV_TEXTS.format(exchange),
            parse_mode=messages.MARKDOWN)
        return ADD_RM_EX
    user_exchanges = mq.get_user_settings(msg.chat_id)[base_config.EXCHANGES]
    if exchange in user_exchanges:
        msg.reply_text(messages.ALREADY_ENABLED_EXCHANGE_TEXT.format(
            exchange_convert(exchange)),
                       parse_mode=messages.MARKDOWN)
        return ADD_RM_EX
    mq.add_to_list(msg.chat_id, list=base_config.EXCHANGES, value=exchange)
    new_user_exchanges = '`' + '`, `'.join(
        set(exchange_convert(user_exchanges + [exchange]))) + '`'
    msg.reply_text(messages.ADD_EXCHANGE_SUCC_TEXT.format(new_user_exchanges),
                   parse_mode=messages.MARKDOWN)
    return ADD_RM_EX
Пример #6
0
def add_remove_exchange(bot, update):
    """
    Begin dialog for change exchange's list
    
    Returns:
        :return: change exchange's list dialog identifier
             
    """
    msg = update.message
    user_ex = '`' + '`, `'.join(
        exchange_convert(
            mq.get_user_settings(msg.chat_id)[base_config.EXCHANGES])) + '`'
    msg.reply_text(messages.ADD_RM_EX_TEXT.format(user_ex),
                   reply_markup=kb_back,
                   parse_mode=messages.MARKDOWN)
    return ADD_RM_EX
Пример #7
0
def show_settings(bot, update):
    """
    Send message to user with his current settings
    """
    msg = update.message
    user_settings = mq.get_user_settings(msg.chat_id)
    coins = '`' + '`, `'.join(user_settings[base_config.COINS]) + '`'
    exchanges = '`' + '`, `'.join(
        exchange_convert(user_settings[base_config.EXCHANGES])) + '`'
    threshold = str(user_settings[base_config.THRESHOLD])
    interval = str(user_settings[base_config.INTERVAL])
    notifications = 'enabled 🔊' if user_settings[
        base_config.NOTIFICATIONS] else 'disabled 🔇'
    settings_message = messages.SETTINGS_TEXT.format(notifications, interval,
                                                     threshold, coins,
                                                     exchanges)
    msg.reply_text(settings_message, parse_mode=messages.MARKDOWN)
    return ALERTS_MENU