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 = this.client.channels.cache.get('580950455581147146') as TextChannel; ch.send({ embeds: [embed] }); this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', replyTo: 'cloud-help@libraryofcode.org', subject: 'Notification', html: `

Library of Code sp-us | Cloud Services

${args.slice(1).join(' ')}

Technician: ${message.author.username}

Library of Code sp-us | Support Team `, }); 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); } } }