mirror of https://github.com/stijndcl/didier
Typing
parent
4e205a02c7
commit
deba3ababa
|
@ -59,6 +59,9 @@ class Discord(commands.Cog):
|
||||||
async with self.client.postgres_session as session:
|
async with self.client.postgres_session as session:
|
||||||
event = await events.get_event_by_id(session, event_id)
|
event = await events.get_event_by_id(session, event_id)
|
||||||
|
|
||||||
|
if event is None:
|
||||||
|
return await self.client.log_error(f"Unable to find event with id {event_id}", log_to_discord=True)
|
||||||
|
|
||||||
channel = self.client.get_channel(event.notification_channel)
|
channel = self.client.get_channel(event.notification_channel)
|
||||||
|
|
||||||
embed = discord.Embed(title="Upcoming Events", colour=discord.Colour.blue())
|
embed = discord.Embed(title="Upcoming Events", colour=discord.Colour.blue())
|
||||||
|
@ -259,20 +262,22 @@ class Discord(commands.Cog):
|
||||||
embed.description = "\n".join(description_items)
|
embed.description = "\n".join(description_items)
|
||||||
return await ctx.reply(embed=embed, mention_author=False)
|
return await ctx.reply(embed=embed, mention_author=False)
|
||||||
else:
|
else:
|
||||||
event = await events.get_event_by_id(session, event_id)
|
result_event = await events.get_event_by_id(session, event_id)
|
||||||
if event is None:
|
if result_event is None:
|
||||||
return await ctx.reply(f"Found no event with id `{event_id}`.", mention_author=False)
|
return await ctx.reply(f"Found no event with id `{event_id}`.", mention_author=False)
|
||||||
|
|
||||||
embed = discord.Embed(title="Upcoming Events", colour=discord.Colour.blue())
|
embed = discord.Embed(title="Upcoming Events", colour=discord.Colour.blue())
|
||||||
embed.add_field(name="Name", value=event.name, inline=True)
|
embed.add_field(name="Name", value=result_event.name, inline=True)
|
||||||
embed.add_field(name="Id", value=event.event_id, inline=True)
|
embed.add_field(name="Id", value=result_event.event_id, inline=True)
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Timer", value=discord.utils.format_dt(event.timestamp, style="R"), inline=True
|
name="Timer", value=discord.utils.format_dt(result_event.timestamp, style="R"), inline=True
|
||||||
)
|
)
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Channel", value=self.client.get_channel(event.notification_channel).mention, inline=False
|
name="Channel",
|
||||||
|
value=self.client.get_channel(result_event.notification_channel).mention,
|
||||||
|
inline=False,
|
||||||
)
|
)
|
||||||
embed.description = event.description
|
embed.description = result_event.description
|
||||||
return await ctx.reply(embed=embed, mention_author=False)
|
return await ctx.reply(embed=embed, mention_author=False)
|
||||||
|
|
||||||
@commands.group(name="github", aliases=["gh", "git"], case_insensitive=True, invoke_without_command=True)
|
@commands.group(name="github", aliases=["gh", "git"], case_insensitive=True, invoke_without_command=True)
|
||||||
|
|
|
@ -45,15 +45,16 @@ class Timer:
|
||||||
# If there is a current (pending) task, and the new timer is sooner than the
|
# If there is a current (pending) task, and the new timer is sooner than the
|
||||||
# pending one, cancel it
|
# pending one, cancel it
|
||||||
if self._task is not None and not self._task.done():
|
if self._task is not None and not self._task.done():
|
||||||
if self.upcoming_timer > event.timestamp:
|
# The upcoming timer will never be None at this point, but Mypy is mad
|
||||||
|
if self.upcoming_timer is not None and self.upcoming_timer > event.timestamp:
|
||||||
self._task.cancel()
|
self._task.cancel()
|
||||||
else:
|
else:
|
||||||
# The new task happens after the existing task, it has to wait for its turn
|
# The new task happens after the existing task, it has to wait for its turn
|
||||||
return
|
return
|
||||||
|
|
||||||
self._task = self.client.loop.create_task(self.end_timer(endtime=event.timestamp, event_id=event.event_id))
|
|
||||||
self.upcoming_timer = event.timestamp
|
self.upcoming_timer = event.timestamp
|
||||||
self.upcoming_event_id = event.event_id
|
self.upcoming_event_id = event.event_id
|
||||||
|
self._task = self.client.loop.create_task(self.end_timer(endtime=event.timestamp, event_id=event.event_id))
|
||||||
|
|
||||||
async def end_timer(self, *, endtime: datetime, event_id: int):
|
async def end_timer(self, *, endtime: datetime, event_id: int):
|
||||||
"""Wait until a timer runs out, and then trigger an event to send the message"""
|
"""Wait until a timer runs out, and then trigger an event to send the message"""
|
||||||
|
|
Loading…
Reference in New Issue