Import the main module properly and fix some oddities in Twisted to prevent it from discarding some data

This commit is contained in:
Mark Veidemanis 2018-03-14 20:13:40 +00:00
parent 5b1e3c6fb1
commit d168d69732
33 changed files with 370 additions and 318 deletions

View File

@ -1,4 +1,4 @@
from core.main import *
import main
import core.helper as helper
class Add:
@ -27,32 +27,32 @@ class Add:
toFail = False
if length < 6:
if config["Default"]["nickname"] == None:
if main.config["Default"]["nickname"] == None:
failure("Choose a nickname, or configure one in defaults")
toFail = True
else:
nickname = config["Default"]["nickname"]
nickname = main.config["Default"]["nickname"]
if length < 5:
if config["Default"]["protocol"] == None:
if main.config["Default"]["protocol"] == None:
failure("Choose a protocol, or configure one in defaults")
toFail = True
else:
protocol = config["Default"]["protocol"]
protocol = main.config["Default"]["protocol"]
if length < 4:
if config["Default"]["port"] == None:
if main.config["Default"]["port"] == None:
failure("Choose a port, or configure one in defaults")
toFail = True
else:
port = config["Default"]["port"]
port = main.config["Default"]["port"]
if length < 3:
if config["Default"]["host"] == None:
if main.config["Default"]["host"] == None:
failure("Choose a host, or configure one in defaults")
toFail = True
else:
host = config["Default"]["host"]
host = main.config["Default"]["host"]
if toFail:
failure("Stopping due to previous error(s)")
return
@ -61,7 +61,7 @@ class Add:
incUsage("add")
return
if name in pool.keys():
if name in main.pool.keys():
failure("Name already exists: %s" % name)
return
@ -77,34 +77,34 @@ class Add:
failure("Port must be an integer, not %s" % port)
return
pool[name] = { "host": host,
main.pool[name] = { "host": host,
"port": port,
"protocol": protocol,
"bind": config["Default"]["bind"],
"timeout": config["Default"]["timeout"],
"maxdelay": config["Default"]["maxdelay"],
"initialdelay": config["Default"]["initialdelay"],
"factor": config["Default"]["factor"],
"jitter": config["Default"]["jitter"],
"bind": main.config["Default"]["bind"],
"timeout": main.config["Default"]["timeout"],
"maxdelay": main.config["Default"]["maxdelay"],
"initialdelay": main.config["Default"]["initialdelay"],
"factor": main.config["Default"]["factor"],
"jitter": main.config["Default"]["jitter"],
"nickname": nickname,
"username": config["Default"]["username"],
"realname": config["Default"]["realname"],
"userinfo": config["Default"]["userinfo"],
"finger": config["Default"]["finger"],
"version": config["Default"]["version"],
"source": config["Default"]["source"],
"autojoin": config["Default"]["autojoin"],
"authtype": config["Default"]["authtype"],
"password": config["Default"]["password"],
"authentity": config["Default"]["authentity"],
"key": config["Default"]["key"],
"certificate": config["Default"]["certificate"],
"enabled": config["ConnectOnCreate"],
"username": main.config["Default"]["username"],
"realname": main.config["Default"]["realname"],
"userinfo": main.config["Default"]["userinfo"],
"finger": main.config["Default"]["finger"],
"version": main.config["Default"]["version"],
"source": main.config["Default"]["source"],
"autojoin": main.config["Default"]["autojoin"],
"authtype": main.config["Default"]["authtype"],
"password": main.config["Default"]["password"],
"authentity": main.config["Default"]["authentity"],
"key": main.config["Default"]["key"],
"certificate": main.config["Default"]["certificate"],
"enabled": main.config["ConnectOnCreate"],
}
if config["ConnectOnCreate"] == True:
helper.addBot(name)
success("Successfully created bot")
saveConf("pool")
main.saveConf("pool")
return
else:
incUsage(None)

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Default:
def __init__(self, register):
@ -9,18 +9,18 @@ class Default:
toUnset = False
if length == 1:
optionMap = ["Viewing defaults"]
for i in config["Default"].keys():
optionMap.append("%s: %s" % (i, config["Default"][i]))
for i in main.config["Default"].keys():
optionMap.append("%s: %s" % (i, main.config["Default"][i]))
info("\n".join(optionMap))
return
elif length == 2:
if not spl[1] in config["Default"].keys():
if not spl[1] in main.config["Default"].keys():
failure("No such key: %s" % spl[1])
return
info("%s: %s" % (spl[1], config["Default"][spl[1]]))
info("%s: %s" % (spl[1], main.config["Default"][spl[1]]))
return
elif length == 3:
if not spl[1] in config["Default"].keys():
if not spl[1] in main.config["Default"].keys():
failure("No such key: %s" % spl[1])
return
@ -48,7 +48,7 @@ class Default:
failure("Protocol must be ssl or plain, not %s" % spl[2])
return
if spl[2] == config["Default"][spl[1]]:
if spl[2] == main.config["Default"][spl[1]]:
failure("Value already exists: %s" % spl[2])
return
@ -58,7 +58,7 @@ class Default:
failure("Authtype must be sp or ns, not %s" % spl[2])
return
if spl[1] == "enabled":
failure("Use the ConnectOnCreate config parameter to set this")
failure("Use the ConnectOnCreate main.config parameter to set this")
return
if spl[1] == "autojoin":
if not toUnset:
@ -66,8 +66,8 @@ class Default:
else:
spl[2] = []
config["Default"][spl[1]] = spl[2]
saveConf("config")
main.config["Default"][spl[1]] = spl[2]
main.saveConf("main.config")
if toUnset:
success("Successfully unset key %s" % spl[1])
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Delete:
def __init__(self, register):
@ -7,20 +7,20 @@ class Delete:
def delete(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
del pool[spl[1]]
if spl[1] in ReactorPool.keys():
if spl[1] in FactoryPool.keys():
FactoryPool[spl[1]].stopTrying()
ReactorPool[spl[1]].disconnect()
if spl[1] in IRCPool.keys():
del IRCPool[spl[1]]
del ReactorPool[spl[1]]
del FactoryPool[spl[1]]
if spl[1] in main.ReactorPool.keys():
if spl[1] in main.FactoryPool.keys():
main.FactoryPool[spl[1]].stopTrying()
main.ReactorPool[spl[1]].disconnect()
if spl[1] in main.IRCPool.keys():
del main.IRCPool[spl[1]]
del main.ReactorPool[spl[1]]
del main.FactoryPool[spl[1]]
success("Successfully removed bot")
saveConf("pool")
main.saveConf("pool")
return
else:
incUsage("del")

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Disable:
def __init__(self, register):
@ -7,19 +7,19 @@ class Disable:
def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
pool[spl[1]]["enabled"] = False
saveConf("pool")
if spl[1] in ReactorPool.keys():
if spl[1] in FactoryPool.keys():
FactoryPool[spl[1]].stopTrying()
ReactorPool[spl[1]].disconnect()
if spl[1] in IRCPool.keys():
del IRCPool[spl[1]]
del ReactorPool[spl[1]]
del FactoryPool[spl[1]]
main.pool[spl[1]]["enabled"] = False
main.saveConf("pool")
if spl[1] in main.ReactorPool.keys():
if spl[1] in main.FactoryPool.keys():
main.FactoryPool[spl[1]].stopTrying()
main.ReactorPool[spl[1]].disconnect()
if spl[1] in main.IRCPool.keys():
del main.IRCPool[spl[1]]
del main.ReactorPool[spl[1]]
del main.FactoryPool[spl[1]]
success("Successfully disabled bot %s" % spl[1])
return
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
from subprocess import run, PIPE
class Dist:
@ -7,9 +7,9 @@ class Dist:
def dist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if config["Dist"]["Enabled"]:
rtrn = run([config["Dist"]["File"]], shell=True, stdout=PIPE)
if config["Dist"]["SendOutput"]:
if main.config["Dist"]["Enabled"]:
rtrn = run([main.config["Dist"]["File"]], shell=True, stdout=PIPE)
if main.config["Dist"]["SendOutput"]:
info("Exit code: %s -- Stdout: %s" % (rtrn.returncode, rtrn.stdout))
else:
info("Exit code: %s" % rtrn.returncode)

View File

@ -1,4 +1,4 @@
from core.main import *
import main
import core.helper as helper
class Enable:
@ -11,9 +11,9 @@ class Enable:
if not spl[1] in pool.keys():
failure("Name does not exist: %s" % spl[1])
return
pool[spl[1]]["enabled"] = True
saveConf("pool")
if not spl[1] in IRCPool.keys():
main.pool[spl[1]]["enabled"] = True
main.saveConf("pool")
if not spl[1] in main.IRCPool.keys():
helper.addBot(spl[1])
else:
pass

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Get:
def __init__(self, register):
@ -7,13 +7,13 @@ class Get:
def get(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
if not spl[1] in IRCPool.keys():
if not spl[1] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
info(str(IRCPool[spl[1]].get(spl[2])))
info(str(main.IRCPool[spl[1]].get(spl[2])))
return
else:
incUsage("get")

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Help:
def __init__(self, register):
@ -7,8 +7,8 @@ class Help:
def help(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
helpMap = []
for i in help.keys():
helpMap.append("%s: %s" % (i, help[i]))
for i in main.help.keys():
helpMap.append("%s: %s" % (i, main.help[i]))
info("\n".join(helpMap))
return
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Join:
def __init__(self, register):
@ -7,23 +7,23 @@ class Join:
def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
if not spl[1] in IRCPool.keys():
if not spl[1] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
IRCPool[spl[1]].join(spl[2])
main.IRCPool[spl[1]].join(spl[2])
success("Joined %s" % spl[2])
return
elif length == 4:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
if not spl[1] in IRCPool.keys():
if not spl[1] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
IRCPool[spl[1]].join(spl[2], spl[3])
main.IRCPool[spl[1]].join(spl[2], spl[3])
success("Joined %s with key %s" % (spl[2], spl[3]))
return
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
import modules.keyword as keyword
class Key:
@ -39,45 +39,45 @@ class Key:
return
if length == 4:
if spl[1] == "except":
if not spl[2] in keyconf["Keywords"]:
if not spl[2] in main.keyconf["Keywords"]:
failure("No such keyword: %s" % spl[2])
return
if spl[2] in keyconf["KeywordsExcept"].keys():
if spl[3] in keyconf["KeywordsExcept"][spl[2]]:
if spl[2] in main.keyconf["KeywordsExcept"].keys():
if spl[3] in main.keyconf["KeywordsExcept"][spl[2]]:
failure("Exception exists: %s" % spl[3])
return
else:
if not spl[2] in spl[3]:
failure("Keyword %s not in exception %s. This won't work" % (spl[2], spl[3]))
return
keyconf["KeywordsExcept"][spl[2]] = []
main.keyconf["KeywordsExcept"][spl[2]] = []
keyconf["KeywordsExcept"][spl[2]].append(spl[3])
saveConf("keyconf")
main.keyconf["KeywordsExcept"][spl[2]].append(spl[3])
main.saveConf("keyconf")
success("Successfully added exception %s for keyword %s" % (spl[3], spl[2]))
return
elif spl[1] == "master":
if not spl[2] in pool.keys():
if not spl[2] in main.pool.keys():
failure("Name does not exist: %s" % spl[2])
return
if spl[2] in IRCPool.keys():
if not spl[3] in IRCPool[spl[2]].channels:
if spl[2] in main.IRCPool.keys():
if not spl[3] in main.IRCPool[spl[2]].channels:
info("Bot not on channel: %s" % spl[3])
config["Master"] = [spl[2], spl[3]]
saveConf("config")
main.config["Master"] = [spl[2], spl[3]]
main.saveConf("config")
success("Master set to %s on %s" % (spl[3], spl[2]))
return
elif spl[1] == "unexcept":
if not spl[2] in keyconf["KeywordsExcept"].keys():
if not spl[2] in main.keyconf["KeywordsExcept"].keys():
failure("No such exception: %s" % spl[2])
return
if not spl[3] in keyconf["KeywordsExcept"][spl[2]]:
if not spl[3] in main.keyconf["KeywordsExcept"][spl[2]]:
failure("Exception %s has no attribute %s" % (spl[2], spl[3]))
return
keyconf["KeywordsExcept"][spl[2]].remove(spl[3])
if keyconf["KeywordsExcept"][spl[2]] == []:
del keyconf["KeywordsExcept"][spl[2]]
saveConf("keyconf")
main.keyconf["KeywordsExcept"][spl[2]].remove(spl[3])
if main.keyconf["KeywordsExcept"][spl[2]] == []:
del main.keyconf["KeywordsExcept"][spl[2]]
main.saveConf("keyconf")
success("Successfully removed exception %s for keyword %s" % (spl[3], spl[2]))
return
else:
@ -85,32 +85,32 @@ class Key:
return
elif length == 3:
if spl[1] == "unexcept":
if not spl[2] in keyconf["KeywordsExcept"].keys():
if not spl[2] in main.keyconf["KeywordsExcept"].keys():
failure("No such exception: %s" % spl[2])
return
del keyconf["KeywordsExcept"][spl[2]]
saveConf("keyconf")
del main.keyconf["KeywordsExcept"][spl[2]]
main.saveConf("keyconf")
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)
if not obj.addr in main.MonitorPool:
main.MonitorPool.append(obj.addr)
success("Keyword monitoring enabled")
if len(masterbuf) == 0:
if len(main.masterbuf) == 0:
return
rtrn = []
for i in range(len(masterbuf)):
rtrn.append(masterbuf.pop(0))
saveConf("masterbuf")
for i in range(len(main.masterbuf)):
rtrn.append(main.masterbuf.pop(0))
main.saveConf("masterbuf")
info("\n".join(rtrn))
return
else:
failure("Keyword monitoring is already enabled")
return
elif spl[2] == "off":
if obj.addr in MonitorPool:
MonitorPool.remove(obj.addr)
if obj.addr in main.MonitorPool:
main.MonitorPool.remove(obj.addr)
success("Keyword monitoring disabled")
return
else:
@ -124,22 +124,22 @@ class Key:
return
elif length == 2:
if spl[1] == "show":
info(",".join(keyconf["Keywords"]))
info(",".join(main.keyconf["Keywords"]))
return
elif spl[1] == "showexcept":
exceptMap = []
for i in keyconf["KeywordsExcept"].keys():
for i in main.keyconf["KeywordsExcept"].keys():
exceptMap.append("Key: %s" % i)
exceptMap.append("%s: %s" % (i, ",".join(keyconf["KeywordsExcept"][i])))
exceptMap.append("%s: %s" % (i, ",".join(main.keyconf["KeywordsExcept"][i])))
exceptMap.append("\n")
info("\n".join(exceptMap))
return
elif spl[1] == "master":
info(" - ".join([str(i) for i in config["Master"]]))
info(" - ".join([str(i) for i in main.config["Master"]]))
return
elif spl[1] == "monitor":
if obj.addr in MonitorPool:
if obj.addr in main.MonitorPool:
info("Keyword monitoring is enabled on this connection")
return
else:
@ -148,7 +148,6 @@ class Key:
else:
incUsage("key")
return
else:
incUsage("key")
return

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class List:
def __init__(self, register):
@ -7,10 +7,10 @@ class List:
def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
poolMap = []
for i in pool.keys():
for i in main.pool.keys():
poolMap.append("Server: %s" % i)
for x in pool[i].keys():
poolMap.append(" %s: %s" % (x, pool[i][x]))
for x in main.pool[i].keys():
poolMap.append(" %s: %s" % (x, main.pool[i][x]))
poolMap.append("\n")
info("\n".join(poolMap))
return

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Load:
def __init__(self, register):
@ -7,14 +7,14 @@ class Load:
def load(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if spl[1] in filemap.keys():
loadConf(spl[1])
success("Loaded %s from %s" % (spl[1], filemap[spl[1]][0]))
if spl[1] in main.filemap.keys():
main.loadConf(spl[1])
success("Loaded %s from %s" % (spl[1], main.filemap[spl[1]][0]))
return
elif spl[1] == "all":
for i in filemap.keys():
loadConf(i)
success("Loaded %s from %s" % (i, filemap[i][0]))
for i in main.filemap.keys():
main.loadConf(i)
success("Loaded %s from %s" % (i, main.filemap[i][0]))
return
else:
incUsage("load")

View File

@ -1,4 +1,4 @@
from core.main import *
import main
from utils.loaders.single_loader import loadSingle
class Loadmod:
@ -8,7 +8,7 @@ class Loadmod:
def loadmod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
rtrn = loadSingle(spl[1], register)
rtrn = loadSingle(spl[1], main.register)
if rtrn == True:
success("Loaded module %s" % spl[1])
return

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Logout:
def __init__(self, register):
@ -7,8 +7,8 @@ class Logout:
def logout(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
obj.authed = False
if obj.addr in MonitorPool:
MonitorPool.remove(obj.addr)
if obj.addr in main.MonitorPool:
main.MonitorPool.remove(obj.addr)
success("Logged out")
return
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Mod:
def __init__(self, register):
@ -8,30 +8,30 @@ class Mod:
if authed:
toUnset = False
if length == 2:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
optionMap = ["Viewing options for %s" % spl[1]]
for i in pool[spl[1]].keys():
optionMap.append(" %s: %s" % (i, pool[spl[1]][i]))
for i in main.pool[spl[1]].keys():
optionMap.append(" %s: %s" % (i, main.pool[spl[1]][i]))
info("\n".join(optionMap))
return
elif length == 3:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
if not spl[2] in pool[spl[1]].keys():
if not spl[2] in main.pool[spl[1]].keys():
failure("No such key: %s" % spl[2])
return
info("%s: %s" % (spl[2], pool[spl[1]][spl[2]]))
info("%s: %s" % (spl[2], main.pool[spl[1]][spl[2]]))
return
elif length == 4:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
if not spl[2] in pool[spl[1]].keys():
if not spl[2] in main.pool[spl[1]].keys():
failure("No such key: %s" % spl[2])
return
@ -39,7 +39,7 @@ class Mod:
if not spl[3] in ["ssl", "plain"]:
failure("Protocol must be ssl or plain, not %s" % spl[3])
return
if spl[3] == pool[spl[1]][spl[2]]:
if spl[3] == main.pool[spl[1]][spl[2]]:
failure("Value already exists: %s" % spl[3])
return
@ -72,10 +72,10 @@ class Mod:
if spl[2] == "autojoin":
spl[3] = spl[3].split(",")
pool[spl[1]][spl[2]] = spl[3]
if spl[1] in IRCPool.keys():
IRCPool[spl[1]].refresh()
saveConf("pool")
main.pool[spl[1]][spl[2]] = spl[3]
if spl[1] in main.IRCPool.keys():
main.IRCPool[spl[1]].refresh()
main.saveConf("pool")
if toUnset:
success("Successfully unset key %s on %s" % (spl[2], spl[1]))
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Part:
def __init__(self, register):
@ -7,13 +7,13 @@ class Part:
def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in pool.keys():
if not spl[1] in main.pool.keys():
failure("Name does not exist: %s" % spl[1])
return
if not spl[1] in IRCPool.keys():
if not spl[1] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
IRCPool[spl[1]].part(spl[2])
main.IRCPool[spl[1]].part(spl[2])
success("Left %s" % spl[2])
return
else:

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Password:
def __init__(self, register):
@ -10,7 +10,7 @@ class Password:
return
else:
if length == 2:
if spl[1] == config["Password"]:
if spl[1] == main.config["Password"]:
success("Authenticated successfully")
obj.authed = True
return

View File

@ -1,4 +1,4 @@
from core.main import *
import main
class Save:
def __init__(self, register):
@ -7,14 +7,14 @@ class Save:
def save(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if spl[1] in filemap.keys():
saveConf(spl[1])
success("Saved %s to %s" % (spl[1], filemap[spl[1]][0]))
if spl[1] in main.filemap.keys():
main.saveConf(spl[1])
success("Saved %s to %s" % (spl[1], main.filemap[spl[1]][0]))
return
elif spl[1] == "all":
for i in filemap.keys():
saveConf(i)
success("Saved %s to %s" % (i, filemap[i][0]))
for i in main.filemap.keys():
main.saveConf(i)
success("Saved %s to %s" % (i, main.filemap[i][0]))
return
else:
incUsage("save")

View File

@ -1,4 +1,4 @@
from core.main import *
import main
import modules.counters as count
class Stats:
@ -11,11 +11,11 @@ class Stats:
stats = []
numChannels = 0
numWhoEntries = 0
for i in IRCPool.keys():
numChannels += len(IRCPool[i].channels)
for i in wholist.keys():
numWhoEntries += len(wholist[i].keys())
stats.append("Servers: %s" % len(IRCPool.keys()))
for i in main.IRCPool.keys():
numChannels += len(main.IRCPool[i].channels)
for i in main.wholist.keys():
numWhoEntries += len(main.wholist[i].keys())
stats.append("Servers: %s" % len(main.IRCPool.keys()))
stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries)
counterEvents = count.getEvents()
@ -34,13 +34,13 @@ class Stats:
numWhoEntries = 0
failures = 0
if spl[1] in IRCPool.keys():
numChannels += len(IRCPool[spl[1]].channels)
if spl[1] in main.IRCPool.keys():
numChannels += len(main.IRCPool[spl[1]].channels)
else:
failure("Name does not exist: %s" % spl[1])
failures += 1
if spl[1] in wholist.keys():
numWhoEntries += len(wholist[spl[1]].keys())
if spl[1] in main.wholist.keys():
numWhoEntries += len(main.wholist[spl[1]].keys())
else:
failure("Who entry does not exist: %s" % spl[1])
failures += 1

View File

@ -1,4 +1,4 @@
from core.main import *
import main
import modules.userinfo as userinfo
class Who:

View File

@ -1,6 +1,7 @@
{
"Keywords": [
"example"
"example",
"s"
],
"KeywordsExcept": {}
}

View File

@ -6,7 +6,7 @@ import modules.keyword as keyword
import modules.userinfo as userinfo
import modules.counters as count
from core.main import *
import main
from utils.logging.log import *
from utils.logging.send import *
@ -14,9 +14,9 @@ class IRCBot(IRCClient):
def __init__(self, name):
self.connected = False
self.channels = []
self.buffer = ""
self.name = name
instance = pool[name]
instance = main.pool[name]
self.nickname = instance["nickname"]
self.realname = instance["realname"]
@ -40,7 +40,7 @@ class IRCBot(IRCClient):
self.password = instance["password"]
def refresh(self):
instance = pool[self.name]
instance = main.pool[self.name]
if not instance["nickname"] == self.nickname:
self.nickname = instance["nickname"]
self.setNick(self.nickname)
@ -69,21 +69,21 @@ class IRCBot(IRCClient):
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "privmsg")
keyword.actKeyword(user, channel, msg, self.nickname, "PRV", self.name)
keyword.actKeyword(user, channel, msg, self.nickname, "MSG", self.name)
def noticed(self, user, channel, msg):
nick, ident, host = self.parsen(user)
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "notice")
keyword.actKeyword(user, channel, msg, self.nickname, "NOT", self.name)
keyword.actKeyword(user, channel, msg, self.nickname, "NOTICE", self.name)
def action(self, user, channel, msg):
nick, ident, host = self.parsen(user)
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "action")
keyword.actKeyword(user, channel, msg, self.nickname, "ACT", self.name)
keyword.actKeyword(user, channel, msg, self.nickname, "ACTION", self.name)
def get(self, var):
try:
@ -148,10 +148,79 @@ class IRCBot(IRCClient):
def got_who(self, whoinfo):
userinfo.setWho(self.name, whoinfo[1])
#twisted sucks so i have to do this to actually get the user info
def irc_JOIN(self, prefix, params):
"""
Called when a user joins a channel.
"""
nick = prefix.split('!')[0]
channel = params[-1]
if nick == self.nickname:
self.joined(channel)
else:
self.userJoined(prefix, channel)
def irc_PART(self, prefix, params):
"""
Called when a user leaves a channel.
"""
nick = prefix.split('!')[0]
channel = params[0]
if len(params) >= 2:
message = params[1]
else:
message = None
if nick == self.nickname:
self.left(channel, message)
else:
self.userLeft(prefix, channel, message)
def irc_QUIT(self, prefix, params):
"""
Called when a user has quit.
"""
#nick = prefix.split('!')[0]
self.userQuit(prefix, params[0])
def irc_NICK(self, prefix, params):
"""
Called when a user changes their nickname.
"""
nick = prefix.split('!', 1)[0]
if nick == self.nickname:
self.nickChanged(params[0])
else:
self.userRenamed(prefix, params[0])
def irc_KICK(self, prefix, params):
"""
Called when a user is kicked from a channel.
"""
#kicker = prefix.split('!')[0]
channel = params[0]
kicked = params[1]
message = params[-1]
if kicked.lower() == self.nickname.lower():
# Yikes!
self.kickedFrom(channel, prefix, message)
else:
self.userKicked(kicked, channel, prefix, message)
def irc_TOPIC(self, prefix, params):
"""
Someone in the channel set the topic.
"""
#user = prefix.split('!')[0]
channel = params[0]
newtopic = params[1]
self.topicUpdated(prefix, channel, newtopic)
#END hacks
def signedOn(self):
self.connected = True
log("signed on: %s" % self.name)
if config["ConnectionNotifications"]:
if main.config["ConnectionNotifications"]:
keyword.sendMaster("SIGNON: %s" % self.name)
if self.authtype == "ns":
self.msg(self.authentity, "IDENTIFY %s" % self.nspass)
@ -164,14 +233,15 @@ class IRCBot(IRCClient):
self.channels.append(channel)
self.who(channel).addCallback(self.got_who)
count.event(self.name, "selfjoin")
if self.name == config["Master"][0] and channel == config["Master"][1]:
for i in range(len(masterbuf)):
self.msg(channel, masterbuf.pop(0))
saveConf("masterbuf")
if self.name == main.config["Master"][0] and channel == main.config["Master"][1]:
for i in range(len(main.masterbuf)):
self.msg(channel, main.masterbuf.pop(0))
main.saveConf("masterbuf")
def left(self, channel):
def left(self, channel, message):
if channel in self.channels:
self.channels.remove(channel)
keyword.actKeyword(user, channel, message, self.nickname, "SELFPART", self.name)
count.event(self.name, "selfpart")
def kickedFrom(self, channel, kicker, message):
@ -185,9 +255,10 @@ class IRCBot(IRCClient):
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "join")
def userLeft(self, user, channel):
def userLeft(self, user, channel, message):
nick, ident, host = self.parsen(user)
userinfo.setWhoSingle(self.name, nick, ident, host)
keyword.actKeyword(user, channel, message, self.nickname, "PART", self.name)
count.event(self.name, "part")
def userQuit(self, user, quitMessage):
@ -195,14 +266,14 @@ class IRCBot(IRCClient):
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "quit")
keyword.actKeyword(user, None, quitMessage, self.nickname, "QUT", self.name)
keyword.actKeyword(user, None, quitMessage, self.nickname, "QUIT", self.name)
def userKicked(self, kickee, channel, kicker, message):
nick, ident, host = self.parsen(kicker)
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "kick")
keyword.actKeyword(kicker, channel, message, self.nickname, "KCK", self.name)
keyword.actKeyword(kicker, channel, message, self.nickname, "KICK", self.name)
def userRenamed(self, oldname, newname):
nick, ident, host = self.parsen(oldname)
@ -215,7 +286,7 @@ class IRCBot(IRCClient):
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "topic")
keyword.actKeyword(user, channel, newTopic, self.nickname, "TOP", self.name)
keyword.actKeyword(user, channel, newTopic, self.nickname, "TOPIC", self.name)
def modeChanged(self, user, channel, toset, modes, args):
nick, ident, host = self.parsen(user)
@ -224,7 +295,7 @@ class IRCBot(IRCClient):
class IRCBotFactory(ReconnectingClientFactory):
def __init__(self, name):
self.instance = pool[name]
self.instance = main.pool[name]
self.name = name
self.client = None
self.maxDelay = self.instance["maxdelay"]
@ -234,7 +305,7 @@ class IRCBotFactory(ReconnectingClientFactory):
def buildProtocol(self, addr):
entry = IRCBot(self.name)
IRCPool[self.name] = entry
main.IRCPool[self.name] = entry
self.client = entry
return entry
@ -245,7 +316,7 @@ class IRCBotFactory(ReconnectingClientFactory):
error = reason.getErrorMessage()
log("%s: connection lost: %s" % (self.name, error))
sendAll("%s: connection lost: %s" % (self.name, error))
if config["ConnectionNotifications"]:
if main.config["ConnectionNotifications"]:
keyword.sendMaster("CONNLOST %s: %s" % (self.name, error))
self.retry(connector)
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)

View File

@ -2,43 +2,43 @@ from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory
from core.bot import IRCBot, IRCBotFactory
from core.main import *
import main
from utils.logging.log import *
def addBot(name):
instance = pool[name]
instance = main.pool[name]
log("Started bot %s to %s:%s protocol %s nickname %s" % (name, instance["host"], instance["port"], instance["protocol"], instance["nickname"]))
if instance["protocol"] == "plain":
if instance["bind"] == None:
bot = IRCBotFactory(name)
rct = reactor.connectTCP(instance["host"], instance["port"], bot, timeout=int(instance["timeout"]))
ReactorPool[name] = rct
FactoryPool[name] = bot
main.ReactorPool[name] = rct
main.FactoryPool[name] = bot
return
else:
bot = IRCBotFactory(name)
rct = reactor.connectTCP(instance["host"], instance["port"], bot, timeout=int(instance["timeout"]), bindAddress=instance["bind"])
ReactorPool[name] = rct
FactoryPool[name] = bot
main.ReactorPool[name] = rct
main.FactoryPool[name] = bot
return
elif instance["protocol"] == "ssl":
keyFN = certPath+instance["key"]
certFN = certPath+instance["certificate"]
keyFN = main.certPath+instance["key"]
certFN = main.certPath+instance["certificate"]
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
if instance["bind"] == None:
bot = IRCBotFactory(name)
rct = reactor.connectSSL(instance["host"], int(instance["port"]), bot, contextFactory)
ReactorPool[name] = rct
FactoryPool[name] = bot
main.ReactorPool[name] = rct
main.FactoryPool[name] = bot
return
else:
bot = IRCBotFactory(name)
rct = reactor.connectSSL(instance["host"], int(instance["port"]), bot, contextFactory, bindAddress=instance["bind"])
ReactorPool[name] = rct
FactoryPool[name] = bot
main.ReactorPool[name] = rct
main.FactoryPool[name] = bot
return

View File

@ -1,12 +1,12 @@
from core.main import *
import main
from utils.logging.log import *
from utils.logging.send import *
def parseCommand(addr, authed, data):
#call command modules with: (addr, authed, data, spl, success, failure, info, incUsage, length)
spl = data.split()
if addr in connections.keys():
obj = connections[addr]
if addr in main.connections.keys():
obj = main.connections[addr]
else:
warn("Got connection object with no instance in the address pool")
return
@ -22,9 +22,9 @@ def parseCommand(addr, authed, data):
else:
failure("No text was sent")
return
for i in CommandMap.keys():
for i in main.CommandMap.keys():
if spl[0] == i:
CommandMap[i](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
main.CommandMap[i](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
return
incUsage(None)
return

View File

@ -1,5 +1,5 @@
from twisted.internet.protocol import Protocol, Factory, ClientFactory
from core.main import *
import main
from utils.logging.log import *
from core.parser import parseCommand
@ -8,7 +8,7 @@ class Server(Protocol):
def __init__(self, addr):
self.addr = addr
self.authed = False
if config["UsePassword"] == False:
if main.config["UsePassword"] == False:
self.authed = True
def send(self, data):
@ -34,22 +34,22 @@ class Server(Protocol):
def connectionLost(self, reason):
self.authed = False
log("Connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
if self.addr in connections.keys():
del connections[self.addr]
if self.addr in main.connections.keys():
del main.connections[self.addr]
else:
warn("Tried to remove a non-existant connection.")
if self.addr in MonitorPool:
MonitorPool.remove(self.addr)
if self.addr in main.MonitorPool:
main.MonitorPool.remove(self.addr)
class ServerFactory(Factory):
def buildProtocol(self, addr):
entry = Server(addr)
connections[addr] = entry
main.connections[addr] = entry
return entry
def send(self, addr, data):
if addr in connections.keys():
connection = connections[addr]
if addr in main.connections.keys():
connection = main.connections[addr]
connection.send(data)
else:
return

View File

@ -1,29 +1,29 @@
from core.main import *
import main
def event(name, eventType):
if not "local" in counters.keys():
counters["local"] = {}
if not "global" in counters.keys():
counters["global"] = {}
if not name in counters["local"].keys():
counters["local"][name] = {}
if eventType not in counters["local"][name].keys():
counters["local"][name][eventType] = 0
if not "local" in main.counters.keys():
main.counters["local"] = {}
if not "global" in main.counters.keys():
main.counters["global"] = {}
if not name in main.counters["local"].keys():
main.counters["local"][name] = {}
if eventType not in main.counters["local"][name].keys():
main.counters["local"][name][eventType] = 0
if eventType not in counters["global"]:
counters["global"][eventType] = 0
if eventType not in main.counters["global"]:
main.counters["global"][eventType] = 0
counters["local"][name][eventType] += 1
counters["global"][eventType] += 1
main.counters["local"][name][eventType] += 1
main.counters["global"][eventType] += 1
def getEvents(name=None):
if name == None:
if "global" in counters.keys():
return counters["global"]
if "global" in main.counters.keys():
return main.counters["global"]
else:
return None
else:
if name in counters["local"].keys():
return counters["local"][name]
if name in main.counters["local"].keys():
return main.counters["local"][name]
else:
return None

View File

@ -1,38 +1,38 @@
from core.main import *
import main
from utils.logging.log import *
import modules.counters as count
def sendMaster(data):
if not len(MonitorPool) == 0:
if not len(main.MonitorPool) == 0:
hasMonitors = True
else:
hasMonitors = False
if config["Master"] == [None, None]:
if main.config["Master"] == [None, None]:
if hasMonitors:
for i in MonitorPool:
connections[i].send(data)
for i in main.MonitorPool:
main.connections[i].send(data)
return
else:
masterbuf.append(data)
saveConf("masterbuf")
main.masterbuf.append(data)
main.saveConf("masterbuf")
return
if config["Master"][0] in IRCPool.keys():
if config["Master"][1] in IRCPool[config["Master"][0]].channels:
IRCPool[config["Master"][0]].msg(config["Master"][1], data)
if main.config["Master"][0] in main.IRCPool.keys():
if main.config["Master"][1] in main.IRCPool[main.config["Master"][0]].channels:
main.IRCPool[main.config["Master"][0]].msg(main.config["Master"][1], data)
else:
if not hasMonitors:
masterbuf.append(data)
saveConf("masterbuf")
main.masterbuf.append(data)
main.saveConf("masterbuf")
else:
if not hasMonitors:
masterbuf.append(data)
saveConf("masterbuf")
main.masterbuf.append(data)
main.saveConf("masterbuf")
warn("Master with no IRC instance defined")
for i in MonitorPool:
connections[i].send(data)
for i in main.MonitorPool:
main.connections[i].send(data)
def isKeyword(msg):
message = msg.lower()
@ -40,10 +40,10 @@ def isKeyword(msg):
toUndo = False
uniqueNum = 0
totalNum = 0
for i in keyconf["Keywords"]:
for i in main.keyconf["Keywords"]:
if i in message:
if i in keyconf["KeywordsExcept"].keys():
for x in keyconf["KeywordsExcept"][i]:
if i in main.keyconf["KeywordsExcept"].keys():
for x in main.keyconf["KeywordsExcept"][i]:
if x in message:
toUndo = True
messageDuplicate = messageDuplicate.replace(x, "\0\r\n\n\0")
@ -68,10 +68,10 @@ def isKeyword(msg):
def actKeyword(user, channel, message, nickname, actType, name):
toSend = isKeyword(message)
if name == config["Master"][0] and channel == config["Master"][1]:
if name == main.config["Master"][0] and channel == main.config["Master"][1]:
pass
else:
if config["HighlightNotifications"]:
if main.config["HighlightNotifications"]:
msgLower = message.lower()
nickLower = nickname.lower()
if nickLower in msgLower:
@ -83,19 +83,19 @@ def actKeyword(user, channel, message, nickname, actType, name):
count.event(name, "keymatch")
def addKeyword(keyword):
if keyword in keyconf["Keywords"]:
if keyword in main.keyconf["Keywords"]:
return "EXISTS"
else:
for i in keyconf["Keywords"]:
for i in main.keyconf["Keywords"]:
if i in keyword or keyword in i:
return "ISIN"
keyconf["Keywords"].append(keyword)
saveConf("keyconf")
main.keyconf["Keywords"].append(keyword)
main.saveConf("keyconf")
return True
def delKeyword(keyword):
if not keyword in keyconf["Keywords"]:
if not keyword in main.keyconf["Keywords"]:
return "NOKEY"
keyconf["Keywords"].remove(keyword)
saveConf("keyconf")
main.keyconf["Keywords"].remove(keyword)
main.saveConf("keyconf")
return True

View File

@ -1,32 +1,34 @@
from core.main import *
import main
from string import digits
#from utils.logging.log import *
def setWho(network, newObjects):
network = "".join([x for x in network if not x in digits])
if not network in wholist.keys():
wholist[network] = {}
if not network in main.wholist.keys():
main.wholist[network] = {}
for i in newObjects.keys():
wholist[network][i] = newObjects[i]
main.wholist[network][i] = newObjects[i]
return
def setWhoSingle(network, nick, ident, host):
network = "".join([x for x in network if not x in digits])
if network in wholist.keys():
if nick in wholist[network].keys():
wholist[network][nick][1] = ident
wholist[network][nick][2] = host
if network in main.wholist.keys():
if nick in main.wholist[network].keys():
main.wholist[network][nick][1] = ident
main.wholist[network][nick][2] = host
else:
wholist[network][nick] = [nick, ident, host, None, None, None]
main.wholist[network][nick] = [nick, ident, host, None, None, None]
else:
main.wholist[network] = {nick: [nick, ident, host, None, None, None]}
def getWho(nick):
result = {}
for i in wholist.keys():
for x in wholist[i].keys():
for i in main.wholist.keys():
for x in main.wholist[i].keys():
if nick.lower() == x.lower():
if not i in result.keys():
result[i] = []
result[i].append(wholist[i][x])
result[i].append(main.wholist[i][x])
return result

View File

@ -6,29 +6,9 @@ from twisted.internet.ssl import DefaultOpenSSLContextFactory
#from sys import stdout
#log.startLogging(stdout)
from core.main import (
configPath,
certPath,
connections,
IRCPool,
ReactorPool,
FactoryPool,
MonitorPool,
saveConf,
loadConf,
initMain,
)
import main
initMain()
from core.main import (
config,
keyconf,
pool,
help,
wholist,
counters,
)
main.initMain()
from utils.logging.log import *
import modules.userinfo as userinfo
@ -37,14 +17,14 @@ from core.server import Server, ServerFactory
if __name__ == "__main__":
listener = ServerFactory()
if config["Listener"]["UseSSL"] == True:
reactor.listenSSL(config["Listener"]["Port"], listener, DefaultOpenSSLContextFactory(certPath+config["Listener"]["Key"], certPath+config["Listener"]["Certificate"]), interface=config["Listener"]["Address"])
log("Threshold running with SSL on %s:%s" % (config["Listener"]["Address"], config["Listener"]["Port"]))
if main.config["Listener"]["UseSSL"] == True:
reactor.listenSSL(main.config["Listener"]["Port"], listener, DefaultOpenSSLContextFactory(main.certPath+main.config["Listener"]["Key"], main.certPath+main.config["Listener"]["Certificate"]), interface=main.config["Listener"]["Address"])
log("Threshold running with SSL on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
else:
reactor.listenTCP(config["Listener"]["Port"], listener, interface=config["Listener"]["Address"])
log("Threshold running on %s:%s" % (config["Listener"]["Address"], config["Listener"]["Port"]))
for i in pool.keys():
if pool[i]["enabled"] == True:
reactor.listenTCP(main.config["Listener"]["Port"], listener, interface=main.config["Listener"]["Address"])
log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
for i in main.pool.keys():
if main.pool[i]["enabled"] == True:
helper.addBot(i)
reactor.run()

View File

@ -1,5 +1,4 @@
from os import listdir
from core.main import *
from utils.logging.log import *
import commands

View File

@ -1,12 +1,12 @@
from os import listdir
from core.main import *
import main
from utils.logging.log import *
import commands
def loadSingle(command, func):
if command+".py" in listdir("commands"):
try:
if command in CommandMap.keys():
if command in main.CommandMap.keys():
return "Cannot reload modules"
else:
className = command.capitalize()

View File

@ -1,7 +1,7 @@
from core.main import connections, help
import main
def sendData(addr, data):
connections[addr].send(data)
main.connections[addr].send(data)
def sendSuccess(addr, data):
sendData(addr, "[y] " + data)
@ -13,14 +13,14 @@ def sendInfo(addr, data):
sendData(addr, "[i] " + data)
def sendAll(data):
for i in connections:
connections[i].send(data)
for i in main.connections:
main.connections[i].send(data)
return
def incorrectUsage(addr, mode):
if mode == None:
sendFailure(addr, "Incorrect usage")
return
if mode in help.keys():
sendFailure(addr, "Usage: " + help[mode])
if mode in main.help.keys():
sendFailure(addr, "Usage: " + main.help[mode])
return