MCPcopy Create free account
hub / github.com/RTByte/rtbyte / run

Method run

src/commands/Developer/Pieces/load.js:19–40  ·  view source on GitHub ↗
(message, [core, store, path])

Source from the content-addressed store, hash-verified

17 }
18
19 async run(message, [core, store, path]) {
20 path = (path.endsWith('.js') ? path : `${path}.js`).split(this.regExp);
21 const timer = new Stopwatch();
22 const piece = await (core ? this.tryEach(store, path) : store.load(store.userDirectory, path));
23
24 try {
25 if (!piece) throw message.language.get('COMMAND_LOAD_FAIL');
26 await piece.init();
27 if (this.client.shard) {
28 await this.client.shard.broadcastEval(`
29 if (String(this.options.shards) !== '${this.client.options.shards}') {
30 const piece = this.${piece.store}.load('${piece.directory}', ${JSON.stringify(path)});
31 if (piece) piece.init();
32 }
33 `);
34 }
35 return message.sendLocale('COMMAND_LOAD', [timer.stop(), store.name, piece.name]);
36 } catch (error) {
37 timer.stop();
38 throw message.language.get('COMMAND_LOAD_ERROR', store.name, piece ? piece.name : path.join('/'), error);
39 }
40 }
41
42 async tryEach(store, path) {
43 for (const dir of store.coreDirectories) if (await pathExists(join(dir, ...path))) return store.load(dir, path);

Callers

nothing calls this directly

Calls 3

tryEachMethod · 0.80
joinMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected