Implement alternative keyword notifications and move the per-instance wholist into the global namespace
This commit is contained in:
parent
96dd71bbdd
commit
fc8a115e17
|
@ -7,6 +7,7 @@
|
|||
"UsePassword": true,
|
||||
"ConnectOnCreate": false,
|
||||
"HighlightNotifications": true,
|
||||
"Debugger": false,
|
||||
"DistEnabled": true,
|
||||
"SendDistOutput": false,
|
||||
"Password": "s",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"del": "del <name>",
|
||||
"mod": "mod <name> [<key>] [<value>]",
|
||||
"get": "get <name> <variable>",
|
||||
"key": "key <master|show|add|del|except|unexcept|showexcept> [<name>] [<target>] [<key>]",
|
||||
"key": "key <master|show|add|del|except|unexcept|showexcept|monitor> [<name>] [<target>] [<key>] [<on|off>]",
|
||||
"join": "join <name> <channel> [<key>]",
|
||||
"enable": "enable <name",
|
||||
"disable": "disable <name>",
|
||||
|
|
70
threshold
70
threshold
|
@ -6,14 +6,24 @@ from twisted.internet.protocol import Protocol, Factory
|
|||
from twisted.internet.endpoints import SSL4ClientEndpoint, TCP4ClientEndpoint, connectProtocol
|
||||
from twisted.words.protocols.irc import IRCClient
|
||||
|
||||
#from twisted.python import log
|
||||
#from sys import stdout
|
||||
#log.startLogging(stdout)
|
||||
|
||||
from json import load, dump, loads
|
||||
from sys import exit
|
||||
from subprocess import run, PIPE
|
||||
|
||||
numbers = "0123456789"
|
||||
|
||||
listener = None
|
||||
connections = {}
|
||||
IRCPool = {}
|
||||
|
||||
MonitorPool = []
|
||||
|
||||
wholist = {}
|
||||
|
||||
def log(data):
|
||||
print("[LOG]", data)
|
||||
|
||||
|
@ -60,7 +70,6 @@ class IRCBot(IRCClient):
|
|||
|
||||
self._who = {}
|
||||
self._getWho = {}
|
||||
self.wholist = {}
|
||||
|
||||
self.authtype = instance["authtype"]
|
||||
if self.authtype == "ns":
|
||||
|
@ -180,7 +189,8 @@ class IRCBot(IRCClient):
|
|||
del self._who[channel]
|
||||
|
||||
def got_who(self, whoinfo):
|
||||
self.wholist[whoinfo[0]] = whoinfo[1]
|
||||
global wholist
|
||||
helper.setWho(self.name, whoinfo[1])
|
||||
|
||||
def signedOn(self):
|
||||
self.connected = True
|
||||
|
@ -235,11 +245,8 @@ class Base(Protocol):
|
|||
if "\n" in data:
|
||||
splitData = [x for x in data.split("\n") if x]
|
||||
if "\n" in data:
|
||||
#timePlus = 0.0
|
||||
for i in splitData:
|
||||
helper.parseCommand(self.addr, self.authed, i)
|
||||
#reactor.callLater(timePlus, lambda: helper.parseCommand(self.addr, self.authed, i))
|
||||
#timePlus += 0.01
|
||||
return
|
||||
helper.parseCommand(self.addr, self.authed, data)
|
||||
|
||||
|
@ -248,7 +255,7 @@ class Base(Protocol):
|
|||
self.send("Hello.")
|
||||
|
||||
def connectionLost(self, reason):
|
||||
global connections
|
||||
global connections, MonitorPool
|
||||
self.authed = False
|
||||
log("Connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
|
||||
if not listener == None:
|
||||
|
@ -258,6 +265,8 @@ class Base(Protocol):
|
|||
warn("Tried to remove a non-existant connection.")
|
||||
else:
|
||||
warn("Tried to remove a connection from a listener that wasn't running.")
|
||||
if self.addr in MonitorPool:
|
||||
MonitorPool.remove(self.addr)
|
||||
|
||||
class BaseFactory(Factory):
|
||||
def buildProtocol(self, addr):
|
||||
|
@ -289,6 +298,23 @@ class Helper(object):
|
|||
else:
|
||||
error("Mandatory values missing from config")
|
||||
|
||||
def setWho(self, network, newObjects):
|
||||
global wholist
|
||||
network = "".join([x for x in network if not x in numbers])
|
||||
if not network in wholist.keys():
|
||||
wholist[network] = {}
|
||||
for i in newObjects.keys():
|
||||
wholist[network][i] = newObjects[i]
|
||||
return
|
||||
|
||||
def setWhoSingle(self, network, nick, ident, host):
|
||||
global wholist
|
||||
network = "".join([x for x in network if not x in numbers])
|
||||
|
||||
if network in wholist.keys():
|
||||
if nick in wholist[network].keys():
|
||||
wholist[network][nick][1] = ident
|
||||
wholist[network][nick][2] = host
|
||||
|
||||
def saveConfig(self):
|
||||
global config
|
||||
|
@ -344,6 +370,8 @@ class Helper(object):
|
|||
def sendMaster(self, data):
|
||||
if config["Master"][0] in IRCPool.keys():
|
||||
IRCPool[config["Master"][0]].msg(config["Master"][1], data)
|
||||
for i in MonitorPool:
|
||||
connections[i].send(data)
|
||||
|
||||
def isKeyword(self, msg):
|
||||
message = msg.lower()
|
||||
|
@ -428,7 +456,7 @@ class Helper(object):
|
|||
return True
|
||||
|
||||
def parseCommand(self, addr, authed, data):
|
||||
global pool
|
||||
global pool, MonitorPool
|
||||
spl = data.split()
|
||||
if addr in connections.keys():
|
||||
obj = connections[addr]
|
||||
|
@ -672,8 +700,29 @@ class Helper(object):
|
|||
helper.saveKeywordConfig()
|
||||
success("Successfully removed exception list of %s" % spl[2])
|
||||
return
|
||||
elif spl[1] == "monitor":
|
||||
if spl[2] == "on":
|
||||
if not obj.addr in MonitorPool:
|
||||
MonitorPool.append(obj.addr)
|
||||
success("Keyword monitoring enabled")
|
||||
return
|
||||
else:
|
||||
failure("Keyword monitoring is already enabled")
|
||||
return
|
||||
elif spl[2] == "off":
|
||||
if obj.addr in MonitorPool:
|
||||
MonitorPool.remove(obj.addr)
|
||||
success("Keyword monitoring disabled")
|
||||
return
|
||||
else:
|
||||
failure("Keyword monitoring is already disabled")
|
||||
return
|
||||
else:
|
||||
incUsage("key")
|
||||
return
|
||||
else:
|
||||
incUsage("key")
|
||||
return
|
||||
elif length == 2:
|
||||
if spl[1] == "show":
|
||||
info(",".join(keyconf["Keywords"]))
|
||||
|
@ -690,6 +739,13 @@ class Helper(object):
|
|||
elif spl[1] == "master":
|
||||
info(" - ".join(config["Master"]))
|
||||
return
|
||||
elif spl[1] == "monitor":
|
||||
if obj.addr in MonitorPool:
|
||||
info("Keyword monitoring is enabled on this connection")
|
||||
return
|
||||
else:
|
||||
info("Keyword monitoring is disabled on this connection")
|
||||
return
|
||||
else:
|
||||
incUsage("key")
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue