dakiny-bot#83 fix the view points bug when someone isn't in the guild anymore.
This commit is contained in:
+23
-5
@@ -264,16 +264,34 @@ def create_points_string(interaction: nextcord.Interaction, quarters: any, point
|
|||||||
sorted_non_members = None
|
sorted_non_members = None
|
||||||
sorted_members = members.sort_values(
|
sorted_members = members.sort_values(
|
||||||
by="UserId",
|
by="UserId",
|
||||||
key=lambda user_ids: (
|
key=lambda user_ids: ([member_lambda_string(interaction.guild, user_id) for user_id in user_ids]),
|
||||||
[interaction.guild.get_member(int(user_id)).display_name.lower() for user_id in user_ids]
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
sorted_all = pd.concat([sorted_members, sorted_non_members], ignore_index=True, sort=False)
|
sorted_all = pd.concat([sorted_members, sorted_non_members], ignore_index=True, sort=False)
|
||||||
for row in sorted_all.itertuples():
|
for row in sorted_all.itertuples():
|
||||||
userid = row.UserId
|
|
||||||
points = row.EventPoints if point_type == PointType.EVENT else row.ClanPoints
|
points = row.EventPoints if point_type == PointType.EVENT else row.ClanPoints
|
||||||
discord_member = row.DiscordMember
|
discord_member = row.DiscordMember
|
||||||
if points > 0:
|
if points > 0:
|
||||||
content += f"<@{userid}>: {points}\n" if discord_member else f"{userid}: {points}\n"
|
content += f"<@{row.UserId}>: {points}\n" if discord_member else f"{row.UserId}: {points}\n"
|
||||||
content += "\n"
|
content += "\n"
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def member_lambda_string(guild: nextcord.Guild, user_id: int) -> str:
|
||||||
|
"""
|
||||||
|
Finds a user in a guild and returns the display name.
|
||||||
|
|
||||||
|
Returns the user id in string form if user is no longer in guild.
|
||||||
|
I don't know if I like this name very much.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
guild (nextcord.Guild): Guild object to find the user in.
|
||||||
|
user_id (int): User id to get display name of.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: String to use for sorting.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return guild.get_member(int(user_id)).display_name.lower()
|
||||||
|
except AttributeError:
|
||||||
|
# The user is no longer a part of the guild
|
||||||
|
return str(user_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user