Esempio n. 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)
Esempio n. 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")
Esempio n. 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))
Esempio n. 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)
Esempio n. 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)
Esempio n. 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))
Esempio n. 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")
Esempio n. 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")
Esempio n. 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")
Esempio n. 10
0
def addtorrent_callback(query, data) -> None:
    db_management.write_support(f"torrent#{data}", query.sender.id)
    query.notify("Send a torrent file")
Esempio n. 11
0
def addmagnet_callback(query, data) -> None:
    db_management.write_support(f"magnet#{data}", query.sender.id)
    query.notify("Send a magnet link")