Reject feedback messages if they contain links, increased image request timeout, some other fixes

This commit is contained in:
TheEssem 2020-08-13 08:47:41 -05:00
parent 23eb83d7b6
commit ba664fd19a
7 changed files with 14 additions and 9 deletions

View file

@ -1,7 +1,9 @@
const client = require("../utils/client.js"); const client = require("../utils/client.js");
const regex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig;
exports.run = async (message, args) => { exports.run = async (message, args) => {
if (args.length !== 0) { if (args.length !== 0) {
if (regex.test(args.join(" "))) return `${message.author.mention}, you can't send a message containing a URL. If you want to report an issue, please join the esmBot Support server instead.`;
const feedbackChannel = client.guilds.get("592399417676529688").channels.get("592429860769497098"); const feedbackChannel = client.guilds.get("592399417676529688").channels.get("592429860769497098");
feedbackChannel.createMessage({ feedbackChannel.createMessage({
embed: { embed: {

View file

@ -1,5 +1,6 @@
const magick = require("../build/Release/image.node"); const magick = require("../build/Release/image.node");
const { promisify } = require("util"); const { promisify } = require("util");
const { clean } = require("../utils/misc.js");
exports.run = async (message) => { exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message); const image = await require("../utils/imagedetect.js")(message);
@ -7,7 +8,7 @@ exports.run = async (message) => {
message.channel.sendTyping(); message.channel.sendTyping();
const {qrText, missing} = await promisify(magick.qrread)(image.path); const {qrText, missing} = await promisify(magick.qrread)(image.path);
if (missing) return `${message.author.mention}, I couldn't find a QR code!`; if (missing) return `${message.author.mention}, I couldn't find a QR code!`;
return `\`\`\`\n${qrText}\n\`\`\``; return `\`\`\`\n${await clean(qrText)}\n\`\`\``;
}; };
exports.category = 1; exports.category = 1;

View file

@ -1,5 +1,4 @@
const fs = require("fs"); const fs = require("fs");
const { promisify } = require("util");
const client = require("../utils/client.js"); const client = require("../utils/client.js");
const database = require("../utils/database.js"); const database = require("../utils/database.js");
const logger = require("../utils/logger.js"); const logger = require("../utils/logger.js");
@ -47,7 +46,7 @@ module.exports = async (message) => {
} else if (typeof result === "object" && result.file) { } else if (typeof result === "object" && result.file) {
if (result.file.length > 8388119 && process.env.TEMPDIR !== "") { if (result.file.length > 8388119 && process.env.TEMPDIR !== "") {
const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`; const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`;
await promisify(fs.writeFile)(`${process.env.TEMPDIR}/${filename}`, result.file); await fs.promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file);
await client.createMessage(message.channel.id, { await client.createMessage(message.channel.id, {
embed: { embed: {
color: 16711680, color: 16711680,

View file

@ -111,5 +111,6 @@
"Schmelf?", "Schmelf?",
"Troll", "Troll",
"ay yo the pizza here", "ay yo the pizza here",
"100 gecs" "100 gecs",
"with limited resources"
] ]

View file

@ -9,6 +9,8 @@ ${process.env.NODE_ENV === "development" ? "\n**You are currently using esmBot D
Default prefix is \`&\`. Default prefix is \`&\`.
**Want to help support esmBot's development? Consider donating on Patreon!** https://patreon.com/TheEssem
> Tip: You can get more info about a command by using \`help [command]\`. > Tip: You can get more info about a command by using \`help [command]\`.
## Table of Contents ## Table of Contents

View file

@ -12,7 +12,7 @@ const typeCheck = async (image, image2, gifv = false) => {
const controller = new AbortController(); const controller = new AbortController();
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
controller.abort(); controller.abort();
}, 15000); }, 25000);
try { try {
const imageRequest = await fetch(image, { signal: controller.signal }); const imageRequest = await fetch(image, { signal: controller.signal });
const imageBuffer = await imageRequest.buffer(); const imageBuffer = await imageRequest.buffer();

View file

@ -1,11 +1,11 @@
module.exports = (string) => { module.exports = (string) => {
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/; const protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
var domainRE = /^[^\s.]+\.\S{2,}$/; const domainRE = /^[^\s.]+\.\S{2,}$/;
var match = string.match(protocolAndDomainRE); const match = string.match(protocolAndDomainRE);
if (!match) { if (!match) {
return false; return false;
} }
var everythingAfterProtocol = match[1]; const everythingAfterProtocol = match[1];
if (!everythingAfterProtocol) { if (!everythingAfterProtocol) {
return false; return false;
} }