Check something

merge-requests/4/head
Bsian 2020-05-04 12:13:17 +01:00
parent 5fffe9f5f2
commit d8267112c7
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
2 changed files with 22 additions and 9 deletions

View File

@ -32,15 +32,26 @@ export default class Util {
* @param options childProcess.ExecOptions * @param options childProcess.ExecOptions
*/ */
public async exec(command: string, options: childProcess.ExecOptions = {}): Promise<string> { public async exec(command: string, options: childProcess.ExecOptions = {}): Promise<string> {
const ex = promisify(childProcess.exec); return new Promise((res, rej) => {
let result: string; let error = false;
try { let output = '';
const res = await ex(command, options); const writeFunction = (data: string|Buffer|Error) => {
result = `${res.stdout}${res.stderr}`; if (data instanceof Error) error = true;
} catch (err) { output += `${data}`;
return Promise.reject(new Error(`Command failed: ${err.cmd}\n${err.stderr}${err.stdout}`)); };
} const cmd = childProcess.exec(command, options);
return result; 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({ 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}`, 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(); return account.save();
} }

View File

@ -37,6 +37,7 @@ export default class CreateAccount extends Command {
const confirmation = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating account...***`); 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); 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(); message.delete();
return confirmation.edit(`${this.client.stores.emojis.success} ***Account successfully created***\n**Username:** \`${args[2]}\`\n**Temporary Password:** \`${data.tempPass}\``); return confirmation.edit(`${this.client.stores.emojis.success} ***Account successfully created***\n**Username:** \`${args[2]}\`\n**Temporary Password:** \`${data.tempPass}\``);