pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 1 | import Discord, { Interaction } from "discord.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 2 | import client from "./client.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 3 | |
| 4 | export default async function (m, interactionFilter, messageFilter) { |
| 5 | let out; |
| 6 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | 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 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 15 | } catch(e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | console.log(e); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 17 | return null; |
| 18 | } |
| 19 | |
| 20 | return out; |
| 21 | } |
| 22 | |
| 23 | export async function modalInteractionCollector(m, modalFilter, interactionFilter) { |
| 24 | let out; |
| 25 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | out = await new Promise((resolve, _reject) => { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 27 | const int = m.createMessageComponentCollector({filter: (m: Interaction) => interactionFilter(m), time: 300000}) |
| 28 | .on("collect", (m: Interaction) => { resolve(m); }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | const mod = new Discord.InteractionCollector( |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 30 | client, { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 31 | filter: (m: Interaction) => modalFilter(m), |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 32 | time: 300000 |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 33 | }) |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 34 | .on("collect", async (m: Interaction) => { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 35 | int.stop(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 36 | (m as Discord.ModalSubmitInteraction).deferUpdate(); |
| 37 | resolve((m as Discord.ModalSubmitInteraction)); }); |
| 38 | int.on("end", () => { mod.stop(); }); |
| 39 | mod.on("end", () => { int.stop(); }); |
| 40 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 41 | } catch(e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 42 | console.log(e); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 43 | return null; |
| 44 | } |
| 45 | return out; |
| 46 | } |