示例#1
0
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)
示例#2
0
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")
示例#3
0
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))
示例#4
0
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)
示例#5
0
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)
示例#6
0
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))
示例#7
0
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")
示例#8
0
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")
示例#9
0
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")
示例#10
0
def addtorrent_callback(query, data) -> None:
    db_management.write_support(f"torrent#{data}", query.sender.id)
    query.notify("Send a torrent file")
示例#11
0
def addmagnet_callback(query, data) -> None:
    db_management.write_support(f"magnet#{data}", query.sender.id)
    query.notify("Send a magnet link")