Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
feat(Commands): add a reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexthemaster committed Jul 31, 2020
1 parent c88baa2 commit f4d4bea
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/commands/Reload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Command } from '../lib/structures/Command';
import { MoonlightClient } from '../lib/Client';
import { Stopwatch } from '../lib/util';
import { BasePool } from '../lib/structures/Pools/Base/BasePool';
import { Message } from 'discord.js';

/** @ignore */
export default class extends Command {
constructor(client: MoonlightClient, pool: BasePool<string, Command>) {
super(client, pool, { cooldown: 5, ownerOnly: true, usage: '[everything] [piece:string]' });
}

public async run(message: Message, args: ReloadCommandArgs) {
if (!args.everything && !args.piece) return message.channel.send('Please provide the name of a piece you want to reload or provide "everything" as an argument to reload everything.');

if (args.everything) {
const stopwatch = new Stopwatch();
await Promise.all(Array.from(this.client.pools).map(async ([_, poolPiece]) => await poolPiece.reload()));
stopwatch.stop();

return message.channel.send(`Done! Reloaded everything in: ${stopwatch.getElapsedHuman}`);
}

if (!args.piece) return message.channel.send('Please provide a piece name to reload!');

if (!this.client.pools.has(args.piece)) return message.channel.send(`No such piece named \`${args.piece}\``);

const pieces = Array.from(this.client.pools).filter(([name]) => name === args.piece).map(([_, piece]) => piece);

const stopwatch = new Stopwatch();
await Promise.all(pieces.map(async piece => await piece.reload()));
stopwatch.stop();

if (pieces.length === 1) return message.channel.send(`Done! Reloaded ${args.piece} in: ${stopwatch.getElapsedHuman}`);
else return message.channel.send(`Done! Reloaded every piece with the name of ${args.piece} in: ${stopwatch.getElapsedHuman}`);
}
}

interface ReloadCommandArgs {
everything?: string;
piece?: string;
}

0 comments on commit f4d4bea

Please sign in to comment.