diff --git a/.gitignore b/.gitignore index 9d56c45..34d919c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ conf/network.dat conf/alias.json conf/irc.json conf/dist.sh +conf/blacklist.json env/ diff --git a/commands/blacklist.py b/commands/blacklist.py new file mode 100644 index 0000000..89d25c6 --- /dev/null +++ b/commands/blacklist.py @@ -0,0 +1,41 @@ +import main +from yaml import dump + +class BlacklistCommand: + def __init__(self, *args): + self.blacklist(*args) + + def blacklist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): + if authed: + if length == 1: + info(dump(main.blacklist)) + return + elif length == 4: + if spl[1] == "add": + if spl[2] in main.blacklist.keys(): + main.blacklist[spl[2]].append(spl[3]) + else: + main.blacklist[spl[2]] = [spl[3]] + success("Blacklisted %s on %s" % (spl[3], spl[2])) + main.saveConf("blacklist") + return + elif spl[1] == "del": + if spl[2] in main.blacklist.keys(): + if spl[3] in main.blacklist[spl[2]]: + main.blacklist[spl[2]].remove(spl[3]) + if len(main.blacklist[spl[2]]) == 0: + del main.blacklist[spl[2]] + else: + failure("Not in list: %s" % spl[3]) + return + else: + failure("No such entry: %s" % spl[2]) + return + success("Removed blacklist %s on %s" % (spl[3], spl[2])) + main.saveConf("blacklist") + return + else: + incUsage("blacklist") + return + else: + incUsage(None) diff --git a/conf/help.json b/conf/help.json index 704d979..e36b6ec 100644 --- a/conf/help.json +++ b/conf/help.json @@ -32,5 +32,6 @@ "confirm": "confirm ", "pending": "pending []", "authcheck": "authcheck []", - "recheckauth": "recheckauth []" + "recheckauth": "recheckauth []", + "blacklist": "blacklist " } diff --git a/core/bot.py b/core/bot.py index 0bb64b2..75cee7c 100644 --- a/core/bot.py +++ b/core/bot.py @@ -181,6 +181,10 @@ class IRCBot(IRCClient): increment = 0.8 for i in channels: if not i in self.channels: + if self.net in main.blacklist.keys(): + if i in main.blacklist[self.net]: + debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num)) + continue debug(self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds") reactor.callLater(sleeptime, self.join, i) sleeptime += increment diff --git a/main.py b/main.py index e5ec77d..caebef7 100644 --- a/main.py +++ b/main.py @@ -24,6 +24,7 @@ filemap = { "aliasdata": ["aliasdata.json", "data for alias generation", "json"], "alias": ["alias.json", "provisioned alias data", "json"], "irc": ["irc.json", "IRC network definitions", "json"], + "blacklist": ["blacklist.json", "IRC channel blacklist", "json"], # Binary (pickle) configs "network": ["network.dat", "network list", "pickle"]