Separate out everything into files and implement a modules system to segment commands
This commit is contained in:
44
core/helper.py
Normal file
44
core/helper.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||
|
||||
from core.bot import IRCBot, IRCBotFactory
|
||||
from core.main import *
|
||||
from utils.logging.log import *
|
||||
|
||||
def addBot(name):
|
||||
instance = 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
|
||||
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
|
||||
return
|
||||
elif instance["protocol"] == "ssl":
|
||||
keyFN = certPath+instance["key"]
|
||||
certFN = 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
|
||||
return
|
||||
else:
|
||||
|
||||
bot = IRCBotFactory(name)
|
||||
rct = reactor.connectSSL(instance["host"], int(instance["port"]), bot, contextFactory, bindAddress=instance["bind"])
|
||||
|
||||
ReactorPool[name] = rct
|
||||
FactoryPool[name] = bot
|
||||
return
|
||||
Reference in New Issue
Block a user