diff --git a/src/modules/utility/avatar.js b/src/modules/utility/avatar.js index 7c3e2b8..41f8b96 100644 --- a/src/modules/utility/avatar.js +++ b/src/modules/utility/avatar.js @@ -11,13 +11,13 @@ avatar.helpText = "Get avatar of a user"; avatar.usage = ""; avatar.callback = async function (msg, line, [user], {server, guild}) { let member = msg.member ?? msg.author; + const guildObj = msg.channel.guild || hf.bot.guilds.get(msg.guildID); if (server || guild) { if (!msg.guildID) { return "`--server/--guild` can only be used within guilds."; } else { - const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID); - const url = CDNEndpoints.GUILD_ICON(guild.id, guild.icon); + const url = CDNEndpoints.GUILD_ICON(guildObj.id, guildObj.icon); const res = await fetch(url, {method: "HEAD"}); const mod = res.headers.get("last-modified"); @@ -55,10 +55,10 @@ 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 guildAvatar = guild ? member.avatar : null; + const guildAvatar = guildObj ? member.avatar : null; const normalUrl = CDNEndpoints.USER_AVATAR(member.id, normalAvatar); - const guildUrl = CDNEndpoints.GUILD_MEMBER_AVATAR(guild.id, member.id, guildAvatar); + const guildUrl = CDNEndpoints.GUILD_MEMBER_AVATAR(guildObj.id, member.id, guildAvatar); const res = await fetch(normalUrl, {method: "HEAD"}); const mod = res.headers.get("last-modified"); @@ -68,17 +68,18 @@ avatar.callback = async function (msg, line, [user], {server, guild}) { modStr = ` \u2022 Updated `; } - const guildRes = await fetch(guildUrl, {method: "HEAD"}); - const guildMod = guildRes.headers.get("last-modified"); let modStrGuild = ""; - if (guildMod) { - const modDate = Math.floor(new Date(guildMod).getTime() / 10000); - modStrGuild = ` \u2022 Updated `; + if (guildAvatar) { + 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); + modStrGuild = ` \u2022 Updated `; + } } baseEmbed.description = - `[Normal avatar](${normalUrl})${modStr}` + - (guild && guildAvatar ? `\n[Guild avatar](${guildUrl})${modStrGuild}` : ""); + `[Normal avatar](${normalUrl})${modStr}` + (guildAvatar ? `\n[Guild avatar](${guildUrl})${modStrGuild}` : ""); baseEmbed.url = normalUrl; const guildEmbed = {...baseEmbed}; diff --git a/src/modules/utility/banner.js b/src/modules/utility/banner.js index 29d983c..74df090 100644 --- a/src/modules/utility/banner.js +++ b/src/modules/utility/banner.js @@ -16,11 +16,10 @@ banner.callback = async function (msg, line, [user], {server, guild}) { if (!msg.guildID) { return "`--server/--guild` can only be used within guilds."; } else { - const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID); + const guildObj = msg.channel.guild ?? hf.bot.guilds.get(msg.guildID); + if (!guildObj.banner) return "This guild does not have a banner."; - if (!guild.banner) return "This guild does not have a banner."; - - const url = CDNEndpoints.BANNER(guild.id, guild.banner); + const url = CDNEndpoints.BANNER(guildObj.id, guildObj.banner); const res = await fetch(url, {method: "HEAD"}); const mod = res.headers.get("last-modified"); @@ -72,12 +71,14 @@ banner.callback = async function (msg, line, [user], {server, guild}) { modStr = `Updated `; } - const guildRes = await fetch(guildUrl, {method: "HEAD"}); - const guildMod = guildRes.headers.get("last-modified"); let modStrGuild; - if (guildMod) { - const modDate = Math.floor(new Date(guildMod).getTime() / 10000); - modStrGuild = `Updated `; + 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); + modStrGuild = `Updated `; + } } return {