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
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()
def setup(client): client.mod_online_lock = allocate_lock() client.online_players = [] if not SingleStat.get(ref='mod_online.count'): SingleStat(dict(ref='mod_online.count', data='0')).add() commit_and_close()