From 62557efecfde48ef562cf81a2c456b129d4040e1 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Wed, 30 Oct 2019 22:10:20 -0400 Subject: [PATCH] add notify command --- src/commands/notify.ts | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/commands/notify.ts diff --git a/src/commands/notify.ts b/src/commands/notify.ts new file mode 100644 index 0000000..4c0ef09 --- /dev/null +++ b/src/commands/notify.ts @@ -0,0 +1,52 @@ +/* eslint-disable consistent-return */ +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]`; + this.permissions = { roles: ['446104438969466890'] }; + 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.***`); + await this.client.util.createModerationLog(account.userID, message.member, 1, args.slice(1).join(' ')); + 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) => { + // @ts-ignore + channel.createMessage({ embed }); + }); + // @ts-ignore + this.client.createMessage('580950455581147146', { embed }); + this.client.util.transport.sendMail({ + to: account.emailAddress, + from: 'Library of Code sp-us | Cloud Services ', + subject: 'Notification', + html: ` +

Library of Code sp-us | Cloud Services

+

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

+

Moderator: ${message.author.username}

+ + Library of Code sp-us | Support Team + `, + }); + edit.edit(`***${this.client.stores.emojis.success} Send notification to ${account.username}.***`); + } catch (error) { + await this.client.util.handleError(error, message, this); + } + } +}