From a7def171e6c136cd1fbbfd9a957a83f568f04a3c Mon Sep 17 00:00:00 2001 From: j4nk Date: Thu, 1 Aug 2024 23:31:39 -0400 Subject: [PATCH] Added in tag capabilities --- bot.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 6e1d605..bbe47ba 100644 --- a/bot.py +++ b/bot.py @@ -122,13 +122,13 @@ class QBittorrentAPICaller(): to_ret += "```" return to_ret - def add(self, url, username): + def add(self, url, username, tag="unknown"): if not url.startswith("magnet:"): return "Please supply a magnet link (begins with \"magnet:\")" the_url = self.url + "/" + "api/v2/torrents/add" - resp = self.session.post(the_url, data={"urls":url,"category":username}) + resp = self.session.post(the_url, data={"urls":url,"category":username,"tags":tag}) if (resp.status_code == 415): return "Torrent file not valid" @@ -300,7 +300,13 @@ class QBBot(slixmpp.ClientXMPP): message += self.api_caller.torrentList("full") case "add": - message += self.api_caller.add(tokens[2], msg['mucnick']) + tag = "unknown" + string_start = 2 + if tokens[2].startswith("t="): + tag = tokens[2].removeprefix("t=") + string_start = 3 + + message += self.api_caller.add(tokens[string_start], msg['mucnick'], tag) case "searchplugins": resp = self.api_caller.get_search_plugins() @@ -356,18 +362,18 @@ class QBBot(slixmpp.ClientXMPP): message += "\n```" # Register the users's latest search in the searchselects structure user = msg['mucnick'] - self.searchselects[user] = the_list + self.searchselects[user] = [category if category != "all" else "unknown", the_list] case "searchselect": user = msg['mucnick'] if self.searchselects[user] is None: message += "Please initiate a search first." else: - selection = self.searchselects[user] + selection = self.searchselects[user][1] index = int(tokens[2]) if index < len(selection): link = selection[index][1] - self.api_caller.add(link, user) + self.api_caller.add(link, user, self.searchselects[user][0]) message += "Successfully added " + selection[index][0] else: @@ -398,7 +404,7 @@ class QBBot(slixmpp.ClientXMPP): message += "help: Displays this help" + "\n" message += "list: Lists torrents, names truncated to 25 characters\n" message += "fulllist: Lists torrents, no name truncation\n" - message += "add MAGNET_URL: Adds torrent corresponding to MAGNET_URL to the download list. Note that this will take about 5 seconds, as there's a check for 0 seeds after 5 seconds as a warning\n" + message += "add [t=TAG] MAGNET_URL: Adds torrent corresponding to MAGNET_URL to the download list.\n\tNote that this will take about 5 seconds, as there's a check for 0 seeds after 5 seconds as a warning.\n\tOptionally include TAG to assist in automated copy.\n\tValid TAG values can be found with the categories in searchplugins\n" message += "searchplugins: List the installed search plugins\n" message += "search [c=CATEGORY] search_string: Search from all enabled plugins for search_string, with optional category CATEGORY. Valid categories can be found from the searchplugins command.\n" message += "searchselect: Selects a torrent from a previous search to download\n"