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
|
||||
|
||||
network = "irc.synirc.net"
|
||||
network = "localhost"
|
||||
nick = "skybot"
|
||||
channel = "#cobol"
|
||||
channel = "#test"
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
@ -12,25 +12,25 @@ sys.path += ['plugins'] # so 'import hook' works without duplication
|
|||
sys.path += ['lib']
|
||||
os.chdir(sys.path[0]) # do stuff relative to the installation directory
|
||||
|
||||
import irc
|
||||
|
||||
|
||||
class Bot(object):
|
||||
pass
|
||||
|
||||
|
||||
bot = Bot()
|
||||
|
||||
print 'Loading plugins'
|
||||
|
||||
# bootstrap the reloader
|
||||
eval(compile(open('core/reload.py', 'U').read(), 'core/reload.py', 'exec'))
|
||||
reload(init=True)
|
||||
|
||||
print 'Connecting to IRC'
|
||||
|
||||
bot.nick = nick
|
||||
bot.channel = channel
|
||||
bot.network = network
|
||||
bot.irc = irc.irc(network, nick)
|
||||
bot.irc = irc(network, nick)
|
||||
bot.irc.join(channel)
|
||||
bot.persist_dir = os.path.abspath('persist')
|
||||
|
||||
|
|
|
@ -8,11 +8,9 @@ if 'mtimes' not in globals():
|
|||
if 'lastfiles' not in globals():
|
||||
lastfiles = set()
|
||||
|
||||
def reload():
|
||||
init = False
|
||||
if not hasattr(bot, 'plugs'):
|
||||
def reload(init=False):
|
||||
if init:
|
||||
bot.plugs = collections.defaultdict(lambda: [])
|
||||
init = True
|
||||
|
||||
for filename in glob.glob("core/*.py"):
|
||||
mtime = os.stat(filename).st_mtime
|
||||
|
@ -26,7 +24,7 @@ def reload():
|
|||
continue
|
||||
|
||||
if filename == 'core/reload.py':
|
||||
reload()
|
||||
reload(init=init)
|
||||
return
|
||||
|
||||
fileset = set(glob.glob("plugins/*py"))
|
||||
|
@ -53,6 +51,12 @@ def reload():
|
|||
if hasattr(obj, '_skybot_hook'): #check for magic
|
||||
for type, data in obj._skybot_hook:
|
||||
bot.plugs[type] += [data]
|
||||
|
||||
if type == 'init':
|
||||
try:
|
||||
obj(bot)
|
||||
except Exception:
|
||||
traceback.print_exc(Exception)
|
||||
|
||||
if init:
|
||||
print ' plugin listing:'
|
||||
|
|
|
@ -30,6 +30,14 @@ def sieve(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):
|
||||
args = {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue