mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
feat: awaitable collector
This commit is contained in:
parent
422cfb2a80
commit
30a066e68d
@ -38,6 +38,7 @@ export interface CreateComponentCollectorResult {
|
|||||||
callback: ComponentCallback<T>,
|
callback: ComponentCallback<T>,
|
||||||
): void;
|
): void;
|
||||||
stop(reason?: string): void;
|
stop(reason?: string): void;
|
||||||
|
asyncRun<T extends CollectorInteraction = CollectorInteraction>(customId: UserMatches): Promise<T | null>;
|
||||||
resetTimeouts(): void;
|
resetTimeouts(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +117,24 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
this.createComponentCollector(messageId, channelId, guildId, options, old.components);
|
this.createComponentCollector(messageId, channelId, guildId, options, old.components);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
asyncRun: customId =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
const collector = this.values.get(messageId);
|
||||||
|
if (!collector) return resolve(null);
|
||||||
|
|
||||||
|
this.values.get(messageId)!.__run(customId, interaction => {
|
||||||
|
this.clearValue(messageId);
|
||||||
|
//@ts-expect-error generic
|
||||||
|
resolve(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (collector?.timeout) clearTimeout(collector.timeout);
|
||||||
|
collector.timeout = setTimeout(() => {
|
||||||
|
this.clearValue(messageId);
|
||||||
|
resolve(null);
|
||||||
|
// by default 15 seconds in case user don't do anything
|
||||||
|
}, collector?.options?.timeout ?? 15_000);
|
||||||
|
}),
|
||||||
resetTimeouts: () => {
|
resetTimeouts: () => {
|
||||||
this.resetTimeouts(messageId);
|
this.resetTimeouts(messageId);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user