Add bot as argument for Message class & pass self in calls (#60)

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
pull/63/head
Matan Shenhav 2019-02-24 02:56:03 +02:00 committed by Mal Hancock
parent ac2491c005
commit 709d05da73
1 changed files with 4 additions and 1 deletions

View File

@ -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,