(rooms): Fetch guilds from other shards.

Manually requests guilds from other shards in `rooms` display.
This commit is contained in:
2022-01-14 18:59:28 +02:00
parent b124cf8e1e
commit beb7a737d4

View File

@@ -525,11 +525,24 @@ async def cmd_rooms(ctx):
), ),
_extra="GROUP BY start_at, slotid, guildid ORDER BY start_at ASC" _extra="GROUP BY start_at, slotid, guildid ORDER BY start_at ASC"
) )
attendees = {row['start_at']: (row['num'], client.get_guild(row['guildid'])) for row in rows} attendees = {
row['start_at']: (row['num'], row['guildid']) for row in rows
}
attendee_pad = max((len(str(num)) for num, _ in attendees.values()), default=1) attendee_pad = max((len(str(num)) for num, _ in attendees.values()), default=1)
# TODO: Allow cancel to accept multiselect keys as args # TODO: Allow cancel to accept multiselect keys as args
show_guild = any(guild != ctx.guild for _, guild in attendees.values()) show_guild = any(guildid != ctx.guild.id for _, guildid in attendees.values())
guild_map = {}
if show_guild:
for _, guildid in attendees.values():
if guildid not in guild_map:
guild = ctx.client.get_guild(guildid)
if not guild:
try:
guild = await ctx.client.fetch_guild(guildid)
except discord.HTTPException:
guild = None
guild_map[guildid] = guild
booked_list = '\n'.join( booked_list = '\n'.join(
"`{:>{}}` attendees | {} {}".format( "`{:>{}}` attendees | {} {}".format(
@@ -537,11 +550,11 @@ async def cmd_rooms(ctx):
attendee_pad, attendee_pad,
time_format(start), time_format(start),
"" if not show_guild else ( "" if not show_guild else (
"on this server" if guild == ctx.guild else "in **{}**".format( "on this server" if guildid == ctx.guild.id else "in **{}**".format(
guild.name if guild else guild.id guild_map[guildid] or "Unknown"
) )
) )
) for start, (num, guild) in attendees.items() ) for start, (num, guildid) in attendees.items()
) )
booked_field = ( booked_field = (
"{}\n\n" "{}\n\n"