merge conflict fixes
commit
09bdc2867e
6
Makefile
6
Makefile
|
@ -7,17 +7,17 @@ storage_files := $(wildcard src/go/storage/*.go)
|
|||
all: check_certificate check_cert_signatures storage typescript
|
||||
|
||||
check_certificate:
|
||||
HOME=/root go build -v -ldflags="-s -w" -o dist/bin/checkCertificate ${check_certificate_files}
|
||||
HOME=/root go build -ldflags="-s -w" -o dist/bin/checkCertificate ${check_certificate_files}
|
||||
@chmod 740 dist/bin/checkCertificate
|
||||
file dist/bin/checkCertificate
|
||||
|
||||
check_cert_signatures:
|
||||
HOME=/root go build -v -ldflags="-s -w" -o dist/bin/checkCertSignatures ${check_certificate_signatures_files}
|
||||
HOME=/root go build -ldflags="-s -w" -o dist/bin/checkCertSignatures ${check_certificate_signatures_files}
|
||||
@chmod 740 dist/bin/checkCertSignatures
|
||||
file dist/bin/checkCertSignatures
|
||||
|
||||
storage:
|
||||
HOME=/root go build -v -ldflags="-s -w" -o dist/bin/storage ${storage_files}
|
||||
HOME=/root go build -ldflags="-s -w" -o dist/bin/storage ${storage_files}
|
||||
@chmod 740 dist/bin/storage
|
||||
file dist/bin/storage
|
||||
|
||||
|
|
|
@ -9,10 +9,8 @@ export default class Collection<V> extends Map<string, V> {
|
|||
*/
|
||||
constructor(iterable: any[]|object = null) {
|
||||
if (iterable && iterable instanceof Array) {
|
||||
// @ts-ignore
|
||||
super(iterable);
|
||||
} else if (iterable && iterable instanceof Object) {
|
||||
// @ts-ignore
|
||||
super(Object.entries(iterable));
|
||||
} else {
|
||||
super();
|
||||
|
|
|
@ -15,23 +15,23 @@ export default class RichEmbed {
|
|||
|
||||
footer?: { text: string, icon_url?: string, proxy_icon_url?: string}
|
||||
|
||||
image?: { url?: string, proxy_url?: string, height?: number, width?: number }
|
||||
image?: { url: string, proxy_url?: string, height?: number, width?: number }
|
||||
|
||||
thumbnail?: { url?: string, proxy_url?: string, height?: number, width?: number }
|
||||
|
||||
video?: { url?: string, height?: number, width?: number }
|
||||
video?: { url: string, height?: number, width?: number }
|
||||
|
||||
provider?: { name?: string, url?: string}
|
||||
provider?: { name: string, url?: string}
|
||||
|
||||
author?: { name?: string, url?: string, proxy_icon_url?: string, icon_url?: string}
|
||||
author?: { name: string, url?: string, proxy_icon_url?: string, icon_url?: string}
|
||||
|
||||
fields?: {name: string, value: string, inline?: boolean}[]
|
||||
|
||||
constructor(data: {
|
||||
title?: string, type?: string, description?: string, url?: string, timestamp?: Date, color?: number, fields?: {name: string, value: string, inline?: boolean}[]
|
||||
footer?: { text: string, icon_url?: string, proxy_icon_url?: string}, image?: { url?: string, proxy_url?: string, height?: number, width?: number },
|
||||
thumbnail?: { url?: string, proxy_url?: string, height?: number, width?: number }, video?: { url?: string, height?: number, width?: number },
|
||||
provider?: { name?: string, url?: string}, author?: { name?: string, url?: string, proxy_icon_url?: string, icon_url?: string},
|
||||
footer?: { text: string, icon_url?: string, proxy_icon_url?: string}, image?: { url: string, proxy_url?: string, height?: number, width?: number },
|
||||
thumbnail?: { url: string, proxy_url?: string, height?: number, width?: number }, video?: { url: string, height?: number, width?: number },
|
||||
provider?: { name: string, url?: string}, author?: { name: string, url?: string, proxy_icon_url?: string, icon_url?: string},
|
||||
} = {}) {
|
||||
/*
|
||||
let types: {
|
||||
|
|
|
@ -171,12 +171,17 @@ export default class Util {
|
|||
public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}): Promise<Message> {
|
||||
const msg = await message.channel.createMessage(question);
|
||||
return new Promise((res, rej) => {
|
||||
setTimeout(() => { if (shouldDelete) msg.delete().catch(); rej(new Error('Did not supply a valid input in time')); }, timeout);
|
||||
this.client.on('messageCreate', (Msg) => {
|
||||
const func = (Msg: Message) => {
|
||||
if (filter(Msg) === false) return;
|
||||
const verif = choices ? choices.includes(Msg.content) : Msg.content;
|
||||
if (verif) { if (shouldDelete) msg.delete().catch(); res(Msg); }
|
||||
});
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
if (shouldDelete) msg.delete().catch(); rej(new Error('Did not supply a valid input in time'));
|
||||
this.client.removeListener('messageCreate', func);
|
||||
}, timeout);
|
||||
this.client.on('messageCreate', func);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -237,7 +242,6 @@ export default class Util {
|
|||
.setTimestamp();
|
||||
if (reason) embed.addField('Reason', reason || 'Not specified');
|
||||
if (type === 2) embed.addField('Lock Expiration', `${date ? moment(date).format('dddd, MMMM Do YYYY, h:mm:ss A') : 'Indefinitely'}`);
|
||||
// @ts-ignore
|
||||
this.client.createMessage('580950455581147146', { embed }); this.client.getDMChannel(userID).then((channel) => channel.createMessage({ embed })).catch();
|
||||
|
||||
return Promise.resolve(log);
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
import fs from 'fs-extra';
|
||||
import fs, { writeFile, unlink } from 'fs-extra';
|
||||
import axios from 'axios';
|
||||
import x509 from '@ghaiklor/x509';
|
||||
import { Message } from 'eris';
|
||||
import { AccountInterface } from '../models';
|
||||
import { Command, RichEmbed } from '../class';
|
||||
import { Client } from '..';
|
||||
import { parseCertificate } from '../functions';
|
||||
|
||||
export default class CWG_Create extends Command {
|
||||
public urlRegex: RegExp;
|
||||
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'create';
|
||||
this.description = 'Bind a domain to the CWG';
|
||||
this.usage = `${this.client.config.prefix}cwg create [User ID | Username] [Domain] [Port] <Path to x509 cert> <Path to x509 key>`;
|
||||
this.usage = `${this.client.config.prefix}cwg create [User ID | Username] [Domain] [Port] <Cert Chain> <Private Key> || Use snippets raw URL`;
|
||||
this.permissions = { roles: ['525441307037007902'] };
|
||||
this.aliases = ['bind'];
|
||||
this.enabled = true;
|
||||
this.urlRegex = /^[a-zA-Z0-9\-._~:/?#[\]@!$&'()*+,;=]+$/;
|
||||
}
|
||||
|
||||
public async run(message: Message, args: string[]) {
|
||||
|
@ -27,69 +30,101 @@ export default class CWG_Create extends Command {
|
|||
*/
|
||||
try {
|
||||
if (!args[2]) return this.client.commands.get('help').run(message, ['cwg', this.name]);
|
||||
const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Binding domain...***`);
|
||||
|
||||
let certs: { cert: string, key: string };
|
||||
|
||||
if (!this.urlRegex.test(args[1])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid URL***`);
|
||||
if (Number(args[2]) < 1024 || Number(args[2]) > 65535) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Port must be greater than 1024 and less than 65535***`);
|
||||
if (!args[1].endsWith('.cloud.libraryofcode.org') && !args[4]) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Certificate Chain and Private Key are required for custom domains***`);
|
||||
|
||||
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
|
||||
if (!account) return edit.edit(`${this.client.stores.emojis.error} Cannot locate account, please try again.`);
|
||||
if (args[3] && !args[4]) return edit.edit(`${this.client.stores.emojis.error} x509 Certificate key required`);
|
||||
let certs: { cert?: string, key?: string }; if (args[4]) certs = { cert: args[3], key: args[4] };
|
||||
if (await this.client.db.Domain.exists({ domain: args[1] })) return edit.edit(`***${this.client.stores.emojis.error} This domain already exists.***`);
|
||||
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} Cannot locate account, please try again.`);
|
||||
|
||||
if (await this.client.db.Domain.exists({ domain: args[1] })) return message.channel.createMessage(`${this.client.stores.emojis.error} ***This domain already exists***`);
|
||||
|
||||
if (await this.client.db.Domain.exists({ port: Number(args[2]) })) {
|
||||
// await edit.edit(`***${this.client.stores.emojis.error} This port is already binded to a domain. Do you wish to continue? (y/n)***`);
|
||||
let answer: Message;
|
||||
try {
|
||||
answer = await this.client.util.messageCollector(message,
|
||||
`***${this.client.stores.emojis.error} This port is already binded to a domain. Do you wish to continue? (y/n)***`,
|
||||
30000, true, ['y', 'n'], (msg) => msg.author.id === message.author.id && msg.channel.id === message.channel.id);
|
||||
answer = await this.client.util.messageCollector(
|
||||
message,
|
||||
`***${this.client.stores.emojis.error} ***This port is already binded to a domain. Do you wish to continue? (y/n)***`,
|
||||
30000, true, ['y', 'n'], (msg) => msg.author.id === message.author.id && msg.channel.id === message.channel.id,
|
||||
);
|
||||
} catch (error) {
|
||||
return edit.edit(`***${this.client.stores.emojis.error} Bind request cancelled***`);
|
||||
return message.channel.createMessage(`${this.client.stores.emojis.error} ***Bind request cancelled***`);
|
||||
}
|
||||
if (answer.content === 'n') return edit.edit(`***${this.client.stores.emojis.error} Bind request cancelled***`);
|
||||
if (answer.content === 'n') return message.channel.createMessage(`${this.client.stores.emojis.error} ***Bind request cancelled***`);
|
||||
}
|
||||
|
||||
const edit = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Binding domain...***`);
|
||||
|
||||
if (!args[1].endsWith('.cloud.libraryofcode.org')) {
|
||||
const urls = args.slice(3, 5);
|
||||
if (urls.some((l) => !l.includes('snippets.cloud.libraryofcode.org/raw/'))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid snippets URL***`);
|
||||
|
||||
const tasks = urls.map((l) => axios({ method: 'GET', url: l }));
|
||||
const response = await Promise.all(tasks);
|
||||
const certAndPrivateKey: string[] = response.map((r) => r.data);
|
||||
|
||||
if (!this.isValidCertificateChain(certAndPrivateKey[0])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid Certificate Chain***`);
|
||||
if (!this.isValidPrivateKey(certAndPrivateKey[1])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid Private Key***`);
|
||||
|
||||
certs = { cert: certAndPrivateKey[0], key: certAndPrivateKey[1] };
|
||||
}
|
||||
|
||||
const domain = await this.createDomain(account, args[1], Number(args[2]), certs);
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Domain Creation');
|
||||
embed.setColor(3066993);
|
||||
embed.addField('Account Username', account.username, true);
|
||||
embed.addField('Account ID', account.id, true);
|
||||
embed.addField('Engineer', `<@${message.author.id}>`, true);
|
||||
embed.addField('Domain', domain.domain, true);
|
||||
embed.addField('Port', String(domain.port), true);
|
||||
const cert = x509.parseCert(await fs.readFile(domain.x509.cert, { encoding: 'utf8' }));
|
||||
embed.addField('Certificate Issuer', cert.issuer.organizationName, true);
|
||||
embed.addField('Certificate Subject', cert.subject.commonName, true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp(new Date(message.timestamp));
|
||||
message.delete();
|
||||
await this.client.util.exec('systemctl reload nginx');
|
||||
edit.edit(`***${this.client.stores.emojis.success} Successfully binded ${domain.domain} to port ${domain.port} for ${account.userID}.***`);
|
||||
// @ts-ignore
|
||||
this.client.createMessage('580950455581147146', { embed });
|
||||
// @ts-ignore
|
||||
this.client.getDMChannel(account.userID).then((r) => r.createMessage({ embed }));
|
||||
await this.client.util.transport.sendMail({
|
||||
to: account.emailAddress,
|
||||
from: 'Library of Code sp-us | Support Team <help@libraryofcode.org>',
|
||||
subject: 'Your domain has been binded',
|
||||
html: `
|
||||
<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.
|
||||
Information is below.</p>
|
||||
<b>Domain:</b> ${domain.domain}<br>
|
||||
<b>Port:</b> ${domain.port}<br>
|
||||
<b>Certificate Issuer:</b> ${cert.issuer.organizationName}<br>
|
||||
<b>Certificate Subject:</b> ${cert.subject.commonName}<br>
|
||||
<b>Responsible Engineer:</b> ${message.author.username}#${message.author.discriminator}<br><br>
|
||||
|
||||
If you have any questions about additional setup, you can reply to this email or send a message in #cloud-support in our Discord server.<br>
|
||||
const tasks = [message.delete(), this.client.util.exec('systemctl reload')];
|
||||
// @ts-ignore
|
||||
await Promise.all(tasks);
|
||||
|
||||
const embed = new RichEmbed()
|
||||
.setTitle('Domain Creation')
|
||||
.setColor(3066993)
|
||||
.addField('Account Username', account.username, true)
|
||||
.addField('Account ID', account.id, true)
|
||||
.addField('Engineer', `<@${message.author.id}>`, true)
|
||||
.addField('Domain', domain.domain, true)
|
||||
.addField('Port', String(domain.port), true);
|
||||
|
||||
const cert = await parseCertificate(this.client, domain.x509.cert);
|
||||
|
||||
embed.addField('Certificate Issuer', cert.issuer.organizationName, true)
|
||||
.addField('Certificate Subject', cert.subject.commonName, true)
|
||||
.setFooter(this.client.user.username, this.client.user.avatarURL)
|
||||
.setTimestamp(new Date(message.timestamp));
|
||||
|
||||
const completed = [
|
||||
edit.edit(`***${this.client.stores.emojis.success} Successfully binded ${domain.domain} to port ${domain.port} for ${account.userID}.***`),
|
||||
this.client.createMessage('580950455581147146', { embed }),
|
||||
this.client.getDMChannel(account.userID).then((r) => r.createMessage({ embed })),
|
||||
this.client.util.transport.sendMail({
|
||||
to: account.emailAddress,
|
||||
from: 'Library of Code sp-us | Support Team <help@libraryofcode.org>',
|
||||
subject: 'Your domain has been binded',
|
||||
html: `
|
||||
<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.
|
||||
Information is below.</p>
|
||||
<b>Domain:</b> ${domain.domain}<br>
|
||||
<b>Port:</b> ${domain.port}<br>
|
||||
<b>Certificate Issuer:</b> ${cert.issuer.organizationName}<br>
|
||||
<b>Certificate Subject:</b> ${cert.subject.commonName}<br>
|
||||
<b>Responsible Engineer:</b> ${message.author.username}#${message.author.discriminator}<br><br>
|
||||
|
||||
If you have any questions about additional setup, you can reply to this email or send a message in #cloud-support in our Discord server.<br>
|
||||
|
||||
<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')) {
|
||||
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.org 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));
|
||||
completed.push(this.client.getDMChannel(account.userID).then((r) => r.createMessage(content)));
|
||||
}
|
||||
return domain;
|
||||
|
||||
return Promise.all(completed);
|
||||
} catch (err) {
|
||||
await fs.unlink(`/etc/nginx/sites-available/${args[1]}`);
|
||||
await fs.unlink(`/etc/nginx/sites-enabled/${args[1]}`);
|
||||
|
@ -103,28 +138,30 @@ export default class CWG_Create extends Command {
|
|||
* @param account The account of the user.
|
||||
* @param subdomain The domain to use. `mydomain.cloud.libraryofcode.org`
|
||||
* @param port The port to use, must be between 1024 and 65535.
|
||||
* @param x509 The paths to the certificate and key files. Must be already existant.
|
||||
* @example await CWG.createDomain('mydomain.cloud.libraryofcode.org', 6781);
|
||||
* @param x509Certificate The contents the certificate and key files.
|
||||
* @example await CWG.createDomain(account, 'mydomain.cloud.libraryofcode.org', 6781);
|
||||
*/
|
||||
public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert?: string, key?: string } = { cert: '/etc/nginx/ssl/cloud-org.chain.crt', key: '/etc/nginx/ssl/cloud-org.key.pem' }) {
|
||||
public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert?: string, key?: string }) {
|
||||
try {
|
||||
if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`);
|
||||
if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`);
|
||||
if (!await this.client.db.Account.exists({ userID: account.userID })) throw new Error(`Cannot find account ${account.userID}.`);
|
||||
await fs.access(x509Certificate.cert, fs.constants.R_OK);
|
||||
await fs.access(x509Certificate.key, fs.constants.R_OK);
|
||||
let x509: { cert: string, key: string };
|
||||
if (x509Certificate) {
|
||||
x509 = await this.createCertAndPrivateKey(domain, x509Certificate.cert, x509Certificate.key);
|
||||
}
|
||||
let cfg = await fs.readFile('/var/CloudServices/dist/static/nginx.conf', { encoding: 'utf8' });
|
||||
cfg = cfg.replace(/\[DOMAIN]/g, domain);
|
||||
cfg = cfg.replace(/\[PORT]/g, String(port));
|
||||
cfg = cfg.replace(/\[CERTIFICATE]/g, x509Certificate.cert);
|
||||
cfg = cfg.replace(/\[KEY]/g, x509Certificate.key);
|
||||
cfg = cfg.replace(/\[CERTIFICATE]/g, x509.cert);
|
||||
cfg = cfg.replace(/\[KEY]/g, x509.key);
|
||||
await fs.writeFile(`/etc/nginx/sites-available/${domain}`, cfg, { encoding: 'utf8' });
|
||||
await fs.symlink(`/etc/nginx/sites-available/${domain}`, `/etc/nginx/sites-enabled/${domain}`);
|
||||
const entry = new this.client.db.Domain({
|
||||
account,
|
||||
domain,
|
||||
port,
|
||||
x509: x509Certificate,
|
||||
x509,
|
||||
enabled: true,
|
||||
});
|
||||
if (domain.includes('cloud.libraryofcode.org')) {
|
||||
|
@ -144,4 +181,47 @@ export default class CWG_Create extends Command {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public async createCertAndPrivateKey(domain: string, certChain: string, privateKey: string) {
|
||||
if (!this.isValidCertificateChain(certChain)) throw new Error('Invalid Certificate Chain');
|
||||
if (!this.isValidPrivateKey(privateKey)) throw new Error('Invalid Private Key');
|
||||
const path = `/var/CloudServices/temp/${domain}`;
|
||||
const temp = [writeFile(`${path}.chain.crt`, certChain), writeFile(`${path}.key.pem`, privateKey)];
|
||||
const removeFiles = [unlink(`${path}.chain.crt`), unlink(`${path}.key.pem`)];
|
||||
await Promise.all(temp);
|
||||
if (!this.isMatchingPair(`${path}.chain.crt`, `${path}.key.pem`)) {
|
||||
await Promise.all(removeFiles);
|
||||
throw new Error('Certificate and Private Key do not match');
|
||||
}
|
||||
|
||||
const tasks = [writeFile(`/etc/nginx/ssl/${domain}.chain.crt`, certChain), writeFile(`/etc/nginx/ssl/${domain}.key.pem`, privateKey)];
|
||||
await Promise.all(tasks);
|
||||
return { cert: `/etc/nginx/ssl/${domain}.chain.crt`, key: `/etc/nginx/ssl/${domain}.key.pem` };
|
||||
}
|
||||
|
||||
public checkOccurance(text: string, query: string) {
|
||||
return (text.match(new RegExp(query, 'g')) || []).length;
|
||||
}
|
||||
|
||||
public isValidCertificateChain(cert: string) {
|
||||
if (!cert.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN CERTIFICATE-----')) return false;
|
||||
if (!cert.replace(/^\s+|\s+$/g, '').endsWith('-----END CERTIFICATE-----')) return false;
|
||||
if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false;
|
||||
if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public isValidPrivateKey(key: string) {
|
||||
if (!key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN PRIVATE KEY-----')) return false;
|
||||
if (!key.replace(/^\s+|\s+$/g, '').endsWith('-----END PRIVATE KEY-----')) return false;
|
||||
if (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) return false;
|
||||
if (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public async isMatchingPair(cert: string, privateKey: string) {
|
||||
const result: string = await this.client.util.exec(`${__dirname}/../bin/checkCertSignatures ${cert} ${privateKey}`);
|
||||
const { ok }: { ok: boolean } = JSON.parse(result);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,7 @@ export default class CWG_Data extends Command {
|
|||
return embed;
|
||||
});
|
||||
this.client.signale.log(embeds);
|
||||
// @ts-ignore
|
||||
if (embeds.length === 1) return message.channel.createMessage({ embed: embeds[0] });
|
||||
// @ts-ignore
|
||||
return createPaginationEmbed(message, this.client, embeds, {});
|
||||
} catch (error) {
|
||||
return this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -52,9 +52,7 @@ export default class CWG_Delete extends Command {
|
|||
await this.client.db.Domain.deleteOne({ domain: domain.domain });
|
||||
await this.client.util.exec('systemctl reload nginx');
|
||||
edit.edit(`***${this.client.stores.emojis.success} Domain ${domain.domain} with port ${domain.port} has been successfully deleted.***`);
|
||||
// @ts-ignore
|
||||
this.client.createMessage('580950455581147146', { embed });
|
||||
// @ts-ignore
|
||||
return this.client.getDMChannel(domain.account.userID).then((channel) => channel.createMessage({ embed })).catch(() => {});
|
||||
} catch (error) {
|
||||
return this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -26,7 +26,6 @@ export default class Disk extends Command {
|
|||
const start = Date.now();
|
||||
const result = await this.client.util.exec(`du -s ${account.homepath}`);
|
||||
const end = Date.now();
|
||||
// @ts-ignore
|
||||
const totalTime: string = moment.preciseDiff(start, end);
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Disk Usage');
|
||||
|
@ -36,7 +35,6 @@ export default class Disk extends Command {
|
|||
embed.addField('Time taken', totalTime, true);
|
||||
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
return diskReply.edit({ content: '', embed });
|
||||
} catch (error) {
|
||||
return this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -40,9 +40,7 @@ export default class Help extends Command {
|
|||
splitCmd.forEach((c) => embed.addField(c.name, c.value, c.inline));
|
||||
return cmdPages.push(embed);
|
||||
});
|
||||
// @ts-ignore
|
||||
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
|
||||
// @ts-ignore
|
||||
return createPaginationEmbed(message, this.client, cmdPages);
|
||||
}
|
||||
const resolved = await this.client.util.resolveCommand(args, message);
|
||||
|
@ -61,7 +59,6 @@ export default class Help extends Command {
|
|||
embed.setTitle(`${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName}${cmd.name}` : cmd.name}`); embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL);
|
||||
const description = `**Description**: ${cmd.description}\n**Usage:** ${cmd.usage}${aliases}${displayedPerms}${subcommands}`;
|
||||
embed.setDescription(description);
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
} catch (error) {
|
||||
this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import moment from 'moment';
|
||||
import moment, { unitOfTime } from 'moment';
|
||||
import { Message } from 'eris';
|
||||
import { Client } from '..';
|
||||
import { Command } from '../class';
|
||||
|
@ -25,8 +25,9 @@ export default class Lock extends Command {
|
|||
|
||||
const expiry = new Date();
|
||||
const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi);
|
||||
// @ts-ignore
|
||||
const momentMilliseconds = moment.duration(Number(lockLength[0]), lockLength[1]).asMilliseconds();
|
||||
const length = Number(lockLength[0]);
|
||||
const unit = lockLength[1] as unitOfTime.Base;
|
||||
const momentMilliseconds = moment.duration(length, unit).asMilliseconds();
|
||||
const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
|
||||
|
||||
await this.client.util.createModerationLog(account.userID, message.member, 2, reason, momentMilliseconds);
|
||||
|
|
|
@ -21,8 +21,7 @@ export default class Modlogs extends Command {
|
|||
const query = await this.client.db.Moderation.find({ $or: [{ username: args.join(' ') }, { userID: args.filter((a) => a)[0].replace(/[<@!>]/g, '') }] });
|
||||
if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`);
|
||||
|
||||
// @ts-ignore
|
||||
const formatted = query.sort((a, b) => a.date - b.date).map((log) => {
|
||||
const formatted = query.sort((a, b) => a.date.getTime() - b.date.getTime()).map((log) => {
|
||||
const { username, moderatorID, reason, type, date, logID } = log;
|
||||
let name: string;
|
||||
switch (type) {
|
||||
|
@ -54,10 +53,8 @@ export default class Modlogs extends Command {
|
|||
});
|
||||
|
||||
if (embeds.length === 1) {
|
||||
// @ts-ignore
|
||||
msg.edit({ content: '', embed: embeds[0] });
|
||||
} else {
|
||||
// @ts-ignore
|
||||
createPaginationEmbed(message, this.client, embeds, {}, msg);
|
||||
}
|
||||
return msg;
|
||||
|
|
|
@ -26,11 +26,9 @@ export default class Notify extends Command {
|
|||
.setFooter(this.client.user.username, this.client.user.avatarURL)
|
||||
.setTimestamp();
|
||||
this.client.getDMChannel(account.userID).then((channel) => {
|
||||
// @ts-ignore
|
||||
channel.createMessage({ embed });
|
||||
});
|
||||
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
|
||||
// @ts-ignore
|
||||
this.client.createMessage('580950455581147146', { embed });
|
||||
this.client.util.transport.sendMail({
|
||||
to: account.emailAddress,
|
||||
|
|
|
@ -61,7 +61,6 @@ export default class Parse extends Command {
|
|||
embed.addField('Expires On', new Date(cert.notAfter).toLocaleString('en-us'), true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
} catch (error) {
|
||||
await this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -2,6 +2,7 @@ import { parseCert } from '@ghaiklor/x509';
|
|||
import { Message } from 'eris';
|
||||
import { readdirSync } from 'fs';
|
||||
import moment from 'moment';
|
||||
import 'moment-precise-range-plugin';
|
||||
import { Client } from '..';
|
||||
import { Command, RichEmbed } from '../class';
|
||||
import { parseCertificate, Certificate } from '../functions';
|
||||
|
@ -33,8 +34,7 @@ export default class Parseall extends Command {
|
|||
return `${acc.homepath}/Validation/${certfile}`;
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
const parsed: ({ status: 'fulfilled', value: Certificate } | { status: 'rejected', reason: Error })[] = await Promise.allSettled(files.map((c) => parseCertificate(this.client, c)));
|
||||
const parsed = await Promise.allSettled(files.map((c) => parseCertificate(this.client, c)));
|
||||
|
||||
const final: string[] = await Promise.all(search.map(async (a) => {
|
||||
const result = parsed[search.findIndex((acc) => acc === a)];
|
||||
|
@ -44,10 +44,8 @@ export default class Parseall extends Command {
|
|||
throw result.reason;
|
||||
}
|
||||
const { notAfter } = result.value;
|
||||
// @ts-ignore
|
||||
const timeObject: {years: number, months: number, days: number, hours: number, minutes: number, seconds: number, firstDateWasLater: boolean} = moment.preciseDiff(new Date(), notAfter, true);
|
||||
const timeObject = moment.preciseDiff(new Date(), notAfter, true);
|
||||
const precise: [number, string][] = [];
|
||||
// @ts-ignore
|
||||
const timeArray: number[] = Object.values(timeObject).filter((v) => typeof v === 'number');
|
||||
timeArray.forEach((t) => { // eslint-disable-line
|
||||
const index = timeArray.indexOf(t);
|
||||
|
@ -66,7 +64,6 @@ export default class Parseall extends Command {
|
|||
split.forEach((s) => embed.addField('\u200B', s));
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
return await msg.edit({ content: '', embed });
|
||||
} catch (error) {
|
||||
return this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -38,7 +38,6 @@ export default class SecureSign_Account extends Command {
|
|||
embed.setAuthor(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
||||
|
||||
// @ts-ignore
|
||||
return msg.edit({ content, embed });
|
||||
} catch (error) {
|
||||
return this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -27,7 +27,6 @@ export default class SecureSign_Build extends Command {
|
|||
embed.setAuthor(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setFooter(`Requested by ${message.member.username}#${message.member.discriminator}`, message.member.avatarURL);
|
||||
|
||||
// @ts-ignore
|
||||
msg.edit({ content, embed });
|
||||
} catch (error) {
|
||||
this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -19,7 +19,6 @@ export default class SecureSign_Init extends Command {
|
|||
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`);
|
||||
if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`);
|
||||
|
||||
// @ts-ignore
|
||||
const options: { s?: string, c?: string, m?: string } = args.length ? Object.fromEntries(` ${args.join(' ')}`.split(' -').filter((a) => a).map((a) => a.split(/ (.+)/)).filter((a) => a.length > 1)) : {};
|
||||
if (options.s && options.s.toLowerCase() !== 'ecc' && options.s.toLowerCase() !== 'rsa') return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid signing type, choose between \`ecc\` or \`rsa\``);
|
||||
if (options.c && (!Number(options.c) || Number(options.c) < 1 || Number(options.c) > 3)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid class selected, choose between Class \`1\`, \`2\` or \`3\``);
|
||||
|
|
|
@ -38,8 +38,7 @@ export default class SecureSign_Init extends Command {
|
|||
}
|
||||
const { id } = verify.data.message;
|
||||
if (id !== message.author.id && !account.root) {
|
||||
// @ts-ignore
|
||||
const channel: TextChannel = this.client.guilds.get('446067825673633794').channels.get('501089664040697858');
|
||||
const channel = this.client.guilds.get('446067825673633794').channels.get('501089664040697858') as TextChannel;
|
||||
channel.createMessage(`**__UNAUTHORIZED ACCESS ALERT__**\n${message.author.mention} tried to initialize their account using <@${id}>'s SecureSign credentials.\nTheir account has been locked under Section 5.2 of the EULA.`);
|
||||
const tasks = [this.client.util.exec(`lock ${account.username}`), account.updateOne({ locked: true }), this.client.util.createModerationLog(account.userID, this.client.user, 2, 'Violation of Section 5.2 of the EULA')];
|
||||
await Promise.all(tasks);
|
||||
|
|
|
@ -30,7 +30,6 @@ export default class SysInfo extends Command {
|
|||
embed.addField('Network Interfaces (IPv6)', os.networkInterfaces().eth0.filter((r) => r.family === 'IPv6')[0].address.replace(/:/gi, '\:'), true); // eslint-disable-line
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ export default class Whois extends Command {
|
|||
if (details) embed.addField('Additional Details', details, true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
} catch (error) {
|
||||
await this.client.util.handleError(error, message, this);
|
||||
|
|
|
@ -44,7 +44,6 @@ export default class Whois_User extends Command {
|
|||
if (details) embed.addField('Additional Details', details, true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
} catch (error) {
|
||||
this.client.util.handleError(error, message, this);
|
||||
|
|
10
src/index.ts
10
src/index.ts
|
@ -1,7 +1,7 @@
|
|||
export { default as Client } from './Client';
|
||||
export { default as config } from './config.json';
|
||||
export { default as Classes } from './class';
|
||||
export { default as Commands } from './commands';
|
||||
export { default as Events } from './events';
|
||||
export { default as Models } from './models';
|
||||
export { default as Stores } from './stores';
|
||||
export * from './class';
|
||||
export * from './commands';
|
||||
export * from './events';
|
||||
export * from './models';
|
||||
export * from './stores';
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import { EmbedOptions } from 'eris';
|
||||
import RichEmbed from '../src/class/RichEmbed';
|
||||
|
||||
declare global {
|
||||
namespace Eris {
|
||||
type MessageContent = string | { content?: string; tts?: boolean; disableEveryone?: boolean; embed?: EmbedOptions | RichEmbed; flags?: number };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
interface PromiseFulfilledResult<T> {
|
||||
status: 'fulfilled';
|
||||
value: T;
|
||||
}
|
||||
|
||||
interface PromiseRejectedResult {
|
||||
status: 'rejected';
|
||||
reason: any;
|
||||
}
|
||||
|
||||
type PromiseSettledResult<T> = PromiseFulfilledResult<T> | PromiseRejectedResult;
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all
|
||||
* of the provided Promises resolve or reject.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
allSettled<T extends readonly unknown[] | readonly [unknown]>(values: T):
|
||||
Promise<{ -readonly [P in keyof T]: PromiseSettledResult<T[P] extends PromiseLike<infer U> ? U : T[P]> }>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all
|
||||
* of the provided Promises resolve or reject.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
allSettled<T>(values: Iterable<T>): Promise<PromiseSettledResult<T extends PromiseLike<infer U> ? U : T>[]>;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import moment from 'moment';
|
||||
|
||||
declare module 'moment' {
|
||||
interface PreciseRangeValueObject extends moment.MomentObjectOutput {
|
||||
firstDateWasLater: boolean;
|
||||
}
|
||||
|
||||
interface Moment {
|
||||
preciseDiff(d2: moment.MomentInput, returnValueObject?: false): string;
|
||||
preciseDiff(d2: moment.MomentInput, returnValueObject: true): PreciseRangeValueObject;
|
||||
}
|
||||
|
||||
function preciseDiff(d1: moment.MomentInput, d2: moment.MomentInput, returnValueObject?: false): string;
|
||||
function preciseDiff(d1: moment.MomentInput, d2: moment.MomentInput, returnValueObject: true): PreciseRangeValueObject;
|
||||
}
|
Loading…
Reference in New Issue