예제 #1
0
파일: tasks.py 프로젝트: Petraea/jsonbot
 def add(self, taskname, func):
     """ add a task. """
     logging.debug("tasks - added task %s - %s" % (taskname, func))
     self.handlers[taskname] = func
     plugin = self.plugins[taskname] = calledfrom(sys._getframe())
     plugs.load_mod(plugin)
     return True
예제 #2
0
파일: tasks.py 프로젝트: NURDspace/jsonbot
 def add(self, taskname, func):
     """ add a task. """
     logging.debug("tasks - added task %s - %s" % (taskname, func))
     self.handlers[taskname] = func
     plugin = self.plugins[taskname] = calledfrom(sys._getframe())
     plugs.load_mod(plugin)
     return True
예제 #3
0
파일: core.py 프로젝트: Lujeni/old-projects
def handle_helpplug(bot, ievent):
    """ arguments: <plugname> - how help on plugin/command or show basic help msg. """
    try: what = ievent.args[0]
    except (IndexError, TypeError):
        ievent.reply("available plugins: ", getpluginlist())
        ievent.reply("see !help <plugin> to get help on a plugin.")
        return
    cmnds.reloadcheck(bot, ievent, what)
    plugin = None
    modname = ""
    perms = []
    for package in plugin_packages:
        try:
             modname = "%s.%s" % (package, what)
             try:
                 plugin = plugs.load_mod(modname)
                 if plugin: break
             except NoSuchPlugin: continue
        except(KeyError, ImportError): pass
    if not plugin:
        ievent.reply("no %s plugin loaded" % what)
        return
    try: phelp = plugin.__doc__
    except (KeyError, AttributeError):
        ievent.reply('no description of %s plugin available' % what)
        return
    cmndresult = []
    if phelp:
        perms = ievent.user.data.perms
        if not perms: perms = ['GUEST', ]
        counter = 1
        for i, j in cmnds.iteritems():
            if what == j.plugname:
                for perm in j.perms:
                    if perm in perms:
                        if True:
                            try:
                                descr = j.func.__doc__
                                if not descr: descr = "no description provided"
                                try: cmndresult.append(u"    <b>!%s</b> - <i>%s</i>" % (i, descr))
                                except KeyError: pass
                            except AttributeError: pass
                            counter += 1
                            break
    if cmndresult and phelp:
        res = []
        for r in cmndresult:
            if bot.type in ['web', ]: res.append("%s<br>" % r)
            if bot.type in ['irc', ]: res.append(r.strip())
            else: res.append(r)
        res.sort()
        what = what.upper()
        ievent.reply('<b>help on plugin %s: </b>%s' % (what,phelp.strip()))
        ievent.reply("commands: ", res, dot="\n")
    else:
        if perms: ievent.reply('no commands available for permissions: %s' % ", ".join(perms))
        else: ievent.reply("can't find help on %s" % what)
예제 #4
0
파일: core.py 프로젝트: Petraea/jsonbot
def handle_helpplug(bot, ievent):
    """ arguments: <plugname> - how help on plugin/command or show basic help msg. """
    try:
        what = ievent.args[0]
    except (IndexError, TypeError):
        ievent.reply("available plugins: ", getpluginlist())
        ievent.reply("see !help <plugin> to get help on a plugin.")
        return
    ievent.untildone = True
    cmnds.reloadcheck(bot, ievent, what)
    plugin = None
    modname = ""
    perms = []
    for package in plugin_packages:
        try:
            modname = "%s.%s" % (package, what)
            try:
                plugin = plugs.load_mod(modname)
                if plugin: break
            except NoSuchPlugin:
                continue
        except (KeyError, ImportError):
            pass
    if not plugin:
        ievent.reply("no %s plugin loaded" % what)
        return
    try:
        phelp = plugin.__doc__
    except (KeyError, AttributeError):
        ievent.reply('no description of %s plugin available' % what)
        return
    cmndresult = []
    if phelp:
        counter = 1
        for i, j in cmnds.iteritems():
            if what == j.plugname:
                try:
                    descr = j.func.__doc__
                    if not descr: descr = "no description provided"
                    try:
                        cmndresult.append(
                            u"    <b>!%s</b> - <i>%s</i> - perms: %s" %
                            (i, descr, j.perms))
                    except KeyError:
                        pass
                except AttributeError:
                    pass
                counter += 1
    if cmndresult and phelp:
        res = []
        for r in cmndresult:
            if bot.type in [
                    'web',
            ]: res.append("%s<br>" % r)
            elif bot.type in [
                    'irc',
            ]: res.append(r.strip())
            else: res.append(r)
        res.sort()
        what = what.upper()
        ievent.reply('<br><b>plugin %s: </b><br>%s' % (what, phelp))
        ievent.reply("<b>commands: </b>", res, dot="count")
    else:
        if perms:
            ievent.reply('no commands available for permissions: %s' %
                         ", ".join(perms))
        else:
            ievent.reply("can't find help on %s" % what)
    ievent.done(silent=True)