trivious 1.3.8 → 1.3.9

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';
@@ -951,6 +951,94 @@ var TriviousClient = class extends Client {
951
951
  return this._options.rolePermissions ?? {};
952
952
  }
953
953
  };
954
+ var ContextMenuCommand = class extends Command {
955
+ /**
956
+ * Base command handler.
957
+ *
958
+ * @public
959
+ * @async
960
+ * @param {TriviousClient} client
961
+ * @param {ContextMenuCommandInteraction} interaction
962
+ * @returns {*}
963
+ */
964
+ async execute(client, interaction) {
965
+ const { run, metadata } = this;
966
+ const memberHasPermission = await this.validateGuildPermission(
967
+ client,
968
+ interaction,
969
+ metadata.permission,
970
+ false
971
+ );
972
+ if (memberHasPermission) await run(client, interaction);
973
+ }
974
+ };
975
+ var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
976
+ _active = true;
977
+ _ownerOnly = false;
978
+ _permission = 0 /* USER */;
979
+ _ephemeralReply = false;
980
+ /**
981
+ * Set the command as disabled.
982
+ *
983
+ * @public
984
+ * @returns {this}
985
+ */
986
+ disable() {
987
+ this._active = false;
988
+ return this;
989
+ }
990
+ /**
991
+ * Set the command as owner only.
992
+ *
993
+ * @public
994
+ * @returns {this}
995
+ */
996
+ setOwnerOnly() {
997
+ this._permission = 5 /* BOT_OWNER */;
998
+ this._ownerOnly = true;
999
+ return this;
1000
+ }
1001
+ /**
1002
+ * Set the permission level required to run the command.
1003
+ *
1004
+ * @public
1005
+ * @param {PermissionLevel} permission
1006
+ * @returns {this}
1007
+ */
1008
+ setPermission(permission) {
1009
+ this._permission = permission;
1010
+ return this;
1011
+ }
1012
+ /**
1013
+ * Set the interaction as ephemeral.
1014
+ *
1015
+ * @public
1016
+ * @returns {this}
1017
+ */
1018
+ setEphemeralReply() {
1019
+ this._ephemeralReply = true;
1020
+ return this;
1021
+ }
1022
+ /**
1023
+ * Build the builder
1024
+ *
1025
+ * @public
1026
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1027
+ */
1028
+ build() {
1029
+ return {
1030
+ data: this,
1031
+ metadata: {
1032
+ active: this._active,
1033
+ ownerOnly: this._ownerOnly,
1034
+ permission: this._permission,
1035
+ ephemeralReply: this._ephemeralReply
1036
+ }
1037
+ };
1038
+ }
1039
+ };
1040
+
1041
+ // src/core/commands/command.base.ts
954
1042
  var Command = class {
955
1043
  /**
956
1044
  * Returns whether the command is a SlashCommand.
@@ -960,7 +1048,7 @@ var Command = class {
960
1048
  * @returns {this is SlashCommand}
961
1049
  */
962
1050
  isSlashCommand() {
963
- return this.data instanceof SlashCommandBuilder;
1051
+ return this.data instanceof SlashCommandBuilder && this instanceof SlashCommand;
964
1052
  }
965
1053
  /**
966
1054
  * Returns whether the command is a ContextMenuCommand.
@@ -970,7 +1058,7 @@ var Command = class {
970
1058
  * @returns {this is ContextMenuCommand}
971
1059
  */
972
1060
  isContextMenuCommand() {
973
- return this.data instanceof ContextMenuCommandBuilder;
1061
+ return this.data instanceof ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
974
1062
  }
975
1063
  /**
976
1064
  * Returns JSON of the command builder.
@@ -1023,6 +1111,48 @@ var Command = class {
1023
1111
  return memberHasPermission;
1024
1112
  }
1025
1113
  };
1114
+ var SlashCommand = class extends Command {
1115
+ /**
1116
+ * General handler for the command and its subcommand, if applicable.
1117
+ *
1118
+ * @public
1119
+ * @async
1120
+ * @param {TriviousClient} client
1121
+ * @param {ChatInputCommandInteraction} interaction
1122
+ * @returns {*}
1123
+ */
1124
+ async execute(client, interaction) {
1125
+ const { run, reply, metadata } = this;
1126
+ const { options } = interaction;
1127
+ if (run) {
1128
+ const memberHasPermission2 = await this.validateGuildPermission(
1129
+ client,
1130
+ interaction,
1131
+ metadata.permission,
1132
+ false
1133
+ );
1134
+ if (memberHasPermission2) await run(client, interaction);
1135
+ }
1136
+ const subcommands = metadata.subcommands;
1137
+ if (subcommands.size <= 0) return;
1138
+ const subcommand = metadata.subcommands.find(
1139
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1140
+ );
1141
+ if (!subcommand) {
1142
+ await reply(interaction, {
1143
+ content: "Ran subcommand is outdated or does not have a handler!"
1144
+ });
1145
+ return;
1146
+ }
1147
+ const memberHasPermission = await this.validateGuildPermission(
1148
+ client,
1149
+ interaction,
1150
+ subcommand.metadata.permission
1151
+ );
1152
+ if (!memberHasPermission) return;
1153
+ await subcommand.execute(client, interaction);
1154
+ }
1155
+ };
1026
1156
  var CommandBuilder = class extends SlashCommandBuilder {
1027
1157
  _active = true;
1028
1158
  _guildOnly = false;
@@ -1188,92 +1318,6 @@ var Subcommand = class {
1188
1318
  await interaction.reply(newOptions);
1189
1319
  }
1190
1320
  };
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
1321
 
1278
1322
  // src/core/components/component.base.ts
1279
1323
  var ComponentBuilder = class {
@@ -1376,6 +1420,6 @@ var Component = class {
1376
1420
  }
1377
1421
  };
1378
1422
 
1379
- export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
1423
+ export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, SlashCommand, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
1380
1424
  //# sourceMappingURL=index.js.map
1381
1425
  //# sourceMappingURL=index.js.map