3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-19 15:30:00 +00:00
zeppelin/backend/src/plugins/Utility/commands/AvatarCmd.ts

34 lines
1.3 KiB
TypeScript
Raw Normal View History

import { MessageEmbedOptions } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { UnknownUser } from "../../../utils";
import { utilityCmd } from "../types";
export const AvatarCmd = utilityCmd({
trigger: ["avatar", "av"],
description: "Retrieves a user's profile picture",
permission: "can_avatar",
signature: {
user: ct.resolvedUserLoose({ required: false }),
},
async run({ message: msg, args, pluginData }) {
const user = args.user || msg.author;
if (!(user instanceof UnknownUser)) {
const avatar = user.avatarURL() || user.defaultAvatarURL;
let extension = avatar.slice(avatar.lastIndexOf("."), avatar.lastIndexOf("?"));
2020-08-05 02:42:40 +03:00
// Some pngs can have the .jpg extention for some reason, so we always use .png for static images
extension = extension === ".gif" ? extension : ".png";
const avatarUrl = avatar.slice(0, avatar.lastIndexOf("."));
const embed: MessageEmbedOptions = {
2020-08-05 02:42:40 +03:00
image: { url: avatarUrl + `${extension}?size=2048` },
};
embed.title = `Avatar of ${user.username}#${user.discriminator}:`;
msg.channel.send({ embed });
} else {
sendErrorMessage(pluginData, msg.channel, "Invalid user ID");
}
},
});