Added the ability for sticker to check for stickers previously posted in a channel
This commit is contained in:
parent
d54e4e0117
commit
d42c67cde2
2 changed files with 35 additions and 30 deletions
|
@ -1,23 +1,24 @@
|
||||||
import Command from "../../classes/command.js";
|
import Command from "../../classes/command.js";
|
||||||
|
import imagedetect from "../../utils/imagedetect.js";
|
||||||
|
|
||||||
class StickerCommand extends Command {
|
class StickerCommand extends Command {
|
||||||
async run() {
|
async run() {
|
||||||
if (!this.message.stickerItems) return "You need to provide a sticker!";
|
const result = await imagedetect(this.client, this.message, false, false, true);
|
||||||
const sticker = this.message.stickerItems[0];
|
if (!result) return "You need to provide a sticker!";
|
||||||
if (sticker.format_type === 1) { // PNG
|
if (result.format_type === 1) { // PNG
|
||||||
return `https://cdn.discordapp.com/stickers/${sticker.id}.png`;
|
return `https://cdn.discordapp.com/stickers/${result.id}.png`;
|
||||||
} else if (sticker.format_type === 2) { // APNG
|
} else if (result.format_type === 2) { // APNG
|
||||||
return {
|
return {
|
||||||
embed: {
|
embed: {
|
||||||
color: 16711680,
|
color: 16711680,
|
||||||
description: `[This sticker is an APNG; however, since Discord doesn't allow displaying APNGs outside of stickers, you'll have to save it or open it in your browser to view it.](https://cdn.discordapp.com/stickers/${sticker.id}.png)`,
|
description: `[This sticker is an APNG; however, since Discord doesn't allow displaying APNGs outside of stickers, you'll have to save it or open it in your browser to view it.](https://cdn.discordapp.com/stickers/${result.id}.png)`,
|
||||||
image: {
|
image: {
|
||||||
url: `https://cdn.discordapp.com/stickers/${sticker.id}.png`
|
url: `https://cdn.discordapp.com/stickers/${result.id}.png`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if (sticker.format_type === 3) { // Lottie
|
} else if (result.format_type === 3) { // Lottie
|
||||||
return `I can't display this sticker because it uses the Lottie animation format; however, I can give you the raw JSON link to it: https://cdn.discordapp.com/stickers/${sticker.id}.json`;
|
return `I can't display this sticker because it uses the Lottie animation format; however, I can give you the raw JSON link to it: https://cdn.discordapp.com/stickers/${result.id}.json`;
|
||||||
} else {
|
} else {
|
||||||
return "I don't recognize that sticker format!";
|
return "I don't recognize that sticker format!";
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,50 +94,54 @@ const getImage = async (image, image2, video, extraReturnTypes, gifv = false) =>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkImages = async (message, extraReturnTypes, video) => {
|
const checkImages = async (message, extraReturnTypes, video, sticker) => {
|
||||||
let type;
|
let type;
|
||||||
// first check the embeds
|
if (sticker && message.stickerItems) {
|
||||||
if (message.embeds.length !== 0) {
|
type = message.stickerItems[0];
|
||||||
// embeds can vary in types, we check for tenor gifs first
|
} else {
|
||||||
if (message.embeds[0].type === "gifv") {
|
// first check the embeds
|
||||||
type = await getImage(message.embeds[0].video.url, message.embeds[0].url, video, extraReturnTypes, true);
|
if (message.embeds.length !== 0) {
|
||||||
// then we check for other image types
|
// embeds can vary in types, we check for tenor gifs first
|
||||||
} else if ((message.embeds[0].type === "video" || message.embeds[0].type === "image") && message.embeds[0].thumbnail) {
|
if (message.embeds[0].type === "gifv") {
|
||||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url, video, extraReturnTypes);
|
type = await getImage(message.embeds[0].video.url, message.embeds[0].url, video, extraReturnTypes, true);
|
||||||
// finally we check both possible image fields for "generic" embeds
|
// then we check for other image types
|
||||||
} else if (message.embeds[0].type === "rich") {
|
} else if ((message.embeds[0].type === "video" || message.embeds[0].type === "image") && message.embeds[0].thumbnail) {
|
||||||
if (message.embeds[0].thumbnail) {
|
|
||||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url, video, extraReturnTypes);
|
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url, video, extraReturnTypes);
|
||||||
} else if (message.embeds[0].image) {
|
// finally we check both possible image fields for "generic" embeds
|
||||||
type = await getImage(message.embeds[0].image.proxy_url, message.embeds[0].image.url, video, extraReturnTypes);
|
} else if (message.embeds[0].type === "rich") {
|
||||||
|
if (message.embeds[0].thumbnail) {
|
||||||
|
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url, video, extraReturnTypes);
|
||||||
|
} else if (message.embeds[0].image) {
|
||||||
|
type = await getImage(message.embeds[0].image.proxy_url, message.embeds[0].image.url, video, extraReturnTypes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// then check the attachments
|
||||||
|
} else if (message.attachments.length !== 0 && message.attachments[0].width) {
|
||||||
|
type = await getImage(message.attachments[0].proxy_url, message.attachments[0].url, video);
|
||||||
}
|
}
|
||||||
// then check the attachments
|
|
||||||
} else if (message.attachments.length !== 0 && message.attachments[0].width) {
|
|
||||||
type = await getImage(message.attachments[0].proxy_url, message.attachments[0].url, video);
|
|
||||||
}
|
}
|
||||||
// if the return value exists then return it
|
// if the return value exists then return it
|
||||||
return type ? type : false;
|
return type ? type : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// this checks for the latest message containing an image and returns the url of the image
|
// this checks for the latest message containing an image and returns the url of the image
|
||||||
export default async (client, cmdMessage, extraReturnTypes = false, video = false) => {
|
export default async (client, cmdMessage, extraReturnTypes = false, video = false, sticker = false) => {
|
||||||
// we start by checking if the message is a reply to another message
|
// we start by checking if the message is a reply to another message
|
||||||
if (cmdMessage.messageReference) {
|
if (cmdMessage.messageReference) {
|
||||||
const replyMessage = await client.getMessage(cmdMessage.messageReference.channelID, cmdMessage.messageReference.messageID).catch(() => undefined);
|
const replyMessage = await client.getMessage(cmdMessage.messageReference.channelID, cmdMessage.messageReference.messageID).catch(() => undefined);
|
||||||
if (replyMessage) {
|
if (replyMessage) {
|
||||||
const replyResult = await checkImages(replyMessage, extraReturnTypes, video);
|
const replyResult = await checkImages(replyMessage, extraReturnTypes, video, sticker);
|
||||||
if (replyResult !== false) return replyResult;
|
if (replyResult !== false) return replyResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// then we check the current message
|
// then we check the current message
|
||||||
const result = await checkImages(cmdMessage, extraReturnTypes, video);
|
const result = await checkImages(cmdMessage, extraReturnTypes, video, sticker);
|
||||||
if (result !== false) return result;
|
if (result !== false) return result;
|
||||||
// if there aren't any replies then iterate over the last few messages in the channel
|
// if there aren't any replies then iterate over the last few messages in the channel
|
||||||
const messages = await client.getMessages(cmdMessage.channel.id);
|
const messages = await client.getMessages(cmdMessage.channel.id);
|
||||||
// iterate over each message
|
// iterate over each message
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
const result = await checkImages(message, extraReturnTypes, video);
|
const result = await checkImages(message, extraReturnTypes, video, sticker);
|
||||||
if (result === false) {
|
if (result === false) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue