From 2885bc4643dc27d41fcd726a5ec30fc2caeb9b7a Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 16 Dec 2019 22:41:28 +0000 Subject: [PATCH 01/18] CI --- .gitlab-ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5c3af4b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,18 @@ +stages: + - build + - test + +typescript_build: + stage: build + script: + - cp /var/CloudServices/src/config.json ./src/config.json + - yarn install --ignore-engines + - tsc -p ./tsconfig.json + +lint: + stage: test + before_script: + - yarn install --ignore-engines + script: + - yarn run lint-find + From 350466a6a9011800fff2ec14d9c8dd961d49c644 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 16 Dec 2019 22:50:16 +0000 Subject: [PATCH 02/18] Fix CI --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5c3af4b..4cbad23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,6 @@ stages: typescript_build: stage: build script: - - cp /var/CloudServices/src/config.json ./src/config.json - yarn install --ignore-engines - tsc -p ./tsconfig.json From 532dbcc320f3835cae04dae16a6578e7e65db28a Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 00:04:39 +0000 Subject: [PATCH 03/18] Message update --- src/commands/pull.ts | 8 ++++---- src/commands/restart.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/pull.ts b/src/commands/pull.ts index 6a861ca..16a392a 100644 --- a/src/commands/pull.ts +++ b/src/commands/pull.ts @@ -16,7 +16,7 @@ export default class Pull extends Command { 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\`\`\``); + const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\n$ git pull\n\`\`\``); let pull: string; try { @@ -40,7 +40,7 @@ export default class Pull extends Command { return updateMessage.edit(updatedMessage); } const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`) - .replace(/```$/, `${pull}\nyarn install\n\`\`\``); + .replace(/```$/, `${pull}\n$ yarn install\n\`\`\``); const passedPull = await updateMessage.edit(continueMessage); @@ -56,11 +56,11 @@ export default class Pull extends Command { let updatedPackages: Message; if (install.includes('Already up-to-date')) { const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`) - .replace(/```$/, `${install}\nyarn run build\n\`\`\``); + .replace(/```$/, `${install}\n$ yarn run build\n\`\`\``); updatedPackages = await updateMessage.edit(updatedMessage); } else if (install.includes('success Saved lockfile.')) { const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`) - .replace(/```$/, `${install}\nyarn run build\n\`\`\``); + .replace(/```$/, `${install}\n$ yarn run build\n\`\`\``); updatedPackages = await updateMessage.edit(updatedMessage); } else { const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***`) diff --git a/src/commands/restart.ts b/src/commands/restart.ts index 80e3a33..b110322 100644 --- a/src/commands/restart.ts +++ b/src/commands/restart.ts @@ -14,7 +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***`); + if (this.client.buildError) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Build error, resolve before restarting. See CI job on Gitlab***`); await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Restarting...***`); return process.exit(1); } catch (error) { From 996e8a520baae7b2b2afcebc45996f3d830d7658 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 00:08:48 +0000 Subject: [PATCH 04/18] CI fix --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4cbad23..b754423 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,7 @@ stages: typescript_build: stage: build script: + - cp ../../config.json ./src/config.json - yarn install --ignore-engines - tsc -p ./tsconfig.json From fbe76e1a98afea7d49aa3a333a80baf787dd9990 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 00:10:34 +0000 Subject: [PATCH 05/18] CI fix --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b754423..2458d76 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: typescript_build: stage: build script: - - cp ../../config.json ./src/config.json + - cp ../config.json ./src/config.json - yarn install --ignore-engines - tsc -p ./tsconfig.json From f0298b4d5392cebc463de55f8a456b79133f5227 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 00:14:16 +0000 Subject: [PATCH 06/18] CI fix --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fd6125c..355e0cc 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "dist/Client.js", "scripts": { "lint": "eslint ./ --ext ts --fix", - "build": "tsc -p ./tsconfig.json" + "build": "tsc -p ./tsconfig.json", + "lint-find": "eslint ./ --ext ts" }, "author": "Library of Code sp-us Engineering Team", "license": "AGPL-3.0-only", From a3eb92cbcbf972af90f5b955d033516fb6596f20 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 00:22:17 +0000 Subject: [PATCH 07/18] CI fix --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2458d76..683d018 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,6 +12,7 @@ typescript_build: lint: stage: test before_script: + - cp ../config.json ./src/config.json - yarn install --ignore-engines script: - yarn run lint-find From 34ecb3a77b11c7c643d2269e5142b7898f05f260 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 00:23:44 +0000 Subject: [PATCH 08/18] Jesus fuck gitlab --- .eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index f1f15b9..af3e032 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -38,6 +38,7 @@ "object-curly-newline": "off", "import/prefer-default-export": "off", "no-useless-constructor": "off", - "@typescript-eslint/no-useless-constructor": 2 + "@typescript-eslint/no-useless-constructor": 2, + "import/extensions": "off" } } \ No newline at end of file From 08effc5b53d5a70331d767af7893b3cae903138a Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:27:12 +0000 Subject: [PATCH 09/18] Attempt 2 --- src/Client.ts | 6 +++++- src/commands/load.ts | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 8e1b637..97cfbb9 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -119,7 +119,11 @@ export default class Client extends Eris.Client { }); this.server = new Server(this, { port: this.config.port }); - require.cache = Object.create(null); + const corepath = '/var/CloudServices/dist'; + const cmdFiles = await fs.readdir('/var/CloudServices/dist/commands'); + cmdFiles.forEach((f) => delete require.cache[`${corepath}/${f}`]); + delete require.cache[`${corepath}/config.json`]; + delete require.cache[`${corepath}/class/Util`]; } } diff --git a/src/commands/load.ts b/src/commands/load.ts index b639c3b..1b952a4 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -9,21 +9,24 @@ export default class Load extends Command { this.description = '(Re)loads command, config or util'; this.aliases = ['reload']; this.permissions = { users: ['253600545972027394', '278620217221971968'] }; - this.enabled = false; + 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 allowed = ['config', 'util', 'command']; 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') { + if (type === 'config') { + this.client.config = require(`${corepath}/config.json`); + delete require.cache[`${corepath}/config.json`]; + } else if (type === 'util') { const Util = require(`${corepath}/class/Util`); this.client.util = new Util(this.client); + delete require.cache[`${corepath}/class/Util.js`]; } else { try { const cmdIndex = require('../commands'); @@ -32,6 +35,8 @@ export default class Load extends Command { Cmd = require(`${corepath}/commands/${args[1]}`).default; this.client.commands.remove(args[1]); this.client.loadCommand(Cmd); + delete require.cache[`${corepath}/commands/index.js`]; + delete require.cache[`${corepath}/commands/${args[1]}.js`]; } catch (error) { if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`); throw error; From c3edc68a844db9fd16e55d4545c7faeed5bbf2cc Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:33:42 +0000 Subject: [PATCH 10/18] Alias only show parent command name if subcommand --- src/commands/help.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/help.ts b/src/commands/help.ts index 9db8143..b4ad446 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -52,7 +52,7 @@ export default class Help extends Command { let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', '); if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); } const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : ''; - const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName}${alias}`).join(', ')}` : ''; + const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName} ` : ''}${alias}`).join(', ')}` : ''; const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => `${cmd.name} ${s.name}`).join(', ')}` : ''; const embed = new RichEmbed(); embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); From d793731bc99381c171f8dae3847cab524bfd00f7 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:35:16 +0000 Subject: [PATCH 11/18] Fix stuff, test --- src/commands/help.ts | 2 +- src/commands/load.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/help.ts b/src/commands/help.ts index b4ad446..9db8143 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -52,7 +52,7 @@ export default class Help extends Command { let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', '); if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); } const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : ''; - const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName} ` : ''}${alias}`).join(', ')}` : ''; + const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName}${alias}`).join(', ')}` : ''; const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => `${cmd.name} ${s.name}`).join(', ')}` : ''; const embed = new RichEmbed(); embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); diff --git a/src/commands/load.ts b/src/commands/load.ts index 1b952a4..8f55fe5 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -24,7 +24,7 @@ export default class Load extends Command { this.client.config = require(`${corepath}/config.json`); delete require.cache[`${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); delete require.cache[`${corepath}/class/Util.js`]; } else { From ccb39a910c59661b86191ca49fc55e5b20a48630 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:41:31 +0000 Subject: [PATCH 12/18] test and fix --- src/commands/help.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/help.ts b/src/commands/help.ts index 9db8143..b4ad446 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -52,7 +52,7 @@ export default class Help extends Command { let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', '); if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); } const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : ''; - const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName}${alias}`).join(', ')}` : ''; + const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName} ` : ''}${alias}`).join(', ')}` : ''; const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => `${cmd.name} ${s.name}`).join(', ')}` : ''; const embed = new RichEmbed(); embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); From 66ef185819c52e7ef0965f398f92feacd0aa7730 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:46:17 +0000 Subject: [PATCH 13/18] test --- 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 8f55fe5..ca6d5a8 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -17,7 +17,7 @@ export default class Load extends Command { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); const allowed = ['config', 'util', 'command']; const type = args[0].toLowerCase(); - if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); + if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to load***`); const corepath = '/var/CloudServices/dist'; if (type === 'config') { From a25274e51a44a1eb5cc618d71769197a695de1bb Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:50:20 +0000 Subject: [PATCH 14/18] test --- 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 ca6d5a8..8f55fe5 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -17,7 +17,7 @@ export default class Load extends Command { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); const allowed = ['config', 'util', 'command']; const type = args[0].toLowerCase(); - if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to load***`); + 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') { From b18cbfe7c360a0047f00033f0c7e91365a5f5b3d Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:53:56 +0000 Subject: [PATCH 15/18] test --- 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 8f55fe5..ca6d5a8 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -17,7 +17,7 @@ export default class Load extends Command { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); const allowed = ['config', 'util', 'command']; const type = args[0].toLowerCase(); - if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); + if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to load***`); const corepath = '/var/CloudServices/dist'; if (type === 'config') { From 6f20ecf178734e49d47c360766655bfadd50508a Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 17 Dec 2019 01:55:52 +0000 Subject: [PATCH 16/18] test --- 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 ca6d5a8..8f55fe5 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -17,7 +17,7 @@ export default class Load extends Command { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); const allowed = ['config', 'util', 'command']; const type = args[0].toLowerCase(); - if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to load***`); + 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') { From f96808e6d6bf42a580f2647810f9ce0992c295e8 Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 18 Dec 2019 23:03:46 +0000 Subject: [PATCH 17/18] Fix failing to find commands --- src/commands/help.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/help.ts b/src/commands/help.ts index b4ad446..c02d6ac 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -44,8 +44,9 @@ 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, message); - if (!cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} **Command not found!**`); + const resolved = await this.client.util.resolveCommand(args, message); + if (!resolved) return message.channel.createMessage(`${this.client.stores.emojis.error} **Command not found!**`); + const { cmd } = resolved; const perms: string[] = []; let allowedRoles = cmd.permissions && cmd.permissions.roles && cmd.permissions.roles.map((r) => `<@&${r}>`).join(', '); if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); } From 23d82e0f3ae2b8f41c082ef288f0b914f03f8cd2 Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 18 Dec 2019 23:26:42 +0000 Subject: [PATCH 18/18] Hopefully fix false positive --- src/commands/pull.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/pull.ts b/src/commands/pull.ts index 16a392a..6205880 100644 --- a/src/commands/pull.ts +++ b/src/commands/pull.ts @@ -33,7 +33,7 @@ export default class Pull extends Command { this.client.updating = false; return updateMessage.edit(updatedMessage); } - if (!pull.includes('origin/master')) { + if (!pull.includes('origin/master') && !pull.includes(' changed, ')) { const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`) .replace(/```$/, `${pull}\n\`\`\``); this.client.updating = false;