Remove image URL from arguments of image commands
This commit is contained in:
		
							parent
							
								
									67be772998
								
							
						
					
					
						commit
						18330d3db9
					
				
					 6 changed files with 17 additions and 12 deletions
				
			
		| 
						 | 
					@ -6,10 +6,11 @@ const gm = require("gm").subClass({
 | 
				
			||||||
exports.run = async (message, args) => {
 | 
					exports.run = async (message, args) => {
 | 
				
			||||||
  const image = await require("../utils/imagedetect.js")(message);
 | 
					  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!`;
 | 
					  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!`;
 | 
					  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 processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
 | 
				
			||||||
  const size = await gm(image.path).sizePromise();
 | 
					  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 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 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);
 | 
					  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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,10 +6,11 @@ const words = ["me irl", "dank", "follow my second account @esmBot_", "2016", "m
 | 
				
			||||||
exports.run = async (message, args) => {
 | 
					exports.run = async (message, args) => {
 | 
				
			||||||
  const image = await require("../utils/imagedetect.js")(message);
 | 
					  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!`;
 | 
					  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 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 text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
				
			||||||
  const size = await gm(image.path).sizePromise();
 | 
					  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 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);
 | 
					  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();
 | 
					  await processMessage.delete();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 === 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!`;
 | 
					  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 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();
 | 
					  await processMessage.delete();
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    file: resultBuffer,
 | 
					    file: resultBuffer,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,9 @@ exports.run = async (message, args) => {
 | 
				
			||||||
  message.channel.sendTyping();
 | 
					  message.channel.sendTyping();
 | 
				
			||||||
  const image = await require("../utils/imagedetect.js")(message);
 | 
					  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!`;
 | 
					  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!`;
 | 
					  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 file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
 | 
				
			||||||
  const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
					  const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
				
			||||||
  const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
					  const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,10 @@ const gm = require("gm").subClass({
 | 
				
			||||||
exports.run = async (message, args) => {
 | 
					exports.run = async (message, args) => {
 | 
				
			||||||
  const image = await require("../utils/imagedetect.js")(message);
 | 
					  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!`;
 | 
					  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!`;
 | 
					  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 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 file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
 | 
				
			||||||
  const text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
					  const text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
				
			||||||
  const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
					  const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ const execPromise = promisify(require("child_process").exec);
 | 
				
			||||||
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
 | 
					const urlRegex = /(?:\w+:)?\/\/(\S+)/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// this checks if the file is, in fact, an image
 | 
					// 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
 | 
					  // download the file to a buffer
 | 
				
			||||||
  const imageRequest = await fetch(image);
 | 
					  const imageRequest = await fetch(image);
 | 
				
			||||||
  const imageBuffer = await imageRequest.buffer();
 | 
					  const imageBuffer = await imageRequest.buffer();
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,8 @@ const typeCheck = async (image, gifv = false) => {
 | 
				
			||||||
      const payload = {
 | 
					      const payload = {
 | 
				
			||||||
        data: imageBuffer,
 | 
					        data: imageBuffer,
 | 
				
			||||||
        type: imageType.ext !== "mp4" ? (imageType.ext === "jpg" ? "jpeg" : imageType.ext) : "gif",
 | 
					        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", "");
 | 
					      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;
 | 
					      return payload;
 | 
				
			||||||
| 
						 | 
					@ -46,22 +47,22 @@ module.exports = async (cmdMessage) => {
 | 
				
			||||||
    if (message.embeds.length !== 0) {
 | 
					    if (message.embeds.length !== 0) {
 | 
				
			||||||
      // embeds can have 2 possible entries with images, we check the thumbnail first
 | 
					      // embeds can have 2 possible entries with images, we check the thumbnail first
 | 
				
			||||||
      if (message.embeds[0].type === "gifv") {
 | 
					      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;
 | 
					        if (type === false) continue;
 | 
				
			||||||
        return type;
 | 
					        return type;
 | 
				
			||||||
      } else if (message.embeds[0].thumbnail) {
 | 
					      } 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;
 | 
					        if (type === false) continue;
 | 
				
			||||||
        return type;
 | 
					        return type;
 | 
				
			||||||
        // if there isn't a thumbnail check the image area
 | 
					        // if there isn't a thumbnail check the image area
 | 
				
			||||||
      } else if (message.embeds[0].image) {
 | 
					      } 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;
 | 
					        if (type === false) continue;
 | 
				
			||||||
        return type;
 | 
					        return type;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else if (message.attachments.length !== 0) {
 | 
					    } else if (message.attachments.length !== 0) {
 | 
				
			||||||
      // get type of file
 | 
					      // 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
 | 
					      // move to the next message if the file isn't an image
 | 
				
			||||||
      if (type === false) continue;
 | 
					      if (type === false) continue;
 | 
				
			||||||
      // if the file is an image then return it
 | 
					      // if the file is an image then return it
 | 
				
			||||||
| 
						 | 
					@ -71,7 +72,7 @@ module.exports = async (cmdMessage) => {
 | 
				
			||||||
      // get url
 | 
					      // get url
 | 
				
			||||||
      const url = message.content.match(urlRegex);
 | 
					      const url = message.content.match(urlRegex);
 | 
				
			||||||
      // get type of file
 | 
					      // 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
 | 
					      // move to the next message if the file isn't an image
 | 
				
			||||||
      if (type === false) continue;
 | 
					      if (type === false) continue;
 | 
				
			||||||
      // if the file is an image then return it
 | 
					      // if the file is an image then return it
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue