2018-02-23 22:05:40 +00:00
|
|
|
from twisted.internet import reactor
|
|
|
|
from core.bot import IRCBot, IRCBotFactory
|
2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2018-02-23 22:05:40 +00:00
|
|
|
from utils.logging.log import *
|
|
|
|
|
|
|
|
def addBot(name):
|
2018-03-14 20:13:40 +00:00
|
|
|
instance = main.pool[name]
|
2019-01-26 01:57:24 +00:00
|
|
|
log("Started bot %s to %s:%s protocol %s nickname %s" % (name,
|
|
|
|
instance["host"],
|
|
|
|
instance["port"],
|
|
|
|
instance["protocol"],
|
|
|
|
instance["nickname"]))
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
|
2019-01-26 01:57:24 +00:00
|
|
|
if instance["protocol"] == "ssl":
|
|
|
|
keyFN = main.certPath+main.config["Key"]
|
|
|
|
certFN = main.certPath+main.config["Certificate"]
|
|
|
|
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"),
|
|
|
|
certFN.encode("utf-8", "replace"))
|
2018-02-23 22:05:40 +00:00
|
|
|
if instance["bind"] == None:
|
|
|
|
bot = IRCBotFactory(name)
|
2019-01-26 01:57:24 +00:00
|
|
|
rct = reactor.connectSSL(instance["host"],
|
|
|
|
int(instance["port"]),
|
|
|
|
bot, contextFactory)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
main.ReactorPool[name] = rct
|
|
|
|
main.FactoryPool[name] = bot
|
2018-02-23 22:05:40 +00:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
|
|
|
|
bot = IRCBotFactory(name)
|
2019-01-26 01:57:24 +00:00
|
|
|
rct = reactor.connectSSL(instance["host"],
|
|
|
|
int(instance["port"]),
|
|
|
|
bot, contextFactory,
|
|
|
|
bindAddress=instance["bind"])
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
main.ReactorPool[name] = rct
|
|
|
|
main.FactoryPool[name] = bot
|
2018-02-23 22:05:40 +00:00
|
|
|
return
|