Implement channel blacklisting

This commit is contained in:
Mark Veidemanis 2020-11-01 19:54:24 +00:00
parent a0bea0b18a
commit 399075afd1
5 changed files with 49 additions and 1 deletions

1
.gitignore vendored
View File

@ -10,4 +10,5 @@ conf/network.dat
conf/alias.json
conf/irc.json
conf/dist.sh
conf/blacklist.json
env/

41
commands/blacklist.py Normal file
View File

@ -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)

View File

@ -32,5 +32,6 @@
"confirm": "confirm <network> <num> <token>",
"pending": "pending [<network>]",
"authcheck": "authcheck [<network>]",
"recheckauth": "recheckauth [<network>]"
"recheckauth": "recheckauth [<network>]",
"blacklist": "blacklist <network> <channel>"
}

View File

@ -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

View File

@ -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"]