feat(tasklist): Show tasklists in private rooms.

Also adds a `get_rooms` method to the `RoomCog`.
This commit is contained in:
2023-09-11 15:16:19 +03:00
parent 8e54186649
commit 494484fc3c
3 changed files with 27 additions and 2 deletions

View File

@@ -9,10 +9,10 @@ active = [
'.ranks', '.ranks',
'.reminders', '.reminders',
'.shop', '.shop',
'.tasklist',
'.statistics', '.statistics',
'.pomodoro', '.pomodoro',
'.rooms', '.rooms',
'.tasklist',
'.rolemenus', '.rolemenus',
'.member_admin', '.member_admin',
'.moderation', '.moderation',

View File

@@ -57,6 +57,21 @@ class RoomCog(LionCog):
for task in self._ticker_tasks.values(): for task in self._ticker_tasks.values():
task.cancel() task.cancel()
def get_rooms(self, guildid: int, userid: Optional[int] = None):
"""
Get the private rooms in the given guild, using cache.
If `userid` is provided, filters by rooms which the given user is a member or owner of.
"""
guild_rooms = self._room_cache[guildid]
if userid:
rooms = {
cid: room for cid, room in guild_rooms.items() if userid in room.members or userid == room.data.ownerid
}
else:
rooms = guild_rooms
return rooms
async def _prepare_rooms(self, room_data: list[RoomData.Room]): async def _prepare_rooms(self, room_data: list[RoomData.Room]):
""" """
Launch or destroy rooms from the provided room data. Launch or destroy rooms from the provided room data.

View File

@@ -173,7 +173,17 @@ class TasklistCog(LionCog):
if not channel.guild: if not channel.guild:
return True return True
channels = (await self.settings.tasklist_channels.get(channel.guild.id)).value channels = (await self.settings.tasklist_channels.get(channel.guild.id)).value
return (channel in channels) or (channel.category in channels) # Also allow private rooms
roomcog = self.bot.get_cog('RoomCog')
if roomcog:
private_rooms = roomcog.get_rooms(channel.guild.id)
private_channels = {room.data.channelid for room in private_rooms.values()}
else:
logger.warning(
"Fetching tasklist channels before private room cog is loaded!"
)
private_channels = {}
return (channel in channels) or (channel.id in private_channels) or (channel.category in channels)
async def call_tasklist(self, interaction: discord.Interaction): async def call_tasklist(self, interaction: discord.Interaction):
await interaction.response.defer(thinking=True, ephemeral=True) await interaction.response.defer(thinking=True, ephemeral=True)