Preliminary DM support, update URLs to point to new repo link

This commit is contained in:
TheEssem 2020-09-01 17:10:19 -05:00
parent 631cdc5ef6
commit c471bd8af8
27 changed files with 105 additions and 66 deletions

View file

@ -3,8 +3,8 @@ const logger = require("./logger.js");
const fs = require("fs");
module.exports = async (output) => {
const template = `# <img src="https://raw.githubusercontent.com/TheEssem/esmBot/master/esmbot.png" width="64"> esmBot${process.env.NODE_ENV === "development" ? " Dev" : ""} Command List
${process.env.NODE_ENV === "development" ? "\n**You are currently using esmBot Dev! Things may change at any time without warning and there will be bugs. Many bugs. If you find one, [report it here](https://github.com/TheEssem/esmBot/issues) or in the esmBot Support server.**\n" : ""}
const template = `# <img src="https://raw.githubusercontent.com/esmBot/esmBot/master/esmbot.png" width="64"> esmBot${process.env.NODE_ENV === "development" ? " Dev" : ""} Command List
${process.env.NODE_ENV === "development" ? "\n**You are currently using esmBot Dev! Things may change at any time without warning and there will be bugs. Many bugs. If you find one, [report it here](https://github.com/esmBot/esmBot/issues) or in the esmBot Support server.**\n" : ""}
\`[]\` means an argument is required, \`{}\` means an argument is optional.
Default prefix is \`&\`.

View file

@ -1,7 +1,25 @@
const magick = require("../build/Release/image.node");
const fetch = require("node-fetch");
const { promisify } = require("util");
const FormData = require("form-data");
const { readFile } = require("fs").promises;
module.exports = async (object) => {
const data = await promisify(magick[object.cmd])(object);
return data;
if (process.env.API === "true") {
const params = [];
for (const element of Object.keys(object)) {
params.push(`${element}=${object[element]}`);
}
const form = new FormData();
const data = await readFile(object.path);
form.append("image", data);
const req = await fetch(`${process.env.API_URL}/${object.cmd}?${params.join("&")}`, {
method: "POST",
body: form
});
return await req.buffer();
} else {
const data = await promisify(magick[object.cmd])(object);
return data;
}
};

View file

@ -2,7 +2,7 @@ const fetch = require("node-fetch");
const AbortController = require("abort-controller");
const fileType = require("file-type");
const { promisify } = require("util");
const writeFile = promisify(require("fs").writeFile);
const { writeFile } = require("fs").promises;
const execPromise = promisify(require("child_process").exec);
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
@ -27,7 +27,6 @@ const typeCheck = async (image, image2, gifv = false) => {
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${imageType.ext}`;
await writeFile(path, imageBuffer);
const payload = {
data: imageBuffer,
type: imageType.ext !== "mp4" ? (imageType.ext === "jpg" ? "jpeg" : imageType.ext) : "gif",
path: path,
url: image2

View file

@ -1,5 +1,7 @@
// eris doesn't come with an awaitMessages method by default, so we make our own
const EventEmitter = require("events").EventEmitter;
const client = require("../client.js");
class MessageCollector extends EventEmitter {
constructor(channel, filter, options = {}) {
super();
@ -8,7 +10,7 @@ class MessageCollector extends EventEmitter {
this.options = options;
this.ended = false;
this.collected = [];
this.bot = channel.guild ? channel.guild.shard.client : channel._client;
this.bot = client;
this.listener = message => this.verify(message);
this.bot.on("messageCreate", this.listener);
if (options.time) setTimeout(() => this.stop("time"), options.time);

View file

@ -1,5 +1,7 @@
// eris doesn't come with an awaitReactions method by default, so we make our own
const EventEmitter = require("events").EventEmitter;
const client = require("../client.js");
class ReactionCollector extends EventEmitter {
constructor(message, filter, options = {}) {
super();
@ -8,7 +10,7 @@ class ReactionCollector extends EventEmitter {
this.options = options;
this.ended = false;
this.collected = [];
this.bot = message.channel.guild ? message.channel.guild.shard.client : message.channel._client;
this.bot = client;
this.listener = (message, emoji, userID) => this.verify(message, emoji, userID);
this.bot.on("messageReactionAdd", this.listener);
if (options.time) setTimeout(() => this.stop("time"), options.time);

View file

@ -2,8 +2,8 @@ const ReactionCollector = require("./awaitreactions.js");
const MessageCollector = require("./awaitmessages.js");
const client = require("../client.js");
const paginationEmbed = async (message, pages, timeout = 120000) => {
const manageMessages = message.channel.guild.members.get(client.user.id).permission.has("manageMessages") || message.channel.permissionsOf(client.user.id).has("manageMessages") ? true : false;
module.exports = async (message, pages, timeout = 120000) => {
const manageMessages = message.channel.guild && (message.channel.guild.members.get(client.user.id).permission.has("manageMessages") || message.channel.permissionsOf(client.user.id).has("manageMessages")) ? true : false;
let page = 0;
let deleted = false;
const currentPage = await message.channel.createMessage(pages[page]);
@ -56,4 +56,3 @@ const paginationEmbed = async (message, pages, timeout = 120000) => {
});
return currentPage;
};
module.exports = paginationEmbed;