General tracker.py improvements
Mostly speed-ups by awaiting multiple awaits where there's not a dependency on each other's results, and bounds checks
This commit is contained in:
parent
62c205aa35
commit
3a06464c29
@ -157,7 +157,7 @@ class Tracker(Extension):
|
|||||||
|
|
||||||
@slash_command(
|
@slash_command(
|
||||||
name="add-alert",
|
name="add-alert",
|
||||||
description="List all alerts you have signed up for"
|
description="Add an alert listener"
|
||||||
)
|
)
|
||||||
async def add_alert(self, ctx: SlashContext):
|
async def add_alert(self, ctx: SlashContext):
|
||||||
if not await self._users.exists(ctx.user.id):
|
if not await self._users.exists(ctx.user.id):
|
||||||
@ -184,8 +184,10 @@ class Tracker(Extension):
|
|||||||
else:
|
else:
|
||||||
alert = Alert(alert_type, flavor, user.region)
|
alert = Alert(alert_type, flavor, user.region)
|
||||||
if not await self._users.is_subscribed(user, alert):
|
if not await self._users.is_subscribed(user, alert):
|
||||||
await self._users.add_alert(user, alert)
|
await asyncio.gather(
|
||||||
await self._alerts.add_user(alert, user)
|
self._users.add_alert(user, alert),
|
||||||
|
self._alerts.add_user(alert, user)
|
||||||
|
)
|
||||||
await ctx.send("Successfully added alert", ephemeral=True)
|
await ctx.send("Successfully added alert", ephemeral=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -197,14 +199,26 @@ class Tracker(Extension):
|
|||||||
description="Remove an alert you have signed up for"
|
description="Remove an alert you have signed up for"
|
||||||
)
|
)
|
||||||
async def remove_alert(self, ctx: SlashContext):
|
async def remove_alert(self, ctx: SlashContext):
|
||||||
|
if not await self._users.exists(ctx.user.id):
|
||||||
|
await ctx.send("You are not registered with any region\n"
|
||||||
|
"Please register with /register before adding alerts",
|
||||||
|
ephemeral=True)
|
||||||
|
return
|
||||||
user = await self._users.get(ctx.user.id)
|
user = await self._users.get(ctx.user.id)
|
||||||
|
alerts = await self._users.list_alerts(user)
|
||||||
|
if len(alerts) == 0:
|
||||||
|
await ctx.send("You do not have any alerts registered", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
alert = await self.remove_alert_select_menu(ctx, user)
|
alert = await self.remove_alert_select_menu(ctx, user)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
await self._users.remove_alert(user, alert)
|
await asyncio.gather(
|
||||||
await self._alerts.remove_user(alert, user)
|
self._users.remove_alert(user, alert),
|
||||||
|
self._alerts.remove_user(alert, user)
|
||||||
|
)
|
||||||
await ctx.send("Successfully removed alert", ephemeral=True)
|
await ctx.send("Successfully removed alert", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user