2020-03-13 19:57:16 -04:00
|
|
|
import { Message } from 'eris';
|
|
|
|
import { Client } from '..';
|
|
|
|
import { Command, RichEmbed } from '../class';
|
|
|
|
|
|
|
|
export default class Notify extends Command {
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'notify';
|
|
|
|
this.description = 'Sends a notification to a user.';
|
|
|
|
this.usage = `${this.client.config.prefix}notify [username | user ID]`;
|
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[]) {
|
|
|
|
try {
|
|
|
|
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
|
|
|
|
const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Sending notification...***`);
|
|
|
|
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.***`);
|
|
|
|
const embed = new RichEmbed()
|
|
|
|
.setTitle('Cloud Account | Notification')
|
|
|
|
.setDescription(args.slice(1).join(' '))
|
|
|
|
.addField('Moderator', `<@${message.author.id}>`, true)
|
|
|
|
.setFooter(this.client.user.username, this.client.user.avatarURL)
|
|
|
|
.setTimestamp();
|
|
|
|
this.client.getDMChannel(account.userID).then((channel) => {
|
|
|
|
channel.createMessage({ embed });
|
|
|
|
});
|
|
|
|
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
|
|
|
|
this.client.createMessage('580950455581147146', { embed });
|
|
|
|
this.client.util.transport.sendMail({
|
|
|
|
to: account.emailAddress,
|
|
|
|
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
|
|
|
|
subject: 'Notification',
|
|
|
|
html: `
|
|
|
|
<h1>Library of Code sp-us | Cloud Services</h1>
|
|
|
|
<p>${args.slice(1).join(' ')}</p>
|
2020-05-01 02:51:02 -04:00
|
|
|
<p><strong>Technician:</strong> ${message.author.username}</p>
|
2020-03-13 19:57:16 -04:00
|
|
|
|
|
|
|
<b><i>Library of Code sp-us | Support Team</i></b>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
message.delete();
|
2020-03-30 07:22:32 -04:00
|
|
|
return edit.edit(`***${this.client.stores.emojis.success} Send notification to ${account.username}.***`);
|
2020-03-13 19:57:16 -04:00
|
|
|
} catch (error) {
|
2020-03-30 07:22:32 -04:00
|
|
|
return this.client.util.handleError(error, message, this);
|
2020-03-13 19:57:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|