def savepluginlist(modname=None): """ save a list of available plugins to db backend. """ global pluginlist if not pluginlist.data: pluginlist.data = [] if modname: target = cpy(pluginlist.data) else: target = [] from jsb.lib.commands import cmnds assert cmnds for cmndname, c in cmnds.iteritems(): if modname and c.modname != modname: continue if c and not c.plugname: logging.info("boot - not adding %s to pluginlist" % cmndname) continue if c and c.plugname not in target: target.append(c.plugname) assert target target.sort() logging.warn("saving plugin list") assert pluginlist pluginlist.data = target pluginlist.save()
def savecmndtable(modname=None, saveperms=True): """ save command -> plugin list to db backend. """ global cmndtable if not cmndtable.data: cmndtable.data = {} if modname: target = LazyDict(cmndtable.data) else: target = LazyDict() global cmndperms #if not cmndperms.data: cmndperms.data = {} from jsb.lib.commands import cmnds assert cmnds if cmnds.subs: for name, clist in cmnds.subs.iteritems(): if name: if clist and len(clist) == 1: target[name] = clist[0].modname for cmndname, c in cmnds.iteritems(): if modname and c.modname != modname or cmndname == "subs": continue if cmndname and c: target[cmndname] = c.modname cmndperms[cmndname] = c.perms logging.warn("saving command table") assert cmndtable assert target cmndtable.data = target cmndtable.save() if saveperms: logging.warn("saving command perms") cmndperms.save()
def savecmndtable(modname=None, saveperms=True): """ save command -> plugin list to db backend. """ global cmndtable if not cmndtable.data: cmndtable.data = {} if modname: target = LazyDict(cmndtable.data) else: target = LazyDict() global cmndperms # if not cmndperms.data: cmndperms.data = {} from jsb.lib.commands import cmnds assert cmnds if cmnds.subs: for name, clist in cmnds.subs.iteritems(): if name: if name in cmnds: continue if clist and len(clist) == 1: target[name] = clist[0].modname for cmndname, c in cmnds.iteritems(): if modname and c.modname != modname or cmndname == "subs": continue if cmndname and c: target[cmndname] = c.modname cmndperms[cmndname] = c.perms logging.warn("saving command table") assert cmndtable assert target cmndtable.data = target cmndtable.save() if saveperms: logging.warn("saving command perms") cmndperms.save()
def removecmnds(modname): """ remove commands belonging to modname form cmndtable. """ global cmndtable assert cmndtable from jsb.lib.commands import cmnds assert cmnds for cmndname, c in cmnds.iteritems(): if c.modname == modname: del cmndtable.data[cmndname] cmndtable.save()
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)
def removecmnds(modname): """ remove commands belonging to modname form cmndtable. """ global cmndtable assert cmndtable from jsb.lib.commands import cmnds assert cmnds for cmndname, c in cmnds.iteritems(): if c.modname == modname: del cmndtable.data[cmndname] cmndtable.save()
def handle_commands(bot, ievent): """ arguments: [<plugname>] - show commands of plugin. """ try: plugin = ievent.args[0].lower() except IndexError: plugin = "" result = [] cmnds = getcmndtable() for cmnd, plugname in cmnds.iteritems(): if plugname: if not plugin or plugin in plugname: result.append(cmnd) if result: result.sort() if not plugin: plugin = "JSONBOT" ievent.reply('%s has the following commands: ' % plugin, result) else: ievent.reply('no commands found for plugin %s' % plugin)
def handle_commands(bot, ievent): """ arguments: [<plugname>] - show commands of plugin. """ try: plugin = ievent.args[0].lower() except IndexError: plugin = "" result = [] cmnds = getcmndtable() for cmnd, plugname in cmnds.iteritems(): if plugname: if not plugin or plugin in plugname: result.append(cmnd) if result: result.sort() if not plugin: plugin = "JSONBOT" ievent.reply('%s has the following commands: ' % plugin, result) else: ievent.reply('no commands found for plugin %s' % plugin)
def savecmndtable(modname=None, saveperms=True): """ save command -> plugin list to db backend. """ global cmndtable if not cmndtable.data: cmndtable.data = {} if modname: target = LazyDict(cmndtable.data) else: target = LazyDict() global shorttable if not shorttable.data: shorttable.data = {} if modname: short = LazyDict(shorttable.data) else: short = LazyDict() global cmndperms from jsb.lib.commands import cmnds assert cmnds for cmndname, c in cmnds.iteritems(): if modname and c.modname != modname or cmndname == "subs": continue if cmndname and c: target[cmndname] = c.modname cmndperms[cmndname] = c.perms try: s = cmndname.split("-")[1] if not target.has_key(s): if not short.has_key(s): short[s] = [ cmndname, ] if cmndname not in short[s]: short[s].append(cmndname) except (ValueError, IndexError): pass logging.warn("saving command table") assert cmndtable assert target cmndtable.data = target cmndtable.save() logging.warn("saving short table") assert shorttable assert short shorttable.data = short shorttable.save() logging.warn("saving RE table") for command in cmnds.regex: retable.data[command.regex] = command.modname assert retable retable.save() if saveperms: logging.warn("saving command perms") cmndperms.save()
def savecmndtable(modname=None, saveperms=True): """ save command -> plugin list to db backend. """ global cmndtable if not cmndtable.data: cmndtable.data = {} if modname: target = LazyDict(cmndtable.data) else: target = LazyDict() global shorttable if not shorttable.data: shorttable.data = {} if modname: short = LazyDict(shorttable.data) else: short = LazyDict() global cmndperms from jsb.lib.commands import cmnds assert cmnds for cmndname, c in cmnds.iteritems(): if modname and c.modname != modname or cmndname == "subs": continue if cmndname and c: target[cmndname] = c.modname cmndperms[cmndname] = c.perms try: s = cmndname.split("-")[1] if not target.has_key(s): if not short.has_key(s): short[s] = [cmndname, ] if cmndname not in short[s]: short[s].append(cmndname) except (ValueError, IndexError): pass logging.warn("saving command table") assert cmndtable assert target cmndtable.data = target cmndtable.save() logging.warn("saving short table") assert shorttable assert short shorttable.data = short shorttable.save() logging.warn("saving RE table") for command in cmnds.regex: retable.data[command.regex] = command.modname assert retable retable.save() if saveperms: logging.warn("saving command perms") cmndperms.save()
def savepluginlist(modname=None): """ save a list of available plugins to db backend. """ global pluginlist if not pluginlist.data: pluginlist.data = [] if modname: target = cpy(pluginlist.data) else: target = [] from jsb.lib.commands import cmnds assert cmnds for cmndname, c in cmnds.iteritems(): if modname and c.modname != modname: continue if c and not c.plugname: logging.info("boot - not adding %s to pluginlist" % cmndname) continue if c and c.plugname not in target: target.append(c.plugname) assert target target.sort() logging.warn("saving plugin list") assert pluginlist pluginlist.data = target pluginlist.save()
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)
def handle_helpplug(bot, ievent): """ 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 plugin = None modname = "" perms = [] for package in plugin_packages: try: modname = "%s.%s" % (package, what) try: plugin = plugs.load(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> - examples: %s" % (i, descr, examples[i].example)) except KeyError: cmndresult.append( u" <b>!%s</b> - <i>%s</i> - no examples" % (i, descr)) 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) else: res.append(r) res.sort() what = what.upper() res.insert(0, "%s\n" % phelp.strip()) ievent.reply('HELP ON %s \n\n' % what, 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)