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

@ -1,5 +1,6 @@
require("dotenv").config();
const magick = require("../utils/image.js");
const { version } = require("../package.json");
const express = require("express");
const multer = require("multer");
const path = require("path");
@ -18,7 +19,7 @@ const port = 3000;
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
app.get("/", (req, res) => {
res.send("Hello World!");
res.send(`esmBot v${version}${process.env.NODE_ENV === "development" ? "-dev" : ""}`);
});
app.post("/:method", upload.single("image"), async (req, res, next) => {

View File

@ -5,7 +5,7 @@ exports.run = async (message, args) => {
return message.mentions[0].dynamicAvatarURL(null, 1024);
} else if (client.users.get(args[0]) !== undefined) {
return client.users.get(args[0]).dynamicAvatarURL(null, 1024);
} else if (args.join(" ") !== "") {
} else if (args.join(" ") !== "" && message.channel.guild) {
const userRegex = new RegExp(args.join("|"), "i");
const member = message.channel.guild.members.find(element => {
return userRegex.test(element.nick) ? userRegex.test(element.nick) : userRegex.test(element.username);

View File

@ -1,6 +1,7 @@
const client = require("../utils/client.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("banMembers")) return `${message.author.mention}, you need to have the \`Ban Members\` permission on this server to ban people!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("banMembers") && !message.channel.permissionsOf(client.user.id).has("banMembers")) return `${message.author.mention}, I don't have the \`Ban Members\` permission!`;
const member = message.mentions[0];

View File

@ -1,6 +1,7 @@
const db = require("../utils/database.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("administrator") && message.member.id !== process.env.OWNER) return `${message.author.mention}, you need to be an administrator to enable/disable me!`;
if (args.length === 0) return `${message.author.mention}, you need to provide whether I should be enabled or disabled in this channel!`;
if (args[0] !== "disable" && args[0] !== "enable") return `${message.author.mention}, that's not a valid option!`;

View File

@ -3,8 +3,8 @@ const paginator = require("../utils/pagination/pagination.js");
const database = require("../utils/database.js");
exports.run = async (message) => {
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
if (message.channel.guild && !message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (message.channel.guild && !message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
const counts = (await database.global.findOne({})).cmdCounts;
const countArray = [];
const sortedValues = [...counts.entries()].sort((a, b) => {

View File

@ -21,7 +21,7 @@ exports.run = async (message, args) => {
value: `${message.author.username}#${message.author.discriminator}`
}, {
name: "👪 Server:",
value: message.channel.guild.name
value: message.channel.guild ? message.channel.guild.name : "N/A"
}, {
name: "💬 Message:",
value: args.join(" ")

View File

@ -6,7 +6,7 @@ const paginator = require("../utils/pagination/pagination.js");
const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem"];
exports.run = async (message, args) => {
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const { prefix } = message.channel.guild ? await database.guilds.findOne({ id: message.channel.guild.id }) : "N/A";
const commands = collections.commands;
const aliases = collections.aliases;
if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(args[0].toLowerCase()))) {
@ -19,7 +19,7 @@ exports.run = async (message, args) => {
"name": "esmBot Help",
"icon_url": client.user.avatarURL
},
"title": `${guild.prefix}${command}`,
"title": `${prefix}${command}`,
"url": "https://projectlounge.pw/esmBot/help.html",
"description": info.description,
"color": 16711680,
@ -101,7 +101,7 @@ exports.run = async (message, args) => {
},
"fields": [{
"name": "Prefix",
"value": guild.prefix
"value": prefix
}, {
"name": "Tip",
"value": misc.random(tips)

View File

@ -3,8 +3,8 @@ const paginator = require("../utils/pagination/pagination.js");
const { image_search } = require("duckduckgo-images-api");
exports.run = async (message, args) => {
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
if (message.channel.guild && !message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (message.channel.guild && !message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
if (args.length === 0) return `${message.author.mention}, you need to provide something to search for!`;
const embeds = [];
const images = await image_search({ query: args.join(" "), moderate: true });

View File

@ -34,7 +34,7 @@ exports.run = async () => {
},
{
"name": "💻 Source Code:",
"value": "[Click here!](https://github.com/TheEssem/esmBot)"
"value": "[Click here!](https://github.com/esmBot/esmBot)"
},
{
"name": "<:twitter:652550515372064768> Twitter:",

View File

@ -1,6 +1,7 @@
const client = require("../utils/client.js");
exports.run = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("kickMembers")) return `${message.author.mention}, you need to have the \`Kick Members\` permission on this server to kick people!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("kickMembers") && !message.channel.permissionsOf(client.user.id).has("kickMembers")) return `${message.author.mention}, I don't have the \`Kick Members\` permission!`;
const member = message.mentions[0];

View File

@ -2,7 +2,7 @@ const client = require("../utils/client.js");
exports.run = async (message) => {
const pingMessage = await client.createMessage(message.channel.id, "🏓 Ping?");
return pingMessage.edit(`🏓 Pong!\n\`\`\`\nLatency: ${pingMessage.timestamp - message.timestamp}ms\nAPI Latency: ${Math.round(client.shards.get(client.guildShardMap[message.channel.guild.id]).latency)}ms\n\`\`\``);
return pingMessage.edit(`🏓 Pong!\n\`\`\`\nLatency: ${pingMessage.timestamp - message.timestamp}ms${message.channel.guild ? `\nShard Latency: ${Math.round(client.shards.get(client.guildShardMap[message.channel.guild.id]).latency)}ms` : ""}\n\`\`\``);
};
exports.aliases = ["pong"];

View File

@ -1,6 +1,7 @@
const database = require("../utils/database.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
if (args.length !== 0) {
if (!message.member.permission.has("administrator") && message.member.id !== process.env.OWNER) return `${message.author.mention}, you need to be an administrator to change the bot prefix!`;

View File

@ -1,6 +1,7 @@
const client = require("../utils/client.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("manageMessages")) return `${message.author.mention}, you need to have the \`Manage Messages\` permission on this server to purge messages!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("manageMessages") && !message.channel.permissionsOf(client.user.id).has("manageMessages")) return `${message.author.mention}, I don't have the \`Manage Messages\` permission!`;
if (args.length === 0 || !args[0].match(/^\d+$/)) return `${message.author.mention}, you need to provide the number of messages to purge!`;

View File

@ -1,4 +1,5 @@
exports.run = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
const owner = await message.channel.guild.members.get(message.channel.guild.ownerID);
const infoEmbed = {
"embed": {

View File

@ -4,6 +4,7 @@ const paginator = require("../utils/pagination/pagination.js");
const { random } = require("../utils/misc.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const tags = guild.tags;

View File

@ -15,7 +15,7 @@ exports.run = async (message, args) => {
user = message.author;
}
//const user = getUser !== undefined ? getUser : (message.author);
const member = message.channel.guild.members.get(user.id);
const member = message.channel.guild ? message.channel.guild.members.get(user.id) : undefined;
const infoEmbed = {
"embed": {
"title": `${user.username}#${user.discriminator}`,

View File

@ -3,6 +3,7 @@ const client = require("../utils/client.js");
const paginator = require("../utils/pagination/pagination.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("manageMessages")) return `${message.author.mention}, you need to have the \`Manage Messages\` permission on this server to warn people!`;
const memberCheck = message.mentions.length >= 1 ? message.mentions[0] : client.users.get(args[0]);
const member = memberCheck ? memberCheck : client.users.get(args[0].replace(/\D/g, ""));

View File

@ -8,15 +8,14 @@ const collections = require("../utils/collections.js");
module.exports = async (message) => {
// ignore dms and other bots
if (message.author.bot) return;
if (!message.channel.guild) return;
// don't run command if bot can't send messages
if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return;
if (message.channel.guild && (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages"))) return;
// prefix can be a mention or a set of special characters
const guildDB = await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec();
const guildDB = message.channel.guild ? await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec() : null;
const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildDB.prefix;
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : (message.channel.guild ? guildDB.prefix : "");
// ignore other stuff
if (message.content.startsWith(prefix) === false) return;
@ -27,7 +26,7 @@ module.exports = async (message) => {
const command = args.shift().toLowerCase();
// don't run if message is in a disabled channel
if (guildDB.disabledChannels && guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
if (guildDB && guildDB.disabledChannels && guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
// check if command exists
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
@ -68,7 +67,7 @@ module.exports = async (message) => {
await client.createMessage(message.channel.id, `${message.author.mention}, the request timed out before I could download that image. Try uploading your image somewhere else.`);
} else {
logger.error(error.toString());
await client.createMessage(message.channel.id, "Uh oh! I ran into an error while running this command. Please report the content of the attached file here or on the esmBot Support server: <https://github.com/TheEssem/esmBot/issues>", [{
await client.createMessage(message.channel.id, "Uh oh! I ran into an error while running this command. Please report the content of the attached file here or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>", [{
file: Buffer.from(`Message: ${error}\n\nStack Trace: ${error.stack}`),
name: "error.txt"
}]);

72
package-lock.json generated
View File

@ -69,9 +69,9 @@
"integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM="
},
"@types/node": {
"version": "14.0.23",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.23.tgz",
"integrity": "sha512-Z4U8yDAl5TFkmYsZdFPdjeMa57NOvnaf1tljHzhouaPEp7LCj2JKkejpI1ODviIAQuW4CcQmxkQ77rnLsOOoKw=="
"version": "14.6.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.2.tgz",
"integrity": "sha512-onlIwbaeqvZyniGPfdw/TEhKIh79pz66L1q06WUQqJLnAb6wbjvOtepLYTGHTqzdXgBYIE3ZdmqHDGsRsbBz7A=="
},
"abort-controller": {
"version": "3.0.0",
@ -209,6 +209,15 @@
"file-uri-to-path": "1.0.0"
}
},
"bl": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
"integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
"requires": {
"readable-stream": "^2.3.5",
"safe-buffer": "^5.1.1"
}
},
"bluebird": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
@ -264,9 +273,9 @@
}
},
"bson": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.4.tgz",
"integrity": "sha512-S/yKGU1syOMzO86+dGpg2qGoDL0zvzcb262G+gqEy6TgP6rt6z6qxSFX/8X6vLC91P7G7C3nLs0+bvDzmvBA3Q=="
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.5.tgz",
"integrity": "sha512-kDuEzldR21lHciPQAIulLs1LZlCXdLziXI6Mb/TDkwXhb//UORJNPXgcRs2CuO4H0DcMkpfT3/ySsP3unoZjBg=="
},
"buffer": {
"version": "5.4.3",
@ -615,9 +624,9 @@
"integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg=="
},
"dblapi.js": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/dblapi.js/-/dblapi.js-2.4.0.tgz",
"integrity": "sha512-SqDYVcV1DBQnyhySTjd+Qvzu7jFr+4eKwl56fGpIti7OlXGF5dmDPeo3jQfRlOXTRn5/I5997MDIJukoDxE3Mg=="
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/dblapi.js/-/dblapi.js-2.4.1.tgz",
"integrity": "sha512-g+u1inF/qOLit5qPK4hBGk5pKL1vy09uBLV+nukkRMvw2S9D1PyiyO70n4fboUXOgbExPp6Sho/Y782OqQOUiQ=="
},
"debug": {
"version": "4.1.1",
@ -1228,12 +1237,12 @@
}
},
"form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
@ -1664,9 +1673,9 @@
"integrity": "sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ=="
},
"mongodb": {
"version": "3.5.9",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.9.tgz",
"integrity": "sha512-vXHBY1CsGYcEPoVWhwgxIBeWqP3dSu9RuRDsoLRPTITrcrgm1f0Ubu1xqF9ozMwv53agmEiZm0YGo+7WL3Nbug==",
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.0.tgz",
"integrity": "sha512-/XWWub1mHZVoqEsUppE0GV7u9kanLvHxho6EvBxQbShXTKYF9trhZC2NzbulRGeG7xMJHD8IOWRcdKx5LPjAjQ==",
"requires": {
"bl": "^2.2.0",
"bson": "^1.1.4",
@ -1674,27 +1683,16 @@
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2",
"saslprep": "^1.0.0"
},
"dependencies": {
"bl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz",
"integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==",
"requires": {
"readable-stream": "^2.3.5",
"safe-buffer": "^5.1.1"
}
}
}
},
"mongoose": {
"version": "5.9.25",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.25.tgz",
"integrity": "sha512-vz/DqJ3mrHqEIlfRbKmDZ9TzQ1a0hCtSQpjHScIxr4rEtLs0tjsXDeEWcJ/vEEc3oLfP6vRx9V+uYSprXDUvFQ==",
"version": "5.10.2",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.10.2.tgz",
"integrity": "sha512-VO5eZawEMFh2gx9XPg9ZafzFg5eIVs4R7PW6kK1MFqBq34YD7GomkalYWVt02HctvTPDI1mkXsm52LXNZR1NxA==",
"requires": {
"bson": "^1.1.4",
"kareem": "2.3.1",
"mongodb": "3.5.9",
"mongodb": "3.6.0",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.7.0",
"mquery": "3.2.2",
@ -2221,6 +2219,18 @@
"cheerio": "^1.0.0-rc.2",
"form-data": "^2.3.3",
"node-fetch": "^2.3.0"
},
"dependencies": {
"form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
}
}
}
},
"rimraf": {

View File

@ -16,22 +16,23 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/TheEssem/esmBot.git"
"url": "git+https://github.com/esmBot/esmBot.git"
},
"dependencies": {
"@lavacord/eris": "0.0.3",
"abort-controller": "^3.0.0",
"cowsay": "^1.4.0",
"dblapi.js": "^2.4.0",
"dblapi.js": "^2.4.1",
"dotenv": "^8.2.0",
"duckduckgo-images-api": "github:benpbolton/duckduckgo-images-api",
"emoji-regex": "^8.0.0",
"eris": "^0.13.3",
"file-type": "^13.1.2",
"form-data": "^3.0.0",
"lavacord": "^1.1.9",
"moment": "^2.27.0",
"moment-duration-format": "^2.3.2",
"mongoose": "^5.9.25",
"mongoose": "^5.10.2",
"node-addon-api": "^3.0.1",
"node-emoji": "^1.10.0",
"node-fetch": "^2.6.0",

View File

@ -1,5 +1,5 @@
# <img src="https://github.com/TheEssem/esmBot/raw/master/esmbot.png" width="128"> esmBot
[![esmBot Support](https://discordapp.com/api/guilds/592399417676529688/embed.png)](https://discord.gg/vfFM7YT) ![GitHub license](https://img.shields.io/github/license/TheEssem/esmBot.svg)
# <img src="https://github.com/esmBot/esmBot/raw/master/esmbot.png" width="128"> esmBot
[![esmBot Support](https://discordapp.com/api/guilds/592399417676529688/embed.png)](https://discord.gg/vfFM7YT) ![GitHub license](https://img.shields.io/github/license/esmBot/esmBot.svg)
esmBot is an easily-extendable, multipurpose, and entertainment-focused Discord bot made using [Eris](https://abal.moe/Eris/) with image, music, and utility commands, alongside many others.

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;