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.cjs CHANGED
@@ -957,6 +957,94 @@ var TriviousClient = class extends discord_js.Client {
957
957
  return this._options.rolePermissions ?? {};
958
958
  }
959
959
  };
960
+ var ContextMenuCommand = class extends Command {
961
+ /**
962
+ * Base command handler.
963
+ *
964
+ * @public
965
+ * @async
966
+ * @param {TriviousClient} client
967
+ * @param {ContextMenuCommandInteraction} interaction
968
+ * @returns {*}
969
+ */
970
+ async execute(client, interaction) {
971
+ const { run, metadata } = this;
972
+ const memberHasPermission = await this.validateGuildPermission(
973
+ client,
974
+ interaction,
975
+ metadata.permission,
976
+ false
977
+ );
978
+ if (memberHasPermission) await run(client, interaction);
979
+ }
980
+ };
981
+ var ContextMenuBuilder = class extends discord_js.ContextMenuCommandBuilder {
982
+ _active = true;
983
+ _ownerOnly = false;
984
+ _permission = 0 /* USER */;
985
+ _ephemeralReply = false;
986
+ /**
987
+ * Set the command as disabled.
988
+ *
989
+ * @public
990
+ * @returns {this}
991
+ */
992
+ disable() {
993
+ this._active = false;
994
+ return this;
995
+ }
996
+ /**
997
+ * Set the command as owner only.
998
+ *
999
+ * @public
1000
+ * @returns {this}
1001
+ */
1002
+ setOwnerOnly() {
1003
+ this._permission = 5 /* BOT_OWNER */;
1004
+ this._ownerOnly = true;
1005
+ return this;
1006
+ }
1007
+ /**
1008
+ * Set the permission level required to run the command.
1009
+ *
1010
+ * @public
1011
+ * @param {PermissionLevel} permission
1012
+ * @returns {this}
1013
+ */
1014
+ setPermission(permission) {
1015
+ this._permission = permission;
1016
+ return this;
1017
+ }
1018
+ /**
1019
+ * Set the interaction as ephemeral.
1020
+ *
1021
+ * @public
1022
+ * @returns {this}
1023
+ */
1024
+ setEphemeralReply() {
1025
+ this._ephemeralReply = true;
1026
+ return this;
1027
+ }
1028
+ /**
1029
+ * Build the builder
1030
+ *
1031
+ * @public
1032
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1033
+ */
1034
+ build() {
1035
+ return {
1036
+ data: this,
1037
+ metadata: {
1038
+ active: this._active,
1039
+ ownerOnly: this._ownerOnly,
1040
+ permission: this._permission,
1041
+ ephemeralReply: this._ephemeralReply
1042
+ }
1043
+ };
1044
+ }
1045
+ };
1046
+
1047
+ // src/core/commands/command.base.ts
960
1048
  var Command = class {
961
1049
  /**
962
1050
  * Returns whether the command is a SlashCommand.
@@ -966,7 +1054,7 @@ var Command = class {
966
1054
  * @returns {this is SlashCommand}
967
1055
  */
968
1056
  isSlashCommand() {
969
- return this.data instanceof discord_js.SlashCommandBuilder;
1057
+ return this.data instanceof discord_js.SlashCommandBuilder && this instanceof SlashCommand;
970
1058
  }
971
1059
  /**
972
1060
  * Returns whether the command is a ContextMenuCommand.
@@ -976,7 +1064,7 @@ var Command = class {
976
1064
  * @returns {this is ContextMenuCommand}
977
1065
  */
978
1066
  isContextMenuCommand() {
979
- return this.data instanceof discord_js.ContextMenuCommandBuilder;
1067
+ return this.data instanceof discord_js.ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
980
1068
  }
981
1069
  /**
982
1070
  * Returns JSON of the command builder.
@@ -1029,6 +1117,48 @@ var Command = class {
1029
1117
  return memberHasPermission;
1030
1118
  }
1031
1119
  };
1120
+ var SlashCommand = class extends Command {
1121
+ /**
1122
+ * General handler for the command and its subcommand, if applicable.
1123
+ *
1124
+ * @public
1125
+ * @async
1126
+ * @param {TriviousClient} client
1127
+ * @param {ChatInputCommandInteraction} interaction
1128
+ * @returns {*}
1129
+ */
1130
+ async execute(client, interaction) {
1131
+ const { run, reply, metadata } = this;
1132
+ const { options } = interaction;
1133
+ if (run) {
1134
+ const memberHasPermission2 = await this.validateGuildPermission(
1135
+ client,
1136
+ interaction,
1137
+ metadata.permission,
1138
+ false
1139
+ );
1140
+ if (memberHasPermission2) await run(client, interaction);
1141
+ }
1142
+ const subcommands = metadata.subcommands;
1143
+ if (subcommands.size <= 0) return;
1144
+ const subcommand = metadata.subcommands.find(
1145
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1146
+ );
1147
+ if (!subcommand) {
1148
+ await reply(interaction, {
1149
+ content: "Ran subcommand is outdated or does not have a handler!"
1150
+ });
1151
+ return;
1152
+ }
1153
+ const memberHasPermission = await this.validateGuildPermission(
1154
+ client,
1155
+ interaction,
1156
+ subcommand.metadata.permission
1157
+ );
1158
+ if (!memberHasPermission) return;
1159
+ await subcommand.execute(client, interaction);
1160
+ }
1161
+ };
1032
1162
  var CommandBuilder = class extends discord_js.SlashCommandBuilder {
1033
1163
  _active = true;
1034
1164
  _guildOnly = false;
@@ -1194,92 +1324,6 @@ var Subcommand = class {
1194
1324
  await interaction.reply(newOptions);
1195
1325
  }
1196
1326
  };
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
1327
 
1284
1328
  // src/core/components/component.base.ts
1285
1329
  var ComponentBuilder = class {
@@ -1401,6 +1445,7 @@ exports.ComponentType = ComponentType;
1401
1445
  exports.ContextMenuBuilder = ContextMenuBuilder;
1402
1446
  exports.ContextMenuCommand = ContextMenuCommand;
1403
1447
  exports.PermissionLevel = PermissionLevel;
1448
+ exports.SlashCommand = SlashCommand;
1404
1449
  exports.Subcommand = Subcommand;
1405
1450
  exports.SubcommandBuilder = SubcommandBuilder;
1406
1451
  exports.TriviousClient = TriviousClient;