Exemplo n.º 1
0
def h_command(bot, id, target, event, body, full_msg, action):
    bot.activity = False

    #=================================================================
    # (This should be in bridge.py.)
    s_event = ('SIMPLE', 'ACTION', event) if action else \
              ('SIMPLE',           event)
    no_echo = [False]
    replies = []
    def cmd_reply(rmsg=None, from_name=None, no_bridge=False, **kwds):
        if rmsg is not None or from_name is not None:
            if rmsg is None: rmsg = from_name(id.nick)
            replies.append(((bot, id, target, rmsg), kwds))
        no_echo[0] = no_echo[0] or no_bridge
    yield sign(s_event, bot, id.nick, target, body, cmd_reply)
    if not no_echo[0]:
        cmsg = ('* %s %s' if action else '<%s> %s') % (id.nick, full_msg)
        yield sign('IRC', bot, target, cmsg)
    for rargs, rkwds in replies:
        reply(*rargs, **rkwds)       
    #=================================================================
        
    if limit.mark_activity(bot, id, notify=target):
        return
    if action:
        event = ('ACTION', event)
    yield sign(event, bot, id, target, body, full_msg)
    if bot.activity: return
    yield sign('CMD_IGNORED', event, bot, id, target, body, full_msg)
Exemplo n.º 2
0
def mark_activity(bot, id, notify=False):
    global flood_count_start
    global flood_ignore_start
    global flood_ignore_notify

    now = time.time()
    userhost = (id.user, id.host)

    if flood_count_start is None \
    or now > flood_count_start + FLOOD_COUNT_PERIOD:
        flood_count.clear()
        flood_count_start = now

    if flood_ignore_start \
    and now > flood_ignore_start + 2*FLOOD_IGNORE_PERIOD:
        flood_ignore_new.clear()

    if flood_ignore_start is None \
    or now > flood_ignore_start + FLOOD_IGNORE_PERIOD:
        flood_ignore_old.clear()
        flood_ignore_old.update(flood_ignore_new)
        flood_ignore_new.clear()        
        flood_ignore_notify &= flood_ignore_old | flood_ignore_new
        flood_ignore_start = now
    
    flood_count[userhost] = flood_count.get(userhost, 0) + 1
    if flood_count[userhost] > FLOOD_COUNT_LIMIT:
        flood_ignore_new.add(userhost)

    if userhost in flood_ignore_new or userhost in flood_ignore_old:
        if notify != False and userhost not in flood_ignore_notify:
            minutes = FLOOD_IGNORE_PERIOD / 30
            if minutes == int(minutes):
                minutes = int(minutes)
            reply(bot, id, notify,
                'You have been ignored for %s minutes for sending'
                ' commands too quickly.' % minutes)
            flood_ignore_notify.add(userhost)
        return True
    else:
        return False
Exemplo n.º 3
0
def h_help(bot, name, target, args, reply, bridge):
    lines = []
    callback = lambda *args: lines.append(args)

    def header(str):
        return '\2%s%s\2' % ('!' if bot.conf['bang_cmd'] else '', str)

    if args:
        # Display help for a particular command.
        cmd, args = re.match(r'!?(\S+)\s*(.*)', args).groups()
        cmd = cmd.lower()
        yield sign(('BRIDGE', 'HELP', cmd) if bridge else ('HELP', cmd),
            bot, callback, args)
        if not lines:
            reply('Error: no help is available for "%s".' % cmd, no_bridge=True)
            return
        for line in lines:
            if line[0]: reply(header(line[0]), prefix=False, no_bridge=True)
            for para in line[1:]:
                if para: reply(para, prefix=False, no_bridge=True)

    elif not bridge:
        # Display general help and a summary of all commands.
        reply(
            'Commands are issued by saying%s "%s: !COMMAND",'
            ' where COMMAND is the command and its parameters.'
            ' The following commands are available:'
            % (' "!COMMAND" or' if bot.conf['bang_cmd'] else '', bot.nick),
            prefix=False, no_bridge=True)

        yield sign('HELP*', bot, callback, args)
        lines = map(lambda l: (header(l[0]),) + l[1:], lines)
        for line in util.align_table(lines):
            reply(line, prefix=False, no_bridge=True)

        del lines[:]
        yield sign('HELP', bot, callback, args)
        if lines: reply('Other commands: %s.' % ', '.join(
            '\2%s\2' % l[0].split()[0] for l in lines),
            prefix=False, no_bridge=True)

    else:
        yield sign(('BRIDGE', 'HELP*'), bot, callback, args)
        yield sign(('BRIDGE', 'HELP'), bot, callback, args)
        if lines:
            reply('Available commands: %s.' % ', '.join(
                '\2%s\2' % l[0].split()[0] for l in lines),
                prefix=False, no_bridge=True)
Exemplo n.º 4
0
def h_help_help(bot, reply, args):
    reply('help [COMMAND]',
    'If COMMAND is given, gives detailed information about its usage;'
    ' otherwise, gives a summary of all available commands.')
Exemplo n.º 5
0
def h_help_help_short(bot, reply, args):
    reply('help [COMMAND]',
    'Gives detailed information about COMMAND, or lists all commands.')