1
0
Fork 0

Support multiple domains using a single port

refactor/models
Bsian 2019-11-01 23:53:21 +00:00
parent 720ff46640
commit a5cf30652c
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 19 additions and 14 deletions

View File

@ -1,6 +1,7 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import moment from 'moment'; import moment from 'moment';
import x509 from '@ghaiklor/x509'; import x509 from '@ghaiklor/x509';
import { createPaginationEmbed } from 'eris-pagination';
import { Message } from 'eris'; import { Message } from 'eris';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';
import { Client } from '..'; import { Client } from '..';
@ -18,8 +19,9 @@ export default class CWG_Data extends Command {
public async run(message: Message, args: string[]) { public async run(message: Message, args: string[]) {
try { try {
if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]); if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]);
const domain = await this.client.db.Domain.findOne({ $or: [{ domain: args[0] }, { port: Number(args[0]) || '' }] }); const dom = await this.client.db.Domain.find({ $or: [{ domain: args[0] }, { port: Number(args[0]) || '' }] });
if (!domain) return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`); if (!dom.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`);
const embeds = dom.map(async (domain) => {
const embed = new RichEmbed(); const embed = new RichEmbed();
embed.setTitle('Domain Information'); embed.setTitle('Domain Information');
embed.addField('Account Username', domain.account.username, true); embed.addField('Account Username', domain.account.username, true);
@ -31,8 +33,11 @@ export default class CWG_Data extends Command {
embed.addField('Certificate Expiration Date', moment(x509.parseCert(await fs.readFile(domain.x509.cert, { encoding: 'utf8' })).notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); embed.addField('Certificate Expiration Date', moment(x509.parseCert(await fs.readFile(domain.x509.cert, { encoding: 'utf8' })).notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
return embed;
});
// @ts-ignore // @ts-ignore
return message.channel.createMessage({ embed }); if (embeds.length === 1) return message.channel.createMessage({ embed: embeds[0] });
return createPaginationEmbed(message, this.client, embeds, {});
} catch (error) { } catch (error) {
return this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }