2020-07-06 02:47:39 +03:00
|
|
|
import { utilityCmd } from "../types";
|
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
2020-07-06 02:57:21 +03:00
|
|
|
import { UnknownUser } from "../../../utils";
|
2020-07-06 02:47:39 +03:00
|
|
|
import { sendErrorMessage } from "../../../pluginUtils";
|
2021-06-02 04:07:50 +02:00
|
|
|
import { MessageEmbedOptions } from "discord.js";
|
2020-07-06 02:47:39 +03:00
|
|
|
|
|
|
|
export const AvatarCmd = utilityCmd({
|
2021-04-02 17:45:00 +04:00
|
|
|
trigger: ["avatar", "av"],
|
2020-07-06 02:47:39 +03:00
|
|
|
description: "Retrieves a user's profile picture",
|
|
|
|
permission: "can_avatar",
|
|
|
|
|
|
|
|
signature: {
|
2020-08-19 00:53:59 +03:00
|
|
|
user: ct.resolvedUserLoose({ required: false }),
|
2020-07-06 02:47:39 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
async run({ message: msg, args, pluginData }) {
|
|
|
|
const user = args.user || msg.author;
|
|
|
|
if (!(user instanceof UnknownUser)) {
|
2021-06-02 04:07:50 +02:00
|
|
|
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";
|
2021-06-02 04:07:50 +02:00
|
|
|
const avatarUrl = avatar.slice(0, avatar.lastIndexOf("."));
|
|
|
|
const embed: MessageEmbedOptions = {
|
2020-08-05 02:42:40 +03:00
|
|
|
image: { url: avatarUrl + `${extension}?size=2048` },
|
2020-07-06 02:47:39 +03:00
|
|
|
};
|
|
|
|
embed.title = `Avatar of ${user.username}#${user.discriminator}:`;
|
2021-06-02 04:07:50 +02:00
|
|
|
msg.channel.send({ embed });
|
2020-07-06 02:47:39 +03:00
|
|
|
} else {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, "Invalid user ID");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|