make help overridable, add ability for plugins to msg, action or notice at will

pull/38/head
Mal Hancock 2018-10-24 14:48:55 -07:00
parent f989deb0d9
commit 34590dfa32
1 changed files with 21 additions and 6 deletions

View File

@ -27,13 +27,16 @@ class Bot(irc.bot.SingleServerIRCBot):
self.load_plugins() self.load_plugins()
class Message: class Message:
def __init__(self, channel, nick, botnick, ops, logger, cmd=None, arg=None, text=None, nick_list=None): def __init__(self, channel, nick, botnick, ops, logger, action, privmsg, notice, 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 self.logger = logger
self.action = action
self.privmsg = privmsg
self.notice = notice
if cmd: if cmd:
self.cmd = cmd self.cmd = cmd
self.arg = arg self.arg = arg
@ -128,6 +131,11 @@ class Bot(irc.bot.SingleServerIRCBot):
def on_action(self, c, e): def on_action(self, c, e):
self.process_event(c, e) self.process_event(c, e)
def call_help(self):
helplist = sorted([i for i in pinhook.plugin.cmds])
msg = ', '.join(helplist)
return self.output_message('Available commands: {}'.format(msg))
def call_internal_commands(self, channel, nick, cmd, text, arg, c): def call_internal_commands(self, channel, nick, cmd, text, arg, c):
output = None output = None
if nick in self.ops: if nick in self.ops:
@ -143,16 +151,14 @@ class Bot(irc.bot.SingleServerIRCBot):
c.quit("See y'all later!") c.quit("See y'all later!")
quit() quit()
elif cmd == '!help': elif cmd == '!help':
helplist = sorted([i for i in pinhook.plugin.cmds]) output = self.call_help()
msg = ', '.join(helplist)
output = self.output_message('Available commands: {}'.format(msg))
elif cmd == '!reload' and op: elif cmd == '!reload' and op:
self.logger.info('reloading plugins per request of {}'.format(nick)) self.logger.info('reloading plugins per request of {}'.format(nick))
self.load_plugins() self.load_plugins()
output = self.output_message('Plugins reloaded') output = self.output_message('Plugins reloaded')
return output return output
def call_plugins(self, chan, cmd, text, nick_list, nick, arg): def call_plugins(self, privmsg, action, notice, chan, cmd, text, nick_list, nick, arg):
output = None output = None
if cmd in pinhook.plugin.cmds: if cmd in pinhook.plugin.cmds:
try: try:
@ -162,6 +168,9 @@ class Bot(irc.bot.SingleServerIRCBot):
nick_list=nick_list, nick_list=nick_list,
nick=nick, nick=nick,
arg=arg, arg=arg,
privmsg=privmsg,
action=action,
notice=notice,
botnick=self.bot_nick, botnick=self.bot_nick,
ops=self.ops, ops=self.ops,
logger=self.logger logger=self.logger
@ -176,6 +185,9 @@ class Bot(irc.bot.SingleServerIRCBot):
text=text, text=text,
nick_list=nick_list, nick_list=nick_list,
nick=nick, nick=nick,
privmsg=privmsg,
action=action,
notice=notice,
botnick=self.bot_nick, botnick=self.bot_nick,
ops=self.ops, ops=self.ops,
logger=self.logger logger=self.logger
@ -212,7 +224,10 @@ class Bot(irc.bot.SingleServerIRCBot):
'text': text, 'text': text,
'nick_list': nick_list, 'nick_list': nick_list,
'nick': nick, 'nick': nick,
'arg': arg 'arg': arg,
'privmsg': c.privmsg,
'action': c.action,
'notice': c.notice,
} }
output = self.call_plugins(**plugin_info) output = self.call_plugins(**plugin_info)
if output: if output: