Fixed some DM command issues, made reload and restart use IPC

This commit is contained in:
TheEssem 2021-04-30 12:31:53 -05:00
parent e0e0c9c7d4
commit 56113a1cf8
18 changed files with 54 additions and 35 deletions

View file

@ -4,7 +4,7 @@ const Command = require("../../classes/command.js");
class LengthenCommand extends Command {
async run() {
this.message.channel.sendTyping();
this.client.sendChannelTyping(this.message.channel.id);
if (this.args.length === 0 || !urlCheck(this.args[0])) return `${this.message.author.mention}, you need to provide a short URL to lengthen!`;
if (urlCheck(this.args[0])) {
const url = await fetch(encodeURI(this.args[0]), { redirect: "manual" });

View file

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

View file

@ -5,7 +5,7 @@ const Command = require("../../classes/command.js");
class QrCreateCommand extends Command {
async run() {
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide some text to generate a QR code!`;
this.message.channel.sendTyping();
this.client.sendChannelTyping(this.message.channel.id);
const writable = new stream.PassThrough();
qrcode.toFileStream(writable, this.content, { margin: 1 });
const file = await this.streamToBuf(writable);

View file

@ -8,7 +8,7 @@ class QrReadCommand extends Command {
async run() {
const image = await require("../../utils/imagedetect.js")(this.client, this.message);
if (image === undefined) return `${this.message.author.mention}, you need to provide an image with a QR code to read!`;
this.message.channel.sendTyping();
this.client.sendChannelTyping(this.message.channel.id);
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);

View file

@ -1,16 +1,23 @@
const handler = require("../../utils/handler.js");
const collections = require("../../utils/collections.js");
const Command = require("../../classes/command.js");
class ReloadCommand extends Command {
async run() {
if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can reload commands!`;
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide a command to reload!`;
const result = await handler.unload(this.args[0]);
if (result) return result;
const result2 = await handler.load(collections.paths.get(this.args[0]));
if (result2) return result2;
return `${this.message.author.mention}, the command \`${this.args[0]}\` has been reloaded.`;
// quite possibly one of the hackiest commands in the bot
run() {
return new Promise((resolve) => {
if (this.message.author.id !== process.env.OWNER) resolve(`${this.message.author.mention}, only the bot owner can reload commands!`);
if (this.args.length === 0) resolve(`${this.message.author.mention}, you need to provide a command to reload!`);
this.ipc.broadcast("reload", { cmd: this.args[0] });
this.ipc.register("reloadSuccess", () => {
this.ipc.unregister("reloadSuccess");
this.ipc.unregister("reloadFail");
resolve(`${this.message.author.mention}, the command \`${this.args[0]}\` has been reloaded.`);
});
this.ipc.register("reloadFail", (message) => {
this.ipc.unregister("reloadSuccess");
this.ipc.unregister("reloadFail");
resolve(message);
});
});
}
static description = "Reloads a command";

View file

@ -5,11 +5,11 @@ const Command = require("../../classes/command.js");
class RestartCommand extends Command {
async run() {
if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can restart me!`;
await this.message.channel.createMessage(`${this.message.author.mention}, esmBot is restarting.`);
await this.client.createMessage(this.message.channel.id, `${this.message.author.mention}, esmBot is restarting.`);
for (const command of collections.commands) {
await handler.unload(command);
}
process.exit(1);
this.ipc.broadcast("restart");
}
static description = "Restarts me";

View file

@ -54,7 +54,7 @@ class StatsCommand extends Command {
},
{
"name": "Shard",
"value": this.client.guildShardMap[this.message.channel.guild.id],
"value": this.message.channel.guild ? this.client.guildShardMap[this.message.channel.guild.id] : "N/A",
"inline": true
}
]

View file

@ -6,7 +6,7 @@ const Command = require("../../classes/command.js");
class YouTubeCommand extends Command {
async run() {
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide something to search for!`;
this.message.channel.sendTyping();
this.client.sendChannelTyping(this.message.channel.id);
const messages = [];
const request = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(this.args.join(" "))}&key=${process.env.GOOGLE}&maxResults=50`);
const result = await request.json();