Ejemplo n.º 1
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")
Ejemplo n.º 2
0
def list_by_status_callback(client: Client,
                            callback_query: CallbackQuery) -> None:
    status_filter = callback_query.data.split("#")[1]
    list_active_torrents(0,
                         callback_query.from_user.id,
                         callback_query.message.message_id,
                         db_management.read_support(
                             callback_query.from_user.id),
                         status_filter=status_filter)
Ejemplo n.º 3
0
def list_callback(client: Client, callback_query: CallbackQuery) -> None:
    list_active_torrents(
        0, callback_query.from_user.id, callback_query.message.message_id,
        db_management.read_support(callback_query.from_user.id))
Ejemplo n.º 4
0
def list_callback(chat, message) -> None:
    btn = botogram.Buttons()
    btn[0].callback("🔙 Menu", "menu")
    list_active_torrents(0, chat, message,
                         db_management.read_support(chat.id))