trivious 1.3.15 → 1.3.17

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.cjs CHANGED
@@ -725,6 +725,10 @@ var interactionCreate_default = {
725
725
  requiredPermission
726
726
  );
727
727
  if (!hasPermission2) return;
728
+ if (!("execute" in command)) {
729
+ await command.reply(interaction, { content: "Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!" });
730
+ return;
731
+ }
728
732
  await command.reply(interaction, { content: "Processing command..." });
729
733
  if (interaction.isChatInputCommand() && command.isSlashCommand()) {
730
734
  await command.execute(client, interaction);
@@ -957,6 +961,94 @@ var TriviousClient = class extends discord_js.Client {
957
961
  return this._options.rolePermissions ?? {};
958
962
  }
959
963
  };
964
+ var ContextMenuCommand = class extends Command {
965
+ /**
966
+ * Base command handler.
967
+ *
968
+ * @public
969
+ * @async
970
+ * @param {TriviousClient} client
971
+ * @param {ContextMenuCommandInteraction} interaction
972
+ * @returns {*}
973
+ */
974
+ async execute(client, interaction) {
975
+ const { run, metadata } = this;
976
+ const memberHasPermission = await this.validateGuildPermission(
977
+ client,
978
+ interaction,
979
+ metadata.permission,
980
+ false
981
+ );
982
+ if (memberHasPermission) await run(client, interaction);
983
+ }
984
+ };
985
+ var ContextMenuBuilder = class extends discord_js.ContextMenuCommandBuilder {
986
+ _active = true;
987
+ _ownerOnly = false;
988
+ _permission = 0 /* USER */;
989
+ _ephemeralReply = false;
990
+ /**
991
+ * Set the command as disabled.
992
+ *
993
+ * @public
994
+ * @returns {this}
995
+ */
996
+ disable() {
997
+ this._active = false;
998
+ return this;
999
+ }
1000
+ /**
1001
+ * Set the command as owner only.
1002
+ *
1003
+ * @public
1004
+ * @returns {this}
1005
+ */
1006
+ setOwnerOnly() {
1007
+ this._permission = 5 /* BOT_OWNER */;
1008
+ this._ownerOnly = true;
1009
+ return this;
1010
+ }
1011
+ /**
1012
+ * Set the permission level required to run the command.
1013
+ *
1014
+ * @public
1015
+ * @param {PermissionLevel} permission
1016
+ * @returns {this}
1017
+ */
1018
+ setPermission(permission) {
1019
+ this._permission = permission;
1020
+ return this;
1021
+ }
1022
+ /**
1023
+ * Set the interaction as ephemeral.
1024
+ *
1025
+ * @public
1026
+ * @returns {this}
1027
+ */
1028
+ setEphemeralReply() {
1029
+ this._ephemeralReply = true;
1030
+ return this;
1031
+ }
1032
+ /**
1033
+ * Build the builder
1034
+ *
1035
+ * @public
1036
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1037
+ */
1038
+ build() {
1039
+ return {
1040
+ data: this,
1041
+ metadata: {
1042
+ active: this._active,
1043
+ ownerOnly: this._ownerOnly,
1044
+ permission: this._permission,
1045
+ ephemeralReply: this._ephemeralReply
1046
+ }
1047
+ };
1048
+ }
1049
+ };
1050
+
1051
+ // src/core/commands/command.base.ts
960
1052
  var Command = class {
961
1053
  /**
962
1054
  * Returns whether the command is a SlashCommand.
@@ -966,7 +1058,7 @@ var Command = class {
966
1058
  * @returns {this is SlashCommand}
967
1059
  */
968
1060
  isSlashCommand() {
969
- return this.data instanceof discord_js.SlashCommandBuilder;
1061
+ return this.data instanceof discord_js.SlashCommandBuilder && this instanceof SlashCommand;
970
1062
  }
971
1063
  /**
972
1064
  * Returns whether the command is a ContextMenuCommand.
@@ -976,7 +1068,7 @@ var Command = class {
976
1068
  * @returns {this is ContextMenuCommand}
977
1069
  */
978
1070
  isContextMenuCommand() {
979
- return this.data instanceof discord_js.ContextMenuCommandBuilder;
1071
+ return this.data instanceof discord_js.ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
980
1072
  }
981
1073
  /**
982
1074
  * Returns JSON of the command builder.
@@ -1029,6 +1121,58 @@ var Command = class {
1029
1121
  return memberHasPermission;
1030
1122
  }
1031
1123
  };
1124
+ var SlashCommand = class extends Command {
1125
+ /**
1126
+ * Optional function to run if the SlashCommand has no subcommands or for extra fuctionality.
1127
+ *
1128
+ * @abstract
1129
+ * @type {?(
1130
+ * client: TriviousClient,
1131
+ * interaction: ChatInputCommandInteraction
1132
+ * ) => Promise<void>}
1133
+ */
1134
+ run;
1135
+ /**
1136
+ * General handler for the command and its subcommand, if applicable.
1137
+ *
1138
+ * @public
1139
+ * @async
1140
+ * @param {TriviousClient} client
1141
+ * @param {ChatInputCommandInteraction} interaction
1142
+ * @returns {*}
1143
+ */
1144
+ async execute(client, interaction) {
1145
+ const { run, reply, metadata } = this;
1146
+ const { options } = interaction;
1147
+ if (run) {
1148
+ const memberHasPermission2 = await this.validateGuildPermission(
1149
+ client,
1150
+ interaction,
1151
+ metadata.permission,
1152
+ false
1153
+ );
1154
+ if (memberHasPermission2) await run(client, interaction);
1155
+ }
1156
+ const subcommands = metadata.subcommands;
1157
+ if (subcommands.size <= 0) return;
1158
+ const subcommand = metadata.subcommands.find(
1159
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1160
+ );
1161
+ if (!subcommand) {
1162
+ await reply(interaction, {
1163
+ content: "Ran subcommand is outdated or does not have a handler!"
1164
+ });
1165
+ return;
1166
+ }
1167
+ const memberHasPermission = await this.validateGuildPermission(
1168
+ client,
1169
+ interaction,
1170
+ subcommand.metadata.permission
1171
+ );
1172
+ if (!memberHasPermission) return;
1173
+ await subcommand.execute(client, interaction);
1174
+ }
1175
+ };
1032
1176
  var CommandBuilder = class extends discord_js.SlashCommandBuilder {
1033
1177
  _active = true;
1034
1178
  _guildOnly = false;
@@ -1194,92 +1338,6 @@ var Subcommand = class {
1194
1338
  await interaction.reply(newOptions);
1195
1339
  }
1196
1340
  };
1197
- var ContextMenuCommand = class extends Command {
1198
- /**
1199
- * Base command handler.
1200
- *
1201
- * @public
1202
- * @async
1203
- * @param {TriviousClient} client
1204
- * @param {ContextMenuCommandInteraction} interaction
1205
- * @returns {*}
1206
- */
1207
- async execute(client, interaction) {
1208
- const { run, metadata } = this;
1209
- const memberHasPermission = await this.validateGuildPermission(
1210
- client,
1211
- interaction,
1212
- metadata.permission,
1213
- false
1214
- );
1215
- if (memberHasPermission) await run(client, interaction);
1216
- }
1217
- };
1218
- var ContextMenuBuilder = class extends discord_js.ContextMenuCommandBuilder {
1219
- _active = true;
1220
- _ownerOnly = false;
1221
- _permission = 0 /* USER */;
1222
- _ephemeralReply = false;
1223
- /**
1224
- * Set the command as disabled.
1225
- *
1226
- * @public
1227
- * @returns {this}
1228
- */
1229
- disable() {
1230
- this._active = false;
1231
- return this;
1232
- }
1233
- /**
1234
- * Set the command as owner only.
1235
- *
1236
- * @public
1237
- * @returns {this}
1238
- */
1239
- setOwnerOnly() {
1240
- this._permission = 5 /* BOT_OWNER */;
1241
- this._ownerOnly = true;
1242
- return this;
1243
- }
1244
- /**
1245
- * Set the permission level required to run the command.
1246
- *
1247
- * @public
1248
- * @param {PermissionLevel} permission
1249
- * @returns {this}
1250
- */
1251
- setPermission(permission) {
1252
- this._permission = permission;
1253
- return this;
1254
- }
1255
- /**
1256
- * Set the interaction as ephemeral.
1257
- *
1258
- * @public
1259
- * @returns {this}
1260
- */
1261
- setEphemeralReply() {
1262
- this._ephemeralReply = true;
1263
- return this;
1264
- }
1265
- /**
1266
- * Build the builder
1267
- *
1268
- * @public
1269
- * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1270
- */
1271
- build() {
1272
- return {
1273
- data: this,
1274
- metadata: {
1275
- active: this._active,
1276
- ownerOnly: this._ownerOnly,
1277
- permission: this._permission,
1278
- ephemeralReply: this._ephemeralReply
1279
- }
1280
- };
1281
- }
1282
- };
1283
1341
 
1284
1342
  // src/core/components/component.base.ts
1285
1343
  var ComponentBuilder = class {
@@ -1401,6 +1459,7 @@ exports.ComponentType = ComponentType;
1401
1459
  exports.ContextMenuBuilder = ContextMenuBuilder;
1402
1460
  exports.ContextMenuCommand = ContextMenuCommand;
1403
1461
  exports.PermissionLevel = PermissionLevel;
1462
+ exports.SlashCommand = SlashCommand;
1404
1463
  exports.Subcommand = Subcommand;
1405
1464
  exports.SubcommandBuilder = SubcommandBuilder;
1406
1465
  exports.TriviousClient = TriviousClient;