45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
from twisted.internet import reactor
|
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
|
|
from core.bot import IRCBot, IRCBotFactory
|
|
import main
|
|
from utils.logging.log import *
|
|
|
|
def addBot(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"]))
|
|
|
|
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"])
|
|
|
|
main.ReactorPool[name] = rct
|
|
main.FactoryPool[name] = bot
|
|
return
|
|
elif instance["protocol"] == "ssl":
|
|
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)
|
|
|
|
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"])
|
|
|
|
main.ReactorPool[name] = rct
|
|
main.FactoryPool[name] = bot
|
|
return
|