commit
90ee813844
|
@ -26,20 +26,8 @@ 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.load_plugins()
|
||||||
|
|
||||||
# load all plugins
|
|
||||||
plugins = []
|
|
||||||
for m in os.listdir(self.plugin_dir):
|
|
||||||
if m.endswith('.py'):
|
|
||||||
name = m[:-3]
|
|
||||||
fp, pathname, description = imp.find_module(name, [self.plugin_dir])
|
|
||||||
plugins.append(imp.load_module(name, fp, pathname, description))
|
|
||||||
|
|
||||||
# gather all commands
|
|
||||||
self.cmds = {}
|
|
||||||
for plugin in plugins:
|
|
||||||
for cmd in plugin.pinhook.plugin.cmds:
|
|
||||||
self.cmds[cmd['cmd']] = cmd['func']
|
|
||||||
|
|
||||||
def set_kwargs(self, **kwargs):
|
def set_kwargs(self, **kwargs):
|
||||||
kwarguments = {
|
kwarguments = {
|
||||||
|
@ -56,6 +44,24 @@ class Bot(irc.bot.SingleServerIRCBot):
|
||||||
if a not in kwargs:
|
if a not in kwargs:
|
||||||
setattr(self, a, kwarguments[a])
|
setattr(self, a, kwarguments[a])
|
||||||
|
|
||||||
|
def load_plugins(self):
|
||||||
|
# load all plugins
|
||||||
|
plugins = []
|
||||||
|
for m in os.listdir(self.plugin_dir):
|
||||||
|
if m.endswith('.py'):
|
||||||
|
try:
|
||||||
|
name = m[:-3]
|
||||||
|
fp, pathname, description = imp.find_module(name, [self.plugin_dir])
|
||||||
|
p = imp.load_module(name, fp, pathname, description)
|
||||||
|
p.pinhook
|
||||||
|
plugins.append(p)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
# gather all commands
|
||||||
|
self.cmds = {}
|
||||||
|
for plugin in plugins:
|
||||||
|
for cmd in plugin.pinhook.plugin.cmds:
|
||||||
|
self.cmds[cmd['cmd']] = cmd['func']
|
||||||
|
|
||||||
def on_welcome(self, c, e):
|
def on_welcome(self, c, e):
|
||||||
if self.ns_pass:
|
if self.ns_pass:
|
||||||
|
@ -91,15 +97,21 @@ class Bot(irc.bot.SingleServerIRCBot):
|
||||||
helplist = sorted([i for i in self.cmds])
|
helplist = sorted([i for i in self.cmds])
|
||||||
msg = ', '.join(helplist)
|
msg = ', '.join(helplist)
|
||||||
c.privmsg(chan, 'Available commands: {}'.format(msg))
|
c.privmsg(chan, 'Available commands: {}'.format(msg))
|
||||||
|
elif cmd == '!reload' and nick in self.ops:
|
||||||
|
self.load_plugins()
|
||||||
|
c.privmsg(chan, 'Plugins reloaded')
|
||||||
elif cmd in self.cmds:
|
elif cmd in self.cmds:
|
||||||
output = self.cmds[cmd](Message(
|
try:
|
||||||
channel=chan,
|
output = self.cmds[cmd](Message(
|
||||||
cmd=cmd,
|
channel=chan,
|
||||||
nick=nick,
|
cmd=cmd,
|
||||||
arg=arg,
|
nick=nick,
|
||||||
botnick=self.bot_nick,
|
arg=arg,
|
||||||
ops=self.ops
|
botnick=self.bot_nick,
|
||||||
))
|
ops=self.ops
|
||||||
|
))
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
if output.msg_type == 'message':
|
if output.msg_type == 'message':
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -72,7 +72,7 @@ class UploadCommand(Command):
|
||||||
# Where the magic happens:
|
# Where the magic happens:
|
||||||
setup(
|
setup(
|
||||||
name=NAME,
|
name=NAME,
|
||||||
version='1.0.2',
|
version='1.1.0',
|
||||||
description=DESCRIPTION,
|
description=DESCRIPTION,
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
author=AUTHOR,
|
author=AUTHOR,
|
||||||
|
|
Loading…
Reference in New Issue