示例#1
0
 def expiry(self):
     """Utility function to get a string like "expires in 10 minutes"."""
     if self.deleted:
         return _('lifted %s') % str_from_timediff(int(itime())-self.deleted)
     elif not self.length:
         return _('permanent')
     elif self.length + self.start < itime():
         return _('expired %s') % str_from_timediff(int(itime())-self.length-self.start)
     else:
         return _("expires %s") % str_from_timediff(self.length+self.start-int(itime()), future=True)
        def _printResult(r):
            if len(r) < 1:
                if args and args[0].startswith('#'):
                    call.reply(_("No record for game #{0}").format(id))
                else:
                    call.reply(_("No game played yet in mode(s): {0}").format(' '.join(games)))
                return
            gamenick, gtime, players_, captains_, id_ = r[0]
            if ',' in players_:
                players = json.loads(players_)
                captains = json.loads(captains_)
            else:
                players = players_.split()
                captains = captains_.split()
            try:
                game = self.pickup.get_game(call, [gamenick])
                gamename = game.name
                teamnameFactory = game.teamname
            except InputError:
                gamename = _("Unknown(%s)") % gamenick
                teamnameFactory = lambda i: _("Team {0}").format(i + 1)

            timestr = str_from_timediff(itime()-gtime)

            if captains:
                call.reply(config.get('Pickup player tracking', 'lastgame').decode('string-escape') % \
                    {
                        'name': gamename,
                        'nick': gamenick,
                        'id': id_,
                        'when': timestr,
                        'playerlist': ', '.join(players),
                        'captainlist': ', '.join(captains)
                    })
            elif not isinstance(players[0], StringTypes):
                call.reply(config.get('Pickup player tracking', 'lastgame autopick').decode('string-escape') % \
                    {
                        'name': gamename,
                        'nick': gamenick,
                        'id': id_,
                        'when': timestr,
                        'teamslist': ', '.join([
                            config.get('Pickup messages', 'game ready autopick team').decode('string-escape')%
                            {
                                'name': teamnameFactory(i),
                                'players': ', '.join(team)
                            }
                            for i, team in enumerate(players)])
                    })
            else:
                call.reply(config.get('Pickup player tracking', 'lastgame nocaptains').decode('string-escape') % \
                    {
                        'name': gamename,
                        'nick': gamenick,
                        'id': id_,
                        'when': timestr,
                        'playerlist': ', '.join(players),
                    })
    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)