forked from engineering/cloudservices
Tidy and added delete account util
parent
26f0b6ef15
commit
3942e96524
14
src/Util.ts
14
src/Util.ts
|
@ -4,7 +4,6 @@ import childProcess from 'child_process';
|
|||
import nodemailer from 'nodemailer';
|
||||
import { Message, TextChannel, PrivateChannel } from 'eris';
|
||||
import { outputFile } from 'fs-extra';
|
||||
import uuid from 'uuid/v4';
|
||||
import { Client } from '.';
|
||||
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(`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({
|
||||
username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false,
|
||||
});
|
||||
await log.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);
|
||||
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) => {
|
||||
if (filter(Msg) === false) return;
|
||||
const verif = choices ? choices.includes(Msg.content) : Msg.content;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Message, PrivateChannel } from 'eris';
|
||||
import uuid from 'uuid/v4';
|
||||
import { Client, config } from '..';
|
||||
import { Command, RichEmbed } from '../class';
|
||||
|
||||
|
@ -43,6 +44,10 @@ export default class CreateAccount extends Command {
|
|||
const etcPasswd = `${acctName},${args[0]},,`;
|
||||
|
||||
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();
|
||||
embed.setTitle('Cloud Account | Create');
|
||||
|
|
Loading…
Reference in New Issue