This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Commands): add a reload command
- Loading branch information
1 parent
c88baa2
commit f4d4bea
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |