1
0
Fork 0

Fixed shit

refactor/models
Bsian 2019-10-28 21:41:23 +00:00
parent 1a5e72f94f
commit 935d2147d3
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 46 additions and 41 deletions

View File

@ -11,49 +11,51 @@ export default class CWG extends Command {
super(client); super(client);
this.name = 'cwg'; this.name = 'cwg';
this.description = 'Manages aspects for the CWG.'; this.description = 'Manages aspects for the CWG.';
this.usage = `${this.client.config.prefix}cwg [User ID/Username] [Domain] [Port] <Path to x509 certificate> <Path to x509 key>`; this.usage = `${this.client.config.prefix}cwg create [User ID/Username] [Domain] [Port] <Path to x509 certificate> <Path to x509 key>`;
this.permissions = { roles: ['525441307037007902'] }; this.permissions = { roles: ['525441307037007902'] };
this.enabled = true; this.enabled = true;
} }
public async run(message: Message, args?: string[]) { public async run(message: Message, args?: string[]) {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]); try {
/* if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
/*
args[1] should be the user's ID OR account username; required args[1] should be the user's ID OR account username; required
args[2] should be the domain; required args[2] should be the domain; required
args[3] should be the port; required args[3] should be the port; required
args[4] should be the path to the x509 certificate; not required args[4] should be the path to the x509 certificate; not required
args[5] should be the path to the x509 key; not required args[5] should be the path to the x509 key; not required
*/ */
if (args[0] === 'create') { if (args[0] === 'create') {
const account = await this.client.db.Account.findOne({ $or: [{ account: args[1] }, { userID: args[1] }] }); if (!args[5]) return this.client.commands.get('help').run(message, [this.name]);
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} Cannot locate account, please try again.`); const account = await this.client.db.Account.findOne({ $or: [{ account: args[1] }, { userID: args[1] }] });
try { if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} Cannot locate account, please try again.`);
const domain = await this.createDomain(account, args[2], Number(args[3]), { cert: args[4], key: args[5] }); try {
const embed = new RichEmbed(); const domain = await this.createDomain(account, args[2], Number(args[3]), { cert: args[4], key: args[5] });
embed.setTitle('Domain Creation'); const embed = new RichEmbed();
embed.setColor(3066993); embed.setTitle('Domain Creation');
embed.addField('Account Username', account.username, true); embed.setColor(3066993);
embed.addField('Account ID', account.id, true); embed.addField('Account Username', account.username, true);
embed.addField('Engineer', `<@${message.author.id}>`, true); embed.addField('Account ID', account.id, true);
embed.addField('Domain', domain.domain, true); embed.addField('Engineer', `<@${message.author.id}>`, true);
embed.addField('Port', String(domain.port), true); embed.addField('Domain', domain.domain, true);
const cert = x509.parseCert(await fs.readFile(domain.x509.cert, { encoding: 'utf8' })); embed.addField('Port', String(domain.port), true);
embed.addField('Certificate Issuer', cert.issuer.organizationName, true); const cert = x509.parseCert(await fs.readFile(domain.x509.cert, { encoding: 'utf8' }));
embed.addField('Certificate Subject', cert.subject.commonName, true); embed.addField('Certificate Issuer', cert.issuer.organizationName, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.addField('Certificate Subject', cert.subject.commonName, true);
embed.setTimestamp(new Date(message.timestamp)); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
// @ts-ignore embed.setTimestamp(new Date(message.timestamp));
message.channel.createMessage({ embed }); // @ts-ignore
// @ts-ignore message.channel.createMessage({ embed });
this.client.createMessage('580950455581147146', { embed }); // @ts-ignore
// @ts-ignore this.client.createMessage('580950455581147146', { embed });
this.client.getDMChannel(account.userID).then((r) => r.createMessage({ embed })); // @ts-ignore
await this.client.util.transport.sendMail({ this.client.getDMChannel(account.userID).then((r) => r.createMessage({ embed }));
to: account.emailAddress, await this.client.util.transport.sendMail({
from: 'Library of Code sp-us | Support Team <support@libraryofcode.org>', to: account.emailAddress,
subject: 'Your domain has been binded', from: 'Library of Code sp-us | Support Team <support@libraryofcode.org>',
html: ` subject: 'Your domain has been binded',
html: `
<h1>Library of Code sp-us | Cloud Services</h1> <h1>Library of Code sp-us | Cloud Services</h1>
<p>Hello, this is an email informing you that a new domain under your account has been binded. <p>Hello, this is an email informing you that a new domain under your account has been binded.
Information is below.</p> Information is below.</p>
@ -67,16 +69,19 @@ export default class CWG extends Command {
<b><i>Library of Code sp-us | Support Team</i></b> <b><i>Library of Code sp-us | Support Team</i></b>
`, `,
}); });
if (!domain.domain.includes('cloud.libraryofcode.org')) { if (!domain.domain.includes('cloud.libraryofcode.org')) {
const content = `_**DNS Record Setup**__\nYou recently a binded a custom domain to your Library of Code sp-us Account. You'll have to update your DNS records. We've provided the records below.\n\n\`${domain.domain} IN CNAME cloud.libraryofcode.us AUTO/500\`\nThis basically means you need to make a CNAME record with the key/host of ${domain.domain} and the value/point to cloud.libraryofcode.org. If you have any questions, don't hesitate to ask us.`; const content = `_**DNS Record Setup**__\nYou recently a binded a custom domain to your Library of Code sp-us Account. You'll have to update your DNS records. We've provided the records below.\n\n\`${domain.domain} IN CNAME cloud.libraryofcode.us AUTO/500\`\nThis basically means you need to make a CNAME record with the key/host of ${domain.domain} and the value/point to cloud.libraryofcode.org. If you have any questions, don't hesitate to ask us.`;
this.client.getDMChannel(account.userID).then((r) => r.createMessage(content)); this.client.getDMChannel(account.userID).then((r) => r.createMessage(content));
}
} catch (err) {
this.client.util.handleError(err, message, this);
} }
} catch (err) { } else { message.channel.createMessage(`${this.client.stores.emojis.error} Not a valid subcommand.`); }
this.client.util.handleError(err, message, this); return true;
} } catch (error) {
} else { message.channel.createMessage(`${this.client.stores.emojis.error} Not a valid subcommand.`); } return this.client.util.handleError(error, message, this);
return true; }
} }
/** /**