diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ad08c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +irc.json + diff --git a/README.md b/README.md index 255c84b..61c5ecb 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,19 @@ A Cards Against Humanity IRC bot This is currently a very poorly written bot, however most of the functionality is complete. -Future versions will focus on making it easier for users to run their own version, simply by editing a json file containing any options that are required. +Future versions will focus on making it easier for users to run their own +version, simply by editing a json file containing any options that are required. + +Configuration file +------------------ + +Simply copy the content of the ``irc-sample.json`` file provided and save it as ``irc.json``. Adapt it to your needs. You can provide the following keys: + +* host +* port +* channel +* identity +* realname +* hostname +* botname +* password diff --git a/irc-sample.json b/irc-sample.json new file mode 100644 index 0000000..800ab19 --- /dev/null +++ b/irc-sample.json @@ -0,0 +1,5 @@ +[{ + "host": "irc.freenode.org", + "port": 6667, + "channel": "#brunobordtest" +}] diff --git a/sprbt.py b/sprbt.py index bf9a3c6..b88dc28 100755 --- a/sprbt.py +++ b/sprbt.py @@ -7,16 +7,19 @@ from datetime import timedelta import select import functions +import json + class IRCConnector( threading.Thread): - def __init__ (self, host, port): - self.host = host - self.port = port - self.channel = "#cah" - self.identity = "superbot" - self.realname = "superbot" - self.hostname = "supermatt.net" - self.botname = "humanitybot" + def __init__ (self, config): + self.host = config.get('host') + self.port = config.get('port') + self.channel = config.get('channel', "#cah") + self.identity = config.get("identity", "superbot") + self.realname = config.get("realname", "superbot") + self.hostname = config.get("hostname", "supermatt.net") + self.botname = config.get('botname', "humanitybot") + self.password = config.get('password', 'hum4n1ty') self.allmessages = [] self.lastmessage = datetime.now() self.pulsetime = 500 @@ -74,7 +77,7 @@ def run (self): if re.search(":End of /MOTD command.", line): joinchannel = "JOIN %s\n" %self.channel self.output(joinchannel) - self.s.send("PRIVMSG nickserv :identify hum4n1ty\n") + self.s.send("PRIVMSG nickserv :identify %s\n" % self.password) self.s.send(joinchannel) self.inchannel = True @@ -140,12 +143,9 @@ def run (self): #print self.allmessages -irc_connections = [{ - "host": "irc.darkmyst.org", - "port": 6667, - "channels": ["#cah"] - }] +if __name__ == '__main__': + irc_connections = json.load(open('irc.json')) -for irc in irc_connections: - IRCThread = IRCConnector(irc['host'], irc['port']) - IRCThread.start() + for config in irc_connections: + IRCThread = IRCConnector(config) + IRCThread.start()