Example #1
0
        def _gotItem(item, length):
            if args and length == None:
                try:
                    length = timediff_from_str(args.pop(0))
                except InvalidTimeDiffString as e:
                    raise InputError(str(e))
            elif length == None:
                length = config.getduration(
                    self.name.capitalize(), 'default duration')
            item.length = length

            if args:
                item.meta['reason'] = ' '.join(args)

            applied = self.retrieve_real_list().addCallback(item.check_applied)
            def _applied(applied):
                if new:
                    self.listed.append(item)
                    synced = item.sync_with_self()
                else:
                    synced = item.update_db()
                def _reply(self):
                    if new:
                        call.reply(_("{item} created.").format(item=item).capitalize())
                    else:
                        call.reply(_("{item} edited.").format(item=item).capitalize())
                synced.addCallback(_reply)
            applied.addCallback(_applied)

            return item
Example #2
0
    def periodic_check(self):
        self.retrieve_real_list().addCallback(self.sync)
        
        try:
            self.next_check.cancel()
        except (AttributeError, AlreadyCalledError, AlreadyCancelledError):
            pass

        self.next_check = reactor.callLater(
                config.getduration(self.name.capitalize(), 'check interval'),
                self.periodic_check
            )
        def _doTransaction(txn):
            params = dict(zip([str(i) for i in range(len(games))], games))
            params.update({'time': itime()-config.getduration("Pickup player tracking", "top10 spread")})
            txn.execute("""
                SELECT name FROM pickup_players_games
                WHERE
                    (""" + \
                    ' OR '.join(['game=:%d' % i for i in range(len(games))]) \
                    + """)
                    AND time>:time""", params )

            players = {}

            for (player,) in txn.fetchall():
                try:
                    players[player] += 1
                except KeyError:
                    players[player] = 1

            ordered = players.items()
            ordered.sort(None, lambda x: x[1], True)

            return ordered[:10]
    def purgeGames(self, call, args):
        """!purgegames [keep]

        Purges the played games list from entries recorded earlier than
        [keep] ago. Uses !top10 spread otherwise if [keep] isn't
        provided."""
        if len(args):
            try:
                keep = timediff_from_str(' '.join(args))
            except InvalidTimeDiffString as e:
                raise InputError(e)
        else:
            keep = config.getduration("Pickup player tracking", "top10 spread")
        d = call.confirm(
            "This will delete the record of every game started earlier than {0}, continue?".format(str_from_timediff(keep))
            )
        def _confirmed(ret):
            if ret:
                def done(*args):
                    call.reply("Done.")
                self._purge(keep).addCallback(done)
            else:
                call.reply("Cancelled.")
        d.addCallback(_confirmed)