1
0
Fork 0
cloudservices/src/commands/lock.ts

55 lines
2.9 KiB
TypeScript
Raw Normal View History

2020-03-13 19:57:16 -04:00
import moment, { unitOfTime } from 'moment';
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
export default class Lock extends Command {
constructor(client: Client) {
super(client);
this.name = 'lock';
this.description = 'Locks an account.';
2020-04-20 16:18:19 -04:00
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
2020-03-13 19:57:16 -04:00
this.enabled = true;
}
public async run(message: Message, args: string[]) { // eslint-disable-line
try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
2020-06-29 02:35:14 -04:00
if (!account) return this.error(message.channel, 'Cannot find user.');
if (account.locked) return this.error(message.channel, 'This account is already locked.');
const edit = await this.loading(message.channel, 'Locking account...');
2020-03-13 19:57:16 -04:00
if (account.username === 'matthew' || account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
await this.client.util.sendMessageToUserTerminal(account.username, 'ACCOUNT LOCKED BY TECHNICIAN | PREPARING TO LOGOUT').catch(() => { });
2020-03-13 19:57:16 -04:00
await this.client.util.exec(`lock ${account.username}`);
await account.updateOne({ locked: true });
const expiry = new Date();
2020-06-09 07:40:02 -04:00
const [length, unit] = args[1].match(/[a-z]+|[^a-z]+/gi);
const momentMilliseconds = moment.duration(Number(length), unit as unitOfTime.Base).asMilliseconds();
2020-03-13 19:57:16 -04:00
const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
await this.client.util.createModerationLog(account.userID, message.member, 2, reason, momentMilliseconds);
2020-05-01 02:51:02 -04:00
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been locked by Technician ${message.author.username}#${message.author.discriminator}.***`);
2020-03-13 19:57:16 -04:00
message.delete();
this.client.util.transport.sendMail({
to: account.emailAddress,
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
subject: 'Your account has been locked',
html: `
<h1>Library of Code | Cloud Services</h1>
<p>Your Cloud Account has been locked until ${momentMilliseconds ? moment(expiry).calendar() : 'indefinitely'} under the EULA.</p>
<p><b>Reason:</b> ${momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ')}</p>
2020-05-01 02:51:02 -04:00
<p><b>Technician:</b> ${message.author.username}</p>
2020-03-13 19:57:16 -04:00
<p><b>Expiration:</b> ${momentMilliseconds ? moment(expiry).format('dddd, MMMM Do YYYY, h:mm:ss A') : 'N/A'}</p>
<b><i>Library of Code sp-us | Support Team</i></b>
`,
});
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}