[scripts/discord-whois] fix a crash on users with the default avatar

This commit is contained in:
Dmytro Meleshko 2021-01-02 00:58:04 +02:00
parent 11e651e1cb
commit ed7835b342

View file

@ -62,18 +62,20 @@ def bool_to_yes_no(value):
print_field("ID", data["id"])
print_field("Name", "{}#{}".format(data["username"], data["discriminator"]))
print_field(
"Avatar",
default_avatar_url = "https://cdn.discordapp.com/embed/avatars/{}.png".format(
int(data["discriminator"], 10) % 5
)
avatar_url = (
"https://cdn.discordapp.com/avatars/{}/{}.{}".format(
data["id"], data["avatar"], "gif" if data["avatar"].startswith("a_") else "png"
),
)
print_field(
"Default avatar",
"https://cdn.discordapp.com/embed/avatars/{}.png".format(
int(data["discriminator"], 10) % 5
),
)
if data["avatar"] is not None
else default_avatar_url
)
print_field("Avatar", avatar_url)
print_field("Default avatar", default_avatar_url)
print_field("Bot", bool_to_yes_no(data.get("bot", False)))
print_field("System user", bool_to_yes_no(data.get("system", False)))