pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 1 | import Discord from 'discord.js'; |
| 2 | import client from './client.js'; |
| 3 | import generateEmojiEmbed from "./generateEmojiEmbed.js"; |
| 4 | |
| 5 | export default async function (m, interactionFilter, messageFilter) { |
| 6 | let out; |
| 7 | try { |
| 8 | out = await new Promise((resolve, reject) => { |
| 9 | let mes, int; |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 10 | mes = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000}) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 11 | .on("collect", (m) => { resolve(m); }) |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 12 | int = m.channel.createMessageCollector({filter: (m) => messageFilter(m), time: 300000}) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 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 | |
| 25 | export async function modalInteractionCollector(m, modalFilter, interactionFilter) { |
| 26 | let out; |
| 27 | try { |
| 28 | out = await new Promise((resolve, reject) => { |
| 29 | let mod, int; |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 30 | int = m.createMessageComponentCollector({filter: (m) => interactionFilter(m), time: 300000}) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 31 | .on("collect", (m) => { resolve(m); }) |
| 32 | mod = new Discord.InteractionCollector( |
| 33 | client, { |
| 34 | filter: (m) => modalFilter(m), |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 35 | time: 300000 |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 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 | } |