trivious 1.3.8 → 1.3.10

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'util';
2
- import { Collection, SlashCommandSubcommandBuilder, Client, REST, Routes, SlashCommandBuilder, ContextMenuCommandBuilder, InteractionContextType, ButtonInteraction, ModalSubmitInteraction } from 'discord.js';
2
+ import { Collection, SlashCommandSubcommandBuilder, Client, REST, Routes, ContextMenuCommandBuilder, SlashCommandBuilder, InteractionContextType, ButtonInteraction, ModalSubmitInteraction } from 'discord.js';
3
3
  export { ClientEvents, Collection } from 'discord.js';
4
4
  import { existsSync, promises } from 'fs';
5
5
  import path, { dirname, join, resolve } from 'path';
@@ -779,7 +779,8 @@ var EventRegistry = class extends BaseRegistry {
779
779
  this.items.set(event.name, event);
780
780
  }
781
781
  }
782
- this.items.set(interactionCreate_default.name, interactionCreate_default);
782
+ if (!this.items.get(interactionCreate_default.name))
783
+ this.items.set(interactionCreate_default.name, interactionCreate_default);
783
784
  return this;
784
785
  }
785
786
  /**
@@ -951,6 +952,94 @@ var TriviousClient = class extends Client {
951
952
  return this._options.rolePermissions ?? {};
952
953
  }
953
954
  };
955
+ var ContextMenuCommand = class extends Command {
956
+ /**
957
+ * Base command handler.
958
+ *
959
+ * @public
960
+ * @async
961
+ * @param {TriviousClient} client
962
+ * @param {ContextMenuCommandInteraction} interaction
963
+ * @returns {*}
964
+ */
965
+ async execute(client, interaction) {
966
+ const { run, metadata } = this;
967
+ const memberHasPermission = await this.validateGuildPermission(
968
+ client,
969
+ interaction,
970
+ metadata.permission,
971
+ false
972
+ );
973
+ if (memberHasPermission) await run(client, interaction);
974
+ }
975
+ };
976
+ var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
977
+ _active = true;
978
+ _ownerOnly = false;
979
+ _permission = 0 /* USER */;
980
+ _ephemeralReply = false;
981
+ /**
982
+ * Set the command as disabled.
983
+ *
984
+ * @public
985
+ * @returns {this}
986
+ */
987
+ disable() {
988
+ this._active = false;
989
+ return this;
990
+ }
991
+ /**
992
+ * Set the command as owner only.
993
+ *
994
+ * @public
995
+ * @returns {this}
996
+ */
997
+ setOwnerOnly() {
998
+ this._permission = 5 /* BOT_OWNER */;
999
+ this._ownerOnly = true;
1000
+ return this;
1001
+ }
1002
+ /**
1003
+ * Set the permission level required to run the command.
1004
+ *
1005
+ * @public
1006
+ * @param {PermissionLevel} permission
1007
+ * @returns {this}
1008
+ */
1009
+ setPermission(permission) {
1010
+ this._permission = permission;
1011
+ return this;
1012
+ }
1013
+ /**
1014
+ * Set the interaction as ephemeral.
1015
+ *
1016
+ * @public
1017
+ * @returns {this}
1018
+ */
1019
+ setEphemeralReply() {
1020
+ this._ephemeralReply = true;
1021
+ return this;
1022
+ }
1023
+ /**
1024
+ * Build the builder
1025
+ *
1026
+ * @public
1027
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1028
+ */
1029
+ build() {
1030
+ return {
1031
+ data: this,
1032
+ metadata: {
1033
+ active: this._active,
1034
+ ownerOnly: this._ownerOnly,
1035
+ permission: this._permission,
1036
+ ephemeralReply: this._ephemeralReply
1037
+ }
1038
+ };
1039
+ }
1040
+ };
1041
+
1042
+ // src/core/commands/command.base.ts
954
1043
  var Command = class {
955
1044
  /**
956
1045
  * Returns whether the command is a SlashCommand.
@@ -960,7 +1049,7 @@ var Command = class {
960
1049
  * @returns {this is SlashCommand}
961
1050
  */
962
1051
  isSlashCommand() {
963
- return this.data instanceof SlashCommandBuilder;
1052
+ return this.data instanceof SlashCommandBuilder && this instanceof SlashCommand;
964
1053
  }
965
1054
  /**
966
1055
  * Returns whether the command is a ContextMenuCommand.
@@ -970,7 +1059,7 @@ var Command = class {
970
1059
  * @returns {this is ContextMenuCommand}
971
1060
  */
972
1061
  isContextMenuCommand() {
973
- return this.data instanceof ContextMenuCommandBuilder;
1062
+ return this.data instanceof ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
974
1063
  }
975
1064
  /**
976
1065
  * Returns JSON of the command builder.
@@ -1023,6 +1112,48 @@ var Command = class {
1023
1112
  return memberHasPermission;
1024
1113
  }
1025
1114
  };
1115
+ var SlashCommand = class extends Command {
1116
+ /**
1117
+ * General handler for the command and its subcommand, if applicable.
1118
+ *
1119
+ * @public
1120
+ * @async
1121
+ * @param {TriviousClient} client
1122
+ * @param {ChatInputCommandInteraction} interaction
1123
+ * @returns {*}
1124
+ */
1125
+ async execute(client, interaction) {
1126
+ const { run, reply, metadata } = this;
1127
+ const { options } = interaction;
1128
+ if (run) {
1129
+ const memberHasPermission2 = await this.validateGuildPermission(
1130
+ client,
1131
+ interaction,
1132
+ metadata.permission,
1133
+ false
1134
+ );
1135
+ if (memberHasPermission2) await run(client, interaction);
1136
+ }
1137
+ const subcommands = metadata.subcommands;
1138
+ if (subcommands.size <= 0) return;
1139
+ const subcommand = metadata.subcommands.find(
1140
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1141
+ );
1142
+ if (!subcommand) {
1143
+ await reply(interaction, {
1144
+ content: "Ran subcommand is outdated or does not have a handler!"
1145
+ });
1146
+ return;
1147
+ }
1148
+ const memberHasPermission = await this.validateGuildPermission(
1149
+ client,
1150
+ interaction,
1151
+ subcommand.metadata.permission
1152
+ );
1153
+ if (!memberHasPermission) return;
1154
+ await subcommand.execute(client, interaction);
1155
+ }
1156
+ };
1026
1157
  var CommandBuilder = class extends SlashCommandBuilder {
1027
1158
  _active = true;
1028
1159
  _guildOnly = false;
@@ -1188,92 +1319,6 @@ var Subcommand = class {
1188
1319
  await interaction.reply(newOptions);
1189
1320
  }
1190
1321
  };
1191
- var ContextMenuCommand = class extends Command {
1192
- /**
1193
- * Base command handler.
1194
- *
1195
- * @public
1196
- * @async
1197
- * @param {TriviousClient} client
1198
- * @param {ContextMenuCommandInteraction} interaction
1199
- * @returns {*}
1200
- */
1201
- async execute(client, interaction) {
1202
- const { run, metadata } = this;
1203
- const memberHasPermission = await this.validateGuildPermission(
1204
- client,
1205
- interaction,
1206
- metadata.permission,
1207
- false
1208
- );
1209
- if (memberHasPermission) await run(client, interaction);
1210
- }
1211
- };
1212
- var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
1213
- _active = true;
1214
- _ownerOnly = false;
1215
- _permission = 0 /* USER */;
1216
- _ephemeralReply = false;
1217
- /**
1218
- * Set the command as disabled.
1219
- *
1220
- * @public
1221
- * @returns {this}
1222
- */
1223
- disable() {
1224
- this._active = false;
1225
- return this;
1226
- }
1227
- /**
1228
- * Set the command as owner only.
1229
- *
1230
- * @public
1231
- * @returns {this}
1232
- */
1233
- setOwnerOnly() {
1234
- this._permission = 5 /* BOT_OWNER */;
1235
- this._ownerOnly = true;
1236
- return this;
1237
- }
1238
- /**
1239
- * Set the permission level required to run the command.
1240
- *
1241
- * @public
1242
- * @param {PermissionLevel} permission
1243
- * @returns {this}
1244
- */
1245
- setPermission(permission) {
1246
- this._permission = permission;
1247
- return this;
1248
- }
1249
- /**
1250
- * Set the interaction as ephemeral.
1251
- *
1252
- * @public
1253
- * @returns {this}
1254
- */
1255
- setEphemeralReply() {
1256
- this._ephemeralReply = true;
1257
- return this;
1258
- }
1259
- /**
1260
- * Build the builder
1261
- *
1262
- * @public
1263
- * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1264
- */
1265
- build() {
1266
- return {
1267
- data: this,
1268
- metadata: {
1269
- active: this._active,
1270
- ownerOnly: this._ownerOnly,
1271
- permission: this._permission,
1272
- ephemeralReply: this._ephemeralReply
1273
- }
1274
- };
1275
- }
1276
- };
1277
1322
 
1278
1323
  // src/core/components/component.base.ts
1279
1324
  var ComponentBuilder = class {
@@ -1376,6 +1421,6 @@ var Component = class {
1376
1421
  }
1377
1422
  };
1378
1423
 
1379
- export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
1424
+ export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, SlashCommand, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
1380
1425
  //# sourceMappingURL=index.js.map
1381
1426
  //# sourceMappingURL=index.js.map