conflict
commit
d583cd969e
|
@ -2,4 +2,5 @@ node_modules
|
||||||
yarn.lock
|
yarn.lock
|
||||||
src/config.json
|
src/config.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
htmlEmail_templates
|
htmlEmail_templates
|
||||||
|
yarn-error.log
|
|
@ -17,6 +17,7 @@
|
||||||
"eris-pagination": "bsian03/eris-pagination",
|
"eris-pagination": "bsian03/eris-pagination",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
|
"moment-precise-range-plugin": "^1.3.0",
|
||||||
"mongoose": "^5.7.4",
|
"mongoose": "^5.7.4",
|
||||||
"nodemailer": "^6.3.1",
|
"nodemailer": "^6.3.1",
|
||||||
"signale": "^1.4.0",
|
"signale": "^1.4.0",
|
||||||
|
|
|
@ -78,12 +78,12 @@ export default class Collection<V> extends Map<string, V> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array with the results of applying the given function to each element
|
* Return an array with the results of applying the given function to each element
|
||||||
* @param func A function that takes an object and returns something
|
* @param callbackfn A function that takes an object and returns something
|
||||||
*/
|
*/
|
||||||
map(func: Function) {
|
map<U>(callbackfn: (value?: V, index?: number, array?: V[]) => U): U[] {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (const item of this.values()) {
|
for (const item of this.values()) {
|
||||||
arr.push(func(item));
|
arr.push(callbackfn(item));
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
@ -102,22 +102,6 @@ export default class Collection<V> extends Map<string, V> {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reduce values by function
|
|
||||||
* @param callbackFn Function to execute on each element in the array
|
|
||||||
* @param initialValue Value to use as the first argument to the first call of the callback
|
|
||||||
* @returns Accumulator
|
|
||||||
*/
|
|
||||||
reduce(func: Function, initialValue = 0) {
|
|
||||||
const iter = this.values();
|
|
||||||
let val: any;
|
|
||||||
let result = initialValue === undefined ? iter.next().value : initialValue;
|
|
||||||
while ((val = iter.next().value) !== undefined) { // eslint-disable-line
|
|
||||||
result = func(result, val);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if at least one element passes the test implemented by the provided function. Returns true if yes, or false if not.
|
* Test if at least one element passes the test implemented by the provided function. Returns true if yes, or false if not.
|
||||||
* @param func A function that takes an object and returns true if it matches
|
* @param func A function that takes an object and returns true if it matches
|
||||||
|
@ -131,20 +115,6 @@ export default class Collection<V> extends Map<string, V> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if all elements passe the test implemented by the provided function. Returns true if yes, or false if not.
|
|
||||||
* @param func A function that takes an object and returns true if it matches
|
|
||||||
* @returns An array containing booleans that matched
|
|
||||||
*/
|
|
||||||
every(func: Function): boolean[] {
|
|
||||||
const array = [];
|
|
||||||
for (const item of this.values()) {
|
|
||||||
if (func(item)) array.push(true);
|
|
||||||
else array.push(false);
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an object
|
* Update an object
|
||||||
* @param key The key of the object
|
* @param key The key of the object
|
||||||
|
|
|
@ -55,7 +55,7 @@ export default class Util {
|
||||||
}
|
}
|
||||||
if (!resolvedCommand) return Promise.resolve({ cmd: null, args });
|
if (!resolvedCommand) return Promise.resolve({ cmd: null, args });
|
||||||
|
|
||||||
let parentLabel = `${command}`;
|
let parentLabel = '';
|
||||||
let hasSubCommands = true;
|
let hasSubCommands = true;
|
||||||
while (hasSubCommands) {
|
while (hasSubCommands) {
|
||||||
if (!resolvedCommand.subcommands.size) {
|
if (!resolvedCommand.subcommands.size) {
|
||||||
|
@ -63,13 +63,15 @@ export default class Util {
|
||||||
} else if (!args[0]) {
|
} else if (!args[0]) {
|
||||||
hasSubCommands = false; break;
|
hasSubCommands = false; break;
|
||||||
} else if (resolvedCommand.subcommands.has(args[0])) {
|
} else if (resolvedCommand.subcommands.has(args[0])) {
|
||||||
resolvedCommand = resolvedCommand.subcommands.get(args[0]);
|
parentLabel += `${resolvedCommand.name} `;
|
||||||
parentLabel += ` ${args[0]}`; args.shift();
|
resolvedCommand = resolvedCommand.subcommands.get(args[0]); args.shift();
|
||||||
} else {
|
} else {
|
||||||
for (const subCmd of resolvedCommand.subcommands.toArray()) {
|
const subcommandArray = resolvedCommand.subcommands.toArray();
|
||||||
|
for (const subCmd of subcommandArray) {
|
||||||
if (subCmd.aliases.includes(args[0])) {
|
if (subCmd.aliases.includes(args[0])) {
|
||||||
resolvedCommand = subCmd; parentLabel += ` ${args[0]}`; args.shift(); break;
|
parentLabel += `${resolvedCommand.name} `; resolvedCommand = subCmd; args.shift(); break;
|
||||||
} else {
|
}
|
||||||
|
if (subcommandArray.findIndex((v) => v === subCmd) === subcommandArray.length - 1) {
|
||||||
hasSubCommands = false; break;
|
hasSubCommands = false; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,8 +175,12 @@ export default class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteAccount(username: string): Promise<void> {
|
public async deleteAccount(username: string): Promise<void> {
|
||||||
|
const account = await this.client.db.Account.findOne({ username });
|
||||||
|
if (!account) return Promise.reject(new Error('Account not found'));
|
||||||
await this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username}`);
|
await this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username}`);
|
||||||
|
await this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted');
|
||||||
await this.client.db.Account.deleteOne({ username });
|
await this.client.db.Account.deleteOne({ username });
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}): Promise<Message> {
|
public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}): Promise<Message> {
|
||||||
|
|
|
@ -16,7 +16,7 @@ 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 create [User ID | Username] [Domain] [Port] <Path to x509 cert> <Path to x509 key>\n${this.client.config.prefix}cwg data [Domain/Port]`;
|
this.usage = `Run ${this.client.config.prefix}${this.name} [subcommand] for usage information`;
|
||||||
this.permissions = { roles: ['446104438969466890'] };
|
this.permissions = { roles: ['446104438969466890'] };
|
||||||
this.subcmds = [Create, Data, Delete];
|
this.subcmds = [Create, Data, Delete];
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
|
|
|
@ -33,7 +33,18 @@ export default class CWG_Create extends Command {
|
||||||
if (args[3] && !args[4]) return edit.edit(`${this.client.stores.emojis.error} x509 Certificate key required`);
|
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] };
|
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 (await this.client.db.Domain.exists({ domain: args[1] })) return edit.edit(`***${this.client.stores.emojis.error} This domain already exists.***`);
|
||||||
if (await this.client.db.Domain.exists({ port: Number(args[2]) })) return message.channel.createMessage('***WARNING: This port is already binded to another domain.***');
|
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);
|
||||||
|
} catch (error) {
|
||||||
|
return edit.edit(`***${this.client.stores.emojis.error} Bind request cancelled***`);
|
||||||
|
}
|
||||||
|
if (answer.content === 'n') return edit.edit(`***${this.client.stores.emojis.error} Bind request cancelled***`);
|
||||||
|
}
|
||||||
const domain = await this.createDomain(account, args[1], Number(args[2]), certs);
|
const domain = await this.createDomain(account, args[1], Number(args[2]), certs);
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Domain Creation');
|
embed.setTitle('Domain Creation');
|
||||||
|
@ -98,7 +109,6 @@ export default class CWG_Create extends Command {
|
||||||
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 } = { cert: '/etc/nginx/ssl/cloud-org.chain.crt', key: '/etc/nginx/ssl/cloud-org.key.pem' }) {
|
||||||
try {
|
try {
|
||||||
if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`);
|
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({ port })) throw new Error(`Port ${port} already exists in the database.`);
|
|
||||||
if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`);
|
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}.`);
|
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.cert, fs.constants.R_OK);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs';
|
||||||
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 { promisify } from 'util';
|
||||||
import { Command, RichEmbed } from '../class';
|
import { Command, RichEmbed } from '../class';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
|
|
||||||
|
@ -18,21 +20,28 @@ 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 embed = new RichEmbed();
|
// const embeds: RichEmbed[] = [];
|
||||||
embed.setTitle('Domain Information');
|
const embeds = dom.map((domain) => {
|
||||||
embed.addField('Account Username', domain.account.username, true);
|
const cert = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' });
|
||||||
embed.addField('Account ID', domain.account.userID, true);
|
const embed = new RichEmbed();
|
||||||
embed.addField('Domain', domain.domain, true);
|
embed.setTitle('Domain Information');
|
||||||
embed.addField('Port', String(domain.port), true);
|
embed.addField('Account Username', domain.account.username, true);
|
||||||
embed.addField('Certificate Issuer', x509.getIssuer(await fs.readFile(domain.x509.cert, { encoding: 'utf8' })).organizationName, true);
|
embed.addField('Account ID', domain.account.userID, true);
|
||||||
embed.addField('Certificate Subject', x509.getSubject(await fs.readFile(domain.x509.cert, { encoding: 'utf8' })).commonName, true);
|
embed.addField('Domain', domain.domain, 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.addField('Port', String(domain.port), true);
|
||||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
embed.addField('Certificate Issuer', x509.getIssuer(cert).organizationName, true);
|
||||||
embed.setTimestamp();
|
embed.addField('Certificate Subject', x509.getSubject(cert).commonName, true);
|
||||||
|
embed.addField('Certificate Expiration Date', moment(x509.parseCert(cert).notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
|
||||||
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||||
|
embed.setTimestamp();
|
||||||
|
return embed;
|
||||||
|
});
|
||||||
|
this.client.signale.log(embeds);
|
||||||
// @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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Message } from 'eris';
|
||||||
import { Command, RichEmbed } from '../class';
|
import { Command, RichEmbed } from '../class';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
|
|
||||||
export default class CWG_Data extends Command {
|
export default class CWG_Delete extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'delete';
|
this.name = 'delete';
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { Message } from 'eris';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { Client } from '..';
|
||||||
|
import { RichEmbed, Command } from '../class';
|
||||||
|
import { dataConversion } from '../functions';
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
import 'moment-precise-range-plugin';
|
||||||
|
|
||||||
|
export default class Disk extends Command {
|
||||||
|
constructor(client: Client) {
|
||||||
|
super(client);
|
||||||
|
this.name = 'disk';
|
||||||
|
this.description = 'Checks the used disk space by a user';
|
||||||
|
this.usage = `${this.client.config.prefix}disk [Username/User ID/Email]`;
|
||||||
|
this.permissions = { roles: ['446104438969466890'] };
|
||||||
|
this.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(message: Message, args: string[]) {
|
||||||
|
try {
|
||||||
|
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }, { emailAddress: args[0] }] });
|
||||||
|
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`);
|
||||||
|
if (account.root || args[0].includes('./')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`);
|
||||||
|
const diskReply = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching total disk size may up to 10 minutes. This message will edit when the disk size has been located.***`);
|
||||||
|
const start = Date.now();
|
||||||
|
const result = await this.client.util.exec(`du -s /home/${account.username}`);
|
||||||
|
const end = Date.now();
|
||||||
|
// @ts-ignore
|
||||||
|
const totalTime: string = moment.preciseDiff(start, end);
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle('Disk Usage');
|
||||||
|
embed.setColor('ff0000');
|
||||||
|
embed.setDescription(`/home/${account.username}`);
|
||||||
|
embed.addField('Result', dataConversion(Number(result)), true);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ export default class Help extends Command {
|
||||||
if (!args[0]) {
|
if (!args[0]) {
|
||||||
const cmdList: Command[] = [];
|
const cmdList: Command[] = [];
|
||||||
this.client.commands.forEach((c) => cmdList.push(c));
|
this.client.commands.forEach((c) => cmdList.push(c));
|
||||||
const commands = this.client.commands.map((c: Command) => {
|
const commands = this.client.commands.map((c) => {
|
||||||
const aliases = c.aliases.map((alias) => `${this.client.config.prefix}${alias}`).join(', ');
|
const aliases = c.aliases.map((alias) => `${this.client.config.prefix}${alias}`).join(', ');
|
||||||
const perms: string[] = [];
|
const perms: string[] = [];
|
||||||
let allowedRoles = c.permissions && c.permissions.roles && c.permissions.roles.map((r) => `<@&${r}>`).join(', ');
|
let allowedRoles = c.permissions && c.permissions.roles && c.permissions.roles.map((r) => `<@&${r}>`).join(', ');
|
||||||
|
@ -51,12 +51,13 @@ export default class Help extends Command {
|
||||||
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
|
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
|
||||||
let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', ');
|
let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', ');
|
||||||
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
|
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
|
||||||
const displayedPerms = perms.length ? `**Permissions:**\n${perms.join('\n')}` : '';
|
const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : '';
|
||||||
const aliases = cmd.aliases.map((alias) => `${this.client.config.prefix}${alias}`).join(', ');
|
const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName}${alias}`).join(', ')}` : '';
|
||||||
|
const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => s.parentName || `${cmd.name} ${s.name}`).join(', ')}` : '';
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
||||||
embed.setTitle(`${this.client.config.prefix}${cmd.parentName}`); embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL);
|
embed.setTitle(`${this.client.config.prefix}${cmd.parentName}${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}\n**Aliases:** ${aliases}\n${displayedPerms}`;
|
const description = `**Description**: ${cmd.description}\n**Usage:** ${cmd.usage}${aliases}${displayedPerms}${subcommands}`;
|
||||||
embed.setDescription(description);
|
embed.setDescription(description);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
message.channel.createMessage({ embed });
|
message.channel.createMessage({ embed });
|
||||||
|
|
|
@ -2,6 +2,7 @@ export { default as Announce } from './announce';
|
||||||
export { default as CreateAccount } from './createaccount';
|
export { default as CreateAccount } from './createaccount';
|
||||||
export { default as CWG } from './cwg';
|
export { default as CWG } from './cwg';
|
||||||
export { default as DeleteAccount } from './deleteaccount';
|
export { default as DeleteAccount } from './deleteaccount';
|
||||||
|
export { default as Disk } from './disk';
|
||||||
export { default as Eval } from './eval';
|
export { default as Eval } from './eval';
|
||||||
export { default as Exec } from './exec';
|
export { default as Exec } from './exec';
|
||||||
export { default as Help } from './help';
|
export { default as Help } from './help';
|
||||||
|
|
|
@ -14,27 +14,64 @@ export default class Pull extends Command {
|
||||||
|
|
||||||
public async run(message: Message) {
|
public async run(message: Message) {
|
||||||
try {
|
try {
|
||||||
const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`);
|
const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\ngit pull\n\`\`\``);
|
||||||
let pull: string;
|
let pull: string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pull = await this.client.util.exec('git pull');
|
pull = await this.client.util.exec('git pull');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return updateMessage.edit(`${this.client.stores.emojis.error} ***Could not fetch latest commit***\n\`\`\`sh\n${error.message}\n\`\`\``);
|
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Could not fetch latest commit***`)
|
||||||
}
|
|
||||||
if (pull.includes('Already up to date')) return updateMessage.edit(`${this.client.stores.emojis.success} ***No updates available***`);
|
|
||||||
if (!pull.includes('origin/master')) return updateMessage.edit(`${this.client.stores.emojis.error} ***Unexpected output:***\n\`\`\`sh\n${pull}\n\`\`\``);
|
|
||||||
|
|
||||||
const passedPull = await updateMessage.edit(`${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Rebuilding files...***\n\`\`\`sh\n${pull}\n\`\`\``);
|
|
||||||
try {
|
|
||||||
await this.client.util.exec('cd ../ && tsc -p ./tsconfig.json');
|
|
||||||
} catch (error) {
|
|
||||||
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***`)
|
|
||||||
.replace(/```$/, `${error.message}\n\`\`\``);
|
.replace(/```$/, `${error.message}\n\`\`\``);
|
||||||
return updateMessage.edit(updatedMessage);
|
return updateMessage.edit(updatedMessage);
|
||||||
}
|
}
|
||||||
|
if (pull.includes('Already up to date')) {
|
||||||
|
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***No updates available***`)
|
||||||
|
.replace(/```$/, `${pull}\n\`\`\``);
|
||||||
|
return updateMessage.edit(updatedMessage);
|
||||||
|
}
|
||||||
|
if (!pull.includes('origin/master')) {
|
||||||
|
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`)
|
||||||
|
.replace(/```$/, `${pull}\n\`\`\``);
|
||||||
|
return updateMessage.edit(updatedMessage);
|
||||||
|
}
|
||||||
|
const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`)
|
||||||
|
.replace(/```$/, `${pull}\nyarn install\n\`\`\``);
|
||||||
|
const passedPull = await updateMessage.edit(continueMessage);
|
||||||
|
|
||||||
const finalMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`);
|
|
||||||
|
let install: string;
|
||||||
|
try {
|
||||||
|
install = await this.client.util.exec('yarn install');
|
||||||
|
} catch (error) {
|
||||||
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Failed to reinstall dependencies***`)
|
||||||
|
.replace(/```$/, `${error.message}\n\`\`\``);
|
||||||
|
return updateMessage.edit(updatedMessage);
|
||||||
|
}
|
||||||
|
let updatedPackages: Message;
|
||||||
|
if (install.includes('Already up-to-date')) {
|
||||||
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
|
||||||
|
.replace(/```$/, `${install}\nyarn run build\n\`\`\``);
|
||||||
|
updatedPackages = await updateMessage.edit(updatedMessage);
|
||||||
|
} else if (install.includes('success Saved lockfile.')) {
|
||||||
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
|
||||||
|
.replace(/```$/, `${install}\nyarn run build\n\`\`\``);
|
||||||
|
updatedPackages = await updateMessage.edit(updatedMessage);
|
||||||
|
} else {
|
||||||
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***`)
|
||||||
|
.replace(/```$/, `${pull}\n\`\`\``);
|
||||||
|
return updateMessage.edit(updatedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
let build: string;
|
||||||
|
try {
|
||||||
|
build = await this.client.util.exec('yarn run build');
|
||||||
|
} catch (error) {
|
||||||
|
const updatedMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***`)
|
||||||
|
.replace(/```$/, `${error.message}\n\`\`\``);
|
||||||
|
return updateMessage.edit(updatedMessage);
|
||||||
|
}
|
||||||
|
const finalMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`)
|
||||||
|
.replace(/```$/, `${build}\n\`\`\``);
|
||||||
|
|
||||||
return updateMessage.edit(finalMessage);
|
return updateMessage.edit(finalMessage);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in New Issue