Tidy and added delete account util

merge-requests/1/merge
Bsian 2019-10-27 16:22:49 +00:00
parent 26f0b6ef15
commit 3942e96524
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
2 changed files with 12 additions and 7 deletions

View File

@ -4,7 +4,6 @@ import childProcess from 'child_process';
import nodemailer from 'nodemailer'; import nodemailer from 'nodemailer';
import { Message, TextChannel, PrivateChannel } from 'eris'; import { Message, TextChannel, PrivateChannel } from 'eris';
import { outputFile } from 'fs-extra'; import { outputFile } from 'fs-extra';
import uuid from 'uuid/v4';
import { Client } from '.'; import { Client } from '.';
import { Command, RichEmbed } from './class'; import { Command, RichEmbed } from './class';
@ -118,20 +117,21 @@ export default class Util {
await this.exec(`useradd -m -p ${hash} -c ${etcPasswd} -s /bin/bash ${username}`); await this.exec(`useradd -m -p ${hash} -c ${etcPasswd} -s /bin/bash ${username}`);
await this.exec(`chage -d0 ${username}`); await this.exec(`chage -d0 ${username}`);
const log = await new this.client.db.Moderation({
username, userID, logID: uuid(), moderatorID, reason: 'User requested account creation', type: 0, date: new Date(),
});
const account = await new this.client.db.Account({ const account = await new this.client.db.Account({
username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false,
}); });
await log.save();
await account.save(); await account.save();
} }
public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}) { public async deleteAccount(username: string): Promise<void> {
await this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username}`);
await this.client.db.Account.deleteOne({ username });
}
public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}): Promise<string> {
const msg = await message.channel.createMessage(question); const msg = await message.channel.createMessage(question);
return new Promise((res, rej) => { return new Promise((res, rej) => {
setTimeout(() => rej(new Error('Did not supply a valid input in time')), timeout); setTimeout(() => { if (shouldDelete) msg.delete(); rej(new Error('Did not supply a valid input in time')); }, timeout);
this.client.on('messageCreate', (Msg) => { this.client.on('messageCreate', (Msg) => {
if (filter(Msg) === false) return; if (filter(Msg) === false) return;
const verif = choices ? choices.includes(Msg.content) : Msg.content; const verif = choices ? choices.includes(Msg.content) : Msg.content;

View File

@ -1,4 +1,5 @@
import { Message, PrivateChannel } from 'eris'; import { Message, PrivateChannel } from 'eris';
import uuid from 'uuid/v4';
import { Client, config } from '..'; import { Client, config } from '..';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';
@ -43,6 +44,10 @@ export default class CreateAccount extends Command {
const etcPasswd = `${acctName},${args[0]},,`; const etcPasswd = `${acctName},${args[0]},,`;
await this.client.util.createAccount(passHash, etcPasswd, args[2], args[0], args[1], message.author.id); await this.client.util.createAccount(passHash, etcPasswd, args[2], args[0], args[1], message.author.id);
const log = await new this.client.db.Moderation({
username: args[2], userID: args[0], logID: uuid(), moderatorID: message.author.id, reason: 'User requested account creation', type: 0, date: new Date(),
});
await log.save();
const embed = new RichEmbed(); const embed = new RichEmbed();
embed.setTitle('Cloud Account | Create'); embed.setTitle('Cloud Account | Create');