Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@duxcore/interactive-discord

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@duxcore/interactive-discord - npm Package Compare versions

Comparing version 1.1.8 to 1.1.9

src/controllers/CommandController.ts

2

package.json

@@ -5,3 +5,3 @@ {

"description": "A package that will allow you to seamlessly integrate discord interactions into your bot.",
"version": "1.1.8",
"version": "1.1.9",
"license": "GPL-3.0",

@@ -8,0 +8,0 @@ "main": "lib/index",

@@ -1,2 +0,4 @@

# interactive-discord
<p align="center">
<h1 align=center>Interactive Discord</h1>
</p>

@@ -3,0 +5,0 @@ This is a package that will allow you to seamlessly integrate discord interactions into your [discord.js](https://discord.js.org/) bot.

import axios from "axios";
import { Collection, Snowflake } from "discord.js";
import InteractiveClient from "..";
import { CommandInteractionController } from "../controllers/CommandInteractionController";
import { CommandController } from "../controllers/CommandController";
import { SlashCommand } from "../structures/SlashCommand";

@@ -12,5 +12,6 @@ import { discord } from "../util/constraints";

private _client: InteractiveClient;
private _commandCache = new Collection<string, CommandInteractionController>();
private _axiosOpts: any;
public cache = new Collection<string, CommandController>();
constructor(client: InteractiveClient) {

@@ -42,12 +43,12 @@ this._client = client;

public async register(command: SlashCommand): Promise<CommandInteractionController> {
let cachedCmd = this._commandCache.get(command.name);
public async register(command: SlashCommand): Promise<CommandController> {
let cachedCmd = this.cache.get(command.name);
if (cachedCmd) return (await cachedCmd.update(command));
const registeredData = await registerCommand(command, this._client);
const controller = new CommandInteractionController(command, registeredData, this._client);
const controller = new CommandController(command, registeredData, this._client);
this._commandCache.set(controller.command.name, controller);
this.cache.set(controller.command.name, controller);
return controller;
}
}

@@ -1,26 +0,16 @@

import axios from "axios";
import InteractiveClient from "..";
import { SlashCommand } from "../structures/SlashCommand";
import registerCommand from "../util/registerCommand";
import { ApplicationCommand } from "../util/types/command";
import { RawInteractionObject } from "../util/types/interactions";
import { CommandController } from "./CommandController";
import { InteractionControllerBase } from "./InteractionControllerBase";
export class CommandInteractionController {
private _command: SlashCommand;
private _client: InteractiveClient;
private _commandDat: ApplicationCommand;
constructor(command: SlashCommand, raw: ApplicationCommand, client: InteractiveClient) {
this._command = command;
this._client = client;
this._commandDat = raw;
export class CommandInteractionController extends InteractionControllerBase {
constructor(raw: RawInteractionObject, client: InteractiveClient) {
super(raw, client);
}
get id(): string { return this._commandDat.id; }
get command(): SlashCommand { return this._command; }
public async update(cmd: SlashCommand): Promise<this> {
this._command = cmd;
this._commandDat = await registerCommand(cmd, this._client);
return this;
get command(): CommandController | null {
const cmd = this.client.commands.cache.get(this.raw.data.name ?? "");
if (!cmd) return null;
return cmd;
}
}
export * from './ButtonInteractionController';
export * from './CommandInteractionController';
export * from './CommandController';
export * from './SelectionInteractionController';

@@ -9,5 +9,5 @@ import axios from 'axios';

export class InteractionControllerBase {
public client: InteractiveClient;
private _raw: RawInteractionObject;
private _client: InteractiveClient;
private _version: number;

@@ -23,3 +23,3 @@ private _type: number;

this._raw = raw;
this._client = client;
this.client = client;

@@ -41,3 +41,3 @@ this._version = raw.version;

get guild(): Guild | null {
const guild = this._client.bot.guilds.cache.get(this._guildId);
const guild = this.client.bot.guilds.cache.get(this._guildId);
return guild ?? null;

@@ -47,3 +47,3 @@ }

get member(): GuildMember | null {
const guild = this._client.bot.guilds.cache.get(this._guildId);
const guild = this.client.bot.guilds.cache.get(this._guildId);
const member = guild?.members.cache.get(this._raw.member.user.id);

@@ -50,0 +50,0 @@

@@ -6,7 +6,10 @@ import { APIMessageContentResolvable, Client, Collection, DMChannel, MessageAdditions, MessageOptions, NewsChannel, TextChannel } from "discord.js";

import { ButtonInteractionController } from "./controllers/ButtonInteractionController";
import { CommandInteractionController } from "./controllers/CommandInteractionController";
import { SelectionInteractionController } from "./controllers/SelectionInteractionController";
import { ButtonComponent } from "./structures/buttons/ButtonComponent";
import { SlashCommand } from "./structures/SlashCommand";
import { getChannelPerms } from "./util/channel";
import compileComponents from "./util/compileComponents";
import { ButtonListenerCallback } from "./util/types/button";
import { ApplicationCommandEventCallback } from "./util/types/command";
import { SendComponentsOptions } from "./util/types/components";

@@ -23,2 +26,3 @@ import { Events } from "./util/types/events";

private _selectionListeners = new Collection<string, SelectionListenerCallback>();
private _commandListeners = new Collection<string, ApplicationCommandEventCallback>();

@@ -70,3 +74,9 @@ public commands: Commands;

if (interaction.type == InteractionType.ApplicationCommand) {
console.log(interaction);
const cmdInteraction = new CommandInteractionController(interaction, this);
this._commandListeners.map((cb, key) => {
if (interaction.data.name == key) return cb(cmdInteraction)
})
this.emit("commandInteraction", cmdInteraction)
}

@@ -88,2 +98,6 @@ })

addCommandListener(cmd: SlashCommand, callback: ApplicationCommandEventCallback) {
this._commandListeners.set(cmd.name, callback);
}
sendComponents({ channel, components, content, embed }: SendComponentsOptions) {

@@ -90,0 +104,0 @@

import { Snowflake } from "discord.js";
import { CommandInteractionController } from "../../controllers/CommandInteractionController";

@@ -63,2 +64,4 @@ export enum ApplicationCommandOptionType {

permission: boolean // Is this user/role allowed?
}
}
export type ApplicationCommandEventCallback = (interaction: CommandInteractionController) => void;
import { ButtonInteractionController } from "../../controllers/ButtonInteractionController";
import { CommandInteractionController } from "../../controllers/CommandInteractionController";
import { SelectionInteractionController } from "../../controllers/SelectionInteractionController";

@@ -7,3 +8,3 @@

"selectionInteraction": (interaction: SelectionInteractionController) => void;
"commandInteraction": (interaction: SelectionInteractionController) => void;
"commandInteraction": (interaction: CommandInteractionController) => void;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc