From 9e4cb85910fa63441649d1a70f9307229fdf5bbc Mon Sep 17 00:00:00 2001 From: Matan Shenhav Date: Sat, 23 Feb 2019 22:34:13 +0200 Subject: [PATCH] Add bot as argument for Message class & pass self in calls Passing the bot object as an argument to the Message class make the pinhook Bot class more extensible. Now it is easy to inherit and pass attributes of the inherited class into plugins. See https://github.com/archangelic/pinhook/issues/59 --- pinhook/bot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pinhook/bot.py b/pinhook/bot.py index b0593ea..22750c2 100644 --- a/pinhook/bot.py +++ b/pinhook/bot.py @@ -37,7 +37,8 @@ class Bot(irc.bot.SingleServerIRCBot): self.load_plugins() class Message: - def __init__(self, channel, nick, botnick, ops, logger, action, privmsg, notice, cmd=None, arg=None, text=None, nick_list=None): + def __init__(self, bot, channel, nick, botnick, ops, logger, action, privmsg, notice, cmd=None, arg=None, text=None, nick_list=None): + self.bot = bot self.datetime = datetime.now(timezone.utc) self.timestamp = self.datetime.timestamp() self.channel = channel @@ -165,6 +166,7 @@ class Bot(irc.bot.SingleServerIRCBot): else: self.logger.debug('executing {}'.format(cmd)) output = pinhook.plugin.cmds[cmd]['run'](self.Message( + bot=self, channel=chan, cmd=cmd, nick_list=nick_list, @@ -184,6 +186,7 @@ class Bot(irc.bot.SingleServerIRCBot): try: self.logger.debug('whispering to listener: {}'.format(lstnr)) listen_output = pinhook.plugin.lstnrs[lstnr](self.Message( + bot=self, channel=chan, text=text, nick_list=nick_list,