diff options
| -rwxr-xr-x | IRC/asybot.py | 7 | ||||
| -rw-r--r-- | TODO | 4 | ||||
| -rwxr-xr-x | commands/caps | 24 | ||||
| -rw-r--r-- | config.py | 1 | 
4 files changed, 30 insertions, 6 deletions
| diff --git a/IRC/asybot.py b/IRC/asybot.py index 048b94c..38f0df1 100755 --- a/IRC/asybot.py +++ b/IRC/asybot.py @@ -2,6 +2,7 @@  #  # //Reaktor/IRC/asybot.py  # +import os  from translate_colors import translate_colors  def is_executable(x):    import os @@ -18,8 +19,11 @@ from sys import exit  from re import split, search, match  from textwrap import TextWrapper  import logging,logging.handlers + +config_filename = 'config.py' +  from getconf import make_getconf -getconf = make_getconf('config.py') +getconf = make_getconf(config_filename)  log = logging.getLogger('asybot')  hdlr = logging.handlers.SysLogHandler(facility=logging.handlers.SysLogHandler.LOG_DAEMON)  formatter = logging.Formatter( '%(filename)s: %(levelname)s: %(message)s') @@ -142,6 +146,7 @@ class asybot(asychat):      env = {}      env['_from'] = prefix.split('!', 1)[0] +    env['config_filename'] = os.path.abspath(config_filename)      start = time()      try:        p = popen(myargv, bufsize=1, stdout=PIPE, stderr=PIPE, env=env) @@ -1,3 +1,7 @@ +commands/caps: merge load_config with IRC/getconf.py +commands/caps: generalize for UDP +commands/caps: replace map/filter with more pythonic way +  getconf: reload inotify  apropros caps: commands need access to config diff --git a/commands/caps b/commands/caps index caa1fe0..eb1d97a 100755 --- a/commands/caps +++ b/commands/caps @@ -1,5 +1,19 @@ -#! /bin/sh -exec echo 'TODO: need access to config.json' -set -euf -cd public_commands -echo `ls` +#! /usr/bin/env python +import imp +import os + +def load_config(filename): +  dirname = os.path.dirname(filename) +  modname, ext = os.path.splitext(os.path.basename(filename)) +  file, pathname, description = imp.find_module(modname, [ dirname ]) +  return imp.load_module(modname, file, pathname, description) + +def not_none(x): +  return x != None + +def pluck(name): +  return lambda x: name in x.keys() and x[name] or None + +config = load_config(os.environ['config_filename']) + +print(' '.join(filter(not_none, map(pluck('capname'), config.irc_commands)))) @@ -16,6 +16,7 @@ irc_channels = [  def default_command(cmd):    return { +    'capname': cmd,      'pattern': '^(?:' + name + '|\\*):\\s*' + cmd + '\\s*$',      'argv': [ 'commands/' + cmd ] } | 
