Port to ESM modules (haha funny), removed cache request, many other changes that I forgot about

This commit is contained in:
Essem 2021-08-19 09:19:14 -05:00
parent 2fe45d842b
commit ae2ebe0337
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
157 changed files with 1661 additions and 897 deletions

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class AvatarCommand extends Command {
async run() {
@ -23,4 +23,4 @@ class AvatarCommand extends Command {
static arguments = ["{mention/id}"];
}
module.exports = AvatarCommand;
export default AvatarCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class BroadcastCommand extends Command {
// yet another very hacky command
@ -24,4 +24,4 @@ class BroadcastCommand extends Command {
static description = "Broadcasts a playing message until the command is run again or the bot restarts";
}
module.exports = BroadcastCommand;
export default BroadcastCommand;

View file

@ -1,5 +1,5 @@
const db = require("../../utils/database.js");
const Command = require("../../classes/command.js");
import db from "../../utils/database.js";
import Command from "../../classes/command.js";
class ChannelCommand extends Command {
async run() {
@ -43,4 +43,4 @@ class ChannelCommand extends Command {
static arguments = ["[enable/disable]", "{id}"];
}
module.exports = ChannelCommand;
export default ChannelCommand;

View file

@ -1,6 +1,6 @@
const db = require("../../utils/database.js");
const Command = require("../../classes/command.js");
const collections = require("../../utils/collections.js");
import db from "../../utils/database.js";
import Command from "../../classes/command.js";
import * as collections from "../../utils/collections.js";
class CommandCommand extends Command {
async run() {
@ -35,4 +35,4 @@ class CommandCommand extends Command {
static arguments = ["[enable/disable]", "[command]"];
}
module.exports = CommandCommand;
export default CommandCommand;

View file

@ -1,6 +1,6 @@
const paginator = require("../../utils/pagination/pagination.js");
const database = require("../../utils/database.js");
const Command = require("../../classes/command.js");
import paginator from "../../utils/pagination/pagination.js";
import database from "../../utils/database.js";
import Command from "../../classes/command.js";
class CountCommand extends Command {
async run() {
@ -46,4 +46,4 @@ class CountCommand extends Command {
static arguments = ["{mention/id}"];
}
module.exports = CountCommand;
export default CountCommand;

View file

@ -1,5 +1,5 @@
const { clean } = require("../../utils/misc.js");
const Command = require("../../classes/command.js");
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
class DecodeCommand extends Command {
async run() {
@ -13,4 +13,4 @@ class DecodeCommand extends Command {
static arguments = ["[text]"];
}
module.exports = DecodeCommand;
export default DecodeCommand;

View file

@ -1,5 +1,5 @@
const fetch = require("node-fetch");
const Command = require("../../classes/command.js");
import fetch from "node-fetch";
import Command from "../../classes/command.js";
class DonateCommand extends Command {
async run() {
@ -27,4 +27,4 @@ class DonateCommand extends Command {
static aliases = ["support", "patreon", "patrons"];
}
module.exports = DonateCommand;
export default DonateCommand;

View file

@ -1,5 +1,5 @@
const emojiRegex = require("emoji-regex");
const Command = require("../../classes/command.js");
import emojiRegex from "emoji-regex";
import Command from "../../classes/command.js";
class EmoteCommand extends Command {
async run() {
@ -22,4 +22,4 @@ class EmoteCommand extends Command {
static arguments = ["[emote]"];
}
module.exports = EmoteCommand;
export default EmoteCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class EncodeCommand extends Command {
async run() {
@ -12,4 +12,4 @@ class EncodeCommand extends Command {
static arguments = ["[text]"];
}
module.exports = EncodeCommand;
export default EncodeCommand;

View file

@ -1,5 +1,5 @@
const { clean } = require("../../utils/misc.js");
const Command = require("../../classes/command.js");
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
class EvalCommand extends Command {
async run() {
@ -28,4 +28,4 @@ class EvalCommand extends Command {
static arguments = ["[code]"];
}
module.exports = EvalCommand;
export default EvalCommand;

View file

@ -1,5 +1,5 @@
const { clean } = require("../../utils/misc.js");
const Command = require("../../classes/command.js");
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
class EvalRawCommand extends Command {
async run() {
@ -26,4 +26,4 @@ class EvalRawCommand extends Command {
static arguments = ["[code]"];
}
module.exports = EvalRawCommand;
export default EvalRawCommand;

View file

@ -1,7 +1,8 @@
const { clean } = require("../../utils/misc.js");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const Command = require("../../classes/command.js");
import { clean } from "../../utils/misc.js";
import * as util from "util";
import { exec as baseExec } from "child_process";
const exec = util.promisify(baseExec);
import Command from "../../classes/command.js";
class ExecCommand extends Command {
async run() {
@ -31,4 +32,4 @@ class ExecCommand extends Command {
static arguments = ["[command]"];
}
module.exports = ExecCommand;
export default ExecCommand;

View file

@ -1,10 +1,10 @@
const database = require("../../utils/database.js");
const collections = require("../../utils/collections.js");
const misc = require("../../utils/misc.js");
const paginator = require("../../utils/pagination/pagination.js");
const help = require("../../utils/help.js");
const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem"];
const Command = require("../../classes/command.js");
import database from "../../utils/database.js";
import * as collections from "../../utils/collections.js";
import { random } from "../../utils/misc.js";
import paginator from "../../utils/pagination/pagination.js";
import * as help from "../../utils/help.js";
import Command from "../../classes/command.js";
const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem", "You can run commands in DMs as well, just message the bot with your command - no prefix needed!"];
class HelpCommand extends Command {
async run() {
@ -89,7 +89,7 @@ class HelpCommand extends Command {
"value": this.message.channel.guild ? prefix : "N/A"
}, {
"name": "Tip",
"value": misc.random(tips)
"value": random(tips)
}]
}
});
@ -103,4 +103,4 @@ class HelpCommand extends Command {
static arguments = ["{command}"];
}
module.exports = HelpCommand;
export default HelpCommand;

View file

@ -1,8 +1,9 @@
const paginator = require("../../utils/pagination/pagination.js");
const { searx } = require("../../servers.json");
const { random } = require("../../utils/misc.js");
const fetch = require("node-fetch");
const Command = require("../../classes/command.js");
import paginator from "../../utils/pagination/pagination.js";
import { readFileSync } from "fs";
const { searx } = JSON.parse(readFileSync(new URL("../../servers.json", import.meta.url)));
import { random } from "../../utils/misc.js";
import fetch from "node-fetch";
import Command from "../../classes/command.js";
class ImageSearchCommand extends Command {
async run() {
@ -40,4 +41,4 @@ class ImageSearchCommand extends Command {
static arguments = ["[query]"];
}
module.exports = ImageSearchCommand;
export default ImageSearchCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class ImageReloadCommand extends Command {
async run() {
@ -15,4 +15,4 @@ class ImageReloadCommand extends Command {
static aliases = ["magickconnect", "magick"];
}
module.exports = ImageReloadCommand;
export default ImageReloadCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class ImageStatsCommand extends Command {
async run() {
@ -28,4 +28,4 @@ class ImageStatsCommand extends Command {
static aliases = ["imgstat", "imstats", "imgstats", "imstat"];
}
module.exports = ImageStatsCommand;
export default ImageStatsCommand;

View file

@ -1,5 +1,6 @@
const { version } = require("../../package.json");
const Command = require("../../classes/command.js");
import { readFileSync } from "fs";
const { version } = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url)));
import Command from "../../classes/command.js";
class InfoCommand extends Command {
async run() {
@ -46,4 +47,4 @@ class InfoCommand extends Command {
static aliases = ["botinfo", "credits"];
}
module.exports = InfoCommand;
export default InfoCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class InviteCommand extends Command {
async run() {
@ -9,4 +9,4 @@ class InviteCommand extends Command {
static aliases = ["botinfo", "credits"];
}
module.exports = InviteCommand;
export default InviteCommand;

View file

@ -1,6 +1,6 @@
const urlCheck = require("../../utils/urlcheck.js");
const fetch = require("node-fetch");
const Command = require("../../classes/command.js");
import urlCheck from "../../utils/urlcheck.js";
import fetch from "node-fetch";
import Command from "../../classes/command.js";
class LengthenCommand extends Command {
async run() {
@ -19,4 +19,4 @@ class LengthenCommand extends Command {
static arguments = ["[url]"];
}
module.exports = LengthenCommand;
export default LengthenCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class PingCommand extends Command {
async run() {
@ -12,4 +12,4 @@ class PingCommand extends Command {
static aliases = ["pong"];
}
module.exports = PingCommand;
export default PingCommand;

View file

@ -1,5 +1,5 @@
const database = require("../../utils/database.js");
const Command = require("../../classes/command.js");
import database from "../../utils/database.js";
import Command from "../../classes/command.js";
class PrefixCommand extends Command {
async run() {
@ -19,4 +19,4 @@ class PrefixCommand extends Command {
static arguments = ["{prefix}"];
}
module.exports = PrefixCommand;
export default PrefixCommand;

View file

@ -1,12 +1,12 @@
const qrcode = require("qrcode");
const stream = require("stream");
const Command = require("../../classes/command.js");
import qrcode from "qrcode";
import { PassThrough } from "stream";
import Command from "../../classes/command.js";
class QrCreateCommand extends Command {
async run() {
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();
const writable = new PassThrough();
qrcode.toFileStream(writable, this.content, { margin: 1 });
const file = await this.streamToBuf(writable);
return {
@ -34,4 +34,4 @@ class QrCreateCommand extends Command {
static arguments = ["[text]"];
}
module.exports = QrCreateCommand;
export default QrCreateCommand;

View file

@ -1,12 +1,13 @@
const jsqr = require("jsqr");
const fetch = require("node-fetch");
const sharp = require("sharp");
const { clean } = require("../../utils/misc.js");
const Command = require("../../classes/command.js");
import jsqr from "jsqr";
import fetch from "node-fetch";
import sharp from "sharp";
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
import imageDetect from "../../utils/imagedetect.js";
class QrReadCommand extends Command {
async run() {
const image = await require("../../utils/imagedetect.js")(this.client, this.message);
const image = await imageDetect(this.client, this.message);
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();
@ -19,4 +20,4 @@ class QrReadCommand extends Command {
static description = "Reads a QR code";
}
module.exports = QrReadCommand;
export default QrReadCommand;

View file

@ -1,5 +1,5 @@
const Command = require("../../classes/command.js");
const imageDetect = require("../../utils/imagedetect.js");
import Command from "../../classes/command.js";
import imageDetect from "../../utils/imagedetect.js";
class RawCommand extends Command {
async run() {
@ -13,4 +13,4 @@ class RawCommand extends Command {
static aliases = ["gif", "getgif", "giflink", "imglink", "getimg", "rawgif", "rawimg"];
}
module.exports = RawCommand;
export default RawCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class ReloadCommand extends Command {
// quite possibly one of the hackiest commands in the bot
@ -24,4 +24,4 @@ class ReloadCommand extends Command {
static arguments = ["[command]"];
}
module.exports = ReloadCommand;
export default ReloadCommand;

View file

@ -1,6 +1,4 @@
const handler = require("../../utils/handler.js");
const collections = require("../../utils/collections.js");
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class RestartCommand extends Command {
async run() {
@ -8,9 +6,6 @@ class RestartCommand extends Command {
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);
}
this.ipc.restartAllClusters(true);
//this.ipc.broadcast("restart");
}
@ -19,4 +14,4 @@ class RestartCommand extends Command {
static aliases = ["reboot"];
}
module.exports = RestartCommand;
export default RestartCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class ServerInfoCommand extends Command {
async run() {
@ -49,4 +49,4 @@ class ServerInfoCommand extends Command {
static aliases = ["server"];
}
module.exports = ServerInfoCommand;
export default ServerInfoCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class SnowflakeCommand extends Command {
async run() {
@ -12,4 +12,4 @@ class SnowflakeCommand extends Command {
static arguments = ["[id]"];
}
module.exports = SnowflakeCommand;
export default SnowflakeCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class SoundReloadCommand extends Command {
// another very hacky command
@ -24,4 +24,4 @@ class SoundReloadCommand extends Command {
static aliases = ["lava", "lavalink", "lavaconnect", "soundconnect"];
}
module.exports = SoundReloadCommand;
export default SoundReloadCommand;

View file

@ -1,6 +1,8 @@
const { version } = require("../../package.json");
const os = require("os");
const Command = require("../../classes/command.js");
import { readFileSync } from "fs";
const { version } = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url)));
import os from "os";
import Command from "../../classes/command.js";
import { VERSION } from "eris";
class StatsCommand extends Command {
async run() {
@ -44,7 +46,7 @@ class StatsCommand extends Command {
},
{
"name": "Library",
"value": `Eris ${require("eris").VERSION}`,
"value": `Eris ${VERSION}`,
"inline": true
},
{
@ -81,4 +83,4 @@ class StatsCommand extends Command {
static aliases = ["status", "stat"];
}
module.exports = StatsCommand;
export default StatsCommand;

View file

@ -1,4 +1,4 @@
const Command = require("../../classes/command.js");
import Command from "../../classes/command.js";
class UserInfoCommand extends Command {
async run() {
@ -54,4 +54,4 @@ class UserInfoCommand extends Command {
static arguments = ["[mention/id]"];
}
module.exports = UserInfoCommand;
export default UserInfoCommand;

View file

@ -1,8 +1,9 @@
const fetch = require("node-fetch");
const { searx } = require("../../servers.json");
const { random } = require("../../utils/misc.js");
const paginator = require("../../utils/pagination/pagination.js");
const Command = require("../../classes/command.js");
import fetch from "node-fetch";
import { readFileSync } from "fs";
const { searx } = JSON.parse(readFileSync(new URL("../../servers.json", import.meta.url)));
import { random } from "../../utils/misc.js";
import paginator from "../../utils/pagination/pagination.js";
import Command from "../../classes/command.js";
class YouTubeCommand extends Command {
async run() {
@ -22,4 +23,4 @@ class YouTubeCommand extends Command {
static arguments = ["[query]"];
}
module.exports = YouTubeCommand;
export default YouTubeCommand;