blob: ae63757af539e296c17b0c5343915be0587003e0 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import Discord from 'discord.js';
2import client from './client.js';
3import generateEmojiEmbed from "./generateEmojiEmbed.js";
4
5export default async function (m, interactionFilter, messageFilter) {
6 let out;
7 try {
8 out = await new Promise((resolve, reject) => {
9 let mes, int;
10 mes = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 600000})
11 .on("collect", (m) => { resolve(m); })
12 int = m.channel.createMessageCollector({filter: (m) => messageFilter(m), time: 600000})
13 .then("collect", (m) => { try {m.delete();} catch {}; resolve(m); })
14 mes.on("end", () => { int.stop(); })
15 int.on("end", () => { mes.stop(); })
16 })
17 } catch(e) {
18 console.log(e)
19 return null;
20 }
21
22 return out;
23}
24
25export async function modalInteractionCollector(m, modalFilter, interactionFilter) {
26 let out;
27 try {
28 out = await new Promise((resolve, reject) => {
29 let mod, int;
30 int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 600000})
31 .on("collect", (m) => { resolve(m); })
32 mod = new Discord.InteractionCollector(
33 client, {
34 filter: (m) => modalFilter(m),
35 time: 600000
36 })
37 .on("collect", async (m) => {
38 int.stop();
39 (m as Discord.ModalSubmitInteraction).deferUpdate()
40 resolve((m as Discord.ModalSubmitInteraction)); })
41 int.on("end", () => { mod.stop(); })
42 mod.on("end", () => { int.stop(); })
43 })
44 } catch(e) {
45 console.log(e)
46 return null;
47 }
48 return out;
49}