Esempio n. 1
0
def h_names(bot, chan, include_prefix):
    if chan.lower() in track_channels and chan.lower() in umode_channels:
        # Return the cached names if they exist.
        nicks = track_channels[chan.lower()]
        umode = umode_channels[chan.lower()]
    else:
        # Otherwise, retrieves the names from the server.
        bot.send_cmd('NAMES %s' % chan)
        while True:
            event, data = yield hold(bot, 'NAMES_SYNC')
            e_bot, e_chan, nicks, umode = data
            if e_chan.lower() == chan.lower(): break
    # Reconstruct the nick prefixes from the nicks and their modes.
    pre_ms, pre_cs = bot.isupport['PREFIX']
    names = []
    for nick in nicks:
        for pre_m, pre_c in izip(pre_ms, pre_cs):
            if pre_m in umode.get(nick.lower(), ''):
                prefix, sort_key = pre_c, (-pre_cs.index(pre_c), nick.lower())
                break
        else:
            prefix, sort_key = '', (None, nick.lower())
        names.append((sort_key, prefix+nick if include_prefix else nick))
    names = [n for (_,n) in sorted(names, reverse=True)]
    yield sign(('channel.names', bot, chan, include_prefix), names)
Esempio n. 2
0
def h_self_join(bot, chan):
    while True:
        _event, (_bot, _chan, _nicks, _mnicks) = yield hold(bot, 'NAMES_SYNC')
        if _chan.lower() == chan.lower(): break
    nicks = sorted(n for n in _nicks if n.lower() != bot.nick.lower())
    ids = yield identity.get_ids(bot, nicks)
    for id in ids:
        if id is not None: notify_msgs(bot, id, chan)
Esempio n. 3
0
def registered(bot, *rargs):
    if conf('password') and bot.nick == getattr(bot, 'auto_nick', None):
        nick_status = yield status(bot, bot.conf['nick'])
        if nick_status == 1:
            bot.send_msg(
                conf('nickserv').nick,
                'GHOST %s %s' % (bot.conf['nick'], conf('password')))
            bot.send_cmd('NICK %s' % bot.conf['nick'])
    if conf('password'):
        timeout = yield runtime.timeout(30)
        yield hold(bot, 'NICKSERV_REGISTERED', timeout)
    yield sign(IDENTIFIED, bot, *rargs)
Esempio n. 4
0
 def mmcall_wait():
     mode.unlink(token, mmcall_wait)
     wait_calls = list(calls)
     results = [None for c in wait_calls]
     complete = [False for c in wait_calls]
     while not all(complete):
         wait_call, (result,) = yield hold(mode, *filter(id, wait_calls))
         i = wait_calls.index(wait_call)
         results[wait_calls.index(wait_call)] = result
         complete[i] = True
         wait_calls[i] = None
     yield msign(mode, (token,), results)
Esempio n. 5
0
def check(bot, id):
    if id.nick not in admins: return just(('RESULT', [False]))
    if id in passed: return just(('RESULT', [True]))
    mode = Mode()
    def notice(bot, nick, user, host, target, msg):
        if target != bot.nick: return
        if ID(nick, user, host) != nickserv: return
        match = re.match(r'STATUS (?P<nick>\S+) (?P<code>\S+)', msg)
        result = int(match.group('code')) >= 3
        if result: passed.add(id)
        yield msign(mode, 'RESULT', result)
        bot.unlink('NOTICE', notice)
    bot.link('NOTICE', notice)
    bot.send_msg(nickserv.nick, 'STATUS ' + id.nick)
    return hold(mode, 'RESULT')
Esempio n. 6
0
def h_topic(bot, chan):
    ret = lambda r: sign(('channel.topic', bot, chan), r)
    # Return the cached topic if it exists.
    if chan.lower() in topic_channels:
        yield ret(topic_channels[chan.lower()])
        return
    # Otherwise, retrieve the topic from the server.
    bot.send_cmd('TOPIC %s' % chan)
    while True:
        (event, data) = yield hold(bot, ERR_NOTONCHAN, 'CHAN_TOPIC')
        if event == 'CHAN_TOPIC':
            e_bot, e_chan, e_topic = data[:3]
            if e_chan.lower() != chan.lower(): continue
            yield ret(e_topic)
        else:
            e_bot, e_src, e_tgt, e_chan = data[:4]
            if e_chan.lower() != chan.lower(): continue
            yield ret(None)
        break
Esempio n. 7
0
def h_mode(bot, chan):
    ret = lambda r: sign(('channel.mode', bot, chan), r)
    # Return the cached mode if it exists.
    if chan.lower() in cmode_channels:
        yield ret(cmode_channels[chan.lower()])
        return
    # Otherwise, retrieve the mode from the server.
    bot.send_cmd('MODE %s' % chan)
    while True:
        event, data = yield hold(bot,
            ERR_NOTONCHAN, ERR_NOSUCHCHAN, 'CHAN_MODE_SYNC')
        if event == 'CHAN_MODE_SYNC':
            e_bot, e_chan, e_mode = data[:3]
            if e_chan.lower() != chan.lower(): continue
            yield ret(e_mode)
        else:
            e_bot, e_src, e_tgt, e_chan = data[:4]
            if e_chan.lower() != chan.lower(): continue
            yield ret(None)
        break
Esempio n. 8
0
def statuses(bot, nicks, ret, timeout_const_s=20, timeout_linear_s=1):
    global status_cache
    earliest = time.time() - STATUS_CACHE_SECONDS
    for nick, (status, stime) in status_cache.items():
        if stime < earliest:
            del status_cache[nick]

    nicks = map(str.lower, nicks)
    send_nicks = [n for n in nicks if n not in status_cache]
    for i in xrange(0, len(send_nicks), STATUS_BATCH):
        batch_nicks = ' '.join(send_nicks[i:i+STATUS_BATCH])
        bot.send_msg(conf('nickserv').nick, 'STATUS %s' % batch_nicks)

    result, remain = dict(), set()
    for nick in nicks:
        if nick not in status_cache:
            status_cache[nick] = (None, time.time())
            remain.add(nick)
        elif status_cache[nick][0] == None:
            remain.add(nick)
        else:
            result[nick] = status_cache[nick][0]

    if remain:
        lines = -(-len(send_nicks) // STATUS_BATCH)
        timeout = yield runtime.timeout(timeout_const_s + lines*timeout_linear_s)
    while remain:
        event, args = yield hold(bot, 'NICKSERV_NOTICE', timeout)
        if event == timeout: break
        e_bot, e_id, e_msg = args
        match = re.match(r'STATUS\s+(?P<nick>\S+)\s+(?P<code>\d+)', e_msg)
        if not match: continue
        nick, code = match.groups()
        if nick.lower() not in remain: continue

        result[nick.lower()] = int(code)
        remain.remove(nick.lower())
        status_cache[nick.lower()] = (int(code), time.time())

    yield ret(result)
Esempio n. 9
0
def h_nuke(bot, id, target, args, full_msg):
    if not target: return
    if not channel.has_op_in(bot, bot.nick, target, 'h'): return

    global nuclear_launch
    target_id = (target.lower(), ('%s!%s@%s' % id).lower())
    try:
        if target_id in nuclear_launch: return
    except NameError:
        nuclear_launch = set()
    nuclear_launch.add(target_id)

    message.reply(bot, id, target, 'Nuclear launch detected.', prefix=False)
    yield runtime.sleep(15)
    bot.send_cmd('KICK %s %s :Akuryou taisan!' % (target, id.nick))
    
    ERR_CHANOPRIVSNEEDED = '482'
    UNREAL_ERR_CANNOTDOCOMMAND = '972'
    timeout = yield runtime.timeout(10)
    while True:
        event, args = yield hold(bot, timeout,
            UNREAL_ERR_CANNOTDOCOMMAND, ERR_CHANOPRIVSNEEDED)
        if event == UNREAL_ERR_CANNOTDOCOMMAND:
            e_bot, e_src, e_tgt, e_cmd, e_args = args
            if e_cmd.upper() != 'KICK': continue
            message.reply(bot, id, target,
                'Nuclear launch failed: "%s".' % e_args, prefix=False)
        elif event == ERR_CHANOPRIVSNEEDED:
            e_bot, e_src, e_tgt, e_chan, e_args = args
            if e_chan.lower() != target.lower(): continue
            message.reply(bot, id, target,
                'Nuclear launch failed: "%s".' % e_args, prefix=False)
        elif event == timeout:
            break

    nuclear_launch.discard(target_id)
Esempio n. 10
0
def who(bot, nick, ret):
    for cnick, (_, ctime) in whois_cache.items():
        if ctime < time.time() - 10:
            del whois_cache[cnick]

    cached = whois_cache.get(nick.lower())
    if cached is not None and cached[0] is not None:
        result = cached[0]
    else:
        if cached is None:
            bot.send_cmd('WHOIS %s' % nick)
            whois_cache[nick.lower()] = (None, time.time())
        timeout = yield runtime.timeout(5)
        result = None
        while True:
            event, args = yield hold(bot, RPL_WHOISUSER, timeout)
            if event != RPL_WHOISUSER: break
            (e_bot, e_source, e_target,
             e_nick, e_user, e_host, e_star, e_real) = args
            if e_nick.lower() != nick.lower(): continue
            result = (e_nick, e_user, e_host, e_real)
            whois_cache[nick.lower()] = (result, time.time())
    
    yield ret(result)
Esempio n. 11
0
    # http://www.youtube.com/watch?v=U-BwZA70ZCI#t=168
    elif 'bananabanana' in strip_msg:
        remaining = [
            'bananabanana', 'cucumber', 'eggplant', 'caviar', 'papaya',
             'giantasparagus']
        start = time.clock()
        while True:
            part = ''
            while remaining and part + remaining[0] in strip_msg:
                part += remaining.pop(0)

            if len(remaining) <= 1: break

            bot.activity = True
            while True:
                _, (e_bot, e_chan, msg) = yield hold(bot, 'FTO_MSG')
                strip_msg = strip(msg)
                if e_chan and e_chan.lower() == chan.lower(): break
            if time.clock() - start > 3600: return
            if 'bananabanana' in strip_msg: return

        if remaining: reply('\2GIANT ASPARAGUS!')

    #---------------------------------------------------------------------------
    # HEYYEYAAEYAAAEYAEYAA
    # http://www.youtube.com/watch?v=6GggY4TEYbk
    elif re.search(r'ands?hetries', strip_msg) and not any(s in strip_msg \
    for s in ('ohmygod', 'doitry', 'itryallthetime', 'inthisinstitution')):
        reply('Oh my god, do I try!')
        yield runtime.sleep(1)
        reply('I try all the time... in this institution!')