fix issues with starting logging, and now sends to plugins
This commit is contained in:
parent
e377527aa6
commit
edb0ae5539
@ -2,5 +2,6 @@ import pinhook.plugin
|
|||||||
|
|
||||||
@pinhook.plugin.register('!test')
|
@pinhook.plugin.register('!test')
|
||||||
def test(msg):
|
def test(msg):
|
||||||
|
msg.logger.info('This is test log output')
|
||||||
return pinhook.plugin.message("{}: Test".format(msg.nick))
|
return pinhook.plugin.message("{}: Test".format(msg.nick))
|
||||||
|
|
||||||
|
@ -12,12 +12,13 @@ irc.client.ServerConnection.buffer_class.errors = 'replace'
|
|||||||
|
|
||||||
|
|
||||||
class Message:
|
class Message:
|
||||||
def __init__(self, channel, nick, botnick, ops, cmd=None, arg=None, text=None, nick_list=None):
|
def __init__(self, channel, nick, botnick, ops, logger, cmd=None, arg=None, text=None, nick_list=None):
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
self.nick_list = nick_list
|
self.nick_list = nick_list
|
||||||
self.botnick = botnick
|
self.botnick = botnick
|
||||||
self.ops = ops
|
self.ops = ops
|
||||||
|
self.logger = logger
|
||||||
if cmd:
|
if cmd:
|
||||||
self.cmd = cmd
|
self.cmd = cmd
|
||||||
if arg:
|
if arg:
|
||||||
@ -31,7 +32,6 @@ class Message:
|
|||||||
class Bot(irc.bot.SingleServerIRCBot):
|
class Bot(irc.bot.SingleServerIRCBot):
|
||||||
def __init__(self, channels, nickname, server, **kwargs):
|
def __init__(self, channels, nickname, server, **kwargs):
|
||||||
self.set_kwargs(**kwargs)
|
self.set_kwargs(**kwargs)
|
||||||
self.start_logging(self.log_level)
|
|
||||||
if self.ssl_required:
|
if self.ssl_required:
|
||||||
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
||||||
irc.bot.SingleServerIRCBot.__init__(self, [(server, self.port)], nickname, nickname, connect_factory=factory)
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, self.port)], nickname, nickname, connect_factory=factory)
|
||||||
@ -39,6 +39,7 @@ class Bot(irc.bot.SingleServerIRCBot):
|
|||||||
irc.bot.SingleServerIRCBot.__init__(self, [(server, self.port)], nickname, nickname)
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, self.port)], nickname, nickname)
|
||||||
self.chanlist = channels
|
self.chanlist = channels
|
||||||
self.bot_nick = nickname
|
self.bot_nick = nickname
|
||||||
|
self.start_logging(self.log_level)
|
||||||
self.load_plugins()
|
self.load_plugins()
|
||||||
|
|
||||||
def set_kwargs(self, **kwargs):
|
def set_kwargs(self, **kwargs):
|
||||||
@ -66,7 +67,8 @@ class Bot(irc.bot.SingleServerIRCBot):
|
|||||||
level = logging.INFO
|
level = logging.INFO
|
||||||
elif level == 'debug':
|
elif level == 'debug':
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
self.logger = logging.getLogger('{}'.format(self.bot_nick))
|
self.logger = logging.getLogger(self.bot_nick)
|
||||||
|
self.logger.setLevel(level)
|
||||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s - %(message)s')
|
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s - %(message)s')
|
||||||
# Set console logger
|
# Set console logger
|
||||||
ch = logging.StreamHandler()
|
ch = logging.StreamHandler()
|
||||||
@ -79,6 +81,7 @@ class Bot(irc.bot.SingleServerIRCBot):
|
|||||||
# Add handlers
|
# Add handlers
|
||||||
self.logger.addHandler(ch)
|
self.logger.addHandler(ch)
|
||||||
self.logger.addHandler(fh)
|
self.logger.addHandler(fh)
|
||||||
|
self.logger.info('Logging started!')
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
# clear plugin list to ensure no old plugins remain
|
# clear plugin list to ensure no old plugins remain
|
||||||
@ -154,7 +157,8 @@ class Bot(irc.bot.SingleServerIRCBot):
|
|||||||
nick=nick,
|
nick=nick,
|
||||||
arg=arg,
|
arg=arg,
|
||||||
botnick=self.bot_nick,
|
botnick=self.bot_nick,
|
||||||
ops=self.ops
|
ops=self.ops,
|
||||||
|
logger=self.logger
|
||||||
))
|
))
|
||||||
if output:
|
if output:
|
||||||
self.process_output(c, chan, output)
|
self.process_output(c, chan, output)
|
||||||
@ -169,7 +173,8 @@ class Bot(irc.bot.SingleServerIRCBot):
|
|||||||
nick_list=list(self.channels[chan].users()),
|
nick_list=list(self.channels[chan].users()),
|
||||||
nick=nick,
|
nick=nick,
|
||||||
botnick=self.bot_nick,
|
botnick=self.bot_nick,
|
||||||
ops=self.ops
|
ops=self.ops,
|
||||||
|
logger=self.logger
|
||||||
))
|
))
|
||||||
if output:
|
if output:
|
||||||
self.process_output(c, chan, output)
|
self.process_output(c, chan, output)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user