Fixed some DM command issues, made reload and restart use IPC
This commit is contained in:
		
							parent
							
								
									e0e0c9c7d4
								
							
						
					
					
						commit
						56113a1cf8
					
				
					 18 changed files with 54 additions and 35 deletions
				
			
		| 
						 | 
					@ -89,31 +89,30 @@ class ImageCommand extends Command {
 | 
				
			||||||
    if (magickParams.type === "image/gif") {
 | 
					    if (magickParams.type === "image/gif") {
 | 
				
			||||||
      status = await this.processMessage(this.message);
 | 
					      status = await this.processMessage(this.message);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      this.message.channel.sendTyping();
 | 
					      this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      const { buffer, type } = await magick.run(magickParams).catch(e => {
 | 
					      const { buffer, type } = await magick.run(magickParams).catch(e => {
 | 
				
			||||||
        throw e;
 | 
					        throw e;
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      if (status && status.channel.messages.get(status.id)) await status.delete();
 | 
					 | 
				
			||||||
      if (type === "nogif" && this.constructor.requiresGIF) return `${this.message.author.mention}, that isn't a GIF!`;
 | 
					      if (type === "nogif" && this.constructor.requiresGIF) return `${this.message.author.mention}, that isn't a GIF!`;
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
        file: buffer,
 | 
					        file: buffer,
 | 
				
			||||||
        name: `${this.constructor.command}.${type}`
 | 
					        name: `${this.constructor.command}.${type}`
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      if (status && status.channel.messages.get(status.id)) await status.delete();
 | 
					 | 
				
			||||||
      if (e.toString().includes("Not connected to image server")) return `${this.message.author.mention}, I'm still trying to connect to the image servers. Please wait a little bit.`;
 | 
					      if (e.toString().includes("Not connected to image server")) return `${this.message.author.mention}, I'm still trying to connect to the image servers. Please wait a little bit.`;
 | 
				
			||||||
      throw e;
 | 
					      throw e;
 | 
				
			||||||
    } finally {
 | 
					    } finally {
 | 
				
			||||||
 | 
					      if (status && await this.client.getMessage(status.channel.id, status.id).catch(() => undefined)) await status.delete();
 | 
				
			||||||
      collections.runningCommands.delete(this.message.author.id);
 | 
					      collections.runningCommands.delete(this.message.author.id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  processMessage(message) {
 | 
					  processMessage(message) {
 | 
				
			||||||
    return message.channel.createMessage(`${random(emotes) || process.env.PROCESSING_EMOJI || "<a:processing:479351417102925854>"} Processing... This might take a while`);
 | 
					    return this.client.createMessage(message.channel.id, `${random(emotes) || process.env.PROCESSING_EMOJI || "<a:processing:479351417102925854>"} Processing... This might take a while`);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static requiresImage = true;
 | 
					  static requiresImage = true;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BirdCommand extends Command {
 | 
					class BirdCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const imageData = await fetch("http://shibe.online/api/birds");
 | 
					    const imageData = await fetch("http://shibe.online/api/birds");
 | 
				
			||||||
    const json = await imageData.json();
 | 
					    const json = await imageData.json();
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CatCommand extends Command {
 | 
					class CatCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const data = await fetch("https://projectlounge.pw/cta/", { redirect: "manual" });
 | 
					    const data = await fetch("https://projectlounge.pw/cta/", { redirect: "manual" });
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      embed: {
 | 
					      embed: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DogCommand extends Command {
 | 
					class DogCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const imageData = await fetch("https://dog.ceo/api/breeds/image/random");
 | 
					    const imageData = await fetch("https://dog.ceo/api/breeds/image/random");
 | 
				
			||||||
    const json = await imageData.json();
 | 
					    const json = await imageData.json();
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
class MCCommand extends Command {
 | 
					class MCCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate a Minecraft achievement!`;
 | 
					    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate a Minecraft achievement!`;
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const request = await fetch(`https://www.minecraftskinstealer.com/achievement/a.php?i=13&h=Achievement+get%21&t=${encodeURIComponent(this.args.join("+"))}`);
 | 
					    const request = await fetch(`https://www.minecraftskinstealer.com/achievement/a.php?i=13&h=Achievement+get%21&t=${encodeURIComponent(this.args.join("+"))}`);
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      file: await request.buffer(),
 | 
					      file: await request.buffer(),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
class RetroCommand extends Command {
 | 
					class RetroCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate some retro text!`;
 | 
					    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate some retro text!`;
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    let [line1, line2, line3] = this.args.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%").split(",").map(elem => elem.trim());
 | 
					    let [line1, line2, line3] = this.args.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%").split(",").map(elem => elem.trim());
 | 
				
			||||||
    if (!line2 && line1.length > 15) {
 | 
					    if (!line2 && line1.length > 15) {
 | 
				
			||||||
      const [split1, split2, split3] = wrap(line1, { width: 15, indent: "" }).split("\n");
 | 
					      const [split1, split2, split3] = wrap(line1, { width: 15, indent: "" }).split("\n");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WikihowCommand extends Command {
 | 
					class WikihowCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const request = await fetch("https://hargrimm-wikihow-v1.p.rapidapi.com/images?count=1", {
 | 
					    const request = await fetch("https://hargrimm-wikihow-v1.p.rapidapi.com/images?count=1", {
 | 
				
			||||||
      headers: {
 | 
					      headers: {
 | 
				
			||||||
        "X-RapidAPI-Key": process.env.MASHAPE,
 | 
					        "X-RapidAPI-Key": process.env.MASHAPE,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LengthenCommand extends Command {
 | 
					class LengthenCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    if (this.args.length === 0 || !urlCheck(this.args[0])) return `${this.message.author.mention}, you need to provide a short URL to lengthen!`;
 | 
					    if (this.args.length === 0 || !urlCheck(this.args[0])) return `${this.message.author.mention}, you need to provide a short URL to lengthen!`;
 | 
				
			||||||
    if (urlCheck(this.args[0])) {
 | 
					    if (urlCheck(this.args[0])) {
 | 
				
			||||||
      const url = await fetch(encodeURI(this.args[0]), { redirect: "manual" });
 | 
					      const url = await fetch(encodeURI(this.args[0]), { redirect: "manual" });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PingCommand extends Command {
 | 
					class PingCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    const pingMessage = await this.message.channel.createMessage("🏓 Ping?");
 | 
					    const pingMessage = await this.client.createMessage(this.message.channel.id, "🏓 Ping?");
 | 
				
			||||||
    return pingMessage.edit(`🏓 Pong!\n\`\`\`\nLatency: ${pingMessage.timestamp - this.message.timestamp}ms${this.message.channel.guild ? `\nShard Latency: ${Math.round(this.client.shards.get(this.client.guildShardMap[this.message.channel.guild.id]).latency)}ms` : ""}\n\`\`\``);
 | 
					    return pingMessage.edit(`🏓 Pong!\n\`\`\`\nLatency: ${pingMessage.timestamp - this.message.timestamp}ms${this.message.channel.guild ? `\nShard Latency: ${Math.round(this.client.shards.get(this.client.guildShardMap[this.message.channel.guild.id]).latency)}ms` : ""}\n\`\`\``);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
class QrCreateCommand extends Command {
 | 
					class QrCreateCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate a QR code!`;
 | 
					    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate a QR code!`;
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const writable = new stream.PassThrough();
 | 
					    const writable = new stream.PassThrough();
 | 
				
			||||||
    qrcode.toFileStream(writable, this.content, { margin: 1 });
 | 
					    qrcode.toFileStream(writable, this.content, { margin: 1 });
 | 
				
			||||||
    const file = await this.streamToBuf(writable);
 | 
					    const file = await this.streamToBuf(writable);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@ class QrReadCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    const image = await require("../../utils/imagedetect.js")(this.client, this.message);
 | 
					    const image = await require("../../utils/imagedetect.js")(this.client, this.message);
 | 
				
			||||||
    if (image === undefined) return `${this.message.author.mention}, you need to provide an image with a QR code to read!`;
 | 
					    if (image === undefined) return `${this.message.author.mention}, you need to provide an image with a QR code to read!`;
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const data = await (await fetch(image.path)).buffer();
 | 
					    const data = await (await fetch(image.path)).buffer();
 | 
				
			||||||
    const rawData = await sharp(data).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
 | 
					    const rawData = await sharp(data).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
 | 
				
			||||||
    const qrBuffer = jsqr(rawData.data, rawData.info.width, rawData.info.height);
 | 
					    const qrBuffer = jsqr(rawData.data, rawData.info.width, rawData.info.height);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,16 +1,23 @@
 | 
				
			||||||
const handler = require("../../utils/handler.js");
 | 
					 | 
				
			||||||
const collections = require("../../utils/collections.js");
 | 
					 | 
				
			||||||
const Command = require("../../classes/command.js");
 | 
					const Command = require("../../classes/command.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ReloadCommand extends Command {
 | 
					class ReloadCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  // quite possibly one of the hackiest commands in the bot
 | 
				
			||||||
    if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can reload commands!`;
 | 
					  run() {
 | 
				
			||||||
    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide a command to reload!`;
 | 
					    return new Promise((resolve) => {
 | 
				
			||||||
    const result = await handler.unload(this.args[0]);
 | 
					      if (this.message.author.id !== process.env.OWNER) resolve(`${this.message.author.mention}, only the bot owner can reload commands!`);
 | 
				
			||||||
    if (result) return result;
 | 
					      if (this.args.length === 0) resolve(`${this.message.author.mention}, you need to provide a command to reload!`);
 | 
				
			||||||
    const result2 = await handler.load(collections.paths.get(this.args[0]));
 | 
					      this.ipc.broadcast("reload", { cmd: this.args[0] });
 | 
				
			||||||
    if (result2) return result2;
 | 
					      this.ipc.register("reloadSuccess", () => {
 | 
				
			||||||
    return `${this.message.author.mention}, the command \`${this.args[0]}\` has been reloaded.`;
 | 
					        this.ipc.unregister("reloadSuccess");
 | 
				
			||||||
 | 
					        this.ipc.unregister("reloadFail");
 | 
				
			||||||
 | 
					        resolve(`${this.message.author.mention}, the command \`${this.args[0]}\` has been reloaded.`);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      this.ipc.register("reloadFail", (message) => {
 | 
				
			||||||
 | 
					        this.ipc.unregister("reloadSuccess");
 | 
				
			||||||
 | 
					        this.ipc.unregister("reloadFail");
 | 
				
			||||||
 | 
					        resolve(message);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static description = "Reloads a command";
 | 
					  static description = "Reloads a command";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,11 +5,11 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
class RestartCommand extends Command {
 | 
					class RestartCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can restart me!`;
 | 
					    if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can restart me!`;
 | 
				
			||||||
    await this.message.channel.createMessage(`${this.message.author.mention}, esmBot is restarting.`);
 | 
					    await this.client.createMessage(this.message.channel.id, `${this.message.author.mention}, esmBot is restarting.`);
 | 
				
			||||||
    for (const command of collections.commands) {
 | 
					    for (const command of collections.commands) {
 | 
				
			||||||
      await handler.unload(command);
 | 
					      await handler.unload(command);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    process.exit(1);
 | 
					    this.ipc.broadcast("restart");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static description = "Restarts me";
 | 
					  static description = "Restarts me";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,7 @@ class StatsCommand extends Command {
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          "name": "Shard",
 | 
					          "name": "Shard",
 | 
				
			||||||
          "value": this.client.guildShardMap[this.message.channel.guild.id],
 | 
					          "value": this.message.channel.guild ? this.client.guildShardMap[this.message.channel.guild.id] : "N/A",
 | 
				
			||||||
          "inline": true
 | 
					          "inline": true
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ const Command = require("../../classes/command.js");
 | 
				
			||||||
class YouTubeCommand extends Command {
 | 
					class YouTubeCommand extends Command {
 | 
				
			||||||
  async run() {
 | 
					  async run() {
 | 
				
			||||||
    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide something to search for!`;
 | 
					    if (this.args.length === 0) return `${this.message.author.mention}, you need to provide something to search for!`;
 | 
				
			||||||
    this.message.channel.sendTyping();
 | 
					    this.client.sendChannelTyping(this.message.channel.id);
 | 
				
			||||||
    const messages = [];
 | 
					    const messages = [];
 | 
				
			||||||
    const request = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(this.args.join(" "))}&key=${process.env.GOOGLE}&maxResults=50`);
 | 
					    const request = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(this.args.join(" "))}&key=${process.env.GOOGLE}&maxResults=50`);
 | 
				
			||||||
    const result = await request.json();
 | 
					    const result = await request.json();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								shard.js
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								shard.js
									
										
									
									
									
								
							| 
						 | 
					@ -106,6 +106,19 @@ class Shard extends Base {
 | 
				
			||||||
      collections.stats = message;
 | 
					      collections.stats = message;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.ipc.register("restart", () => {
 | 
				
			||||||
 | 
					      process.exit(1);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.ipc.register("reload", async (message) => {
 | 
				
			||||||
 | 
					      const result = await handler.unload(message.cmd);
 | 
				
			||||||
 | 
					      if (result) return this.ipc.broadcast("reloadFail", { result: result });
 | 
				
			||||||
 | 
					      const result2 = await handler.load(collections.paths.get(message.cmd));
 | 
				
			||||||
 | 
					      if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
 | 
				
			||||||
 | 
					      //return this.ipc.broadcast("reloadSuccess", this.clusterID);
 | 
				
			||||||
 | 
					      return this.ipc.broadcast("reloadSuccess");
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    // connect to lavalink
 | 
					    // connect to lavalink
 | 
				
			||||||
    if (!sound.status && !sound.connected) await sound.connect(this.bot);
 | 
					    if (!sound.status && !sound.connected) await sound.connect(this.bot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,7 +113,7 @@ const checkImages = async (message, video) => {
 | 
				
			||||||
module.exports = async (client, cmdMessage, video = false) => {
 | 
					module.exports = async (client, cmdMessage, video = 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);
 | 
					    const replyMessage = await client.getMessage(cmdMessage.messageReference.channelID, cmdMessage.messageReference.messageID).catch(() => undefined);
 | 
				
			||||||
    if (replyMessage) {
 | 
					    if (replyMessage) {
 | 
				
			||||||
      const replyResult = await checkImages(replyMessage, video);
 | 
					      const replyResult = await checkImages(replyMessage, video);
 | 
				
			||||||
      if (replyResult !== false) return replyResult;
 | 
					      if (replyResult !== false) return replyResult;
 | 
				
			||||||
| 
						 | 
					@ -123,7 +123,7 @@ module.exports = async (client, cmdMessage, video = false) => {
 | 
				
			||||||
  const result = await checkImages(cmdMessage, video);
 | 
					  const result = await checkImages(cmdMessage, video);
 | 
				
			||||||
  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 cmdMessage.channel.getMessages();
 | 
					  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, video);
 | 
					    const result = await checkImages(message, video);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ const MessageCollector = require("./awaitmessages.js");
 | 
				
			||||||
module.exports = async (client, message, pages, timeout = 120000) => {
 | 
					module.exports = async (client, message, pages, timeout = 120000) => {
 | 
				
			||||||
  const manageMessages = message.channel.guild && message.channel.permissionsOf(client.user.id).has("manageMessages") ? true : false;
 | 
					  const manageMessages = message.channel.guild && message.channel.permissionsOf(client.user.id).has("manageMessages") ? true : false;
 | 
				
			||||||
  let page = 0;
 | 
					  let page = 0;
 | 
				
			||||||
  let currentPage = await message.channel.createMessage(pages[page]);
 | 
					  let currentPage = await client.createMessage(message.channel.id, pages[page]);
 | 
				
			||||||
  const emojiList = ["◀", "🔢", "▶", "🗑"];
 | 
					  const emojiList = ["◀", "🔢", "▶", "🗑"];
 | 
				
			||||||
  for (const emoji of emojiList) {
 | 
					  for (const emoji of emojiList) {
 | 
				
			||||||
    await currentPage.addReaction(emoji);
 | 
					    await currentPage.addReaction(emoji);
 | 
				
			||||||
| 
						 | 
					@ -19,13 +19,13 @@ module.exports = async (client, message, pages, timeout = 120000) => {
 | 
				
			||||||
          if (manageMessages) msg.removeReaction("◀", member.id);
 | 
					          if (manageMessages) msg.removeReaction("◀", member.id);
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case "🔢":
 | 
					        case "🔢":
 | 
				
			||||||
          message.channel.createMessage(`${message.author.mention}, what page do you want to jump to?`).then(askMessage => {
 | 
					          client.createMessage(message.channel.id, `${message.author.mention}, what page do you want to jump to?`).then(askMessage => {
 | 
				
			||||||
            const messageCollector = new MessageCollector(client, askMessage.channel, (response) => response.author.id === message.author.id && !isNaN(response.content) && Number(response.content) <= pages.length && Number(response.content) > 0, {
 | 
					            const messageCollector = new MessageCollector(client, askMessage.channel, (response) => response.author.id === message.author.id && !isNaN(response.content) && Number(response.content) <= pages.length && Number(response.content) > 0, {
 | 
				
			||||||
              time: timeout,
 | 
					              time: timeout,
 | 
				
			||||||
              maxMatches: 1
 | 
					              maxMatches: 1
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            return messageCollector.on("message", async (response) => {
 | 
					            return messageCollector.on("message", async (response) => {
 | 
				
			||||||
              if (askMessage.channel.messages.get(askMessage.id)) askMessage.delete();
 | 
					              if (await client.getMessage(askMessage.channel.id, askMessage.id).catch(() => undefined)) askMessage.delete();
 | 
				
			||||||
              if (manageMessages) await response.delete();
 | 
					              if (manageMessages) await response.delete();
 | 
				
			||||||
              page = Number(response.content) - 1;
 | 
					              page = Number(response.content) - 1;
 | 
				
			||||||
              currentPage = await currentPage.edit(pages[page]);
 | 
					              currentPage = await currentPage.edit(pages[page]);
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case "🗑":
 | 
					        case "🗑":
 | 
				
			||||||
          reactionCollector.emit("end");
 | 
					          reactionCollector.emit("end");
 | 
				
			||||||
          if (currentPage.channel.messages.get(currentPage.id)) await currentPage.delete();
 | 
					          if (await client.getMessage(currentPage.channel.id, currentPage.id).catch(() => undefined)) await currentPage.delete();
 | 
				
			||||||
          return;
 | 
					          return;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
  reactionCollector.once("end", async () => {
 | 
					  reactionCollector.once("end", async () => {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      await currentPage.channel.getMessage(currentPage.id);
 | 
					      await client.getMessage(currentPage.channel, currentPage.id);
 | 
				
			||||||
      if (manageMessages) {
 | 
					      if (manageMessages) {
 | 
				
			||||||
        await currentPage.removeReactions();
 | 
					        await currentPage.removeReactions();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue