Remove image URL from arguments of image commands

This commit is contained in:
TheEssem 2020-04-23 17:38:01 -05:00
parent 67be772998
commit 18330d3db9
6 changed files with 17 additions and 12 deletions

View file

@ -6,10 +6,11 @@ const gm = require("gm").subClass({
exports.run = async (message, args) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`;
const newArgs = args.filter(item => !item.includes(image.url) );
if (args.length === 0) return `${message.author.mention}, you need to provide some text to add a caption!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const size = await gm(image.path).sizePromise();
const output = await gm().out("-size", `${size.width - ((size.width / 25) * 2)}x`).background("white").fill("black").font("./assets/caption.otf", size.width / 10).gravity("Center").out(`caption:${args.join(" ")}`).extent(size.width, `%[fx:h+${size.width / 25}]`).bufferPromise("png");
const output = await gm().out("-size", `${size.width - ((size.width / 25) * 2)}x`).background("white").fill("black").font("./assets/caption.otf", size.width / 10).gravity("Center").out(`caption:${newArgs.join(" ")}`).extent(size.width, `%[fx:h+${size.width / 25}]`).bufferPromise("png");
const size2 = await gm(output).sizePromise();
//const output2 = await gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).streamPromise();
const outputFinal = await gm(output).in("(").gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).out(")").background("white").out("-alpha", "set").out("(").out(image.path).out("-coalesce").out(")").colorspace("sRGB").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite").bufferPromise(image.type, image.delay);

View file

@ -6,10 +6,11 @@ const words = ["me irl", "dank", "follow my second account @esmBot_", "2016", "m
exports.run = async (message, args) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`;
const newArgs = args.filter(item => !item.includes(image.url) );
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const size = await gm(image.path).sizePromise();
await gm().out("-size", `${size.width - ((size.width / 25) * 2)}x`).background("white").fill("black").font("Helvetica Neue").out("-pointsize", size.width / 17).out(`pango:${args.length !== 0 ? args.join(" ") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" ")}`).gravity("Center").extent(size.width, `%[fx:h+${size.width / 25}]`).writePromise(text);
await gm().out("-size", `${size.width - ((size.width / 25) * 2)}x`).background("white").fill("black").font("Helvetica Neue").out("-pointsize", size.width / 17).out(`pango:${newArgs.length !== 0 ? newArgs.join(" ") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" ")}`).gravity("Center").extent(size.width, `%[fx:h+${size.width / 25}]`).writePromise(text);
const size2 = await gm(text).sizePromise();
const outputFinal = await gm(image.path).gravity("North").extent(size.width, size2.height + size.height).out("null:", "(", text, "-set", "page", `+0+${size.height}`, ")", "-layers", "composite", "-layers", "optimize").bufferPromise(image.type, image.delay);
await processMessage.delete();

View file

@ -7,7 +7,7 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to add some magik!`;
if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const resultBuffer = await gm(image.path).in("(").in("(").coalesce().scale(600, 600).out(")").out("-liquid-rescale", "300x300").out(")").out("-liquid-rescale", "800x800").bufferPromise(image.type, image.delay);
const resultBuffer = await gm(image.path).in("(").in("(").coalesce().scale(600, 600).out(")").out("-liquid-rescale", "300x300").out(")").out("-liquid-rescale", "600x600").bufferPromise(image.type, image.delay);
await processMessage.delete();
return {
file: resultBuffer,

View file

@ -6,8 +6,9 @@ exports.run = async (message, args) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to generate a meme!`;
const newArgs = args.filter(item => !item.includes(image.url) );
if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a meme!`;
const [topText, bottomText] = args.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;

View file

@ -5,9 +5,10 @@ const gm = require("gm").subClass({
exports.run = async (message, args) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to make a motivational poster!`;
const newArgs = args.filter(item => !item.includes(image.url) );
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a motivational poster!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const [topText, bottomText] = args.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;

View file

@ -6,7 +6,7 @@ const execPromise = promisify(require("child_process").exec);
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
// this checks if the file is, in fact, an image
const typeCheck = async (image, gifv = false) => {
const typeCheck = async (image, image2, gifv = false) => {
// download the file to a buffer
const imageRequest = await fetch(image);
const imageBuffer = await imageRequest.buffer();
@ -23,7 +23,8 @@ const typeCheck = async (image, gifv = false) => {
const payload = {
data: imageBuffer,
type: imageType.ext !== "mp4" ? (imageType.ext === "jpg" ? "jpeg" : imageType.ext) : "gif",
path: path
path: path,
url: image2
};
if (gifv) payload.delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${path}`)).stdout.replace("\n", "");
return payload;
@ -46,22 +47,22 @@ module.exports = async (cmdMessage) => {
if (message.embeds.length !== 0) {
// embeds can have 2 possible entries with images, we check the thumbnail first
if (message.embeds[0].type === "gifv") {
const type = await typeCheck(message.embeds[0].video.url, true);
const type = await typeCheck(message.embeds[0].video.url, message.embeds[0].video.url, true);
if (type === false) continue;
return type;
} else if (message.embeds[0].thumbnail) {
const type = await typeCheck(message.embeds[0].thumbnail.proxy_url);
const type = await typeCheck(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url);
if (type === false) continue;
return type;
// if there isn't a thumbnail check the image area
} else if (message.embeds[0].image) {
const type = await typeCheck(message.embeds[0].image.proxy_url);
const type = await typeCheck(message.embeds[0].image.proxy_url, message.embeds[0].image.url);
if (type === false) continue;
return type;
}
} else if (message.attachments.length !== 0) {
// get type of file
const type = await typeCheck(message.attachments[0].proxy_url);
const type = await typeCheck(message.attachments[0].proxy_url, message.attachments[0].url);
// move to the next message if the file isn't an image
if (type === false) continue;
// if the file is an image then return it
@ -71,7 +72,7 @@ module.exports = async (cmdMessage) => {
// get url
const url = message.content.match(urlRegex);
// get type of file
const type = await typeCheck(url[0]);
const type = await typeCheck(url[0], url[0]);
// move to the next message if the file isn't an image
if (type === false) continue;
// if the file is an image then return it