2021-08-12 23:45:17 +00:00
|
|
|
// eris doesn't come with a method to wait for interactions by default, so we make our own
|
2021-08-19 14:19:14 +00:00
|
|
|
import { EventEmitter } from "events";
|
2021-08-12 23:45:17 +00:00
|
|
|
|
|
|
|
class InteractionCollector extends EventEmitter {
|
2021-10-23 18:58:19 +00:00
|
|
|
constructor(client, message, timeout = 120000) {
|
2021-08-12 23:45:17 +00:00
|
|
|
super();
|
|
|
|
this.message = message;
|
2021-10-23 18:58:19 +00:00
|
|
|
//this.time = timeout;
|
2021-08-12 23:45:17 +00:00
|
|
|
this.ended = false;
|
|
|
|
this.bot = client;
|
|
|
|
this.listener = async (packet) => {
|
|
|
|
if (packet.t !== "INTERACTION_CREATE") return;
|
2021-08-14 21:15:21 +00:00
|
|
|
await this.verify(packet.d.message, packet.d.data.custom_id, packet.d.id, packet.d.token, packet.d.member ? packet.d.member.user.id : packet.d.user.id);
|
2021-08-12 23:45:17 +00:00
|
|
|
};
|
|
|
|
this.bot.on("rawWS", this.listener);
|
2021-10-23 18:58:19 +00:00
|
|
|
setTimeout(() => this.stop("time"), timeout);
|
2021-08-12 23:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async verify(message, interaction, id, token, member) {
|
|
|
|
if (this.message.id !== message.id) return false;
|
2021-08-14 21:15:21 +00:00
|
|
|
this.emit("interaction", interaction, id, token, member);
|
2021-08-12 23:45:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(reason) {
|
|
|
|
if (this.ended) return;
|
|
|
|
this.ended = true;
|
|
|
|
this.bot.removeListener("rawWS", this.listener);
|
|
|
|
this.emit("end", this.collected, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export default InteractionCollector;
|