blob: 67cef5c08ba118680007faff4af1ee316d8453e8 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import Discord from 'discord.js';
2import client from './client.js';
pineafan4edb7762022-06-26 19:21:04 +01003import EmojiEmbed from "./generateEmojiEmbed.js";
pineafan6702cef2022-06-13 17:52:37 +01004
5export default async function (m, interactionFilter, messageFilter) {
6 let out;
7 try {
8 out = await new Promise((resolve, reject) => {
9 let mes, int;
pineafanc6158ab2022-06-17 16:34:07 +010010 mes = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
pineafan6702cef2022-06-13 17:52:37 +010011 .on("collect", (m) => { resolve(m); })
pineafanc6158ab2022-06-17 16:34:07 +010012 int = m.channel.createMessageCollector({filter: (m) => messageFilter(m), time: 300000})
pineafan6702cef2022-06-13 17:52:37 +010013 .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;
pineafanc6158ab2022-06-17 16:34:07 +010030 int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
pineafan6702cef2022-06-13 17:52:37 +010031 .on("collect", (m) => { resolve(m); })
32 mod = new Discord.InteractionCollector(
33 client, {
34 filter: (m) => modalFilter(m),
pineafanc6158ab2022-06-17 16:34:07 +010035 time: 300000
pineafan6702cef2022-06-13 17:52:37 +010036 })
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}