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)
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)
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())
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"')
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')
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')
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))
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())
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')
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')
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"')
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')
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')
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')
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')
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"')
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')
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')
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('强制继续 "开启"')
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))
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)')
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')
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')
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')
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"}' )
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')
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')
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')
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('请再次确认')
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')