From a283542048cdb8b358002405258c6b3fdc384d72 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 26 Nov 2019 08:24:24 +0000 Subject: [PATCH 01/21] What the fuck is wrong with returning? Aint no need for another unnecessary line --- src/commands/deleteaccount.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/deleteaccount.ts b/src/commands/deleteaccount.ts index 7254235..e620d3e 100644 --- a/src/commands/deleteaccount.ts +++ b/src/commands/deleteaccount.ts @@ -1,4 +1,3 @@ -/* eslint-disable consistent-return */ import { Message, PrivateChannel } from 'eris'; import uuid from 'uuid/v4'; import { Command } from '../class'; @@ -57,7 +56,7 @@ export default class DeleteAccount extends Command { `, }); - deleting.edit(`${this.client.stores.emojis.success} ***Account ${username} has been deleted by Engineer ${message.author.username}#${message.author.discriminator}***`); + return deleting.edit(`${this.client.stores.emojis.success} ***Account ${username} has been deleted by Engineer ${message.author.username}#${message.author.discriminator}***`); } catch (error) { return this.client.util.handleError(error, message, this); } From a718bf23b3806c187be84b048e1a5d085963f6a4 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 22:09:24 +0000 Subject: [PATCH 02/21] rewrite command resolver --- src/class/Util.ts | 58 ++++++++++++------------------------- src/commands/help.ts | 2 +- src/events/messageCreate.ts | 4 +-- 3 files changed, 20 insertions(+), 44 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 24b0cd1..cd48333 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -38,50 +38,30 @@ export default class Util { /** * Resolves a command - * @param command Parent command label - * @param args Use to resolve subcommands + * @param query Command input * @param message Only used to check for errors */ - public resolveCommand(command: string, args?: string[], message?: Message): Promise<{cmd: Command, args: string[] }> { + public resolveCommand(query: string | string[], message?: Message): Promise<{cmd: Command, args: string[] }> { try { let resolvedCommand: Command; + if (typeof query === 'string') query = query.split(' '); + query = query.map((q) => q.toLowerCase()); + const commands = this.client.commands.toArray(); + resolvedCommand = commands.find((c) => c.name === query[0] || c.aliases.includes(query[0])); - if (this.client.commands.has(command)) resolvedCommand = this.client.commands.get(command); - else { - for (const cmd of this.client.commands.toArray()) { - if (cmd.aliases.includes(command)) { resolvedCommand = cmd; break; } - } + if (!resolvedCommand) return Promise.resolve(null); + query.shift(); + while (resolvedCommand.subcommands.size) { + const subCommands = resolvedCommand.subcommands.toArray(); + const found = subCommands.find((c) => c.name === query[0] || c.aliases.includes(query[0])); + if (!found) break; + resolvedCommand = found; + query.shift(); } - if (!resolvedCommand) return Promise.resolve({ cmd: null, args }); - - let parentLabel = ''; - let hasSubCommands = true; - while (hasSubCommands) { - if (!resolvedCommand.subcommands.size) { - hasSubCommands = false; break; - } else if (!args[0]) { - hasSubCommands = false; break; - } else if (resolvedCommand.subcommands.has(args[0])) { - parentLabel += `${resolvedCommand.name} `; - resolvedCommand = resolvedCommand.subcommands.get(args[0]); args.shift(); - } else { - const subcommandArray = resolvedCommand.subcommands.toArray(); - for (const subCmd of subcommandArray) { - if (subCmd.aliases.includes(args[0])) { - parentLabel += `${resolvedCommand.name} `; resolvedCommand = subCmd; args.shift(); break; - } - if (subcommandArray.findIndex((v) => v === subCmd) === subcommandArray.length - 1) { - hasSubCommands = false; break; - } - } - } - } - const finalCommand = resolvedCommand; - finalCommand.parentName = parentLabel; - - return Promise.resolve({ cmd: finalCommand, args }); + return Promise.resolve({ cmd: resolvedCommand, args: query }); } catch (error) { - this.handleError(error, message); + if (message) this.handleError(error, message); + else this.handleError(error); return Promise.reject(error); } } @@ -107,9 +87,7 @@ export default class Util { } await this.client.createMessage('595788220764127272', info); const msg = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); - const label = msg[0]; - const args = msg.slice(1); - if (command) this.resolveCommand(label, args).then((c) => { c.cmd.enabled = false; }); + if (command) this.resolveCommand(msg).then((c) => { c.cmd.enabled = false; }); if (message) message.channel.createMessage(`***${this.client.stores.emojis.error} An unexpected error has occured - please contact a member of the Engineering Team.${command ? ' This command has been disabled.' : ''}***`); } catch (err) { this.client.signale.error(err); diff --git a/src/commands/help.ts b/src/commands/help.ts index d597f3f..9db8143 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -44,7 +44,7 @@ export default class Help extends Command { if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] }); return createPaginationEmbed(message, this.client, cmdPages); } - const { cmd } = await this.client.util.resolveCommand(args[0], args.slice(1), message); + const { cmd } = await this.client.util.resolveCommand(args, message); if (!cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} **Command not found!**`); const perms: string[] = []; let allowedRoles = cmd.permissions && cmd.permissions.roles && cmd.permissions.roles.map((r) => `<@&${r}>`).join(', '); diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 69dda08..4f0f605 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -14,9 +14,7 @@ export default class { if (message.author.bot) return; if (message.content.indexOf(this.client.config.prefix) !== 0) return; const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); - const command: string = noPrefix[0].toLowerCase(); - const args: string[] = noPrefix.slice(1); - const resolved = await this.client.util.resolveCommand(command, args, message); + const resolved = await this.client.util.resolveCommand(noPrefix, message); if (!resolved.cmd) return; if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return; let hasUserPerms: boolean; From f806afa1da55bf82d6b37c3dcccb86aae195fac4 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 22:55:53 +0000 Subject: [PATCH 03/21] Memory saving --- src/Client.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Client.ts b/src/Client.ts index 2547f71..e86e2b6 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -115,6 +115,9 @@ export default class Client extends Eris.Client { this.signale.complete(`Loaded interval ${interval.split('.')[0]}`); }); this.server = new Server(this, { port: this.config.port }); + + const files = Object.keys(require.cache).filter((path) => path.startsWith('/var/CloudServices/dist')); + files.forEach((file) => delete require.cache[file]); } } From d52e698fde062516d59aa1880b578cc61d1053e5 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:00:11 +0000 Subject: [PATCH 04/21] Memory saving --- src/Client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index e86e2b6..70a9691 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -116,8 +116,7 @@ export default class Client extends Eris.Client { }); this.server = new Server(this, { port: this.config.port }); - const files = Object.keys(require.cache).filter((path) => path.startsWith('/var/CloudServices/dist')); - files.forEach((file) => delete require.cache[file]); + require.cache = {}; } } From a7966d7adb7036c1747097938565c50e71503f9d Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:14:50 +0000 Subject: [PATCH 05/21] Added build error --- src/Client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Client.ts b/src/Client.ts index 70a9691..5de9827 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -28,7 +28,9 @@ export default class Client extends Eris.Client { public server: Server; - public updating: Boolean; + public updating: boolean; + + public buildError: boolean constructor() { super(config.token, { getAllUsers: true, restMode: true, defaultImageFormat: 'png' }); @@ -47,6 +49,7 @@ export default class Client extends Eris.Client { displayFilename: true, }); this.updating = false; + this.buildError = false; this.events(); this.loadFunctions(); this.init(); From ceb613c95fe3fe233c36d6848b776128075bce72 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:47:47 +0000 Subject: [PATCH 06/21] Added reload command --- src/commands/index.ts | 47 ++++++++++++++++++++++--------------------- src/commands/load.ts | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 src/commands/load.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index ee72450..7312475 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,23 +1,24 @@ -export { default as Announce } from './announce'; -export { default as Bearer } from './bearer'; -export { default as CreateAccount } from './createaccount'; -export { default as CWG } from './cwg'; -export { default as DeleteAccount } from './deleteaccount'; -export { default as Disk } from './disk'; -export { default as Eval } from './eval'; -export { default as Exec } from './exec'; -export { default as Help } from './help'; -export { default as Lock } from './lock'; -export { default as Modlogs } from './modlogs'; -export { default as Notify } from './notify'; -export { default as Parse } from './parse'; -export { default as Parseall } from './parseall'; -export { default as Ping } from './ping'; -export { default as Pull } from './pull'; -export { default as Restart } from './restart'; -export { default as SecureSign } from './securesign'; -export { default as Sysinfo } from './sysinfo'; -export { default as Unban } from './unban'; -export { default as Unlock } from './unlock'; -export { default as Warn } from './warn'; -export { default as Whois } from './whois'; +export { default as announce } from './announce'; +export { default as bearer } from './bearer'; +export { default as createAccount } from './createaccount'; +export { default as cwg } from './cwg'; +export { default as deleteaccount } from './deleteaccount'; +export { default as disk } from './disk'; +export { default as eval } from './eval'; +export { default as exec } from './exec'; +export { default as help } from './help'; +export { default as load } from './load'; +export { default as lock } from './lock'; +export { default as modlogs } from './modlogs'; +export { default as notify } from './notify'; +export { default as parse } from './parse'; +export { default as parseall } from './parseall'; +export { default as ping } from './ping'; +export { default as pull } from './pull'; +export { default as restart } from './restart'; +export { default as securesign } from './securesign'; +export { default as sysinfo } from './sysinfo'; +export { default as unban } from './unban'; +export { default as unlock } from './unlock'; +export { default as warn } from './warn'; +export { default as whois } from './whois'; diff --git a/src/commands/load.ts b/src/commands/load.ts new file mode 100644 index 0000000..a7c7830 --- /dev/null +++ b/src/commands/load.ts @@ -0,0 +1,41 @@ +import { Message } from 'eris'; +import { Client } from '..'; +import { Command } from '../class'; + +export default class Ping extends Command { + constructor(client: Client) { + super(client); + this.name = 'load'; + this.description = '(Re)loads command, config or util'; + this.aliases = ['reload']; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + const allowed = ['config', 'util', 'command', 'function']; + const type = args[0].toLowerCase(); + if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); + + const corepath = '/var/CloudServices/dist'; + if (type === 'config') this.client.config = require(`${corepath}/config.json`); + else if (type === 'util') { + const Util = require(`${corepath}/class/Util`); + this.client.util = new Util(this.client); + } else { + try { + const Cmd = require(`${corepath}/commands`)[args[1]]; + this.client.commands.remove(args[1]); + this.client.loadCommand(Cmd); + } catch (error) { + if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`); + throw error; + } + } + return message.channel.createMessage(`${this.client.stores.emojis.success} Reloaded ${type}`); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} From 7bc601b68570201a2653b88420955154983880b0 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:53:23 +0000 Subject: [PATCH 07/21] Perms fix --- src/commands/load.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/load.ts b/src/commands/load.ts index a7c7830..ec22ab3 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -8,6 +8,7 @@ export default class Ping extends Command { this.name = 'load'; this.description = '(Re)loads command, config or util'; this.aliases = ['reload']; + this.permissions = { users: ['253600545972027394', '278620217221971968'] }; this.enabled = true; } From 495159336b85f3c95dcb003b12fb3761c8167929 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:55:49 +0000 Subject: [PATCH 08/21] Don't restart if build error --- src/commands/pull.ts | 3 +++ src/commands/restart.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/src/commands/pull.ts b/src/commands/pull.ts index 4ad34da..6a861ca 100644 --- a/src/commands/pull.ts +++ b/src/commands/pull.ts @@ -14,6 +14,7 @@ export default class Pull extends Command { public async run(message: Message) { try { + if (this.client.updating) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`); this.client.updating = true; const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\ngit pull\n\`\`\``); let pull: string; @@ -74,12 +75,14 @@ export default class Pull extends Command { } catch (error) { const updatedMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***`) .replace(/```$/, `${error.message}\n\`\`\``); + this.client.buildError = true; this.client.updating = false; return updateMessage.edit(updatedMessage); } const finalMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`) .replace(/```$/, `${build}\n\`\`\``); this.client.updating = false; + this.client.buildError = false; return updateMessage.edit(finalMessage); } catch (error) { this.client.updating = false; diff --git a/src/commands/restart.ts b/src/commands/restart.ts index 0f80600..80e3a33 100644 --- a/src/commands/restart.ts +++ b/src/commands/restart.ts @@ -14,6 +14,7 @@ export default class Restart extends Command { public async run(message: Message, args: string[]) { try { if (this.client.updating && args[0] !== '-f') return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`); + if (this.client.buildError) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Build error, resolve before restarting***`); await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Restarting...***`); return process.exit(1); } catch (error) { From af1827337f9c3c2c58342a90df48b43c53a70120 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 30 Nov 2019 23:59:13 +0000 Subject: [PATCH 09/21] Fix no args --- src/commands/load.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index ec22ab3..fe5f340 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -2,7 +2,7 @@ import { Message } from 'eris'; import { Client } from '..'; import { Command } from '../class'; -export default class Ping extends Command { +export default class Load extends Command { constructor(client: Client) { super(client); this.name = 'load'; @@ -27,6 +27,7 @@ export default class Ping extends Command { } else { try { const Cmd = require(`${corepath}/commands`)[args[1]]; + if (!Cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); this.client.commands.remove(args[1]); this.client.loadCommand(Cmd); } catch (error) { From 429a5fda8e63eeeb1dbbbef38cbc24e97750b227 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 00:10:49 +0000 Subject: [PATCH 10/21] Fix args lowercase --- src/class/Util.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index cd48333..bad0b79 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -45,15 +45,14 @@ export default class Util { try { let resolvedCommand: Command; if (typeof query === 'string') query = query.split(' '); - query = query.map((q) => q.toLowerCase()); const commands = this.client.commands.toArray(); - resolvedCommand = commands.find((c) => c.name === query[0] || c.aliases.includes(query[0])); + resolvedCommand = commands.find((c) => c.name === query[0].toLowerCase() || c.aliases.includes(query[0].toLowerCase())); if (!resolvedCommand) return Promise.resolve(null); query.shift(); while (resolvedCommand.subcommands.size) { const subCommands = resolvedCommand.subcommands.toArray(); - const found = subCommands.find((c) => c.name === query[0] || c.aliases.includes(query[0])); + const found = subCommands.find((c) => c.name === query[0].toLowerCase() || c.aliases.includes(query[0].toLowerCase())); if (!found) break; resolvedCommand = found; query.shift(); From f7822fa2cb4b8ff015895a7b7d754952ac426fe8 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 00:17:44 +0000 Subject: [PATCH 11/21] Fix util reloading --- src/commands/load.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index fe5f340..5017327 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -22,7 +22,7 @@ export default class Load extends Command { const corepath = '/var/CloudServices/dist'; if (type === 'config') this.client.config = require(`${corepath}/config.json`); else if (type === 'util') { - const Util = require(`${corepath}/class/Util`); + const Util = require(`${corepath}/class/Util`).default; this.client.util = new Util(this.client); } else { try { From c11a7e62c3bac9a6291c5ec83b82d7c90f57bef1 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 00:22:51 +0000 Subject: [PATCH 12/21] Reverting and fixing command reloader --- src/commands/load.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 5017327..57b00df 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -22,12 +22,14 @@ export default class Load extends Command { const corepath = '/var/CloudServices/dist'; if (type === 'config') this.client.config = require(`${corepath}/config.json`); else if (type === 'util') { - const Util = require(`${corepath}/class/Util`).default; + const Util = require(`${corepath}/class/Util`); this.client.util = new Util(this.client); } else { try { - const Cmd = require(`${corepath}/commands`)[args[1]]; + const cmdIndex = require(`${corepath}/commands`); + let Cmd = cmdIndex[args[1]]; if (!Cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); + Cmd = require(`${corepath}/commands/${args[1]}`); this.client.commands.remove(args[1]); this.client.loadCommand(Cmd); } catch (error) { From d481d7c90cd64a5fe20c72abe33b2fd32e0e9279 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 00:25:47 +0000 Subject: [PATCH 13/21] Fix util reloading --- src/commands/load.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 57b00df..4582e47 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -22,7 +22,7 @@ export default class Load extends Command { const corepath = '/var/CloudServices/dist'; if (type === 'config') this.client.config = require(`${corepath}/config.json`); else if (type === 'util') { - const Util = require(`${corepath}/class/Util`); + const Util = require(`${corepath}/class/Util`).default; this.client.util = new Util(this.client); } else { try { From 1473aaec117b3cdf133ee52d15fbd83d8fbb9145 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 00:38:01 +0000 Subject: [PATCH 14/21] reverting for util, fixing for command --- src/commands/load.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 4582e47..afd977f 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -22,14 +22,14 @@ export default class Load extends Command { const corepath = '/var/CloudServices/dist'; if (type === 'config') this.client.config = require(`${corepath}/config.json`); else if (type === 'util') { - const Util = require(`${corepath}/class/Util`).default; + const Util = require(`${corepath}/class/Util`); this.client.util = new Util(this.client); } else { try { const cmdIndex = require(`${corepath}/commands`); let Cmd = cmdIndex[args[1]]; if (!Cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); - Cmd = require(`${corepath}/commands/${args[1]}`); + Cmd = require(`${corepath}/commands/${args[1]}`).default; this.client.commands.remove(args[1]); this.client.loadCommand(Cmd); } catch (error) { From 98c3b22f66aa129637c804f46e26a12230900b71 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 00:44:36 +0000 Subject: [PATCH 15/21] Fix util reloading --- src/commands/load.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index afd977f..df8c4ef 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -20,7 +20,7 @@ export default class Load extends Command { if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); const corepath = '/var/CloudServices/dist'; - if (type === 'config') this.client.config = require(`${corepath}/config.json`); + if (type === 'config') this.client.config = require(`${corepath}/config.json`).default; else if (type === 'util') { const Util = require(`${corepath}/class/Util`); this.client.util = new Util(this.client); From 85a60c00e7ba6fb071f5e4d8dcbe4b42f6bb9575 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 01:29:24 +0000 Subject: [PATCH 16/21] Fixed errors throwing starting prefix --- src/commands/load.ts | 6 +++--- src/events/messageCreate.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index df8c4ef..2c5b139 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -20,13 +20,13 @@ export default class Load extends Command { if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); const corepath = '/var/CloudServices/dist'; - if (type === 'config') this.client.config = require(`${corepath}/config.json`).default; + if (type === 'config') this.client.config = require(`${corepath}/config.json`); else if (type === 'util') { - const Util = require(`${corepath}/class/Util`); + const Util = require(`${corepath}/class/Util`).default; this.client.util = new Util(this.client); } else { try { - const cmdIndex = require(`${corepath}/commands`); + const cmdIndex = require('../commands'); let Cmd = cmdIndex[args[1]]; if (!Cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); Cmd = require(`${corepath}/commands/${args[1]}`).default; diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 4f0f605..b9048cb 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -15,7 +15,7 @@ export default class { if (message.content.indexOf(this.client.config.prefix) !== 0) return; const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); const resolved = await this.client.util.resolveCommand(noPrefix, message); - if (!resolved.cmd) return; + if (!resolved) return; if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return; let hasUserPerms: boolean; if (resolved.cmd.permissions.users) { From d9cc8ac1ecb5d3174bad4feb2e5dec2aff3e7f4b Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 01:32:26 +0000 Subject: [PATCH 17/21] stay in same format --- src/Client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.ts b/src/Client.ts index 5de9827..8e1b637 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -119,7 +119,7 @@ export default class Client extends Eris.Client { }); this.server = new Server(this, { port: this.config.port }); - require.cache = {}; + require.cache = Object.create(null); } } From 00343fe7f335b4994b4a0a2e6870a21346320fd2 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 01:35:15 +0000 Subject: [PATCH 18/21] testing --- src/commands/load.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 2c5b139..d65f498 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -22,7 +22,7 @@ export default class Load extends Command { const corepath = '/var/CloudServices/dist'; if (type === 'config') this.client.config = require(`${corepath}/config.json`); else if (type === 'util') { - const Util = require(`${corepath}/class/Util`).default; + const Util = require(`${corepath}/class/Util`); this.client.util = new Util(this.client); } else { try { From 6796317c6c5829c4d9b28680d54f53623ccedf8f Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 1 Dec 2019 01:50:47 +0000 Subject: [PATCH 19/21] this shit doesn't work --- src/commands/load.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index d65f498..b639c3b 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -9,7 +9,7 @@ export default class Load extends Command { this.description = '(Re)loads command, config or util'; this.aliases = ['reload']; this.permissions = { users: ['253600545972027394', '278620217221971968'] }; - this.enabled = true; + this.enabled = false; } public async run(message: Message, args: string[]) { From ba71d2ebdf4e27bac84ed219f854e85b30b16948 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 3 Dec 2019 23:26:10 +0000 Subject: [PATCH 20/21] Fixed stuff for subcommands --- src/class/Util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index bad0b79..adc5aa0 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -50,7 +50,7 @@ export default class Util { if (!resolvedCommand) return Promise.resolve(null); query.shift(); - while (resolvedCommand.subcommands.size) { + while (resolvedCommand.subcommands.size && query.length) { const subCommands = resolvedCommand.subcommands.toArray(); const found = subCommands.find((c) => c.name === query[0].toLowerCase() || c.aliases.includes(query[0].toLowerCase())); if (!found) break; From 1d3e6ce8119c94542ec30a9df4e0828ce5b69533 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 9 Dec 2019 10:07:59 +0000 Subject: [PATCH 21/21] Eris update --- package.json | 2 +- src/class/Util.ts | 4 ++-- src/commands/createaccount.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ad00d84..fd6125c 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@ghaiklor/x509": "^1.0.0", "axios": "^0.19.0", "body-parser": "^1.19.0", - "eris": "^0.10.1", + "eris": "abalabahaha/eris#dev", "eris-pagination": "bsian03/eris-pagination", "express": "^4.17.1", "fs-extra": "^8.1.0", diff --git a/src/class/Util.ts b/src/class/Util.ts index adc5aa0..1f7481f 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -2,7 +2,7 @@ import { promisify } from 'util'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; -import { Message, PrivateChannel, Member, User } from 'eris'; +import { Message, PrivateChannel, GroupChannel, Member, User } from 'eris'; import uuid from 'uuid/v4'; import moment from 'moment'; import fs from 'fs'; @@ -78,7 +78,7 @@ export default class Util { embed.addField('User', `${message.author.mention} (\`${message.author.id}\`)`, true); embed.addField('Channel', message.channel.mention, true); let guild: string; - if (message.channel instanceof PrivateChannel) guild = '@me'; + if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) guild = '@me'; else guild = message.channel.guild.id; embed.addField('Message link', `[Click here](https://discordapp.com/channels/${guild}/${message.channel.id}/${message.id})`, true); embed.setTimestamp(new Date(message.timestamp)); diff --git a/src/commands/createaccount.ts b/src/commands/createaccount.ts index aff9360..e45e86e 100644 --- a/src/commands/createaccount.ts +++ b/src/commands/createaccount.ts @@ -1,4 +1,4 @@ -import { Message, PrivateChannel } from 'eris'; +import { Message, PrivateChannel, GroupChannel } from 'eris'; import uuid from 'uuid/v4'; import { Client } from '..'; import { Command, RichEmbed } from '../class'; @@ -22,7 +22,7 @@ export default class CreateAccount extends Command { public async run(message: Message, args: string[]) { try { - if (message.channel instanceof PrivateChannel) return message; // Stop TS being gay + if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) return message; // Stop TS being gay if (!args[2]) return this.client.commands.get('help').run(message, [this.name]); if (!message.channel.guild.members.has(args[0])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***User not found***`); if (message.channel.guild.members.get(args[0]).bot) return message.channel.createMessage(`${this.client.stores.emojis.error} ***I cannot create accounts for bots***`);