def modify_category_callback(chat, message, data): btn = botogram.Buttons() if data is not None: btn[2].callback("π Menu", "menu") db_management.write_support(f"category_dir_modify#{data}", chat.id) message.edit(f"Send new path for category {data}", attach=btn) return categories = qbittorrent_control.get_categories() if categories is None: btn[0].callback("π Menu", "menu") message.edit("There are no categories", attach=btn) return for key, i in enumerate(categories): btn[key].callback(i, "modify_category", i) btn[key + 1].callback("π Menu", "menu") try: message.edit("Choose a category:", attach=btn) except botogram.api.APIError: chat.send("Choose a category:", attach=btn)
def add_category_callback(chat, message) -> None: db_management.write_support("category_name", chat.id) btn = botogram.Buttons() btn[2].callback("π Menu", "menu") try: message.edit("Send the category name") except botogram.api.APIError: chat.send("Send the category name")
def modify_category_callback(client: Client, callback_query: CallbackQuery) -> None: buttons = [[InlineKeyboardButton("π Menu", "menu")]] db_management.write_support( f"category_dir_modify#{callback_query.data.split('#')[1]}", callback_query.from_user.id) app.edit_message_text( callback_query.from_user.id, callback_query.message.message_id, f"Send new path for category {callback_query.data.split('#')[1]}", reply_markup=InlineKeyboardMarkup(buttons))
def add_category_callback(client: Client, callback_query: CallbackQuery) -> None: db_management.write_support("category_name", callback_query.from_user.id) button = InlineKeyboardMarkup([[InlineKeyboardButton("π Menu", "menu")]]) try: app.edit_message_text(callback_query.from_user.id, callback_query.message.message_id, "Send the category name", reply_markup=button) except MessageIdInvalid: app.send_message(callback_query.from_user.id, "Send the category name", reply_markup=button)
def send_menu(message, chat) -> None: db_management.write_support("None", chat.id) btn = botogram.Buttons() btn[0].callback("π List", "list") btn[1].callback("β Add Magnet", "category", "add_magnet") btn[1].callback("β Add Torrent", "category", "add_torrent") btn[2].callback("βΈ Pause", "pause") btn[2].callback("βΆοΈ Resume", "resume") btn[3].callback("βΈ Pause All", "pause_all") btn[3].callback("βΆοΈ Resume All", "resume_all") btn[4].callback("π Delete", "delete_one") btn[4].callback("π Delete All", "delete_all") btn[5].callback("β Add Category", "add_category") btn[5].callback("π Remove Category", "remove_category") btn[6].callback("π Modify Category", "modify_category") try: message.edit("Qbitorrent Control", attach=btn) except botogram.api.APIError: chat.send("Qbitorrent Control", attach=btn)
def send_menu(message, chat) -> None: db_management.write_support("None", chat) buttons = [[InlineKeyboardButton("π List", "list")], [ InlineKeyboardButton("β Add Magnet", "category#add_magnet"), InlineKeyboardButton("β Add Torrent", "category#add_torrent") ], [ InlineKeyboardButton("βΈ Pause", "pause"), InlineKeyboardButton("βΆοΈ Resume", "resume") ], [ InlineKeyboardButton("βΈ Pause All", "pause_all"), InlineKeyboardButton("βΆοΈ Resume All", "resume_all") ], [ InlineKeyboardButton("π Delete", "delete_one"), InlineKeyboardButton("π Delete All", "delete_all") ], [ InlineKeyboardButton("β Add Category", "add_category"), InlineKeyboardButton("π Remove Category", "select_category#remove_category") ], [ InlineKeyboardButton("π Modify Category", "select_category#modify_category") ]] try: app.edit_message_text(chat, message, text="Qbittorrent Control", reply_markup=InlineKeyboardMarkup(buttons)) except MessageIdInvalid: app.send_message(chat, text="Qbittorrent Control", reply_markup=InlineKeyboardMarkup(buttons))
def on_text(client: Client, message: Message) -> None: action = db_management.read_support(message.from_user.id) if "magnet" in action: if message.text.startswith("magnet:?xt"): magnet_link = message.text.split("\n") category = db_management.read_support( message.from_user.id).split("#")[1] qbittorrent_control.add_magnet(magnet_link=magnet_link, category=category) send_menu(message.message_id, message.from_user.id) db_management.write_support("None", message.from_user.id) else: message.reply_text("This magnet link is invalid! Retry") elif "torrent" in action and message.document: if ".torrent" in message.document.file_name: with tempfile.TemporaryDirectory() as tempdir: name = f"{tempdir}/{message.document.file_name}" category = db_management.read_support( message.from_user.id).split("#")[1] message.download(name) qbittorrent_control.add_torrent(file_name=name, category=category) send_menu(message.message_id, message.from_user.id) db_management.write_support("None", message.from_user.id) else: message.reply_text("This is not a torrent file! Retry") elif action == "category_name": db_management.write_support(f"category_dir#{message.text}", message.from_user.id) message.reply_text( f"now send me the path for the category {message.text}") elif "category_dir" in action: if os.path.exists(message.text): name = db_management.read_support( message.from_user.id).split("#")[1] if "modify" in action: qbittorrent_control.edit_category(name=name, save_path=message.text) send_menu(message.message_id, message.from_user.id) return qbittorrent_control.create_category(name=name, save_path=message.text) send_menu(message.message_id, message.from_user.id) else: message.reply_text("The path entered does not exist! Retry")
def addtorrent_callback(client: Client, callback_query: CallbackQuery) -> None: db_management.write_support(f"torrent#{callback_query.data.split('#')[1]}", callback_query.from_user.id) app.answer_callback_query(callback_query.id, "Send a torrent file")
def addmagnet_callback(client: Client, callback_query: CallbackQuery) -> None: db_management.write_support(f"magnet#{callback_query.data.split('#')[1]}", callback_query.from_user.id) app.answer_callback_query(callback_query.id, "Send a magnet link")
def addtorrent_callback(query, data) -> None: db_management.write_support(f"torrent#{data}", query.sender.id) query.notify("Send a torrent file")
def addmagnet_callback(query, data) -> None: db_management.write_support(f"magnet#{data}", query.sender.id) query.notify("Send a magnet link")