| 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); |