utility: fix extra 0 and fix default avatar

This commit is contained in:
Cynthia Foxwell 2024-07-28 16:16:30 -06:00
parent 9873780ac0
commit 3ec48e2bc9
2 changed files with 10 additions and 10 deletions

View file

@ -23,7 +23,7 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
const mod = res.headers.get("last-modified");
let description;
if (mod) {
const modDate = Math.floor(new Date(mod).getTime() / 10000);
const modDate = Math.floor(new Date(mod).getTime() / 1000);
description = `Updated <t:${modDate}:R>`;
}
@ -54,26 +54,26 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
};
const defaultAvatar = getDefaultAvatar(member.id, member.user?.discriminator ?? member.discriminator ?? 0);
const normalAvatar = member.user ? member.user.avatar ?? defaultAvatar : member.avatar ?? defaultAvatar;
const normalAvatar = member.user?.avatar ?? member.avatar;
const guildAvatar = guildObj ? member.avatar : null;
const normalUrl = CDNEndpoints.USER_AVATAR(member.id, normalAvatar);
const guildUrl = CDNEndpoints.GUILD_MEMBER_AVATAR(guildObj.id, member.id, guildAvatar);
const normalUrl = normalAvatar ? CDNEndpoints.USER_AVATAR(member.id, normalAvatar) : defaultAvatar;
const guildUrl = guildAvatar && CDNEndpoints.GUILD_MEMBER_AVATAR(guildObj.id, member.id, guildAvatar);
const res = await fetch(normalUrl, {method: "HEAD"});
const mod = res.headers.get("last-modified");
let modStr = "";
if (mod) {
const modDate = Math.floor(new Date(mod).getTime() / 10000);
const modDate = Math.floor(new Date(mod).getTime() / 1000);
modStr = ` \u2022 Updated <t:${modDate}:R>`;
}
let modStrGuild = "";
if (guildAvatar) {
if (guildUrl) {
const guildRes = await fetch(guildUrl, {method: "HEAD"});
const guildMod = guildRes.headers.get("last-modified");
if (guildMod) {
const modDate = Math.floor(new Date(guildMod).getTime() / 10000);
const modDate = Math.floor(new Date(guildMod).getTime() / 1000);
modStrGuild = ` \u2022 Updated <t:${modDate}:R>`;
}
}

View file

@ -25,7 +25,7 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
const mod = res.headers.get("last-modified");
let description;
if (mod) {
const modDate = Math.floor(new Date(mod).getTime() / 10000);
const modDate = Math.floor(new Date(mod).getTime() / 1000);
description = `Updated <t:${modDate}:R>`;
}
@ -67,7 +67,7 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
const mod = res.headers.get("last-modified");
let modStr;
if (mod) {
const modDate = Math.floor(new Date(mod).getTime() / 10000);
const modDate = Math.floor(new Date(mod).getTime() / 1000);
modStr = `Updated <t:${modDate}:R>`;
}
@ -76,7 +76,7 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
const guildRes = await fetch(guildUrl, {method: "HEAD"});
const guildMod = guildRes.headers.get("last-modified");
if (guildMod) {
const modDate = Math.floor(new Date(guildMod).getTime() / 10000);
const modDate = Math.floor(new Date(guildMod).getTime() / 1000);
modStrGuild = `Updated <t:${modDate}:R>`;
}
}