コード例 #1
0
def no_notification_cb(update: Update, context: CallbackContext):
    logger.info('no notification inline button')

    if not config.notifications.no_notification_tag:
        update.callback_query.answer("tag not set in the config file",
                                     cache_time=10)
        return

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash, get_torrent_generic_properties=False)

    torrent_tags = torrent.tags_list(lower=True)
    no_notification_tag = config.notifications.no_notification_tag

    is_torrent_tagged = no_notification_tag.lower() in torrent_tags
    if is_torrent_tagged:
        torrent.remove_tags(no_notification_tag)
        callback_answer = f'Tag "{no_notification_tag}" removed -> 🔔'
    else:
        torrent.add_tags(no_notification_tag)
        callback_answer = f'Tag "{no_notification_tag}" added -> 🔕'

    update.callback_query.edit_message_reply_markup(
        kb.short_markup(torrent_hash, not is_torrent_tagged))
    update.callback_query.answer(callback_answer)
コード例 #2
0
def on_add_or_remove_tags_command(update: Update, context: CallbackContext):
    logger.info('+tags from %s', update.message.from_user.first_name)

    replied_to_text = update.message.reply_to_message.text
    hash_match = re.search(r"infohash:(\w+)", replied_to_text)
    if not hash_match:
        update.message.reply_text(
            "Reply to a torrent's info message (it must contain the torrent hash)"
        )
        return

    torrent_hash = hash_match.group(1)
    torrent = qb.torrent(torrent_hash)

    action = context.matches[0].group(1)
    tags_list_str = context.matches[0].group(2)
    tags_list = [tag.strip() for tag in tags_list_str.split(",")]

    if action == "+":
        text = f"Tags added to <b>{torrent.name_escaped}</b>: <code>{tags_list_str}</code> " \
               f"[<a href=\"{torrent.info_deeplink}\">info</a>]"
        torrent.add_tags(tags_list)
    else:
        text = f"Tags removed from <b>{torrent.name_escaped}</b>: <code>{tags_list_str}</code> " \
               f"[<a href=\"{torrent.info_deeplink}\">info</a>]"
        torrent.remove_tags(tags_list)

    update.message.reply_html(text)
コード例 #3
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def on_info_deeplink(update: Update, context: CallbackContext):
    logger.info('info deeplink from %s', update.message.from_user.first_name)

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)

    update.message.reply_html(torrent.string(), reply_markup=torrent.short_markup())
コード例 #4
0
def force_start_torrent_cb(update: Update, context: CallbackContext):
    logger.info('force start torrent inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash, get_torrent_generic_properties=False)
    torrent.toggle_force_start(True)

    update.callback_query.answer('Force-start set to "true"')
コード例 #5
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def recheck_cb(update: Update, context: CallbackContext):
    logger.info('recheck inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.recheck()

    update.callback_query.answer('Re-check started')
コード例 #6
0
def pause_torrent_cb(update: Update, context: CallbackContext):
    logger.info('pause torrent inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash, get_torrent_generic_properties=False)
    torrent.pause()

    update.callback_query.answer('Paused')
コード例 #7
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def confirm_delete_with_files_cb(update: Update, context: CallbackContext):
    logger.info('confirmation delete with files inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.delete(with_files=True)

    update.callback_query.edit_message_text('{} deleted (with files)'.format(torrent.name))
コード例 #8
0
def on_info_deeplink(_, update, groups=[]):
    logger.info('info deeplink from %s', update.message.from_user.first_name)

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)

    update.message.reply_html(torrent.string(),
                              reply_markup=torrent.short_markup())
コード例 #9
0
def pause_torrent_cb(_, update, groups):
    logger.info('pause torrent inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.pause()

    update.callback_query.answer('Paused')
コード例 #10
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def resume_torrent_cb(update: Update, context: CallbackContext):
    logger.info('resume torrent inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.resume()

    update.callback_query.answer('Resumed')
コード例 #11
0
def unforce_start_torrent_cb(_, update, groups):
    logger.info('unforce start torrent inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.toggle_force_start(False)

    update.callback_query.answer('Force-start set to "false"')
コード例 #12
0
def priority_up_cb(_, update, groups):
    logger.info('priority up inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.increase_priority()

    update.callback_query.answer('Increased priority')
コード例 #13
0
def recheck_cb(_, update, groups):
    logger.info('recheck inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.recheck()

    update.callback_query.answer('Re-check started')
コード例 #14
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def max_priority_cb(update: Update, context: CallbackContext):
    logger.info('max priority inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.max_priority()

    update.callback_query.answer('Max priority set')
コード例 #15
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def priority_up_cb(update: Update, context: CallbackContext):
    logger.info('priority up inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.increase_priority()

    update.callback_query.answer('Increased priority')
コード例 #16
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def unforce_start_torrent_cb(update: Update, context: CallbackContext):
    logger.info('unforce start torrent inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.toggle_force_start(False)

    update.callback_query.answer('Force-start set to "false"')
コード例 #17
0
def max_priority_cb(_, update, groups):
    logger.info('max priority inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.max_priority()

    update.callback_query.answer('Max priority set')
コード例 #18
0
def resume_torrent_cb(_, update, groups):
    logger.info('resume torrent inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.resume()

    update.callback_query.answer('Resumed')
コード例 #19
0
ファイル: manage.py プロジェクト: Ukenn2112/qbittorrent-bot
def force_start_torrent_cb(_, update, groups):
    logger.info('force start torrent inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.toggle_force_start(True)

    update.callback_query.answer('强制继续 "开启"')
コード例 #20
0
def confirm_delete_with_files_cb(_, update, groups):
    logger.info('confirmation delete with files inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.delete(with_files=True)

    update.callback_query.edit_message_text('{} deleted (with files)'.format(
        torrent.name))
コード例 #21
0
def confirm_delete_with_files_cb(update: Update, context: CallbackContext):
    logger.info('confirmation delete with files inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash, get_torrent_generic_properties=False)
    torrent.delete(with_files=True)

    update.callback_query.edit_message_text(
        f'{torrent.name} deleted (with files)')
コード例 #22
0
ファイル: manage.py プロジェクト: ronioncloud/qbittorrent-bot
def force_resume_torrent_cb(update: Update, context: CallbackContext):
    logger.info('force-resume torrent inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.resume()
    time.sleep(1)
    torrent.toggle_force_start(True)

    update.callback_query.answer('Force-resumed')
コード例 #23
0
def force_resume_torrent_cb(_, update, groups):
    logger.info('force-resume torrent inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    torrent.resume()
    time.sleep(1)
    torrent.toggle_force_start(True)

    update.callback_query.answer('Force-resumed')
コード例 #24
0
def manage_torrent_cb(_, update, groups):
    logger.info('manage torrent inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)

    update.callback_query.edit_message_text(
        torrent.string(refresh_properties=True),
        reply_markup=torrent.actions_keyboard,
        parse_mode=ParseMode.HTML)
    update.callback_query.answer('Use the keyboard to manage the torrent')
コード例 #25
0
def toggle_atm_cb(update: Update, context: CallbackContext):
    logger.info('toggle ATM inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash, get_torrent_generic_properties=False)
    atm_status = torrent['auto_tmm']
    torrent.toggle_atm(not atm_status)

    update.callback_query.answer(
        f'Automatic Torrent Management {"disabled" if atm_status else "enabled"}'
    )
コード例 #26
0
def manage_torrent_cb(update: Update, context: CallbackContext):
    logger.info('manage torrent inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)

    update.callback_query.edit_message_text(
        torrent.string(refresh=True),
        reply_markup=torrent.actions_keyboard,
        parse_mode=ParseMode.HTML)
    update.callback_query.answer('Use the keyboard to manage the torrent')
コード例 #27
0
def reduce_buttons(update: Update, context: CallbackContext):
    logger.info('remove buttons inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)

    update.callback_query.edit_message_text(
        torrent.string(refresh=True),
        reply_markup=torrent.short_markup(),
        parse_mode=ParseMode.HTML)
    update.callback_query.answer('Inline keyboard reduced')
コード例 #28
0
def reduce_buttons(_, update, groups):
    logger.info('remove buttons inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)

    update.callback_query.edit_message_text(
        torrent.string(refresh_properties=True),
        reply_markup=torrent.short_markup(),
        parse_mode=ParseMode.HTML)
    update.callback_query.answer('Inline keyboard reduced')
コード例 #29
0
ファイル: manage.py プロジェクト: Ukenn2112/qbittorrent-bot
def ask_confirm_delete_with_files_cb(_, update, groups):
    logger.info('delete with files inline button')

    torrent_hash = groups[0]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash)
    # torrent.delete(with_files=True)

    update.callback_query.edit_message_text(
        '你确定要删除吗 {}, <b>连同文件一起删除</b>?'.format(u.html_escape(torrent.name)),
        reply_markup=kb.confirm_delete(torrent.hash),
        parse_mode=ParseMode.HTML)
    update.callback_query.answer('请再次确认')
コード例 #30
0
def ask_confirm_delete_with_files_cb(update: Update, context: CallbackContext):
    logger.info('delete with files inline button')

    torrent_hash = context.match[1]
    logger.info('torrent hash: %s', torrent_hash)

    torrent = qb.torrent(torrent_hash, get_torrent_generic_properties=False)
    # torrent.delete(with_files=True)

    update.callback_query.edit_message_text(
        f'Are you sure you want to delete {torrent.name_escaped}, <b>with all the connected files included</b>?',
        reply_markup=kb.confirm_delete(torrent.hash),
        parse_mode=ParseMode.HTML)
    update.callback_query.answer('Confirmation needed')