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.'; this.permissions = { roles: ['455972169449734144', '662163685439045632'] }; 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, '') }] }); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`); if (account.locked) return message.channel.createMessage(`***${this.client.stores.emojis.error} This account is already locked.***`); const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Locking account...***`); if (account.username === 'matthew' || account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`); await this.client.util.exec(`lock ${account.username}`); await account.updateOne({ locked: true }); const expiry = new Date(); const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi); const length = Number(lockLength[0]); const unit = lockLength[1] as unitOfTime.Base; const momentMilliseconds = moment.duration(length, unit).asMilliseconds(); const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' '); await this.client.util.createModerationLog(account.userID, message.member, 2, reason, momentMilliseconds); edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been locked by Moderator ${message.author.username}#${message.author.discriminator}.***`); message.delete(); this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', subject: 'Your account has been locked', html: `

Library of Code | Cloud Services

Your Cloud Account has been locked until ${momentMilliseconds ? moment(expiry).calendar() : 'indefinitely'} under the EULA.

Reason: ${momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ')}

Supervisor: ${message.author.username}

Expiration: ${momentMilliseconds ? moment(expiry).format('dddd, MMMM Do YYYY, h:mm:ss A') : 'N/A'}

Library of Code sp-us | Support Team `, }); } catch (error) { return this.client.util.handleError(error, message, this); } } }