53 lines
2.5 KiB
TypeScript
53 lines
2.5 KiB
TypeScript
import { Message, MessageEmbed, TextChannel } from 'discord.js';
|
|
import { Client, Command } 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]`;
|
|
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
|
|
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 this.loading(message.channel, '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 MessageEmbed()
|
|
.setTitle('Cloud Account | Notification')
|
|
.setDescription(args.slice(1).join(' '))
|
|
.addField('Technician', message.author.toString(), true)
|
|
.setFooter(this.client.user.username, this.client.user.avatarURL())
|
|
.setTimestamp();
|
|
this.client.users.fetch(account.userId).then((u) => {
|
|
u.send({ embeds: [embed] });
|
|
});
|
|
embed.addField('User', `${account.username} | <@${account.userId}>`, true);
|
|
const ch = await this.client.channels.fetch('580950455581147146') as TextChannel;
|
|
ch.send({ embeds: [embed] });
|
|
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: 'Notification',
|
|
html: `
|
|
<h1>Library of Code sp-us | Cloud Services</h1>
|
|
<p>${args.slice(1).join(' ')}</p>
|
|
<p><strong>Technician:</strong> ${message.author.username}</p>
|
|
|
|
<b><i>Library of Code sp-us | Support Team</i></b>
|
|
`,
|
|
});
|
|
message.delete();
|
|
await this.client.util.sendMessageToUserTerminal(account.username, `NOTIFICATION FROM TECHNICIAN: ${args.slice(1).join(' ')}`).catch(() => { });
|
|
return edit.edit(`***${this.client.stores.emojis.success} Sent notification to ${account.username}.***`);
|
|
} catch (error) {
|
|
return this.client.util.handleError(error, message, this);
|
|
}
|
|
}
|
|
}
|