Beispiel #1
0
    async def _make_new_race(self):
        # Make the race
        self._race_number += 1
        self._previous_race = self._current_race
        self._current_race = Race(self, self.race_info)
        await self._current_race.initialize()
        await self.update()

        # Send @mention message
        self._mentioned_users = []
        mention_text = ''
        for user in self._mention_on_new_race:
            mention_text += user.mention + ' '
            self._mentioned_users.append(user)

        self._mention_on_new_race = []

        if self.race_info.seeded:
            await self.client.send_message(
                self._channel,
                '{0}\nRace number {1} is open for entry. Seed: {2}.'.format(
                    mention_text, self._race_number,
                    self.current_race.race_info.seed))
        else:
            await self.client.send_message(
                self._channel,
                '{0}\nRace number {1} is open for entry.'.format(
                    mention_text, self._race_number))
Beispiel #2
0
    async def _begin_new_race(self):
        """Begin a new race"""
        # Shift to during-match commands
        self.channel_commands = self._during_match_channel_commands

        # Make the race
        match_race_data = await matchdb.get_match_race_data(self.match.match_id
                                                            )
        self._current_race = Race(self,
                                  self.match.race_info,
                                  race_config=RaceConfig(finalize_time_sec=15,
                                                         auto_forfeit=1))
        self._current_race_number = match_race_data.num_races + 1
        await self._current_race.initialize()

        # Enter the racers automatically
        for racer in self.match.racers:
            await self.current_race.enter_member(racer.member, mute=True)

        # Output text
        await self.write(
            'Please input the seed ({1}) and type `.ready` when you are ready for the {0} race. '
            'When both racers `.ready`, the race will begin.'.format(
                ordinal.num_to_text(match_race_data.num_finished + 1),
                self.current_race.race_info.seed))

        if self._countdown_to_match_future is not None:
            self._countdown_to_match_future.cancel()
Beispiel #3
0
async def record_race(race: Race) -> None:
    type_id = await get_race_type_id(race.race_info, register=True)

    async with DBConnect(commit=True) as cursor:
        # Record the race
        race_params = (
            race.start_datetime.strftime('%Y-%m-%d %H:%M:%S'),
            type_id,
            race.race_info.seed if race.race_info.seeded else 0,
            race.race_info.condor_race,
            race.race_info.private_race,
        )

        cursor.execute(
            """
            INSERT INTO {0}
                (timestamp, type_id, seed, condor, private)
            VALUES (%s,%s,%s,%s,%s)
            """.format(tn('races')),
            race_params
        )

        # Store the new race ID in the Race object
        cursor.execute("SELECT LAST_INSERT_ID()")
        race.race_id = int(cursor.fetchone()[0])

        # Record each racer in race_runs
        rank = 1
        for racer in race.racers:
            racer_params = (race.race_id, racer.user_id, racer.time, rank, racer.igt, racer.comment, racer.level)
            cursor.execute(
                """
                INSERT INTO {0}
                    (race_id, user_id, time, rank, igt, comment, level)
                VALUES (%s,%s,%s,%s,%s,%s,%s)
                """.format(tn('race_runs')),
                racer_params
            )
            if racer.is_finished:
                rank += 1