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')
async def update(self, channel: TextChannel, **_: Dict[str, Any]) -> None: """Forces an update to legal cards and bugs.""" oracle.legal_cards(force=True) multiverse.update_bugged_cards() multiverse.update_cache() multiverse.reindex() oracle.init(force=True) await channel.send('Reloaded legal cards and bugs.')
async def update(ctx: MtgContext) -> None: """Forces an update to legal cards and bugs.""" await ctx.send('Begun reloading legal cards and bugs.') multiverse.set_legal_cards() oracle.legal_cards(force=True) multiverse.update_bugged_cards() multiverse.rebuild_cache() multiverse.reindex() oracle.init(force=True) await ctx.send('Reloaded legal cards and bugs.')
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)
async def update(self, client: Client, channel: Channel, **_: Dict[str, Any]) -> None: """Forces an update to legal cards and bugs.""" oracle.legal_cards(force=True) multiverse.update_bugged_cards() await client.send_message(channel, 'Reloaded legal cards and bugs.')
def init(self) -> None: multiverse.init() multiverse.update_bugged_cards() oracle.init() self.run(configuration.get('token'))
async def update(self, bot, channel): """Forces an update to legal cards and bugs.""" oracle.legal_cards(force=True) multiverse.update_bugged_cards() await bot.client.send_message(channel, 'Reloaded legal cards and bugs.')
def scrape() -> None: multiverse.update_bugged_cards() multiverse.update_cache()
def init(self) -> None: multiverse.init() multiverse.update_bugged_cards() oracle.init() discordbot.commands.setup(self) self.run(configuration.get('token'))
def scrape(): multiverse.update_bugged_cards()
def init(self): multiverse.set_legal_cards() multiverse.update_bugged_cards() self.client.run(configuration.get('token'))
def init(self) -> None: multiverse.init() multiverse.update_bugged_cards() oracle.init() self.searcher = WhooshSearcher() self.client.run(configuration.get('token'))