logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_filter_command(_, update, args): logger.info('/filter command used by %s (query: %s)', update.effective_user.first_name, args) if not args[0:]: update.message.reply_text('Please provide a search term') return query = ' '.join(args[0:]) torrents = qb.filter(query) if not torrents: update.message.reply_text('No results for "{}"'.format(query)) return strings_list = [torrent.string() for torrent in torrents] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True) updater.add_handler( CommandHandler(['filter', 'f'], on_filter_command, pass_args=True))
• magnet url: add a torrent by magnet url <i>EDIT commands</i> • /altdown: change the alternative max download speed from a keyboard • /altdown <code>[kb/s]</code>: change the alternative max download speed • /altup <code>[kb/s]</code>: change the alternative max upload speed • /pauseall: pause all torrents • /resumeall: resume all torrents • /set <code>[setting] [new value]</code>: change a setting <i>ADMIN commands</i> • /permissions: get the current permissions configuration • /pset <code>[key] [val]</code>: change the value of a permission key • /config: get the qbittorrent's section of the config file <i>FREE commands</i> • /rmkb: remove the keyboard, if any""" @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_help(update: Update, context: CallbackContext): logger.info('/help from %s', update.message.from_user.first_name) update.message.reply_html(HELP_MESSAGE) updater.add_handler(CommandHandler('help', on_help), bot_command=BotCommand("help", "show the help message")) updater.add_handler(MessageHandler(Filters.regex(r'^\/start$'), on_help))
import logging from pprint import pformat # noinspection PyPackageRequirements from telegram import Update, BotCommand from telegram.ext import CommandHandler, CallbackContext from bot.updater import updater from utils import u from utils import Permissions from config import config logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.ADMIN) @u.failwithmessage def on_config_command(update: Update, context: CallbackContext): logger.info('/config from %s', update.effective_user.first_name) update.message.reply_html('<code>{}</code>'.format( pformat(config.qbittorrent))) updater.add_handler(CommandHandler('config', on_config_command), bot_command=BotCommand("config", "get the current config"))
@u.check_permissions(required_permission=Permissions.WRITE) @u.failwithmessage def add_from_file(bot, update): logger.info('document from %s', update.effective_user.first_name) if update.message.document.mime_type != 'application/x-bittorrent': update.message.reply_markdown('Please send me a `.torrent` file') return file_id = update.message.document.file_id torrent_file = bot.get_file(file_id) file_path = './downloads/{}'.format(update.message.document.file_name) torrent_file.download(file_path) with open(file_path, 'rb') as f: # this method always returns an empty json: # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_file qb.download_from_file(f) os.remove(file_path) update.message.reply_text('Torrent added', quote=True) updater.add_handler( MessageHandler(Filters.text & Filters.regex(r'^magnet:\?.*'), add_from_magnet)) updater.add_handler(MessageHandler(Filters.document, add_from_file))
torrents = qb.torrents(filter='all', get_torrent_generic_properties=True) logger.info('qbittirrent request returned %d torrents', len(torrents)) if not torrents: update.message.reply_html('There is no torrent') return update.message.reply_text("Sending file, it might take a while...") result_dict = defaultdict(list) for torrent in torrents: torrent_dict = torrent.dict() torrent_dict["_trackers"] = torrent.trackers() result_dict[torrent.state].append(torrent_dict) file_path = os.path.join('downloads', f'{update.message.message_id}.json') with open(file_path, 'w+') as f: json.dump(result_dict, f, indent=2) update.message.reply_document(open(file_path, 'rb'), caption='#torrents_list', timeout=60 * 10) os.remove(file_path) updater.add_handler(CommandHandler('json', on_json_command), bot_command=BotCommand("json", "backup the torrents list"))
@u.failwithmessage def add_from_url(update: Update, context: CallbackContext): logger.info('url from %s', update.effective_user.first_name) torrent_url = update.message.text kwargs = dict() if config.qbittorrent.get("added_torrents_tag", None): kwargs["tags"] = config.qbittorrent.added_torrents_tag qb.download_from_link(torrent_url, **kwargs) # always returns an empty json: # https://python-qbittorrent.readthedocs.io/en/latest/modules/api.html#qbittorrent.client.Client.download_from_link update.message.reply_text('Torrent url added', quote=True) target_chat_id = notify_addition(update.effective_chat.id) if not target_chat_id: return text = "User {} [{}] added a torrent from an url: {}".format( update.effective_user.full_name, update.effective_user.id, torrent_url ) context.bot.send_message(target_chat_id, text) updater.add_handler(MessageHandler(Filters.document, add_from_file)) updater.add_handler(MessageHandler(Filters.text & Filters.regex(r'^magnet:\?.*'), add_from_magnet)) updater.add_handler(MessageHandler(Filters.text & Filters.regex(r"^https?:\/\/.*(jackett|\.torren|\/torrent).*"), add_from_url))
TORRENT_STRING = '{t.priority}. <code>{t.name}</code> (<b>{t.state_pretty}</b>, [<a href="{t.info_deeplink}">manage</a>])' @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_priorities_command(_, update): logger.info('/priorities from %s', update.effective_user.first_name) torrents = qb.torrents(sort='priority', reverse=False) # filter out paused completed torrents non_completed_torrents = list() for torrent in torrents: if torrent.state in ('pausedUP', ): continue non_completed_torrents.append(torrent) if len(non_completed_torrents) == 25: # list must contain 25 torrents max break lines = [TORRENT_STRING.format(t=t) for t in non_completed_torrents] for strings_chunk in u.split_text(lines): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True) updater.add_handler(CommandHandler(['priorities'], on_priorities_command))
import logging # noinspection PyPackageRequirements from telegram.ext import CommandHandler from bot.updater import updater from utils import u from utils import Permissions logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.ADMIN) @u.failwithmessage def send_log_file(_, update): logger.info('/getlog from %s', update.effective_user.first_name) with open('logs/qbtbot.log', 'rb') as f: update.message.reply_document(f, timeout=600) updater.add_handler(CommandHandler(['getlog', 'log'], send_log_file))
torrents = [ t for t in all_torrents if t.hash not in completed_torrents and t.hash not in active_torrents ] logger.info('qbittirrent request returned %d torrents', len(torrents)) if not torrents: update.message.reply_html( 'There is no torrent to be listed for <i>{}</i>'.format(qbfilter)) return if qbfilter == 'completed': base_string = TORRENT_STRING_COMPLETED # use a shorter string with less info for completed torrents else: base_string = TORRENT_STRING_COMPACT strings_list = [ base_string.format(**torrent.dict()) for torrent in torrents ] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True) updater.add_handler( RegexHandler(TORRENT_CATEG_REGEX, on_torrents_list_selection, pass_groups=True))
@u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_priorities_command(update: Update, context: CallbackContext): logger.info('/priorities from %s', update.effective_user.first_name) torrents = qb.torrents(sort='priority', reverse=False) # filter out paused completed torrents non_completed_torrents = list() for torrent in torrents: if torrent.state in ('pausedUP', ): continue non_completed_torrents.append(torrent) if len(non_completed_torrents) == 25: # list must contain 25 torrents max break lines = [TORRENT_STRING.format(t=t) for t in non_completed_torrents] for strings_chunk in u.split_text(lines): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True) updater.add_handler(CommandHandler(['priorities'], on_priorities_command), bot_command=BotCommand( "priorities", "see the torrents list sorted by priority"))
@u.ignore_not_modified_exception 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') updater.add_handler(CommandHandler(['overview', 'ov'], on_overview_command), bot_command=BotCommand( "overview", "overview of what we're downloading and uploading")) updater.add_handler(CommandHandler(['quick'], on_overview_command)) updater.add_handler( MessageHandler(Filters.regex(r'^[aA\.]$'), on_overview_refresh)) updater.add_handler( CallbackQueryHandler(on_refresh_button_overview, pattern=r'^(?:quick|overview):refresh:(\w+)$')) updater.add_handler( CallbackQueryHandler(on_free_space_button_overview, pattern=r'^overview:freespace')) updater.add_handler( CallbackQueryHandler(on_transfer_info_button_overview, pattern=r'^overview:transferinfo')) updater.add_handler( CallbackQueryHandler(on_manage_alt_speed_button_overview,
logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_filter_command(update: Update, context: CallbackContext): logger.info('/filter command used by %s (query: %s)', update.effective_user.first_name, context.args) if not context.args[0:]: update.message.reply_text('Please provide a search term') return query = ' '.join(context.args[0:]) torrents = qb.filter(query) if not torrents: update.message.reply_text('No results for "{}"'.format(query)) return strings_list = [torrent.string() for torrent in torrents] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk)) updater.add_handler(CommandHandler(['filter', 'f'], on_filter_command), bot_command=BotCommand("filter", "filter torrents by substring"))
update.message.reply_html( 'Usage: /pset <code>[permission key] [true/false/1/0]</code>') return key = context.args[0].lower() val = context.args[1].lower() if val.lower() not in ('true', 'false', '0', '1'): update.message.reply_html( 'Wrong value passed. Usage: /pset <code>[permission key] [true/false/1/0]</code>' ) return if permissions.get(key, None) is None: update.message.reply_text( 'Wrong key. Use /permissions to see the current permissions config' ) return actual_val = True if val in ('true', '1') else False permissions.set(key, actual_val) update.message.reply_html('<b>New config</b>:\n\n<code>{}</code>'.format( str(permissions))) updater.add_handler(CommandHandler(['permissions', 'p'], get_permissions), bot_command=BotCommand( "permissions", "see how permissions are configured")) updater.add_handler(CommandHandler(['pset'], set_permission), bot_command=BotCommand("pset", "change a permission"))
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) updater.add_handler( MessageHandler( Filters.regex(r"^(\+|\-)(.+)") & Filters.reply, on_add_or_remove_tags_command))
@u.failwithmessage def on_speed_command(update: Update, context: CallbackContext): logger.info('/transferinfo from %s', update.effective_user.first_name) text = get_speed_text() update.message.reply_html(text, reply_markup=kb.REFRESH_TRANSFER_INFO) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage @u.ignore_not_modified_exception def on_refresh_button_speed(update: Update, context: CallbackContext): logger.info('transfer info: refresh button') text = get_speed_text() update.callback_query.edit_message_text( text, parse_mode=ParseMode.HTML, reply_markup=kb.REFRESH_TRANSFER_INFO) update.callback_query.answer('Refreshed') updater.add_handler( CommandHandler(['transferinfo', 'ti', 'speed'], on_speed_command), bot_command=BotCommand( "transferinfo", "overview about the current speed, queueing and rateo settings")) updater.add_handler( CallbackQueryHandler(on_refresh_button_speed, pattern=r'^refreshtransferinfo$'))
import logging # noinspection PyPackageRequirements from telegram import Update, BotCommand from telegram.ext import CommandHandler, CallbackContext from bot.qbtinstance import qb from bot.updater import updater from utils import u from utils import Permissions logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.ADMIN) @u.failwithmessage def on_freespace_command(update: Update, context: CallbackContext): logger.info('/space from %s', update.message.from_user.first_name) drive_free_space = u.free_space(qb.save_path) text = f"{drive_free_space} free, save path: <code>{qb.save_path}</code>" update.message.reply_html(text) updater.add_handler(CommandHandler(["space", "freespace"], on_freespace_command), bot_command=BotCommand("freespace", "free space from download path"))
qb.set_preferences(**preferences_to_edit) update.message.reply_markdown('`{}` set to {} kb/s'.format( preference_key, kbs)) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage 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)) updater.add_handler( CommandHandler(['altdown', 'altup'], change_alternative_limits, pass_args=True)) updater.add_handler( CallbackQueryHandler(altdown_speed_callback, pattern=r'^altdown:(\d+)$', pass_groups=True))
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') updater.add_handler( RegexHandler(r'^\/start info(.*)$', on_info_deeplink, pass_groups=True)) updater.add_handler( CallbackQueryHandler(manage_torrent_cb, pattern=r'^manage:(.*)$', pass_groups=True)) updater.add_handler( CallbackQueryHandler(see_trackers_cb, pattern=r'^trackers:(.*)$', pass_groups=True)) updater.add_handler( CallbackQueryHandler(refresh_torrent_cb, pattern=r'^refresh:(.*)$', pass_groups=True)) updater.add_handler( CallbackQueryHandler(pause_torrent_cb, pattern=r'^pause:(.*)$',
import logging # noinspection PyPackageRequirements from telegram.ext import CommandHandler from bot.qbtinstance import qb from bot.updater import updater from utils import u from utils import Permissions logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_version_command(_, update): logger.info('/version from %s', update.message.from_user.first_name) text = 'qBittorrent version: <code>{}</code>\nAPI version: <code>{}</code>'.format( qb.qbittorrent_version, qb.api_version) update.message.reply_html(text) updater.add_handler(CommandHandler('version', on_version_command))
preferences = qb.preferences() lines = sorted( ['{}: <code>{}</code>'.format(k, v) for k, v in preferences.items()]) for strings_chunk in u.split_text(lines): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True) @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage def change_setting(_, update, args): logger.info('/set from %s', update.effective_user.first_name) if len(args) < 2: update.message.reply_html('Usage: /set <code>[setting] [value]</code>') return key = args[0].lower() val = args[1] qb.set_preferences(**{key: val}) update.message.reply_html( '<b>Setting changed</b>:\n\n<code>{}</code>'.format(val)) updater.add_handler(CommandHandler(['settings', 's'], on_settings_command)) updater.add_handler(CommandHandler(['set'], change_setting, pass_args=True))
@u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_atm_list_command(update: Update, context: CallbackContext): logger.info('/atmyes or /atmno command used by %s', update.effective_user.first_name) torrents = qb.torrents() atm_enabled = update.message.text.lower().endswith("atmyes") base_string = "• <code>{short_name}</code> ({size_pretty}, {state_pretty}) [<a href=\"{info_deeplink}\">info</a>]" strings_list = [torrent.string(base_string=base_string) for torrent in torrents if torrent['auto_tmm'] is atm_enabled] update.message.reply_html( f"There are <b>{len(strings_list)}/{len(torrents)}</b> torrents with " f"Automatic Torrent Management {'enabled' if atm_enabled else 'disabled'}:" ) if not strings_list: update.message.reply_text("-") return for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk)) updater.add_handler(CommandHandler(['atm'], on_atm_command), bot_command=BotCommand("atm", "info about auto torrent management")) updater.add_handler(CommandHandler(['atmyes'], on_atm_list_command), bot_command=BotCommand("atmyes", "list torrents which have ATM enabled")) updater.add_handler(CommandHandler(['atmno'], on_atm_list_command), bot_command=BotCommand("atmno", "list torrents which have ATM disabled"))
• 磁力链接: 通过磁力链接添加种子 <i>设置</i> • /altdown: 通过按钮设置备用最大下载速度 • /altdown <code>[单位 kb/s]</code>: 设置备用最大下载速度 • /altup <code>[单位 kb/s]</code>: 设置备用最大上传速度 • /pauseall: 暂停所有种子 • /resumeall: 开始所有的种子 • /set <code>[设置项目] [变更参数]</code>: 更改设置 <i>管理</i> • /getlog 或 /log: 获取日志文件 • /permissions: 获取当前的权限配置。 • /pset <code>[key] [val]</code>: 更改密钥权限 • /config: 获取qbittorrent的配置文件部分 <i>FREE commands</i> • /rmkb: remove the keyboard, if any""" @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_help(_, update): logger.info('/help from %s', update.message.from_user.first_name) update.message.reply_html(HELP_MESSAGE) updater.add_handler(CommandHandler('help', on_help)) updater.add_handler(RegexHandler(r'^\/start$', on_help))
def on_schedon_button_quick(_, update): logger.info('quick info: schedon button') qb.set_preferences(**{'scheduler_enabled': True}) 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 on') @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage @u.ignore_not_modified_exception 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') updater.add_handler(CommandHandler(['quick'], on_quick_info_command, pass_user_data=True)) updater.add_handler(RegexHandler(r'^[aA]$', on_quick_info_refresh, pass_user_data=True)) updater.add_handler(CallbackQueryHandler(on_refresh_button_quick, pattern=r'^quick:refresh:(\w+)$', pass_groups=True)) updater.add_handler(CallbackQueryHandler(on_alton_button_quick, pattern=r'^quick:alton$')) updater.add_handler(CallbackQueryHandler(on_altoff_button_quick, pattern=r'^quick:altoff$')) updater.add_handler(CallbackQueryHandler(on_schedon_button_quick, pattern=r'^quick:schedon')) updater.add_handler(CallbackQueryHandler(on_schedoff_button_quick, pattern=r'^quick:schedoff'))
if not torrents: update.callback_query.answer('Cannot refresh: no torrents') return strings_list = [ TORRENT_STRING_COMPACT.format(**torrent.dict()) for torrent in torrents ] # we assume the list doesn't require more than one message try: update.callback_query.edit_message_text('\n'.join(strings_list), reply_markup=kb.REFRESH_ACTIVE, parse_mode=ParseMode.HTML) except BadRequest as br: logger.error( 'Telegram error when refreshing the active torrents list: %s', br.message) update.callback_query.answer('Error: {}'.format(br.message)) return update.callback_query.answer('Refreshed') updater.add_handler( RegexHandler(TORRENT_CATEG_REGEX, on_torrents_list_selection, pass_groups=True)) updater.add_handler( CallbackQueryHandler(refresh_active_torrents, pattern=r'^refreshactive$'))
@u.failwithmessage def on_settings_command(update: Update, context: CallbackContext): logger.info('/settings from %s', update.effective_user.first_name) preferences = qb.preferences() lines = sorted(['{}: <code>{}</code>'.format(k, v) for k, v in preferences.items()]) for strings_chunk in u.split_text(lines): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True) @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage 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)) updater.add_handler(CommandHandler(['settings', 's'], on_settings_command), bot_command=BotCommand("settings", "see qbittorrent's settings list")) updater.add_handler(CommandHandler(['set'], change_setting), bot_command=BotCommand("set", "change a qbittorrent setting"))
update.message.reply_markdown('`{}` set to {} kb/s'.format(preference_key, kbs)) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage 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 ) updater.add_handler(CommandHandler(['altdown', 'altup'], change_alternative_limits), bot_command=[ BotCommand("altdown", "set the alternative download speed"), BotCommand("altup", "set the alternative upload speed"), ]) updater.add_handler(CallbackQueryHandler(alt_speed_callback, pattern=r'^altspeed:(\d+):(\d+)$'))
logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage def on_resume_all_command(update: Update, context: CallbackContext): logger.info('resume all command from %s', update.message.from_user.first_name) qb.resume_all() update.message.reply_text('Resumed all torrents') @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage def on_pause_all_command(update: Update, context: CallbackContext): logger.info('pause all command from %s', update.message.from_user.first_name) qb.pause_all() update.message.reply_text('Paused all torrents') updater.add_handler(CommandHandler(['resumeall'], on_resume_all_command), bot_command=BotCommand("resumeall", "start all torrents")) updater.add_handler(CommandHandler(['pauseall'], on_pause_all_command), bot_command=BotCommand("pauseall", "pause all torrents"))
from bot.qbtinstance import qb from bot.updater import updater from utils import u from utils import Permissions logger = logging.getLogger(__name__) @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage def on_resume_all_command(_, update): logger.info('resume all command from %s', update.message.from_user.first_name) qb.resume_all() update.message.reply_text('Resumed all torrents') @u.check_permissions(required_permission=Permissions.EDIT) @u.failwithmessage def on_pause_all_command(_, update): logger.info('pause all command from %s', update.message.from_user.first_name) qb.pause_all() update.message.reply_text('Paused all torrents') updater.add_handler(CommandHandler(['resumeall'], on_resume_all_command)) updater.add_handler(CommandHandler(['pauseall'], on_pause_all_command))
import logging # noinspection PyPackageRequirements from telegram import Update, BotCommand from telegram.ext import CommandHandler, CallbackContext from bot.updater import updater from utils import u from utils import kb logger = logging.getLogger(__name__) @u.failwithmessage def remove_keyboard(update: Update, context: CallbackContext): logger.info('/rmkb from %s', update.effective_user.first_name) update.message.reply_text('Keyboard removed', reply_markup=kb.REMOVE) updater.add_handler(CommandHandler(['rmkb'], remove_keyboard), bot_command=BotCommand( "rmkb", "force-remove the virtual keyboard"))
base_string.format(**torrent.dict()) for torrent in torrents ] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk)) @u.check_permissions(required_permission=Permissions.READ) @u.failwithmessage def on_available_filters_command(update: Update, context: CallbackContext): logger.info('/available_filters from %s') update.message.reply_text("\n".join([f"/{c}" for c in TORRENTS_CATEGORIES])) updater.add_handler( MessageHandler(Filters.regex(TORRENT_CATEG_REGEX), on_torrents_list_selection), bot_command=[ BotCommand(c, f"filter only {c} torrents") for c in TORRENTS_CATEGORIES ], ) updater.add_handler( CommandHandler(["available_filters", "af"], on_available_filters_command), bot_command=[ BotCommand("available_filters", "show commands to filter the torrents list by status") ], )