From d8267112c71f38f842f2473eca3070b5482f070b Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 12:13:17 +0100 Subject: [PATCH 1/7] Check something --- src/class/Util.ts | 30 +++++++++++++++++++++--------- src/commands/createaccount.ts | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index c2d8649..a60eecd 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -32,15 +32,26 @@ export default class Util { * @param options childProcess.ExecOptions */ public async exec(command: string, options: childProcess.ExecOptions = {}): Promise { - const ex = promisify(childProcess.exec); - let result: string; - try { - const res = await ex(command, options); - result = `${res.stdout}${res.stderr}`; - } catch (err) { - return Promise.reject(new Error(`Command failed: ${err.cmd}\n${err.stderr}${err.stdout}`)); - } - return result; + return new Promise((res, rej) => { + let error = false; + let output = ''; + const writeFunction = (data: string|Buffer|Error) => { + if (data instanceof Error) error = true; + output += `${data}`; + }; + const cmd = childProcess.exec(command, options); + cmd.stdout.on('data', writeFunction); + cmd.stderr.on('data', writeFunction); + cmd.on('error', writeFunction); + cmd.once('close', (code, signal) => { + output += `Command exited with code ${code}${signal ? `/${signal}` : ''}`; + cmd.stdout.removeListener('data', writeFunction); + cmd.stderr.removeListener('data', writeFunction); + cmd.removeListener('error', writeFunction); + if (error) rej(output); + res(output); + }); + }); } /** @@ -155,6 +166,7 @@ export default class Util { const account = new this.client.db.Account({ username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, tier: 1, supportKey: code, ssInit: false, ramLimitNotification: tier.resourceLimits.ram - 50, homepath: `/home/${username}`, }); + this.client.createMessage('592170164322041856', JSON.stringify(account)); return account.save(); } diff --git a/src/commands/createaccount.ts b/src/commands/createaccount.ts index d9047b0..f677dbc 100644 --- a/src/commands/createaccount.ts +++ b/src/commands/createaccount.ts @@ -37,6 +37,7 @@ export default class CreateAccount extends Command { const confirmation = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating account...***`); const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id); + this.client.createMessage('592170164322041856', JSON.stringify(data)); message.delete(); return confirmation.edit(`${this.client.stores.emojis.success} ***Account successfully created***\n**Username:** \`${args[2]}\`\n**Temporary Password:** \`${data.tempPass}\``); From 723c46e3c4407f2b036c5cc7647d8b9e0debedd2 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 12:18:57 +0100 Subject: [PATCH 2/7] Remove the shit that's breaking shit --- src/class/Util.ts | 2 -- src/commands/createaccount.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index a60eecd..d3880d8 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -44,7 +44,6 @@ export default class Util { cmd.stderr.on('data', writeFunction); cmd.on('error', writeFunction); cmd.once('close', (code, signal) => { - output += `Command exited with code ${code}${signal ? `/${signal}` : ''}`; cmd.stdout.removeListener('data', writeFunction); cmd.stderr.removeListener('data', writeFunction); cmd.removeListener('error', writeFunction); @@ -166,7 +165,6 @@ export default class Util { const account = new this.client.db.Account({ username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, tier: 1, supportKey: code, ssInit: false, ramLimitNotification: tier.resourceLimits.ram - 50, homepath: `/home/${username}`, }); - this.client.createMessage('592170164322041856', JSON.stringify(account)); return account.save(); } diff --git a/src/commands/createaccount.ts b/src/commands/createaccount.ts index f677dbc..d9047b0 100644 --- a/src/commands/createaccount.ts +++ b/src/commands/createaccount.ts @@ -37,7 +37,6 @@ export default class CreateAccount extends Command { const confirmation = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating account...***`); const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id); - this.client.createMessage('592170164322041856', JSON.stringify(data)); message.delete(); return confirmation.edit(`${this.client.stores.emojis.success} ***Account successfully created***\n**Username:** \`${args[2]}\`\n**Temporary Password:** \`${data.tempPass}\``); From 810ad6e7be0f835b012ede5fa4e5ab8162ae89c5 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 12:21:42 +0100 Subject: [PATCH 3/7] Fix message --- src/intervals/memory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index a77ee17..41a5996 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -73,7 +73,7 @@ export default function memory(client: Client) { if ((memoryConversion >= acc.ramLimitNotification) && (acc.ramLimitNotification !== 0)) { const notifyEmbed = new RichEmbed() .setTitle('Cloud Account | Notification') - .setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard - 10)} MB'. Please correct your usage to avoid further action.\nYou can set your notification preferences by running \`=limits set-ram-notification \`, you can disable these notifications by running \`=limits set-ram-notification -1\`.`) + .setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard - 10)} MB'. Please correct your usage to avoid further action.\nYou can set your notification preferences by running \`=limits set-ram-notification \`, you can disable these notifications by running \`=limits set-ram-notification 0\`.`) .addField('User', `${acc.username} | <@${acc.userID}>`, true) .addField('Technician', 'SYSTEM', true) .setFooter(client.user.username, client.user.avatarURL) From e6b18182224366998d11698e0479a8d1a03abc73 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 12:51:16 +0100 Subject: [PATCH 4/7] Trying to fix something with the CI? --- .gitlab-ci.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 683d018..b1544f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,19 +1,19 @@ -stages: - - build - - test - -typescript_build: - stage: build - script: - - cp ../config.json ./src/config.json - - yarn install --ignore-engines - - tsc -p ./tsconfig.json - -lint: - stage: test - before_script: - - cp ../config.json ./src/config.json - - yarn install --ignore-engines - script: - - yarn run lint-find - +stages: + - build + - test + +typescript_build: + stage: build + script: + - cp ../config.json ./src/config.json + - yarn install --ignore-engines + - tsc -p ./tsconfig.json --traceResolution + +lint: + stage: test + before_script: + - cp ../config.json ./src/config.json + - yarn install --ignore-engines + script: + - yarn run lint-find + From 1b9d3c56f1c00e74be687b6a970eefaf4d4aef3f Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 13:07:55 +0100 Subject: [PATCH 5/7] Fix CI --- package.json | 3 ++- src/api/Security.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 17183e4..47f9981 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "uuid": "^3.3.3" }, "devDependencies": { - "@types/express": "^4.17.2", + "@types/express": "^4.17.6", + "@types/express-serve-static-core": "^4.17.5", "@types/fs-extra": "^8.0.0", "@types/helmet": "^0.0.45", "@types/ioredis": "^4.0.18", diff --git a/src/api/Security.ts b/src/api/Security.ts index 2dc019f..5488662 100644 --- a/src/api/Security.ts +++ b/src/api/Security.ts @@ -70,7 +70,7 @@ export default class Security { return req.headers.authorization.split(' ')[1]; } if (req.query && req.query.token) { - return req.query.token; + return req.query.token as string; } return '0000000000'; } From 9f4a7fcff7af2a311b22cbd814aaaae8550e3bcf Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 13:08:21 +0100 Subject: [PATCH 6/7] Remove trace res --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b1544f5..a592cac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ typescript_build: script: - cp ../config.json ./src/config.json - yarn install --ignore-engines - - tsc -p ./tsconfig.json --traceResolution + - tsc -p ./tsconfig.json lint: stage: test From e646685bc3c6a492241e4b2347beb3fb34281cc4 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 4 May 2020 13:12:38 +0100 Subject: [PATCH 7/7] Lint --- 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 39df7c9..2e44703 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -32,7 +32,7 @@ export default class Load extends Command { delete require.cache[`${corepath}/commands/index.js`]; delete require.cache[`${corepath}/commands/${args[1]}.js`]; Object.keys(require.cache).filter((path) => path.includes(`${args[1]}_`)).forEach((path) => delete require.cache[path]); - const cmdIndex = require('../commands'); + const cmdIndex = require('.'); 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;