Esempio n. 1
0
 def setup_tournaments(self) -> None:
     info = tournaments.next_tournament_info()
     self.next_tournament_name = info['next_tournament_name']
     self.next_tournament_time = info['next_tournament_time']
     self.tournaments = sorted(tournaments.all_series_info(),
                               key=lambda t: t.time)
     leagues = competition.load_competitions(
         "c.competition_series_id IN (SELECT id FROM competition_series WHERE name = 'League') AND c.end_date > UNIX_TIMESTAMP(NOW())"
     )
     end_date, prev_month, shown_end = None, None, False
     for t in self.tournaments:
         month = t.time.strftime('%b')
         if month != prev_month:
             t.month = month
             prev_month = month
         t.date = t.time.day
         if leagues and t.time >= leagues[
                 -1].start_date and t.time < leagues[-1].end_date:
             t.league = leagues.pop(-1)
             t.league.display = True
             end_date = t.league.end_date
         elif not shown_end and end_date and t.time >= end_date:
             t.league = {'class': 'begin', 'display': False}
             shown_end = True
         elif end_date:
             t.league = {'class': 'ongoing', 'display': False}
    def __init__(self):

        info = tournaments.next_tournament_info()
        self.next_tournament_name = info['next_tournament_name']
        self.next_tournament_time = info['next_tournament_time']

        self.tournaments = [
            {
                'name': 'Penny Dreadful Mondays',
                'host': 'stash86',
                'display_time': '7pm Eastern',
                'time': info['pdm_time'],
                'chat_room': '#PDM'
            },
            {
                'name': 'Penny Dreadful Thursdays',
                'host': 'silasary',
                'display_time': '7pm Eastern',
                'time': info['pdt_time'],
                'chat_room': '#PDT'
            },
            {
                'name': 'Penny Dreadful Sundays',
                'host': 'bakert99',
                'display_time': '1:30pm Eastern',
                'time': info['pds_time'],
                'chat_room': '#PDS'
            }
        ]
    def __init__(self):

        info = tournaments.next_tournament_info()
        self.next_tournament_name = info['next_tournament_name']
        self.next_tournament_time = info['next_tournament_time']
        self.leaderboards_url = url_for('tournament_leaderboards')

        self.tournaments = sorted(tournaments.all_series_info(),
                                  key=lambda t: t.time)
        leagues = competition.load_competitions(
            "c.competition_series_id IN (SELECT id FROM competition_series WHERE name = 'League') AND c.end_date > UNIX_TIMESTAMP(NOW())"
        )
        end_date, prev_month, shown_end = None, None, False
        for t in self.tournaments:
            month = t.time.strftime('%b')
            if month != prev_month:
                t.month = month
                prev_month = month
            t.date = t.time.day
            if len(leagues) > 0 and t.time >= leagues[
                    -1].start_date and t.time < leagues[-1].end_date:
                t.league = leagues.pop(-1)
                t.league.display = True
                end_date = t.league.end_date
            elif not shown_end and end_date and t.time >= end_date:
                t.league = {'class': 'begin', 'display': False}
                shown_end = True
            elif end_date:
                t.league = {'class': 'ongoing', 'display': False}
        self.num_tournaments = inflect.engine().number_to_words(
            len(self.tournaments))
        self.bugs_url = url_for('bugs')
        self.prizes = tournaments.prizes_by_finish()
Esempio n. 4
0
async def background_task_tournaments():
    await BOT.client.wait_until_ready()
    tournament_channel_id = configuration.get('tournament_channel_id')
    if not tournament_channel_id:
        return
    channel = discord.Object(id=tournament_channel_id)
    while not BOT.client.is_closed:
        info = tournaments.next_tournament_info()
        diff = info['next_tournament_time_precise']
        if diff <= 14400:
            embed = discord.Embed(title=info['next_tournament_name'], description='Starting in {0}.'.format(info['next_tournament_time']), colour=0xDEADBF)
            embed.set_image(url=fetcher.decksite_url('/favicon-152.png'))
            await BOT.client.send_message(channel, embed=embed)

        if diff <= 300:
            # Five minutes, final warning.  Sleep until the tournament has started.
            timer = 301
        elif diff <= 1800:
            # Half an hour. Sleep until 5 minute warning.
            timer = diff - 300
        elif diff <= 3600:
            # One hour.  Sleep until half-hour warning.
            timer = diff - 1800
        else:
            # Wait until four hours before tournament.
            timer = min(3600, diff - 14400)
        await asyncio.sleep(timer)
Esempio n. 5
0
    async def background_task_tournaments(self) -> None:
        try:
            await self.wait_until_ready()
            tournament_channel_id = configuration.get_int(
                'tournament_channel_id')
            if not tournament_channel_id:
                return
            channel = self.get_channel(tournament_channel_id)
            while not self.is_closed:
                info = tournaments.next_tournament_info()
                diff = info['next_tournament_time_precise']
                if info['sponsor_name']:
                    message = 'A {sponsor} sponsored tournament'.format(
                        sponsor=info['sponsor_name'])
                else:
                    message = 'A free tournament'
                embed = discord.Embed(title=info['next_tournament_name'],
                                      description=message)
                if diff <= 0:
                    embed.add_field(
                        name='Starting now',
                        value=
                        'Check <#334220558159970304> for further annoucements')
                elif diff <= 14400:
                    embed.add_field(name='Starting in:',
                                    value=dtutil.display_time(diff, 2))
                    embed.add_field(name='Pre-register now:',
                                    value='https://gatherling.com')

                if diff <= 14400:
                    embed.set_image(
                        url=fetcher.decksite_url('/favicon-152.png'))
                    # See #2809.
                    # pylint: disable=no-value-for-parameter,unexpected-keyword-arg
                    await channel.send(embed=embed)

                if diff <= 300:
                    # Five minutes, final warning.  Sleep until the tournament has started.
                    timer = 301
                elif diff <= 1800:
                    # Half an hour. Sleep until 5 minute warning.
                    timer = diff - 300
                elif diff <= 3600:
                    # One hour.  Sleep until half-hour warning.
                    timer = diff - 1800
                else:
                    # Wait until four hours before tournament.
                    timer = 3600 + diff % 3600
                    if diff > 3600 * 6:
                        # The timer can afford to get off-balance by doing other background work.
                        await self.background_task_spoiler_season()
                        multiverse.update_bugged_cards()

                if timer < 300:
                    timer = 300
                print('diff={0}, timer={1}'.format(diff, timer))
                await asyncio.sleep(timer)
        except Exception:  # pylint: disable=broad-except
            await self.on_error('background_task_tournaments')
Esempio n. 6
0
    async def background_task_tournaments(self) -> None:
        tournament_channel_id = configuration.get_int(
            'tournament_reminders_channel_id')
        if not tournament_channel_id:
            logging.warning('tournament channel is not configured')
            return
        channel = self.get_channel(tournament_channel_id)
        if not isinstance(channel, discord.abc.Messageable):
            logging.warning('ERROR: could not find tournament_channel_id {id}',
                            id=tournament_channel_id)
            return
        while self.is_ready:
            info = tournaments.next_tournament_info()
            diff = info['next_tournament_time_precise']
            if info['sponsor_name']:
                message = 'A {sponsor} sponsored tournament'.format(
                    sponsor=info['sponsor_name'])
            else:
                message = 'A free tournament'
            embed = discord.Embed(title=info['next_tournament_name'],
                                  description=message)
            if diff <= 1:
                embed.add_field(
                    name='Starting now',
                    value='Check <#334220558159970304> for further annoucements'
                )
            elif diff <= 14400:
                embed.add_field(name='Starting in:',
                                value=dtutil.display_time(diff, 2))
                embed.add_field(name='Pre-register now:',
                                value='https://gatherling.com')

            if diff <= 14400:
                embed.set_image(url=fetcher.decksite_url('/favicon-152.png'))
                # See #2809.
                # pylint: disable=no-value-for-parameter,unexpected-keyword-arg
                await channel.send(embed=embed)

            if diff <= 300:
                # Five minutes, final warning.  Sleep until the tournament has started.
                timer = 301
            elif diff <= 1800:
                # Half an hour. Sleep until 5 minute warning.
                timer = diff - 300
            elif diff <= 3600:
                # One hour.  Sleep until half-hour warning.
                timer = diff - 1800
            else:
                # Sleep for one hour plus enough to have a whole number of hours left.
                timer = 3600 + diff % 3600
                if diff > 3600 * 6:
                    # The timer can afford to get off-balance by doing other background work.
                    await multiverse.update_bugged_cards_async()

            if timer < 300:
                timer = 300
            await asyncio.sleep(timer)
        logging.warning('naturally stopping tournament reminders')
Esempio n. 7
0
 async def tournament(self, bot, channel):
     """!tournament` Get information about the next tournament."""
     t = tournaments.next_tournament_info()
     await bot.client.send_message(
         channel,
         'The next tournament is {name} in {time}.\nSign up on <http://gatherling.com/>.\nMore information: {url}'
         .format(name=t['next_tournament_name'],
                 time=t['next_tournament_time'],
                 url=fetcher.decksite_url('/tournaments/')))
 async def tournament(self, client: Client, channel: Channel, **_: Dict[str, Any]) -> None:
     """`!tournament` Get information about the next tournament."""
     t = tournaments.next_tournament_info()
     prev = tournaments.previous_tournament_info()
     if prev['near']:
         started = 'it started '
     else:
         started = ''
     prev_message = 'The last tournament was {name}, {started}{time} ago'.format(name=prev['next_tournament_name'], started=started, time=prev['next_tournament_time'])
     next_time = 'in ' + t['next_tournament_time'] if t['next_tournament_time'] != dtutil.display_time(0, 0) else t['next_tournament_time']
     await client.send_message(channel, 'The next tournament is {name} {next_time}.\nSign up on <http://gatherling.com/>\nMore information: {url}\n{prev_message}'.format(name=t['next_tournament_name'], next_time=next_time, prev_message=prev_message, url=fetcher.decksite_url('/tournaments/')))
Esempio n. 9
0
async def tournament(ctx: MtgContext) -> None:
    """Information about the next tournament."""
    t = tournaments.next_tournament_info()
    prev = tournaments.previous_tournament_info()
    if prev['near']:
        started = 'it started '
    else:
        started = ''
    prev_message = 'The last tournament was {name}, {started}{time} ago'.format(
        name=prev['next_tournament_name'], started=started, time=prev['next_tournament_time'])
    next_time = 'in ' + t['next_tournament_time'] if t['next_tournament_time'] != dtutil.display_time(
        0, 0) else t['next_tournament_time']
    await ctx.send('The next tournament is {name} {next_time}.\nSign up on <http://gatherling.com/>\nMore information: {url}\n{prev_message}'.format(name=t['next_tournament_name'], next_time=next_time, prev_message=prev_message, url=fetcher.decksite_url('/tournaments/')))
Esempio n. 10
0
async def background_task_tournaments() -> None:
    await BOT.client.wait_until_ready()
    tournament_channel_id = configuration.get('tournament_channel_id')
    if not tournament_channel_id:
        return
    channel = discord.Object(id=tournament_channel_id)
    while not BOT.client.is_closed:
        info = tournaments.next_tournament_info()
        diff = info['next_tournament_time_precise']
        if diff <= 0:
            message = 'Tournament starting!'
        elif diff <= 14400:
            message = 'Starting: {0}.'.format(dtutil.display_time(diff, 2))

        if diff <= 14400:
            embed = discord.Embed(title=info['next_tournament_name'],
                                  description=message)
            embed.set_image(url=fetcher.decksite_url('/favicon-152.png'))
            # See #2809.
            # pylint: disable=no-value-for-parameter,unexpected-keyword-arg
            await BOT.client.send_message(channel, embed=embed)

        if diff <= 300:
            # Five minutes, final warning.  Sleep until the tournament has started.
            timer = 301
        elif diff <= 1800:
            # Half an hour. Sleep until 5 minute warning.
            timer = diff - 300
        elif diff <= 3600:
            # One hour.  Sleep until half-hour warning.
            timer = diff - 1800
        else:
            # Wait until four hours before tournament.
            timer = 3600 + diff % 3600
            if diff > 3600 * 6:
                # The timer can afford to get off-balance by doing other background work.
                await background_task_spoiler_season()
                multiverse.update_bugged_cards()

        if timer < 300:
            timer = 300
        print('diff={0}, timer={1}'.format(diff, timer))
        await asyncio.sleep(timer)