mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-05 06:26:08 +00:00
fix: onFail callback
This commit is contained in:
parent
9320010161
commit
a059959fb5
@ -19,6 +19,8 @@ export interface ComponentHandlerLike {
|
|||||||
readonly commands: (ComponentCommand | ModalCommand)[];
|
readonly commands: (ComponentCommand | ModalCommand)[];
|
||||||
readonly modals: Map<string, ModalSubmitCallback> | LimitedCollection<string, ModalSubmitCallback>;
|
readonly modals: Map<string, ModalSubmitCallback> | LimitedCollection<string, ModalSubmitCallback>;
|
||||||
|
|
||||||
|
onFail: ComponentHandler['onFail'];
|
||||||
|
|
||||||
createComponentCollector: ComponentHandler['createComponentCollector'];
|
createComponentCollector: ComponentHandler['createComponentCollector'];
|
||||||
|
|
||||||
hasModal: ComponentHandler['hasModal'];
|
hasModal: ComponentHandler['hasModal'];
|
||||||
@ -37,7 +39,7 @@ export interface ComponentHandlerLike {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ComponentHandler extends BaseHandler {
|
export class ComponentHandler extends BaseHandler {
|
||||||
onFail?: OnFailCallback;
|
onFail: OnFailCallback = err => this.logger.warn('<Client>.components.onFail', err);
|
||||||
readonly values = new Map<string, COMPONENTS>();
|
readonly values = new Map<string, COMPONENTS>();
|
||||||
// 10 minutes timeout, because discord dont send an event when the user cancel the modal
|
// 10 minutes timeout, because discord dont send an event when the user cancel the modal
|
||||||
readonly modals = new LimitedCollection<string, ModalSubmitCallback>({ expire: 60e3 * 10 });
|
readonly modals = new LimitedCollection<string, ModalSubmitCallback>({ expire: 60e3 * 10 });
|
||||||
@ -51,10 +53,6 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
super(logger);
|
super(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
set OnFail(cb: OnFailCallback) {
|
|
||||||
this.onFail = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
createComponentCollector(messageId: string, options: ListenerOptions = {}) {
|
createComponentCollector(messageId: string, options: ListenerOptions = {}) {
|
||||||
this.values.set(messageId, {
|
this.values.set(messageId, {
|
||||||
components: [],
|
components: [],
|
||||||
@ -229,7 +227,7 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.onFail?.(e);
|
await this.onFail(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,7 +240,7 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.onFail?.(e);
|
await this.onFail(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,18 +26,15 @@ export interface EventHandlerLike {
|
|||||||
reload: EventHandler['reload'];
|
reload: EventHandler['reload'];
|
||||||
reloadAll: EventHandler['reloadAll'];
|
reloadAll: EventHandler['reloadAll'];
|
||||||
values: EventHandler['values'];
|
values: EventHandler['values'];
|
||||||
|
onFail: EventHandler['onFail'];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventHandler extends BaseHandler {
|
export class EventHandler extends BaseHandler {
|
||||||
protected onFail: OnFailCallback = err => this.logger.warn('<Client>.events.OnFail', err);
|
onFail: OnFailCallback = err => this.logger.warn('<Client>.events.onFail', err);
|
||||||
protected filter = (path: string) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
|
protected filter = (path: string) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
|
||||||
|
|
||||||
values: Partial<Record<GatewayEvents, EventValue>> = {};
|
values: Partial<Record<GatewayEvents, EventValue>> = {};
|
||||||
|
|
||||||
set OnFail(cb: OnFailCallback) {
|
|
||||||
this.onFail = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
async load(eventsDir: string) {
|
async load(eventsDir: string) {
|
||||||
for (const i of await this.loadFilesK<ClientEvent>(await this.getFiles(eventsDir))) {
|
for (const i of await this.loadFilesK<ClientEvent>(await this.getFiles(eventsDir))) {
|
||||||
const instance = i.file;
|
const instance = i.file;
|
||||||
@ -108,7 +105,7 @@ export class EventHandler extends BaseHandler {
|
|||||||
const hook = await RawEvents[name]?.(client, packet as never);
|
const hook = await RawEvents[name]?.(client, packet as never);
|
||||||
await Event.run(...[hook, client, shardId]);
|
await Event.run(...[hook, client, shardId]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.onFail?.(e);
|
await this.onFail(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user