fix (rent): Handle non-existent objects.

Handle room channel being deleted before expiry.
Handle room owner leaving the server before expiry.
This commit is contained in:
2021-10-25 14:37:38 +03:00
parent e9c812b65a
commit cf610ef44d
2 changed files with 14 additions and 5 deletions

View File

@@ -37,6 +37,15 @@ async def cmd_rent(ctx):
# Fetch the members' room, if it exists # Fetch the members' room, if it exists
room = Room.fetch(ctx.guild.id, ctx.author.id) room = Room.fetch(ctx.guild.id, ctx.author.id)
# Handle pre-deletion of the room
if room and not room.channel:
ctx.guild_settings.event_log.log(
title="Private study room not found!",
description="{}'s study room was deleted before it expired!".format(ctx.author.mention)
)
room.delete()
room = None
if room: if room:
# Show room status, or add/remove remebers # Show room status, or add/remove remebers
lower = ctx.args.lower() lower = ctx.args.lower()

View File

@@ -112,7 +112,8 @@ class Room:
@property @property
def owner(self): def owner(self):
""" """
The Member owning the room, if we can find them The Member owning the room.
May be `None` if the member is no longer in the guild, or is otherwise not visible.
""" """
guild = client.get_guild(self.data.guildid) guild = client.get_guild(self.data.guildid)
if guild: if guild:
@@ -122,6 +123,7 @@ class Room:
def channel(self): def channel(self):
""" """
The Channel corresponding to this rented room. The Channel corresponding to this rented room.
May be `None` if the channel was already deleted.
""" """
guild = client.get_guild(self.data.guildid) guild = client.get_guild(self.data.guildid)
if guild: if guild:
@@ -176,9 +178,6 @@ class Room:
""" """
Expire the room. Expire the room.
""" """
owner = self.owner
guild_settings = GuildSettings(owner.guild.id)
if self.channel: if self.channel:
# Delete the discord channel # Delete the discord channel
try: try:
@@ -189,9 +188,10 @@ class Room:
# Delete the room from data (cascades to member deletion) # Delete the room from data (cascades to member deletion)
self.delete() self.delete()
guild_settings = GuildSettings(self.data.guildid)
guild_settings.event_log.log( guild_settings.event_log.log(
title="Private study room expired!", title="Private study room expired!",
description="{}'s private study room expired.".format(owner.mention) description="<@{}>'s private study room expired.".format(self.data.ownerid)
) )
async def add_members(self, *members): async def add_members(self, *members):