blob: c785d0a5478b3ff07896dbed81e89ba39185ca1e [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import Discord from "discord.js";
2import client from "./client.js";
pineafan6702cef2022-06-13 17:52:37 +01003
4export default async function (m, interactionFilter, messageFilter) {
5 let out;
6 try {
pineafan63fc5e22022-08-04 22:04:10 +01007 out = await new Promise((resolve, _reject) => {
8 const mes = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
9 .on("collect", (m) => { resolve(m); });
10 const int = m.channel.createMessageCollector({filter: (m) => messageFilter(m), time: 300000})
11 .then("collect", (m) => { try {m.delete();} catch (e) { client._error(e); } resolve(m); });
12 mes.on("end", () => { int.stop(); });
13 int.on("end", () => { mes.stop(); });
14 });
pineafan6702cef2022-06-13 17:52:37 +010015 } catch(e) {
pineafan63fc5e22022-08-04 22:04:10 +010016 console.log(e);
pineafan6702cef2022-06-13 17:52:37 +010017 return null;
18 }
19
20 return out;
21}
22
23export async function modalInteractionCollector(m, modalFilter, interactionFilter) {
24 let out;
25 try {
pineafan63fc5e22022-08-04 22:04:10 +010026 out = await new Promise((resolve, _reject) => {
27 const int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000})
28 .on("collect", (m) => { resolve(m); });
29 const mod = new Discord.InteractionCollector(
pineafan6702cef2022-06-13 17:52:37 +010030 client, {
31 filter: (m) => modalFilter(m),
pineafanc6158ab2022-06-17 16:34:07 +010032 time: 300000
pineafan6702cef2022-06-13 17:52:37 +010033 })
34 .on("collect", async (m) => {
35 int.stop();
pineafan63fc5e22022-08-04 22:04:10 +010036 (m as Discord.ModalSubmitInteraction).deferUpdate();
37 resolve((m as Discord.ModalSubmitInteraction)); });
38 int.on("end", () => { mod.stop(); });
39 mod.on("end", () => { int.stop(); });
40 });
pineafan6702cef2022-06-13 17:52:37 +010041 } catch(e) {
pineafan63fc5e22022-08-04 22:04:10 +010042 console.log(e);
pineafan6702cef2022-06-13 17:52:37 +010043 return null;
44 }
45 return out;
46}