mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix: implement stopIffail in reloadAll
This commit is contained in:
parent
4e4ab20769
commit
0b60586847
@ -196,7 +196,7 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
x.__filePath?.endsWith(path) ||
|
x.__filePath?.endsWith(path) ||
|
||||||
x.__filePath === path,
|
x.__filePath === path,
|
||||||
);
|
);
|
||||||
if (!component || !component.__filePath) return null;
|
if (!component?.__filePath) return null;
|
||||||
delete require.cache[component.__filePath];
|
delete require.cache[component.__filePath];
|
||||||
const index = this.client.components.commands.findIndex(x => x.__filePath === component.__filePath!);
|
const index = this.client.components.commands.findIndex(x => x.__filePath === component.__filePath!);
|
||||||
if (index === -1) return null;
|
if (index === -1) return null;
|
||||||
@ -208,11 +208,15 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
return imported;
|
return imported;
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadAll() {
|
async reloadAll(stopIfFail = true) {
|
||||||
if (!this.client.components) return;
|
for (const i of this.commands) {
|
||||||
for (const i of this.client.components.commands) {
|
try {
|
||||||
if (!i.__filePath) return this.logger.warn('Unknown command dont have __filePath property', i);
|
await this.reload(i.__filePath ?? '');
|
||||||
await this.reload(i.__filePath);
|
} catch (e) {
|
||||||
|
if (stopIfFail) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ export class EventHandler extends BaseHandler {
|
|||||||
async reload(name: ClientNameEvents) {
|
async reload(name: ClientNameEvents) {
|
||||||
const eventName = ReplaceRegex.snake(name).toUpperCase() as GatewayEvents;
|
const eventName = ReplaceRegex.snake(name).toUpperCase() as GatewayEvents;
|
||||||
const event = this.values[eventName];
|
const event = this.values[eventName];
|
||||||
if (!event) return null;
|
if (!event?.__filePath) return null;
|
||||||
delete require.cache[event.__filePath];
|
delete require.cache[event.__filePath];
|
||||||
const imported = await magicImport(event.__filePath).then(x => x.default ?? x);
|
const imported = await magicImport(event.__filePath).then(x => x.default ?? x);
|
||||||
imported.__filePath = event.__filePath;
|
imported.__filePath = event.__filePath;
|
||||||
@ -100,9 +100,15 @@ export class EventHandler extends BaseHandler {
|
|||||||
return imported;
|
return imported;
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadAll() {
|
async reloadAll(stopIfFail = true) {
|
||||||
for (const i in this.values) {
|
for (const i in this.values) {
|
||||||
await this.reload(ReplaceRegex.camel(i) as ClientNameEvents);
|
try {
|
||||||
|
await this.reload(ReplaceRegex.camel(i) as ClientNameEvents);
|
||||||
|
} catch (e) {
|
||||||
|
if (stopIfFail) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user