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.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';
@@ -719,6 +719,10 @@ var interactionCreate_default = {
719
719
  requiredPermission
720
720
  );
721
721
  if (!hasPermission2) return;
722
+ if (!("execute" in command)) {
723
+ await command.reply(interaction, { content: "Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!" });
724
+ return;
725
+ }
722
726
  await command.reply(interaction, { content: "Processing command..." });
723
727
  if (interaction.isChatInputCommand() && command.isSlashCommand()) {
724
728
  await command.execute(client, interaction);
@@ -951,6 +955,94 @@ var TriviousClient = class extends Client {
951
955
  return this._options.rolePermissions ?? {};
952
956
  }
953
957
  };
958
+ var ContextMenuCommand = class extends Command {
959
+ /**
960
+ * Base command handler.
961
+ *
962
+ * @public
963
+ * @async
964
+ * @param {TriviousClient} client
965
+ * @param {ContextMenuCommandInteraction} interaction
966
+ * @returns {*}
967
+ */
968
+ async execute(client, interaction) {
969
+ const { run, metadata } = this;
970
+ const memberHasPermission = await this.validateGuildPermission(
971
+ client,
972
+ interaction,
973
+ metadata.permission,
974
+ false
975
+ );
976
+ if (memberHasPermission) await run(client, interaction);
977
+ }
978
+ };
979
+ var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
980
+ _active = true;
981
+ _ownerOnly = false;
982
+ _permission = 0 /* USER */;
983
+ _ephemeralReply = false;
984
+ /**
985
+ * Set the command as disabled.
986
+ *
987
+ * @public
988
+ * @returns {this}
989
+ */
990
+ disable() {
991
+ this._active = false;
992
+ return this;
993
+ }
994
+ /**
995
+ * Set the command as owner only.
996
+ *
997
+ * @public
998
+ * @returns {this}
999
+ */
1000
+ setOwnerOnly() {
1001
+ this._permission = 5 /* BOT_OWNER */;
1002
+ this._ownerOnly = true;
1003
+ return this;
1004
+ }
1005
+ /**
1006
+ * Set the permission level required to run the command.
1007
+ *
1008
+ * @public
1009
+ * @param {PermissionLevel} permission
1010
+ * @returns {this}
1011
+ */
1012
+ setPermission(permission) {
1013
+ this._permission = permission;
1014
+ return this;
1015
+ }
1016
+ /**
1017
+ * Set the interaction as ephemeral.
1018
+ *
1019
+ * @public
1020
+ * @returns {this}
1021
+ */
1022
+ setEphemeralReply() {
1023
+ this._ephemeralReply = true;
1024
+ return this;
1025
+ }
1026
+ /**
1027
+ * Build the builder
1028
+ *
1029
+ * @public
1030
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1031
+ */
1032
+ build() {
1033
+ return {
1034
+ data: this,
1035
+ metadata: {
1036
+ active: this._active,
1037
+ ownerOnly: this._ownerOnly,
1038
+ permission: this._permission,
1039
+ ephemeralReply: this._ephemeralReply
1040
+ }
1041
+ };
1042
+ }
1043
+ };
1044
+
1045
+ // src/core/commands/command.base.ts
954
1046
  var Command = class {
955
1047
  /**
956
1048
  * Returns whether the command is a SlashCommand.
@@ -960,7 +1052,7 @@ var Command = class {
960
1052
  * @returns {this is SlashCommand}
961
1053
  */
962
1054
  isSlashCommand() {
963
- return this.data instanceof SlashCommandBuilder;
1055
+ return this.data instanceof SlashCommandBuilder && this instanceof SlashCommand;
964
1056
  }
965
1057
  /**
966
1058
  * Returns whether the command is a ContextMenuCommand.
@@ -970,7 +1062,7 @@ var Command = class {
970
1062
  * @returns {this is ContextMenuCommand}
971
1063
  */
972
1064
  isContextMenuCommand() {
973
- return this.data instanceof ContextMenuCommandBuilder;
1065
+ return this.data instanceof ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
974
1066
  }
975
1067
  /**
976
1068
  * Returns JSON of the command builder.
@@ -1023,6 +1115,58 @@ var Command = class {
1023
1115
  return memberHasPermission;
1024
1116
  }
1025
1117
  };
1118
+ var SlashCommand = class extends Command {
1119
+ /**
1120
+ * Optional function to run if the SlashCommand has no subcommands or for extra fuctionality.
1121
+ *
1122
+ * @abstract
1123
+ * @type {?(
1124
+ * client: TriviousClient,
1125
+ * interaction: ChatInputCommandInteraction
1126
+ * ) => Promise<void>}
1127
+ */
1128
+ run;
1129
+ /**
1130
+ * General handler for the command and its subcommand, if applicable.
1131
+ *
1132
+ * @public
1133
+ * @async
1134
+ * @param {TriviousClient} client
1135
+ * @param {ChatInputCommandInteraction} interaction
1136
+ * @returns {*}
1137
+ */
1138
+ async execute(client, interaction) {
1139
+ const { run, reply, metadata } = this;
1140
+ const { options } = interaction;
1141
+ if (run) {
1142
+ const memberHasPermission2 = await this.validateGuildPermission(
1143
+ client,
1144
+ interaction,
1145
+ metadata.permission,
1146
+ false
1147
+ );
1148
+ if (memberHasPermission2) await run(client, interaction);
1149
+ }
1150
+ const subcommands = metadata.subcommands;
1151
+ if (subcommands.size <= 0) return;
1152
+ const subcommand = metadata.subcommands.find(
1153
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1154
+ );
1155
+ if (!subcommand) {
1156
+ await reply(interaction, {
1157
+ content: "Ran subcommand is outdated or does not have a handler!"
1158
+ });
1159
+ return;
1160
+ }
1161
+ const memberHasPermission = await this.validateGuildPermission(
1162
+ client,
1163
+ interaction,
1164
+ subcommand.metadata.permission
1165
+ );
1166
+ if (!memberHasPermission) return;
1167
+ await subcommand.execute(client, interaction);
1168
+ }
1169
+ };
1026
1170
  var CommandBuilder = class extends SlashCommandBuilder {
1027
1171
  _active = true;
1028
1172
  _guildOnly = false;
@@ -1188,92 +1332,6 @@ var Subcommand = class {
1188
1332
  await interaction.reply(newOptions);
1189
1333
  }
1190
1334
  };
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
1335
 
1278
1336
  // src/core/components/component.base.ts
1279
1337
  var ComponentBuilder = class {
@@ -1376,6 +1434,6 @@ var Component = class {
1376
1434
  }
1377
1435
  };
1378
1436
 
1379
- export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
1437
+ export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, SlashCommand, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
1380
1438
  //# sourceMappingURL=index.js.map
1381
1439
  //# sourceMappingURL=index.js.map