Fixed image API request closing prematurely, disabled music commands in production, various fixes regarding direct messages, fixed reply image checking, and removed yoda

This commit is contained in:
TheEssem 2020-12-26 12:17:10 -06:00
parent 7a254a5139
commit 8a2d4e6669
16 changed files with 57 additions and 52 deletions

View file

@ -157,9 +157,12 @@ if (isMainThread) {
log(`${job.uuid} is done`, job.threadNum); log(`${job.uuid} is done`, job.threadNum);
const server = net.createServer(function(socket) { const server = net.createServer(function(socket) {
socket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data])); socket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]), (err) => {
socket.end(); if (err) console.error(err);
process.exit(); socket.end(() => {
process.exit();
});
});
}); });
server.listen(job.port, job.addr); server.listen(job.port, job.addr);
// handle address in use errors // handle address in use errors

View file

@ -24,7 +24,7 @@ exports.run = async (message, args) => {
"name": "esmBot Help", "name": "esmBot Help",
"icon_url": client.user.avatarURL "icon_url": client.user.avatarURL
}, },
"title": `${prefix}${command}`, "title": `${message.channel.guild ? prefix : ""}${command}`,
"url": "https://projectlounge.pw/esmBot/help.html", "url": "https://projectlounge.pw/esmBot/help.html",
"description": command === "tags" ? "The main tags command. Check the help page for more info: https://projectlounge.pw/esmBot/help.html" : info.description, "description": command === "tags" ? "The main tags command. Check the help page for more info: https://projectlounge.pw/esmBot/help.html" : info.description,
"color": 16711680, "color": 16711680,
@ -106,7 +106,7 @@ exports.run = async (message, args) => {
}, },
"fields": [{ "fields": [{
"name": "Prefix", "name": "Prefix",
"value": prefix "value": message.channel.guild ? prefix : "N/A"
}, { }, {
"name": "Tip", "name": "Tip",
"value": misc.random(tips) "value": misc.random(tips)

View file

@ -16,7 +16,7 @@ exports.run = async () => {
}, },
{ {
"name": "📝 Credits:", "name": "📝 Credits:",
"value": "Bot by **[Essem](https://essem.space)**\nIcon by **[MintBorrow](https://mintborrow.newgrounds.com)**" "value": "Bot by **[Essem](https://essem.space)** and **[various contributors](https://github.com/esmBot/esmBot/graphs/contributors)**\nIcon by **[MintBorrow](https://mintborrow.newgrounds.com)**"
}, },
{ {
"name": "💬 Total Servers:", "name": "💬 Total Servers:",

View file

@ -1,6 +1,7 @@
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
exports.run = async (message) => { exports.run = async (message) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
return await soundPlayer.loop(message); return await soundPlayer.loop(message);
}; };

View file

@ -1,6 +1,7 @@
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
exports.run = async (message) => { exports.run = async (message) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
return await soundPlayer.playing(message); return await soundPlayer.playing(message);
}; };

View file

@ -1,6 +1,7 @@
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
exports.run = async (message) => { exports.run = async (message) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
return await soundPlayer.pause(message); return await soundPlayer.pause(message);
}; };

View file

@ -3,6 +3,7 @@ const urlRegex = /(?:\w+:)?\/\/(\S+)/;
const searchRegex = /^(sc|yt)search:/; const searchRegex = /^(sc|yt)search:/;
exports.run = async (message, args) => { exports.run = async (message, args) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
if (!args[0]) return `${message.author.mention}, you need to provide what you want to play!`; if (!args[0]) return `${message.author.mention}, you need to provide what you want to play!`;
const query = args.join(" ").trim(); const query = args.join(" ").trim();
const search = urlRegex.test(query) ? query : (searchRegex.test(query) ? query : `ytsearch:${query}`); const search = urlRegex.test(query) ? query : (searchRegex.test(query) ? query : `ytsearch:${query}`);

View file

@ -1,11 +1,13 @@
const jsqr = require("jsqr"); const jsqr = require("jsqr");
const fetch = require("node-fetch");
const sharp = require("sharp"); const sharp = require("sharp");
exports.run = async (message) => { exports.run = async (message) => {
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 with a QR code to read!`; if (image === undefined) return `${message.author.mention}, you need to provide an image with a QR code to read!`;
message.channel.sendTyping(); message.channel.sendTyping();
const rawData = await sharp(image.path).ensureAlpha().raw().toBuffer({ resolveWithObject: true }); const data = await (await fetch(image.path)).buffer();
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);
if (!qrBuffer) return `${message.author.mention}, I couldn't find a QR code!`; if (!qrBuffer) return `${message.author.mention}, I couldn't find a QR code!`;
return `\`\`\`\n${qrBuffer.data}\n\`\`\``; return `\`\`\`\n${qrBuffer.data}\n\`\`\``;

View file

@ -1,6 +1,7 @@
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
exports.run = async (message) => { exports.run = async (message) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
return await soundPlayer.queue(message); return await soundPlayer.queue(message);
}; };

View file

@ -1,6 +1,7 @@
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
exports.run = async (message) => { exports.run = async (message) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
return await soundPlayer.skip(message); return await soundPlayer.skip(message);
}; };

View file

@ -1,6 +1,7 @@
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
exports.run = async (message) => { exports.run = async (message) => {
if (process.env.NODE_ENV === "production") return "Music commands are coming soon, but they aren't ready yet. Stay tuned to @esmBot_ on Twitter for updates!";
return await soundPlayer.stop(message); return await soundPlayer.stop(message);
}; };

View file

@ -1,14 +0,0 @@
const fetch = require("node-fetch");
exports.run = async (message, args) => {
return `${message.author.mention}, this command is currently disabled due to various issues. We are looking for a fix.`;
/*if (args.length === 0) return `${message.author.mention}, you need to provide some text to translate to Yodish!`;
const request = await fetch(`https://yoda-api.appspot.com/api/v1/yodish?text=${encodeURIComponent(args.join(" "))}`);
const json = await request.json();
return json.yodish;*/
};
exports.aliases = ["yodish"];
exports.category = 4;
exports.help = "Translates a message to Yodish (disabled)";
exports.params = "[text]";

View file

@ -24,15 +24,17 @@ module.exports = async (message) => {
if (!valid) return; if (!valid) return;
let prefixCandidate; let prefixCandidate;
if (collections.prefixCache.has(message.channel.guild.id)) { if (message.channel.guild) {
prefixCandidate = collections.prefixCache.get(message.channel.guild.id); if (collections.prefixCache.has(message.channel.guild.id)) {
} else { prefixCandidate = collections.prefixCache.get(message.channel.guild.id);
let guildDB = message.channel.guild ? await database.getGuild(message.channel.guild.id) : null; } else {
if (message.channel.guild && !(guildDB && guildDB.disabled)) { let guildDB = message.channel.guild ? await database.getGuild(message.channel.guild.id) : null;
guildDB = await database.fixGuild(message.channel.guild); if (message.channel.guild && !(guildDB && guildDB.disabled)) {
guildDB = await database.fixGuild(message.channel.guild);
}
prefixCandidate = guildDB.prefix;
collections.prefixCache.set(message.channel.guild.id, guildDB.prefix);
} }
prefixCandidate = guildDB.prefix;
collections.prefixCache.set(message.channel.guild.id, guildDB.prefix);
} }
// this line be like Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. // this line be like Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain.
@ -48,13 +50,15 @@ module.exports = async (message) => {
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
// don't run if message is in a disabled channel // don't run if message is in a disabled channel
if (collections.disabledCache.has(message.channel.guild.id)) { if (message.channel.guild) {
const disabled = collections.disabledCache.get(message.channel.guild.id); if (collections.disabledCache.has(message.channel.guild.id)) {
if (disabled.includes(message.channel.id) && command != "channel") return; const disabled = collections.disabledCache.get(message.channel.guild.id);
} else if (message.channel.guild) { if (disabled.includes(message.channel.id) && command != "channel") return;
const guildDB = await database.getGuild(message.channel.guild.id); } else if (message.channel.guild) {
collections.disabledCache.set(message.channel.guild.id, guildDB.disabled); const guildDB = await database.getGuild(message.channel.guild.id);
if (guildDB.disabled.includes(message.channel.id) && command !== "channel") return; collections.disabledCache.set(message.channel.guild.id, guildDB.disabled);
if (guildDB.disabled.includes(message.channel.id) && command !== "channel") return;
}
} }
// check if command exists // check if command exists

View file

@ -45,12 +45,14 @@ const getIdeal = () => {
}); });
if (!serversLeft) { if (!serversLeft) {
clearTimeout(timeout); clearTimeout(timeout);
try { socket.close(async () => {
const server = await chooseServer(idealServers); try {
resolve(server); const server = await chooseServer(idealServers);
} catch (e) { resolve(server);
reject(e); } catch (e) {
} reject(e);
}
});
} }
} }
}); });

View file

@ -85,16 +85,10 @@ module.exports = async (cmdMessage) => {
if (result !== false) return result; if (result !== false) return result;
// if there aren't any in the current message then check if there's a reply // if there aren't any in the current message then check if there's a reply
if (cmdMessage.messageReference) { if (cmdMessage.messageReference) {
const replyGuild = client.guilds.get(cmdMessage.messageReference.guildID); const replyMessage = await client.getMessage(cmdMessage.messageReference.channelID, cmdMessage.messageReference.messageID);
if (replyGuild) { if (replyMessage) {
const replyChannel = replyGuild.channels.get(cmdMessage.messageReference.channelID); const replyResult = await checkImages(replyMessage);
if (replyChannel) { if (replyResult !== false) return replyResult;
const replyMessage = replyChannel.messages.get(cmdMessage.messageReference.messageID);
if (replyMessage) {
const replyResult = await checkImages(replyMessage);
if (replyResult !== false) return replyResult;
}
}
} }
} }
// 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

View file

@ -47,6 +47,7 @@ exports.connect = async () => {
}; };
exports.play = async (sound, message, music = false) => { exports.play = async (sound, message, music = false) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return `${message.author.mention}, I can't join this voice channel!`; if (!message.channel.guild.members.get(client.user.id).permission.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return `${message.author.mention}, I can't join this voice channel!`;
const voiceChannel = message.channel.guild.channels.get(message.member.voiceState.channelID); const voiceChannel = message.channel.guild.channels.get(message.member.voiceState.channelID);
@ -148,6 +149,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel,
}; };
exports.stop = async (message) => { exports.stop = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`; if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
if (this.players.get(message.channel.guild.id).host !== message.author.id) return `${message.author.mention}, only the current voice session host can stop the music!`; if (this.players.get(message.channel.guild.id).host !== message.author.id) return `${message.author.mention}, only the current voice session host can stop the music!`;
@ -160,6 +162,7 @@ exports.stop = async (message) => {
}; };
exports.skip = async (message) => { exports.skip = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`; if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
const player = this.players.get(message.channel.guild.id); const player = this.players.get(message.channel.guild.id);
@ -184,6 +187,7 @@ exports.skip = async (message) => {
}; };
exports.pause = async (message) => { exports.pause = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`; if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
if (this.players.get(message.channel.guild.id).host !== message.author.id) return `${message.author.mention}, only the current voice session host can pause/resume the music!`; if (this.players.get(message.channel.guild.id).host !== message.author.id) return `${message.author.mention}, only the current voice session host can pause/resume the music!`;
@ -193,6 +197,7 @@ exports.pause = async (message) => {
}; };
exports.playing = async (message) => { exports.playing = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`; if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
const player = this.players.get(message.channel.guild.id).player; const player = this.players.get(message.channel.guild.id).player;
@ -227,6 +232,7 @@ exports.playing = async (message) => {
}; };
exports.queue = async (message) => { exports.queue = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`; if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
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("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
@ -274,6 +280,7 @@ exports.queue = async (message) => {
}; };
exports.loop = async (message) => { exports.loop = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`; if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`; if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
if (this.players.get(message.channel.guild.id).host !== message.author.id) return `${message.author.mention}, only the current voice session host can loop the music!`; if (this.players.get(message.channel.guild.id).host !== message.author.id) return `${message.author.mention}, only the current voice session host can loop the music!`;