Made command outputs post as replies, fixed status changing on cluster restart, extra stuff
This commit is contained in:
parent
08ecfc7d10
commit
364d8bf006
41 changed files with 212 additions and 159 deletions
|
@ -3,10 +3,10 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class ChannelCommand extends Command {
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return `${this.message.author.mention}, this command only works in servers!`;
|
||||
if (!this.message.member.permission.has("administrator") && this.message.member.id !== process.env.OWNER) return `${this.message.author.mention}, you need to be an administrator to enable/disable me!`;
|
||||
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide whether I should be enabled or disabled in this channel!`;
|
||||
if (this.args[0] !== "disable" && this.args[0] !== "enable") return `${this.message.author.mention}, that's not a valid option!`;
|
||||
if (!this.message.channel.guild) return "This command only works in servers!";
|
||||
if (!this.message.member.permission.has("administrator") && this.message.member.id !== process.env.OWNER) return "You need to be an administrator to enable/disable me!";
|
||||
if (this.args.length === 0) return "You need to provide whether I should be enabled or disabled in this channel!";
|
||||
if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!";
|
||||
|
||||
const guildDB = await db.getGuild(this.message.channel.guild.id);
|
||||
|
||||
|
@ -14,28 +14,28 @@ class ChannelCommand extends Command {
|
|||
let channel;
|
||||
if (this.args[1] && this.args[1].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
|
||||
const id = this.args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
|
||||
if (guildDB.disabled.includes(id)) return `${this.message.author.mention}, I'm already disabled in this channel!`;
|
||||
if (guildDB.disabled.includes(id)) return "I'm already disabled in this channel!";
|
||||
channel = this.message.channel.guild.channels.get(id);
|
||||
} else {
|
||||
if (guildDB.disabled.includes(this.message.channel.id)) return `${this.message.author.mention}, I'm already disabled in this channel!`;
|
||||
if (guildDB.disabled.includes(this.message.channel.id)) return "I'm already disabled in this channel!";
|
||||
channel = this.message.channel;
|
||||
}
|
||||
|
||||
await db.disableChannel(channel);
|
||||
return `${this.message.author.mention}, I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
|
||||
return `I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
|
||||
} else if (this.args[0].toLowerCase() === "enable") {
|
||||
let channel;
|
||||
if (this.args[1] && this.args[1].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752) {
|
||||
const id = this.args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
|
||||
if (!guildDB.disabled.includes(id)) return `${this.message.author.mention}, I'm not disabled in that channel!`;
|
||||
if (!guildDB.disabled.includes(id)) return "I'm not disabled in that channel!";
|
||||
channel = this.message.channel.guild.channels.get(id);
|
||||
} else {
|
||||
if (!guildDB.disabled.includes(this.message.channel.id)) return `${this.message.author.mention}, I'm not disabled in this channel!`;
|
||||
if (!guildDB.disabled.includes(this.message.channel.id)) return "I'm not disabled in this channel!";
|
||||
channel = this.message.channel;
|
||||
}
|
||||
|
||||
await db.enableChannel(channel);
|
||||
return `${this.message.author.mention}, I have been re-enabled in this channel.`;
|
||||
return "I have been re-enabled in this channel.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class CountCommand extends Command {
|
||||
async run() {
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("addReactions")) return `${this.message.author.mention}, I don't have the \`Add Reactions\` permission!`;
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return `${this.message.author.mention}, I don't have the \`Embed Links\` permission!`;
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("addReactions")) return "I don't have the `Add Reactions` permission!";
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
|
||||
const counts = await database.getCounts();
|
||||
const countArray = [];
|
||||
for (const entry of Object.entries(counts)) {
|
||||
|
|
|
@ -3,8 +3,8 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class DecodeCommand extends Command {
|
||||
async run() {
|
||||
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide a string to decode!`;
|
||||
const b64Decoded = Buffer.from(this.args.join(" "), "base64").toString("utf-8");
|
||||
if (this.args.length === 0) return "You need to provide a string to decode!";
|
||||
const b64Decoded = Buffer.from(this.args.join(" "), "base64").toString("utf8");
|
||||
return `\`\`\`\n${await clean(b64Decoded)}\`\`\``;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class EmoteCommand extends Command {
|
||||
async run() {
|
||||
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide an emoji!`;
|
||||
if (this.args.length === 0) return "You need to provide an emoji!";
|
||||
if (this.content.split(" ")[0].match(/^<a?:.+:\d+>$/)) {
|
||||
return `https://cdn.discordapp.com/emojis/${this.content.split(" ")[0].replace(/^<(a)?:.+:(\d+)>$/, "$2")}.${this.content.split(" ")[0].replace(/^<(a)?:.+:(\d+)>$/, "$1") === "a" ? "gif" : "png"}`;
|
||||
} else if (this.args[0].match(emojiRegex)) {
|
||||
|
@ -13,7 +13,7 @@ class EmoteCommand extends Command {
|
|||
}
|
||||
return `https://twemoji.maxcdn.com/v/latest/72x72/${codePoints.join("-").replace("-fe0f", "")}.png`;
|
||||
} else {
|
||||
return `${this.message.author.mention}, you need to provide a valid emoji to get an image!`;
|
||||
return "You need to provide a valid emoji to get an image!";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class EncodeCommand extends Command {
|
||||
async run() {
|
||||
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide a string to encode!`;
|
||||
const b64Encoded = Buffer.from(this.args.join(" ")).toString("base64");
|
||||
if (this.args.length === 0) return "You need to provide a string to encode!";
|
||||
const b64Encoded = Buffer.from(this.args.join(" "), "utf8").toString("base64");
|
||||
return `\`\`\`\n${b64Encoded}\`\`\``;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class EvalCommand extends Command {
|
||||
async run() {
|
||||
if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can use eval!`;
|
||||
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can use eval!";
|
||||
const code = this.args.join(" ");
|
||||
try {
|
||||
const evaled = eval(code);
|
||||
|
|
|
@ -5,7 +5,7 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class ExecCommand extends Command {
|
||||
async run() {
|
||||
if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can use exec!`;
|
||||
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can use exec!";
|
||||
const code = this.args.join(" ");
|
||||
try {
|
||||
const execed = await exec(code);
|
||||
|
|
|
@ -4,13 +4,13 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class ImageSearchCommand extends Command {
|
||||
async run() {
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("addReactions")) return `${this.message.author.mention}, I don't have the \`Add Reactions\` permission!`;
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return `${this.message.author.mention}, I don't have the \`Embed Links\` permission!`;
|
||||
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide something to search for!`;
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("addReactions")) return "I don't have the `Add Reactions` permission!";
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
|
||||
if (this.args.length === 0) return "You need to provide something to search for!";
|
||||
const embeds = [];
|
||||
const images = await image_search({ query: this.args.join(" "), moderate: true });
|
||||
if (images.error && images.error.code === 403) return `${this.message.author.mention}, the daily search quota has been exceeded. Check back later.`;
|
||||
if (images.length === 0) return `${this.message.author.mention}, I couldn't find any results!`;
|
||||
if (images.error && images.error.code === 403) return "The daily search quota has been exceeded. Check back later.";
|
||||
if (images.length === 0) return "I couldn't find any results!";
|
||||
for (const [i, value] of images.entries()) {
|
||||
embeds.push({
|
||||
"embed": {
|
||||
|
|
|
@ -4,7 +4,7 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class ImageReloadCommand extends Command {
|
||||
async run() {
|
||||
if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can reload the image servers!`;
|
||||
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can reload the image servers!";
|
||||
await image.disconnect();
|
||||
await image.repopulate();
|
||||
let amount = 0;
|
||||
|
@ -19,7 +19,7 @@ class ImageReloadCommand extends Command {
|
|||
if (amount > 0) {
|
||||
return `Successfully connected to ${amount} image servers.`;
|
||||
} else {
|
||||
return `${this.message.author.mention}, I couldn't connect to any image servers!`;
|
||||
return "I couldn't connect to any image servers!";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class InviteCommand extends Command {
|
||||
async run() {
|
||||
return `${this.message.author.mention}, you can invite me to your server here: <https://projectlounge.pw/invite>`;
|
||||
return "You can invite me to your server here: <https://projectlounge.pw/invite>";
|
||||
}
|
||||
|
||||
static description = "Gets my invite link";
|
||||
|
|
|
@ -5,12 +5,12 @@ const Command = require("../../classes/command.js");
|
|||
class LengthenCommand extends Command {
|
||||
async run() {
|
||||
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 (this.args.length === 0 || !urlCheck(this.args[0])) return "You need to provide a short URL to lengthen!";
|
||||
if (urlCheck(this.args[0])) {
|
||||
const url = await fetch(encodeURI(this.args[0]), { redirect: "manual" });
|
||||
return url.headers.get("location") || this.args[0];
|
||||
} else {
|
||||
return `${this.message.author.mention}, that isn't a URL!`;
|
||||
return "That isn't a URL!";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class PingCommand extends Command {
|
||||
async run() {
|
||||
const pingMessage = await this.client.createMessage(this.message.channel.id, "🏓 Ping?");
|
||||
const pingMessage = await this.client.createMessage(this.message.channel.id, Object.assign({
|
||||
content: "🏓 Ping?"
|
||||
}, this.reference));
|
||||
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\`\`\``);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class PrefixCommand extends Command {
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return `${this.message.author.mention}, this command only works in servers!`;
|
||||
if (!this.message.channel.guild) return "This command only works in servers!";
|
||||
const guild = await database.getGuild(this.message.channel.guild.id);
|
||||
if (this.args.length !== 0) {
|
||||
if (!this.message.member.permission.has("administrator") && this.message.member.id !== process.env.OWNER) return `${this.message.author.mention}, you need to be an administrator to change the bot prefix!`;
|
||||
if (!this.message.member.permission.has("administrator") && this.message.member.id !== process.env.OWNER) return "You need to be an administrator to change the bot prefix!";
|
||||
await database.setPrefix(this.args[0], this.message.channel.guild);
|
||||
return `The prefix has been changed to ${this.args[0]}.`;
|
||||
} else {
|
||||
return `${this.message.author.mention}, the current prefix is \`${guild.prefix}\`.`;
|
||||
return `The current prefix is \`${guild.prefix}\`.`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,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!`;
|
||||
if (this.args.length === 0) return "You need to provide some text to generate a QR code!";
|
||||
this.client.sendChannelTyping(this.message.channel.id);
|
||||
const writable = new stream.PassThrough();
|
||||
qrcode.toFileStream(writable, this.content, { margin: 1 });
|
||||
|
|
|
@ -7,12 +7,12 @@ const Command = require("../../classes/command.js");
|
|||
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!`;
|
||||
if (image === undefined) return "You need to provide an image with a QR code to read!";
|
||||
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);
|
||||
if (!qrBuffer) return `${this.message.author.mention}, I couldn't find a QR code!`;
|
||||
if (!qrBuffer) return "I couldn't find a QR code!";
|
||||
return `\`\`\`\n${await clean(qrBuffer.data)}\n\`\`\``;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ class ReloadCommand extends Command {
|
|||
// 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!`);
|
||||
if (this.message.author.id !== process.env.OWNER) resolve("Only the bot owner can reload commands!");
|
||||
if (this.args.length === 0) resolve("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.`);
|
||||
resolve(`The command \`${this.args[0]}\` has been reloaded.`);
|
||||
});
|
||||
this.ipc.register("reloadFail", (message) => {
|
||||
this.ipc.unregister("reloadSuccess");
|
||||
|
|
|
@ -4,8 +4,10 @@ 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.client.createMessage(this.message.channel.id, `${this.message.author.mention}, esmBot is restarting.`);
|
||||
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can restart me!";
|
||||
await this.client.createMessage(this.message.channel.id, Object.assign({
|
||||
content: "esmBot is restarting."
|
||||
}, this.reference));
|
||||
for (const command of collections.commands) {
|
||||
await handler.unload(command);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class ServerInfoCommand extends Command {
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return `${this.message.author.mention}, this command only works in servers!`;
|
||||
if (!this.message.channel.guild) return "This command only works in servers!";
|
||||
const owner = await this.message.channel.guild.members.get(this.message.channel.guild.ownerID);
|
||||
return {
|
||||
"embed": {
|
||||
|
|
|
@ -2,8 +2,8 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class SnowflakeCommand extends Command {
|
||||
async run() {
|
||||
if (!this.args[0]) return `${this.message.author.mention}, you need to provide a snowflake ID!`;
|
||||
if (!this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] < 21154535154122752) return `${this.message.author.mention}, that's not a valid snowflake!`;
|
||||
if (!this.args[0]) return "You need to provide a snowflake ID!";
|
||||
if (!this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] < 21154535154122752) return "That's not a valid snowflake!";
|
||||
return new Date((this.args[0].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "") / 4194304) + 1420070400000).toUTCString();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class SoundReloadCommand extends Command {
|
||||
async run() {
|
||||
if (this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, only the bot owner can reload Lavalink!`;
|
||||
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can reload Lavalink!";
|
||||
const soundStatus = await soundPlayer.checkStatus();
|
||||
if (!soundStatus) {
|
||||
const length = await soundPlayer.connect(this.client);
|
||||
return `Successfully connected to ${length} Lavalink node(s).`;
|
||||
} else {
|
||||
return `${this.message.author.mention}, I couldn't connect to any Lavalink nodes!`;
|
||||
return "I couldn't connect to any Lavalink nodes!";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ 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!`;
|
||||
if (this.args.length === 0) return "You need to provide something to search for!";
|
||||
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();
|
||||
if (result.error && result.error.code === 403) return `${this.message.author.mention}, I've exceeded my YouTube API search quota for the day. Check back later.`;
|
||||
if (result.error && result.error.code === 403) return "I've exceeded my YouTube API search quota for the day. Check back later.";
|
||||
for (const [i, value] of result.items.entries()) {
|
||||
if (value.id.kind === "youtube#channel") {
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nhttps://youtube.com/channel/${value.id.channelId}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue