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