示例#1
0
def seen(client, nick, crawler):
    """
    `.seen <player>|(most [num:5])` -- get the last time the given player was 
    seen, or a list of the most seen players.
    """
    if crawler.chain:
        pl = crawler.quoted()
        a0 = pl.lower()
    else:
        a0 = 'most'
    
    if _is_bot(a0):
        return 'That isn\'t important!'
    
    ticks = int(SingleStat.get(ref='mod_online.count').data)
    
    if a0 == 'most':
        arg = crawler.chain.strip()
        top = int(arg) if (arg and arg.isdigit()) else 5
        # Show max of ten entries
        top = min(top, 10)
        
        # Inefficient -_-
        L = list(Sighting.all())
        L.sort(key=lambda sighting: sighting.count, reverse=True)
        
        msg = ''
        new = True
        for s in L[:top]:
            pl = s.player
            msg += ('Last seen %s, ' % time_msg(s.time, client, pl) + 
                    '%s was seen %s;' % (pl, count_msg(s.count, ticks)) + 
                    (' ' if new else '\n'))
            
            new = not new
        
    else:
        s = Sighting.get(player=a0)
        if not s:
            return 'Sorry, but I haven\'t ever seen %s.' % pl
        msg = 'I last saw %s %s. ' % (pl, time_msg(s.time, client, a0))
        msg += 'I saw %s %s. ' % (pl, count_msg(s.count, ticks))
    
    close_connection()
    return msg
示例#2
0
def refresh_sightings(client):
    """
    Refresh the list of player sightings.
    """
    for p in client.online_players:
        if _is_bot(p):
            continue
        
        s = Sighting.get(player=p)
        if not s:
            s = Sighting(dict(player=p, time=0, count=0))
            s.add()
        s.count += 1
        s.time = time()
    
    stats = SingleStat.get(ref='mod_online.count')
    stats.data = str(int(stats.data) + 1)
    commit_and_close()
示例#3
0
def recent(client, nick, crawler):
    """
    `.recently-seen [number:5]` -- get a list of the most recently seen players.
    """
    number = int(crawler.chain) if crawler.chain else 5
    number = min(number, 20)    # Need a maximum!
    L = list(Sighting.all())
    L.sort(key=lambda sighting: sighting.time, reverse=True)
    
    msg = ''
    new = True
    for s in L[:number]:
        pl = s.player
        msg += '%s was last seen %s' % (pl, time_msg(s.time, client, pl))
        msg += ', ' if new else ';\n'
        
        new = not new
    
    close_connection()
    return msg[:-2] + '.'