@duxcore/interactive-discord
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -5,3 +5,3 @@ { | ||
"description": "A package that will allow you to seamlessly integrate discord interactions into your bot.", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"license": "GPL-3.0", | ||
@@ -8,0 +8,0 @@ "main": "lib/index", |
@@ -58,3 +58,2 @@ import axios from 'axios'; | ||
.then(dat => { | ||
console.log(dat.data) | ||
resolve() | ||
@@ -61,0 +60,0 @@ }) |
@@ -1,4 +0,6 @@ | ||
import { Client } from "discord.js"; | ||
import { Client, Collection } from "discord.js"; | ||
import { TypedEmitter } from 'tiny-typed-emitter'; | ||
import { ButtonInteractionController } from "./controllers/ButtonInteractionController"; | ||
import { ButtonComponent } from "./structures/buttons/ButtonComponent"; | ||
import { ButtonListenerCallback } from "./util/types/button"; | ||
import { Events } from "./util/types/events"; | ||
@@ -11,2 +13,5 @@ import { InteractionType, RawInteractionObject } from "./util/types/interactions"; | ||
private _buttonListeners = new Collection<string, ButtonListenerCallback>(); | ||
private _singleButtonListeners = new Collection<string, ButtonListenerCallback>(); | ||
constructor(bot: Client, applicationId: string) { | ||
@@ -17,3 +22,16 @@ super(); | ||
bot.ws.on("INTERACTION_CREATE", (interaction: RawInteractionObject) => { | ||
if (interaction.type == InteractionType.MessageComponent) this.emit("buttonInteraction", new ButtonInteractionController(interaction, this)); | ||
if (interaction.type == InteractionType.MessageComponent) { | ||
const btnController = new ButtonInteractionController(interaction, this) | ||
this.emit("buttonInteraction", btnController); | ||
this._buttonListeners.map((cb, key) => { | ||
if (btnController.customId == key) return cb(btnController); | ||
}); | ||
this._singleButtonListeners.map((cb, key) => { | ||
if (btnController.customId == key) { | ||
this._singleButtonListeners.delete(key); | ||
return cb(btnController); | ||
} | ||
}); | ||
} | ||
}) | ||
@@ -24,2 +42,10 @@ | ||
} | ||
addButtonListener(button: ButtonComponent, callback: ButtonListenerCallback) { | ||
this._buttonListeners.set(button.customId, callback); | ||
} | ||
addSingleButtonListener(button: ButtonComponent, callback: ButtonListenerCallback) { | ||
this._singleButtonListeners.set(button.customId, callback); | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
import { ButtonInteractionController } from "../../controllers/ButtonInteractionController"; | ||
import { InteractiveClient } from "../../InteractiveClient"; | ||
import { ButtonStyle, EmojiPartial } from "./components"; | ||
@@ -8,2 +10,4 @@ | ||
disabled?: boolean | ||
} | ||
} | ||
export type ButtonListenerCallback = (interaction: ButtonInteractionController) => void; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54323
494