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:
parent
7a254a5139
commit
8a2d4e6669
16 changed files with 57 additions and 52 deletions
|
@ -157,10 +157,13 @@ if (isMainThread) {
|
|||
|
||||
log(`${job.uuid} is done`, job.threadNum);
|
||||
const server = net.createServer(function(socket) {
|
||||
socket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]));
|
||||
socket.end();
|
||||
socket.write(Buffer.concat([Buffer.from(type ? type : "image/png"), Buffer.from("\n"), data]), (err) => {
|
||||
if (err) console.error(err);
|
||||
socket.end(() => {
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
});
|
||||
server.listen(job.port, job.addr);
|
||||
// handle address in use errors
|
||||
server.on("error", (e) => {
|
||||
|
|
|
@ -24,7 +24,7 @@ exports.run = async (message, args) => {
|
|||
"name": "esmBot Help",
|
||||
"icon_url": client.user.avatarURL
|
||||
},
|
||||
"title": `${prefix}${command}`,
|
||||
"title": `${message.channel.guild ? prefix : ""}${command}`,
|
||||
"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,
|
||||
"color": 16711680,
|
||||
|
@ -106,7 +106,7 @@ exports.run = async (message, args) => {
|
|||
},
|
||||
"fields": [{
|
||||
"name": "Prefix",
|
||||
"value": prefix
|
||||
"value": message.channel.guild ? prefix : "N/A"
|
||||
}, {
|
||||
"name": "Tip",
|
||||
"value": misc.random(tips)
|
||||
|
|
|
@ -16,7 +16,7 @@ exports.run = async () => {
|
|||
},
|
||||
{
|
||||
"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:",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ const urlRegex = /(?:\w+:)?\/\/(\S+)/;
|
|||
const searchRegex = /^(sc|yt)search:/;
|
||||
|
||||
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!`;
|
||||
const query = args.join(" ").trim();
|
||||
const search = urlRegex.test(query) ? query : (searchRegex.test(query) ? query : `ytsearch:${query}`);
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
const jsqr = require("jsqr");
|
||||
const fetch = require("node-fetch");
|
||||
const sharp = require("sharp");
|
||||
|
||||
exports.run = async (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!`;
|
||||
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);
|
||||
if (!qrBuffer) return `${message.author.mention}, I couldn't find a QR code!`;
|
||||
return `\`\`\`\n${qrBuffer.data}\n\`\`\``;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const soundPlayer = require("../utils/soundplayer.js");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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]";
|
|
@ -24,6 +24,7 @@ module.exports = async (message) => {
|
|||
if (!valid) return;
|
||||
|
||||
let prefixCandidate;
|
||||
if (message.channel.guild) {
|
||||
if (collections.prefixCache.has(message.channel.guild.id)) {
|
||||
prefixCandidate = collections.prefixCache.get(message.channel.guild.id);
|
||||
} else {
|
||||
|
@ -34,6 +35,7 @@ module.exports = async (message) => {
|
|||
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.
|
||||
// there's also bit of a workaround here due to member.mention not accounting for both mention types
|
||||
|
@ -48,6 +50,7 @@ module.exports = async (message) => {
|
|||
const command = args.shift().toLowerCase();
|
||||
|
||||
// don't run if message is in a disabled channel
|
||||
if (message.channel.guild) {
|
||||
if (collections.disabledCache.has(message.channel.guild.id)) {
|
||||
const disabled = collections.disabledCache.get(message.channel.guild.id);
|
||||
if (disabled.includes(message.channel.id) && command != "channel") return;
|
||||
|
@ -56,6 +59,7 @@ module.exports = async (message) => {
|
|||
collections.disabledCache.set(message.channel.guild.id, guildDB.disabled);
|
||||
if (guildDB.disabled.includes(message.channel.id) && command !== "channel") return;
|
||||
}
|
||||
}
|
||||
|
||||
// check if command exists
|
||||
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
|
||||
|
|
|
@ -45,12 +45,14 @@ const getIdeal = () => {
|
|||
});
|
||||
if (!serversLeft) {
|
||||
clearTimeout(timeout);
|
||||
socket.close(async () => {
|
||||
try {
|
||||
const server = await chooseServer(idealServers);
|
||||
resolve(server);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -85,18 +85,12 @@ module.exports = async (cmdMessage) => {
|
|||
if (result !== false) return result;
|
||||
// if there aren't any in the current message then check if there's a reply
|
||||
if (cmdMessage.messageReference) {
|
||||
const replyGuild = client.guilds.get(cmdMessage.messageReference.guildID);
|
||||
if (replyGuild) {
|
||||
const replyChannel = replyGuild.channels.get(cmdMessage.messageReference.channelID);
|
||||
if (replyChannel) {
|
||||
const replyMessage = replyChannel.messages.get(cmdMessage.messageReference.messageID);
|
||||
const replyMessage = await client.getMessage(cmdMessage.messageReference.channelID, 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
|
||||
const messages = await cmdMessage.channel.getMessages();
|
||||
// iterate over each message
|
||||
|
|
|
@ -47,6 +47,7 @@ exports.connect = async () => {
|
|||
};
|
||||
|
||||
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.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);
|
||||
|
@ -148,6 +149,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel,
|
|||
};
|
||||
|
||||
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.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!`;
|
||||
|
@ -160,6 +162,7 @@ exports.stop = 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.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);
|
||||
|
@ -184,6 +187,7 @@ exports.skip = 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.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!`;
|
||||
|
@ -193,6 +197,7 @@ exports.pause = 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.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;
|
||||
|
@ -227,6 +232,7 @@ exports.playing = 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.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!`;
|
||||
|
@ -274,6 +280,7 @@ exports.queue = 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.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!`;
|
||||
|
|
Loading…
Reference in a new issue