forked from engineering/cloudservices
45 lines
2.4 KiB
TypeScript
45 lines
2.4 KiB
TypeScript
import { Message } from 'discord.js';
|
|
import { Converter } from 'showdown';
|
|
import { Client, Command } from '../class';
|
|
|
|
export default class Warn extends Command {
|
|
constructor(client: Client) {
|
|
super(client);
|
|
this.name = 'warn';
|
|
this.description = 'Sends an official warning to user.';
|
|
this.usage = `${this.client.config.prefix}warn [username | user ID] [reason]`;
|
|
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
|
|
this.enabled = true;
|
|
}
|
|
|
|
public async run(message: Message, args: string[]) {
|
|
try {
|
|
if (!args.length || !args[1]) return this.client.commands.get('help').run(message, [this.name]);
|
|
const edit = await this.loading(message.channel, 'Processing warning...');
|
|
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
|
|
if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`);
|
|
if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
|
|
await this.client.util.createModerationLog(account.userID, message.author, 1, args.slice(1).join(' '));
|
|
message.delete();
|
|
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been warned by Technician ${message.author.username}#${message.author.discriminator}.***`);
|
|
await this.client.util.sendMessageToUserTerminal(account.username, `WARNING FROM TECHNICIAN: ${args.slice(1).join(' ')}`).catch(() => { });
|
|
return this.client.util.transport.sendMail({
|
|
to: account.emailAddress,
|
|
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
|
replyTo: 'cloud-help@libraryofcode.org',
|
|
subject: 'Your account has been warned',
|
|
html: `
|
|
<h1>Library of Code sp-us | Cloud Services</h1>
|
|
<p>Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p>
|
|
<p><strong>Reason:</strong> ${args.slice(1).length ? new Converter().makeHtml(args.slice(1).join(' ')) : 'Not Specified'}</p>
|
|
<p><strong>Technician:</strong> ${message.author.username}</p>
|
|
|
|
<b><i>Library of Code sp-us | Support Team</i></b>
|
|
`,
|
|
});
|
|
} catch (error) {
|
|
return this.client.util.handleError(error, message, this);
|
|
}
|
|
}
|
|
}
|