Example #1
0
def handle_throttleset(bot, ievent):
    try:
        (nick, cpm) = ievent.args
    except ValueError:
        ievent.missing('<nick> <commands per minute>')
        return
    uh = getwho(bot, nick)
    if not uh:
        ievent.reply("can't find userhost of %s" % nick)
        return
    perms = users.getperms(uh)
    if 'OPER' in perms:
        ievent.reply("can't throttle a OPER")
        return
    try:
        cpm = float(cpm)
        if cpm == 0:
            ievent.reply("cpm can't be zero")
            return
        state['level'][uh] = cpm
        state['cpm'][uh] = 0
        state.save()
    except ValueError:
        ievent.reply('%s is not an integer' % cpm)
        return
    try:
        bot.throttle.remove(uh)
    except ValueError:
        pass
    ievent.reply('cpm set to %s for %s' % (cpm, uh))
Example #2
0
def handle_apro(bot, ievent):
    """ apro <cmnd> .. apropos for command. """

    try:
        what = ievent.args[0]
    except IndexError:
        ievent.missing('<what>')
        return

    result = []
    perms = users.getperms(ievent.userhost)

    for i in cmnds.apropos(re.escape(what), perms=perms):
        alias = aliasreverse(i)
        if alias:
            result.append('%s (%s)' % (i, alias))
        else:
            result.append(i)

    res = []

    for alias in aliases.data:
        if what in alias and not what in result:
            res.append(alias)

    result.extend(res)

    if result:
        ievent.reply("commands matching %s: " % what, result, nr=1)
    else:
        ievent.reply('no matching commands found for %s' % what)
Example #3
0
def handle_throttleset(bot, ievent):
    try:
        (nick, cpm) = ievent.args
    except ValueError:
        ievent.missing('<nick> <commands per minute>')
        return
    uh = getwho(bot, nick)
    if not uh:
        ievent.reply("can't find userhost of %s" % nick)
        return
    perms = users.getperms(uh)
    if 'OPER' in perms:
        ievent.reply("can't throttle a OPER")
        return
    try:
        cpm = float(cpm)
        if cpm == 0:
            ievent.reply("cpm can't be zero")
            return
        state['level'][uh] = cpm
        state['cpm'][uh] = 0
        state.save()
    except ValueError:
        ievent.reply('%s is not an integer' % cpm)
        return
    try:
        bot.throttle.remove(uh)
    except ValueError:
        pass
    ievent.reply('cpm set to %s for %s' % (cpm, uh))
Example #4
0
def handle_apro(bot, ievent):

    """ apro <cmnd> .. apropos for command. """

    try:
        what = ievent.args[0]
    except IndexError:
        ievent.missing('<what>')
        return

    result = []
    perms = users.getperms(ievent.userhost)

    for i in cmnds.apropos(re.escape(what), perms=perms):
        alias = aliasreverse(i)
        if alias:
            result.append('%s (%s)' % (i, alias))
        else:
            result.append(i)

    res = []

    for alias in aliases.data:
        if what in alias and not what in result:
            res.append(alias)

    result.extend(res)

    if result:
        ievent.reply("commands matching %s: " % what, result , nr=1)
    else: 
        ievent.reply('no matching commands found for %s' % what)
Example #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))
Example #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))