@somehiddenkey/discord-command-utils 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@somehiddenkey/discord-command-utils",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A utility library for building Discord bot commands using discord.js",
5
5
  "author": {
6
6
  "email": "k3y.throwaway@gmail.com",
@@ -44,9 +44,9 @@ export default class Interaction {
44
44
  */
45
45
  static On(custom_id, type, scope, target) {
46
46
  if(Array.isArray(scope))
47
- scope.forEach(s => InteractionContainer.add(new Interaction(custom_id, s, type, target)));
47
+ scope.forEach(s => InteractionContainer.add(new Interaction(custom_id, type, s, target)));
48
48
  else;
49
- InteractionContainer.add(new Interaction(custom_id, scope, type, target));
49
+ InteractionContainer.add(new Interaction(custom_id, type, scope, target));
50
50
  return custom_id;
51
51
  }
52
52
 
@@ -74,7 +74,10 @@ export default class InteractionContainer {
74
74
  */
75
75
  call_message_interaction(interaction, on_error = async () => {}) {
76
76
  if (interaction.author.bot) return;
77
-
77
+
78
+ if(!interaction.content.startsWith(this.#local_config.prefix))
79
+ return;
80
+
78
81
  const scope =
79
82
  (interaction.channel.type === ChannelType.DM) ?
80
83
  InteractionScope.DM : this.#global_config.guilds.get_scope(interaction.guild.id);
@@ -82,7 +85,7 @@ export default class InteractionContainer {
82
85
  const customId = interaction.content.slice(this.#local_config.prefix?.length)
83
86
 
84
87
  return InteractionContainer
85
- .#call(InteractionType.Message, scope, customId, interaction)
88
+ .#call(InteractionType.Message, scope, [customId], interaction)
86
89
  .catch(error => {
87
90
  if (error instanceof CommandError)
88
91
  return error.error_as_message()
@@ -137,16 +140,16 @@ export default class InteractionContainer {
137
140
  *
138
141
  * @param {InteractionType} type
139
142
  * @param {InteractionScope} scope
140
- * @param {InteractionID} customId
143
+ * @param {InteractionID[]} customId
141
144
  * @param {DiscordBaseInteraction} interaction
142
145
  * @returns {Promise<any>}
143
146
  * @throws {CommandError}
144
147
  */
145
- static #call(type, scope, customId, interaction) {
148
+ static async #call(type, scope, customId, interaction) {
146
149
  const interaction_command = InteractionContainer.get(type, scope, customId?.[0]);
147
150
  if(!interaction_command)
148
- return consola.error(`No interaction found for id ${customId}`);
151
+ return consola.error(`No interaction found for id ${customId.join('?')} with type ${type} and scope ${scope}`);
149
152
 
150
- return interaction_command.interaction_command_function.apply(null, [interaction, ...customId.slice(1)]);
153
+ return await interaction_command.interaction_command_function.apply(null, [interaction, ...customId.slice(1)]);
151
154
  }
152
155
  }