Beispiel #1
0
def handle_commands(bot, ievent):
    """ commands <plugin> .. show commands of <plugin>. """

    try:
        plugin = ievent.args[0].lower()
    except IndexError:
        ievent.missing('<plugin> .. see the list command for available \
plugins')
        return

    if not plugins.plugs.has_key(plugin):
        ievent.reply('no %s plugin is loaded .. see the available command for \
available plugins (reload to enable)' % plugin)
        return

    result = []

    for i, j in cmnds.iteritems():
        if plugin == j.plugname:
            txt = ""
            alias = aliasreverse(i)
            if alias:
                txt += "%s (%s)" % (i, alias)
            else:
                txt = i
            if txt:
                result.append(txt)

    if result:
        result.sort()
        ievent.reply('%s has the following commands: ' % plugin, result, \
dot=True)
    else:
        ievent.reply('no commands found for plugin %s' % plugin)
Beispiel #2
0
def handle_commands(bot, ievent):

    """ commands <plugin> .. show commands of <plugin>. """

    try:
        plugin = ievent.args[0].lower()
    except IndexError:
        ievent.missing('<plugin> .. see the list command for available \
plugins')
        return

    if not plugins.plugs.has_key(plugin):
        ievent.reply('no %s plugin is loaded .. see the available command for \
available plugins (reload to enable)' % plugin)
        return

    result = []

    for i, j in cmnds.iteritems():
        if plugin == j.plugname:
            txt = ""
            alias = aliasreverse(i)
            if alias:
                txt += "%s (%s)" % (i, alias)
            else:
                txt = i
            if txt:
                result.append(txt)

    if result:
        result.sort()
        ievent.reply('%s has the following commands: ' % plugin, result, \
dot=True)
    else:
        ievent.reply('no commands found for plugin %s' % plugin)
Beispiel #3
0
def gendoc(f):
    base = os.path.basename(f).replace('.py', '')
    print '=' * (len(base) + 2)
    print ' %s ' % base.upper()
    print '=' * (len(base) + 2)
    print "| \n"
    print "about"
    print "-----"
    print "| \n"
    try:
        author = plugins.plugs[base].__author__
        print ":author:  %s" % author.strip()
    except AttributeError:
        print ":author:  Bart Thate <*****@*****.**>"
    print ":contact: IRCNET/#dunkbots"
    if 'gozerplugs' in f:
        print ':distribution: core'
    else:
        print ":distribution: http://plugins.gozerbot.org"
    try:
        license = plugins.plugs[base].__license__
        print ":license:  %s" % license.strip()
    except AttributeError:
        print ":license: Public Domain"
    print " "
    print "| \n"
    data = {'author': 'unknown', 'description': '', 'commands':[], 'examples':{}, \
'descriptions':{}, 'callbacks': {}, 'aliases': {}, 'permissions': {}}
    data['description'] = plughelp[base]
    cmndlist = []
    for j, z in cmnds.iteritems():
        if j in donot:
            continue
        if z.plugname == base:
            cmndlist.append(j)
    relist = []
    for reitem in rebefore.relist:
        if reitem.plugname == base:
            relist.append(reitem)
    for reitem in reafter.relist:
        if reitem.plugname == base:
            relist.append(reitem)
    cmndlist.sort()
    try:
        first = plugins.plugs[base].__gendocfirst__
        for i in first[::-1]:
            try:
                cmndlist.remove(i)
            except ValueError:
                continue
            cmndlist.insert(0, i)
    except AttributeError:
        pass
    try:
        first = plugins.plugs[base].__gendoclast__
        for i in first[::-1]:
            try:
                cmndlist.remove(i)
            except ValueError:
                continue
            cmndlist.append(i)
    except AttributeError:
        pass
    try:
        skip = plugins.plugs[base].__gendocskip__
        for i in skip[::-1]:
            try:
                cmndlist.remove(i)
            except ValueError:
                continue
    except AttributeError:
        pass
    for command in cmndlist:
        data['commands'].append(command)
        alias = aliasreverse(command)
        if alias:
            data['aliases'][command] = alias
        try:
            ex = examples[command]
        except Exception, exx:
            continue
        try:
            data['permissions'][command] = cmnds.perms(command)
        except:
            pass
        data['examples'][command] = []
        exampleslist = re.split('\d\)', ex.example)
        for e in exampleslist:
            data['examples'][command].append(e.strip())
            data['descriptions'][command] = ex.descr
Beispiel #4
0
def gendoc(f):
    base = os.path.basename(f).replace(".py", "")
    print "=" * (len(base) + 2)
    print " %s " % base.upper()
    print "=" * (len(base) + 2)
    print "| \n"
    print "about"
    print "-----"
    print "| \n"
    try:
        author = plugins.plugs[base].__author__
        print ":author:  %s" % author.strip()
    except AttributeError:
        print ":author:  Bart Thate <*****@*****.**>"
    print ":contact: IRCNET/#dunkbots"
    if "gozerplugs" in f:
        print ":distribution: core"
    else:
        print ":distribution: http://plugins.gozerbot.org"
    try:
        license = plugins.plugs[base].__license__
        print ":license:  %s" % license.strip()
    except AttributeError:
        print ":license: Public Domain"
    print " "
    print "| \n"
    data = {
        "author": "unknown",
        "description": "",
        "commands": [],
        "examples": {},
        "descriptions": {},
        "callbacks": {},
        "aliases": {},
        "permissions": {},
    }
    data["description"] = plughelp[base]
    cmndlist = []
    for j, z in cmnds.iteritems():
        if j in donot:
            continue
        if z.plugname == base:
            cmndlist.append(j)
    relist = []
    for reitem in rebefore.relist:
        if reitem.plugname == base:
            relist.append(reitem)
    for reitem in reafter.relist:
        if reitem.plugname == base:
            relist.append(reitem)
    cmndlist.sort()
    try:
        first = plugins.plugs[base].__gendocfirst__
        for i in first[::-1]:
            try:
                cmndlist.remove(i)
            except ValueError:
                continue
            cmndlist.insert(0, i)
    except AttributeError:
        pass
    try:
        first = plugins.plugs[base].__gendoclast__
        for i in first[::-1]:
            try:
                cmndlist.remove(i)
            except ValueError:
                continue
            cmndlist.append(i)
    except AttributeError:
        pass
    try:
        skip = plugins.plugs[base].__gendocskip__
        for i in skip[::-1]:
            try:
                cmndlist.remove(i)
            except ValueError:
                continue
    except AttributeError:
        pass
    for command in cmndlist:
        data["commands"].append(command)
        alias = aliasreverse(command)
        if alias:
            data["aliases"][command] = alias
        try:
            ex = examples[command]
        except Exception, exx:
            continue
        try:
            data["permissions"][command] = cmnds.perms(command)
        except:
            pass
        data["examples"][command] = []
        exampleslist = re.split("\d\)", ex.example)
        for e in exampleslist:
            data["examples"][command].append(e.strip())
            data["descriptions"][command] = ex.descr
Beispiel #5
0
def handle_help(bot, ievent):
    """ help [<cmnd>|<plugin>] .. show help on plugin/command or show basic help msg. """

    try:
        what = ievent.args[0]
    except IndexError:
        ievent.reply('help <cmnd> or help <plugin> .. see the !list \
command for a list of available plugins or see !available command for a list \
of plugins to be reloaded')
        return

    phelp = plughelp.get(what)
    cmndresult = []

    if phelp:
        ievent.reply('plugin description: %s' % phelp)
        perms = list(users.getperms(ievent.userhost))

        for i, j in cmnds.iteritems():
            if what == j.plugname:
                for perm in j.perms:
                    if perm in perms:
                        if i not in cmndresult:
                            cmndresult.append(i)

        if cmndresult:
            cmndresult.sort()
            resultstr = ""
            for i in cmndresult:
                alias = aliasreverse(i)
                if alias:
                    resultstr += "%s (%s) .. " % (i, alias)
                else:
                    resultstr += "%s .. " % i
            ievent.reply('commands: %s'\
 % resultstr[:-4])
        else:
            ievent.reply('no commands available for permission %s' % \
str(perms))

        result = []

        for i in rebefore.relist:
            if what == i.plugname:
                if users.allowed(ievent.userhost, i.perms):
                    result.append(i.regex)

        for i in reafter.relist:
            if what == i.plugname:
                if users.allowed(ievent.userhost, i.perms):
                    result.append(i.regex)

        if result:
            resultstr = ""
            for i in result:
                resultstr += '"%s" .. ' % i
            ievent.reply('regular expressions: %s' % resultstr[:-4])
        else:
            pass

        result = []

        for i, j in callbacks.cbs.items():
            for z in j:
                if what == z.plugname:
                    result.append(i)

        if result:
            resultstr = ""
            for i in result:
                resultstr += "%s .. " % i
            ievent.reply('callbacks: %s' % resultstr[:-4])
        else:
            pass

        if not cmndresult:
            return

    if what in aliases.data:
        ievent.reply('%s is an alias for %s' % (what, aliases.data[what]))
        what = aliases.data[what]

    try:
        example = examples[what]
    except KeyError:
        return

    ievent.reply('%s .. alias: %s .. examples: %s' %
                 (example.descr, aliasreverse(what), example.example))
Beispiel #6
0
def handle_help(bot, ievent):

    """ help [<cmnd>|<plugin>] .. show help on plugin/command or show basic help msg. """

    try:
        what = ievent.args[0]
    except IndexError:
        ievent.reply('help <cmnd> or help <plugin> .. see the !list \
command for a list of available plugins or see !available command for a list \
of plugins to be reloaded')
        return

    phelp = plughelp.get(what)
    cmndresult = []

    if phelp:
        ievent.reply('plugin description: %s' % phelp)
        perms = list(users.getperms(ievent.userhost))

        for i, j in cmnds.iteritems():
            if what == j.plugname:
                for perm in j.perms:
                    if perm in perms:
                        if i not in cmndresult:
                            cmndresult.append(i)

        if cmndresult:
            cmndresult.sort()
            resultstr = ""
            for i in cmndresult:
                alias = aliasreverse(i)
                if alias:
                    resultstr += "%s (%s) .. " % (i, alias)
                else:
                    resultstr += "%s .. " % i
            ievent.reply('commands: %s'\
 % resultstr[:-4])
        else:
            ievent.reply('no commands available for permission %s' % \
str(perms))

        result = []

        for i in rebefore.relist:
            if what == i.plugname:
                if users.allowed(ievent.userhost, i.perms):
                    result.append(i.regex)

        for i in reafter.relist:
            if what == i.plugname:
                if users.allowed(ievent.userhost, i.perms):
                    result.append(i.regex)

        if result:
            resultstr = ""
            for i in result:
                resultstr += '"%s" .. ' % i
            ievent.reply('regular expressions: %s' % resultstr[:-4])
        else:
            pass

        result = []

        for i, j in callbacks.cbs.items():
            for z in j:
                if what == z.plugname:
                    result.append(i)

        if result:
            resultstr = ""
            for i in result:
                resultstr += "%s .. " % i
            ievent.reply('callbacks: %s' % resultstr[:-4])
        else:
            pass

        if not cmndresult:
            return

    if what in aliases.data:
        ievent.reply('%s is an alias for %s' % (what, aliases.data[what]))
        what = aliases.data[what]

    try:
        example = examples[what]
    except KeyError:
        return

    ievent.reply('%s .. alias: %s .. examples: %s' % (example.descr, aliasreverse(what), example.example))