async def next_event_finish(self): await self.bot.wait_until_ready() query = """SELECT id, start, finish, event_name, guild_id, channel_id, finish - CURRENT_TIMESTAMP AS "until_finish" FROM events ORDER BY "until_finish" LIMIT 1; """ event = await self.bot.pool.fetchrow(query) if not event: return await asyncio.sleep(3600) slim_config = SlimEventConfig(event['id'], event['start'], event['finish'], event['event_name'], event['channel_id'], event['guild_id']) # self.bot.utils.board_config.invalidate(self.bot.utils, slim_config.channel_id) if event['until_start'].total_seconds() < 0: await self.on_event_finish(slim_config) await asyncio.sleep(event['until_finish'].total_seconds()) await self.on_event_finish(slim_config)
async def next_event_starts(self): await self.bot.wait_until_ready() query = """SELECT id, start, finish, event_name, guild_id, channel_id, start - CURRENT_TIMESTAMP AS "until_start" FROM events WHERE start_report = False ORDER BY "until_start" LIMIT 1; """ event = await self.bot.pool.fetchrow(query) if not event: return await asyncio.sleep(3600) slim_config = SlimEventConfig(event['id'], event['start'], event['finish'], event['event_name'], event['channel_id'], event['guild_id']) if event['until_start'].total_seconds() < 0: await self.on_event_start(slim_config) await asyncio.sleep(event['until_start'].total_seconds()) await self.on_event_start(slim_config) query = "UPDATE events SET start_report = True WHERE id = $1" await self.bot.pool.execute(query, event['id'])
async def event_config_id(self, event_id: int) -> Union[None, SlimEventConfig]: query = """SELECT id, start, finish, event_name, channel_id, guild_id FROM events WHERE id = $1 """ fetch = await self.bot.pool.fetchrow(query, event_id) if not fetch: return None return SlimEventConfig(fetch['id'], fetch['start'], fetch['finish'], fetch['event_name'], fetch['channel_id'], fetch['guild_id'])
async def event_config(self, guild_id: int) -> Union[SlimEventConfig, None]: query = """SELECT id, start, finish, event_name, channel_id, guild_id FROM events WHERE guild_id = $1 AND CURRENT_TIMESTAMP < finish ORDER BY start DESC; """ fetch = await self.bot.pool.fetchrow(query, guild_id) if not fetch: return None return SlimEventConfig(fetch['id'], fetch['start'], fetch['finish'], fetch['event_name'], fetch['channel_id'], fetch['guild_id'])