multiple servers at once

This commit is contained in:
iou1name 2018-05-11 17:44:13 -04:00
parent 14f7356957
commit cb68972816
2 changed files with 30 additions and 17 deletions

View File

@ -3,22 +3,22 @@ It sits in a torrent tracker's IRC announce channel and downloads any new torren
This bot was designed with Oppaitime in mind (hence the name) but it's general enough that it should work with any tracker. Because I'm too lazy to make it login to the tracker site properly, it requires you to extract your session cookie for the site into a text file. How you do that is up to you.
In the future I might add functionality to work on multiple sites at once.
Supports connecting to multiple tracker IRC servers at once. Simply make separate config sections for each tracker and it will just werk.
## Requirements
Python 3+
Python modules: `requests, twisted`
## Config
`server` - This is the address of the IRC server the bot should connect to.
`port` - This is the server port the bot should use. SSL probably won't work and isn't recommended.
`nickname` - This is the nickname the bot will use to initially connect to the server with. It's not actually important since the tracker's bot will (usually) rename you upon authentication.
`ident` - This is the IRC username (aka ident) the bot uses to connect to the server. This rarely makes any different.
`server` - The address of the IRC server the bot should connect to.
`port` - The server port the bot should use. SSL probably won't work and isn't recommended.
`nickname` - The nickname the bot will use to initially connect to the server with. It's not actually important since the tracker's bot will (~~usually~~ sometimes) rename you upon authentication.
`ident` - The IRC username (aka ident) the bot uses to connect to the server. This usually isn't important.
`tracker_bot` - The name of the tracker's IRC bot to authenticate with.
`auth_msg` - The message to send to the `tracker_bot` to authenticate with and access the announce channel. It's up to you figure it out.
`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 you session cookie is 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, so the 'tag' can be any substring appearing in the announce message.
`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.
### Example config.cfg
```
@ -32,4 +32,15 @@ auth_msg = BOT #oppaitime-announce iou1name SpaghettiIsAFaggot
watch_dir = /home/iou1name/torrent/oppaitime/Watch/
cookies_txt = cookies.txt
tags = English,Dual Language
[redacted]
server = irc.scratch-network.net
port = 6667
nickname = iou1name|bot
ident = OppaiBot
tracker_bot = Drone
auth_msg = enter #red-announce iou1name TheyllAlwaysBePTHToMe
watch_dir = /home/iou1name/torrent/passtheheadphones/Watch/
cookies_txt = cookies.txt
tags = rock,metal
```

View File

@ -19,6 +19,7 @@ HEADERS = {"User-Agent": "spaghetti is a faggot"}
class OppaiBot(irc.IRCClient):
def __init__(self, config):
self.config = config
self.tracker = self.config.name
self.nickname = self.config["nickname"]
self.username = self.config["ident"]
@ -38,7 +39,7 @@ class OppaiBot(irc.IRCClient):
fname = re.search(r'filename="(.+)"',res.headers['content-disposition'])
fname = fname.group(1)
fname = fname.replace(u"â\x80\x93", "")
print("Saving torrent:", fname)
print(self.tracker + ": Saving torrent:", fname)
with open(os.path.join(directory, fname), "wb") as file:
for chunk in res.iter_content(100000):
file.write(chunk)
@ -58,19 +59,19 @@ class OppaiBot(irc.IRCClient):
def joined(self, channel):
"""Called when the bot joins a new channel."""
print("Joined", channel)
print(self.tracker + ": Joined", channel)
def signedOn(self):
"""Called when the bot successfully connects to the server."""
print("Signed on as", self.nickname)
print(self.tracker + ": Signed on as", self.nickname)
self.mode(self.nickname, True, "B") # set +B on self
self.msg(self.config["tracker_bot"], self.config["auth_msg"])
def nickChanged(self, nick):
"""Called when my nick has been changed."""
print("Nick changed to", nick)
print(self.tracker + ": Nick changed to", nick)
class OppaiBotFactory(protocol.ReconnectingClientFactory):
@ -96,10 +97,11 @@ if __name__ == "__main__":
config = configparser.ConfigParser()
config.read(args.config)
tracker = config.sections()[0]
config = config[tracker] # only handle the entry for now
for tracker in config.sections():
tracker_config = config[tracker]
server = config["server"]
port = int(config["port"])
reactor.connectTCP(server, port, OppaiBotFactory(config))
server = tracker_config["server"]
port = tracker_config.getint("port")
print("Connecting to:", tracker_config.name)
reactor.connectTCP(server, port, OppaiBotFactory(tracker_config))
reactor.run()