move irc into core/, fix reload plugin display
This commit is contained in:
parent
84f66e55ab
commit
038793c226
10
bot.py
10
bot.py
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
network = "irc.synirc.net"
|
network = "localhost"
|
||||||
nick = "skybot"
|
nick = "skybot"
|
||||||
channel = "#cobol"
|
channel = "#test"
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
@ -12,25 +12,25 @@ sys.path += ['plugins'] # so 'import hook' works without duplication
|
||||||
sys.path += ['lib']
|
sys.path += ['lib']
|
||||||
os.chdir(sys.path[0]) # do stuff relative to the installation directory
|
os.chdir(sys.path[0]) # do stuff relative to the installation directory
|
||||||
|
|
||||||
import irc
|
|
||||||
|
|
||||||
|
|
||||||
class Bot(object):
|
class Bot(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
bot = Bot()
|
bot = Bot()
|
||||||
|
|
||||||
print 'Loading plugins'
|
print 'Loading plugins'
|
||||||
|
|
||||||
# bootstrap the reloader
|
# bootstrap the reloader
|
||||||
eval(compile(open('core/reload.py', 'U').read(), 'core/reload.py', 'exec'))
|
eval(compile(open('core/reload.py', 'U').read(), 'core/reload.py', 'exec'))
|
||||||
|
reload(init=True)
|
||||||
|
|
||||||
print 'Connecting to IRC'
|
print 'Connecting to IRC'
|
||||||
|
|
||||||
bot.nick = nick
|
bot.nick = nick
|
||||||
bot.channel = channel
|
bot.channel = channel
|
||||||
bot.network = network
|
bot.network = network
|
||||||
bot.irc = irc.irc(network, nick)
|
bot.irc = irc(network, nick)
|
||||||
bot.irc.join(channel)
|
bot.irc.join(channel)
|
||||||
bot.persist_dir = os.path.abspath('persist')
|
bot.persist_dir = os.path.abspath('persist')
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,9 @@ if 'mtimes' not in globals():
|
||||||
if 'lastfiles' not in globals():
|
if 'lastfiles' not in globals():
|
||||||
lastfiles = set()
|
lastfiles = set()
|
||||||
|
|
||||||
def reload():
|
def reload(init=False):
|
||||||
init = False
|
if init:
|
||||||
if not hasattr(bot, 'plugs'):
|
|
||||||
bot.plugs = collections.defaultdict(lambda: [])
|
bot.plugs = collections.defaultdict(lambda: [])
|
||||||
init = True
|
|
||||||
|
|
||||||
for filename in glob.glob("core/*.py"):
|
for filename in glob.glob("core/*.py"):
|
||||||
mtime = os.stat(filename).st_mtime
|
mtime = os.stat(filename).st_mtime
|
||||||
|
@ -26,7 +24,7 @@ def reload():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if filename == 'core/reload.py':
|
if filename == 'core/reload.py':
|
||||||
reload()
|
reload(init=init)
|
||||||
return
|
return
|
||||||
|
|
||||||
fileset = set(glob.glob("plugins/*py"))
|
fileset = set(glob.glob("plugins/*py"))
|
||||||
|
@ -54,6 +52,12 @@ def reload():
|
||||||
for type, data in obj._skybot_hook:
|
for type, data in obj._skybot_hook:
|
||||||
bot.plugs[type] += [data]
|
bot.plugs[type] += [data]
|
||||||
|
|
||||||
|
if type == 'init':
|
||||||
|
try:
|
||||||
|
obj(bot)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc(Exception)
|
||||||
|
|
||||||
if init:
|
if init:
|
||||||
print ' plugin listing:'
|
print ' plugin listing:'
|
||||||
for type, plugs in sorted(bot.plugs.iteritems()):
|
for type, plugs in sorted(bot.plugs.iteritems()):
|
||||||
|
|
|
@ -30,6 +30,14 @@ def sieve(func):
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
def init(func):
|
||||||
|
if func.func_code.co_argcount != 1:
|
||||||
|
raise ValueError(
|
||||||
|
'initializers must take 1 argument: bot')
|
||||||
|
_hook_add(func, ['init', (_make_sig(func), func)])
|
||||||
|
return func
|
||||||
|
|
||||||
|
|
||||||
def command(func=None, hook=None, **kwargs):
|
def command(func=None, hook=None, **kwargs):
|
||||||
args = {}
|
args = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue