From c61c599f93e61fc9e0561a7ed79b6c770d21f107 Mon Sep 17 00:00:00 2001 From: iou1name Date: Thu, 17 May 2018 13:28:57 -0400 Subject: [PATCH 1/2] logic AND/OR for tags --- README.md | 6 +++--- oppaiBot.py | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 71ec3cb..742e817 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Python modules: `requests, twisted` `auth_msg` - The message to send to the `tracker_bot` to authenticate with and access the announce channel. It's up to you figure this out. `watch_dir` - The directory to save torrents to. `cookies_txt` - The path to where your session cookie(s) are stored. Should be in Netscape format. -`tags` - Comma-delineated list of tags to look for in each announce message. The script is just performing simple string comparisons on the entire message, so the 'tag' can be any substring appearing in the announce message. Note that this is essentially an OR operation. I'm too lazy to get more complex than that. +`tags` - Comma-delineated list of tags to look for in each announce message. The script is just performing simple string comparisons on the entire message, so the 'tag' can be any substring appearing in the announce message. Tag inside of brackets are AND'd together, tag groups are then OR'd together. In the example below, announce messages with ['Manga' AND 'English' AND 'Archived'] OR 'Dual Language' OR 'Softsubs' will be matched. ### Example config.cfg ``` @@ -31,7 +31,7 @@ tracker_bot = Udon auth_msg = BOT #oppaitime-announce iou1name SpaghettiIsAFaggot watch_dir = /home/iou1name/torrent/oppaitime/Watch/ cookies_txt = cookies.txt -tags = English,Dual Language +tags = [Manga,English,Archived],[Dual Language],[Softsubs] [redacted] server = irc.scratch-network.net @@ -42,5 +42,5 @@ tracker_bot = Drone auth_msg = enter #red-announce iou1name TheyllAlwaysBePTHToMe watch_dir = /home/iou1name/torrent/passtheheadphones/Watch/ cookies_txt = cookies.txt -tags = rock,metal +tags = [rock],[metal] ``` diff --git a/oppaiBot.py b/oppaiBot.py index a4c8f3c..51347d0 100755 --- a/oppaiBot.py +++ b/oppaiBot.py @@ -27,7 +27,8 @@ class OppaiBot(irc.IRCClient): self.cj.load() self.watch_dir = self.config["watch_dir"] - self.tags = self.config["tags"].split(",") + self.tags = re.findall(r"\[(.+?)\]", self.config["tags"]) + self.tags = [tag.split(",") for tag in self.tags] def save_torrent(self, url, directory): @@ -51,7 +52,9 @@ class OppaiBot(irc.IRCClient): or users alike. """ # More advanced logic is left as an exercise to the reader. - tags_in_msg = [tag in message for tag in self.tags] + tags_in_msg = [] + for tag_group in self.tags: + tags_in_msg.append(all([tag in msg for tag in tag_group])) if any(tags_in_msg): url = re.findall(r"(http.+?) ", message)[1] self.save_torrent(url, self.watch_dir) From 6762a4a137ec73f0de8bc7bb0877b88e3e851016 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 18 May 2018 08:40:30 -0400 Subject: [PATCH 2/2] added logical NOT --- README.md | 6 +++--- oppaiBot.py | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 742e817..f29ed6f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Python modules: `requests, twisted` `auth_msg` - The message to send to the `tracker_bot` to authenticate with and access the announce channel. It's up to you figure this out. `watch_dir` - The directory to save torrents to. `cookies_txt` - The path to where your session cookie(s) are stored. Should be in Netscape format. -`tags` - Comma-delineated list of tags to look for in each announce message. The script is just performing simple string comparisons on the entire message, so the 'tag' can be any substring appearing in the announce message. Tag inside of brackets are AND'd together, tag groups are then OR'd together. In the example below, announce messages with ['Manga' AND 'English' AND 'Archived'] OR 'Dual Language' OR 'Softsubs' will be matched. +`tags` - Comma-delineated list of tags to look for in each announce message. The script is just performing simple string comparisons on the entire message, so the 'tag' can be any substring appearing in the announce message. Tag inside of brackets are AND'd together, tag groups are then OR'd together. Tags starting with ! are treated as NOT [tag]. In the example below, announce messages with ['English' AND NOT 'Manga'] OR ['Manga' AND 'English' AND 'Archived'] OR 'Dual Language' OR 'Softsubs' will be matched. ### Example config.cfg ``` @@ -31,7 +31,7 @@ tracker_bot = Udon auth_msg = BOT #oppaitime-announce iou1name SpaghettiIsAFaggot watch_dir = /home/iou1name/torrent/oppaitime/Watch/ cookies_txt = cookies.txt -tags = [Manga,English,Archived],[Dual Language],[Softsubs] +tags = [English,!Manga],[Manga,English,Archived],[Dual Language],[Softsubs] [redacted] server = irc.scratch-network.net @@ -42,5 +42,5 @@ tracker_bot = Drone auth_msg = enter #red-announce iou1name TheyllAlwaysBePTHToMe watch_dir = /home/iou1name/torrent/passtheheadphones/Watch/ cookies_txt = cookies.txt -tags = [rock],[metal] +tags = [rock] ``` diff --git a/oppaiBot.py b/oppaiBot.py index 51347d0..fda67a7 100755 --- a/oppaiBot.py +++ b/oppaiBot.py @@ -54,7 +54,15 @@ class OppaiBot(irc.IRCClient): # More advanced logic is left as an exercise to the reader. tags_in_msg = [] for tag_group in self.tags: - tags_in_msg.append(all([tag in msg for tag in tag_group])) + #tags_in_msg.append(all([tag in message for tag in tag_group])) + tags_in_group = [] + for tag in tag_group: + if tag.startswith("!"): + tags_in_group.append(tag[1:] not in message) + else: + tags_in_group.append(tag in message) + tags_in_msg.append(all(tags_in_group)) + if any(tags_in_msg): url = re.findall(r"(http.+?) ", message)[1] self.save_torrent(url, self.watch_dir)