cloudservices/src/commands/emailcode.ts

44 lines
2.1 KiB
TypeScript

import { randomBytes } from 'crypto';
import { Message } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
export default class EmailCode extends Command {
constructor(client: Client) {
super(client);
this.name = 'emailcode';
this.description = 'Sends a code to an email address to use for address verification.';
this.usage = `${this.client.config.prefix}emailcode <email address>`;
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
this.aliases = ['code'];
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 code = randomBytes(5).toString('hex');
if (!this.client.util.isValidEmail(args[0])) return this.error(message.channel, 'The email address provided is invalid.');
this.client.util.transport.sendMail({
to: args[0],
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
subject: 'Email Verification Code',
html: `
<body>
<style>* {font-family: 'Calibri';}</style>
<h1>Library of Code | Cloud Services</h1>
<p>Please provide the code provided below to the Staff member working with you on account creation.</p>
<h2>${code}</h2>
<h3>Want to support us?</h3>
<p>You can support us on Patreon! Head to <a target="_blank" href="https://www.patreon.com/libraryofcode">our Patreon page</a> and feel free to donate as much or as little as you want!<br>Donating $5 or more will grant you Tier 3, which means we will manage your account at your request, longer certificates, increased Tier limits as well as some roles in the server!</p>
<b><i>Library of Code sp-us | Support Team</i></b>
</body>
`,
});
return this.success(message.channel, `Code: \`${code}\` | Email Address: ${args[0]}`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}