def change_alternative_limits(_, update, args):
    logger.info('/altdown or /altup from %s',
                update.message.from_user.first_name)

    if re.search(r'^[!/]altdown$', update.message.text, re.I):
        logger.info(
            '/altdown: showing alternative download speed limits presets')

        reply_markup = kb.alternative_download_limits(PRESETS)
        update.message.reply_markdown('Select the alternative download speed',
                                      reply_markup=reply_markup)

        return

    preferences_to_edit = dict()

    preference_key = 'alt_dl_limit'
    if update.message.text.lower().startswith('/altup'):
        preference_key = 'alt_up_limit'

    kbs: str = args[0]
    if not kbs.isdigit():
        update.message.reply_text(
            'Please pass the alternative speed limit in kb/s, as an integer')
        return

    preferences_to_edit[preference_key] = int(kbs) * 1014
    qb.set_preferences(**preferences_to_edit)

    update.message.reply_markdown('`{}` set to {} kb/s'.format(
        preference_key, kbs))
Exemple #2
0
def on_schedoff_button_quick(_, update):
    logger.info('quick info: schedoff button')

    qb.set_preferences(**{'scheduler_enabled': False})

    text = get_quick_info_text()
    update.callback_query.edit_message_text(text, parse_mode=ParseMode.HTML, reply_markup=kb.QUICK_MENU_BUTTON)
    update.callback_query.answer('Scheduled altenrative speed off')
Exemple #3
0
def on_schedoff_button_overview(update: Update, context: CallbackContext):
    logger.info('overview: schedoff button')

    qb.set_preferences(**{'scheduler_enabled': False})

    text = get_quick_info_text()
    update.callback_query.edit_message_text(
        text,
        parse_mode=ParseMode.HTML,
        reply_markup=kb.get_overview_schedule_markup())
    update.callback_query.answer('Scheduled altenrative speed off')
def altdown_speed_callback(_, update, groups):
    logger.info('remove buttons inline button')

    speed_kbs = int(groups[0]) * 1024
    preferences_to_edit = dict()
    preference_key = 'alt_dl_limit'

    preferences_to_edit[preference_key] = speed_kbs
    qb.set_preferences(**preferences_to_edit)

    update.callback_query.answer(
        'Alternative dl speed set to {} kb/s'.format(speed_kbs))
Exemple #5
0
def change_setting(update: Update, context: CallbackContext):
    logger.info('/set from %s', update.effective_user.first_name)

    if len(context.args) < 2:
        update.message.reply_html('Usage: /set <code>[setting] [value]</code>')
        return

    key = context.args[0].lower()
    val = context.args[1]

    qb.set_preferences(**{key: val})

    update.message.reply_html('<b>Setting changed</b>:\n\n<code>{}</code>'.format(val))
def alt_speed_callback(update: Update, context: CallbackContext):
    logger.info('alternative speed inline button')

    speed_up_kbs = int(context.match[1]) * 1024
    speed_down_kbs = int(context.match[2]) * 1024

    preferences_to_edit = dict(
        alt_up_limit=speed_up_kbs,
        alt_dl_limit=speed_down_kbs
    )

    qb.set_preferences(**preferences_to_edit)

    update.callback_query.answer(
        f'Alternative speed set to:\n▲ {context.match[1]} kb/s\n▼ {context.match[2]} kb/s',
        show_alert=True
    )