trivious 1.3.7 → 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';
@@ -543,14 +543,12 @@ async function exists(path2) {
543
543
  function hasPermission(client, options) {
544
544
  const { permission, user, member } = options;
545
545
  if (user) {
546
- if (permission === 5 /* BOT_OWNER */) {
547
- return !(user.id === "424764032667484171");
548
- }
546
+ if (permission === 5 /* BOT_OWNER */) return user.id === "424764032667484171";
549
547
  return true;
550
548
  }
551
549
  if (member) {
552
550
  const memberPermission = getPermissionLevel(client, member);
553
- return permission > memberPermission;
551
+ return memberPermission >= permission;
554
552
  }
555
553
  return false;
556
554
  }
@@ -953,6 +951,94 @@ var TriviousClient = class extends Client {
953
951
  return this._options.rolePermissions ?? {};
954
952
  }
955
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
956
1042
  var Command = class {
957
1043
  /**
958
1044
  * Returns whether the command is a SlashCommand.
@@ -962,7 +1048,7 @@ var Command = class {
962
1048
  * @returns {this is SlashCommand}
963
1049
  */
964
1050
  isSlashCommand() {
965
- return this.data instanceof SlashCommandBuilder;
1051
+ return this.data instanceof SlashCommandBuilder && this instanceof SlashCommand;
966
1052
  }
967
1053
  /**
968
1054
  * Returns whether the command is a ContextMenuCommand.
@@ -972,7 +1058,7 @@ var Command = class {
972
1058
  * @returns {this is ContextMenuCommand}
973
1059
  */
974
1060
  isContextMenuCommand() {
975
- return this.data instanceof ContextMenuCommandBuilder;
1061
+ return this.data instanceof ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
976
1062
  }
977
1063
  /**
978
1064
  * Returns JSON of the command builder.
@@ -1025,6 +1111,48 @@ var Command = class {
1025
1111
  return memberHasPermission;
1026
1112
  }
1027
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
+ };
1028
1156
  var CommandBuilder = class extends SlashCommandBuilder {
1029
1157
  _active = true;
1030
1158
  _guildOnly = false;
@@ -1190,92 +1318,6 @@ var Subcommand = class {
1190
1318
  await interaction.reply(newOptions);
1191
1319
  }
1192
1320
  };
1193
- var ContextMenuCommand = class extends Command {
1194
- /**
1195
- * Base command handler.
1196
- *
1197
- * @public
1198
- * @async
1199
- * @param {TriviousClient} client
1200
- * @param {ContextMenuCommandInteraction} interaction
1201
- * @returns {*}
1202
- */
1203
- async execute(client, interaction) {
1204
- const { run, metadata } = this;
1205
- const memberHasPermission = await this.validateGuildPermission(
1206
- client,
1207
- interaction,
1208
- metadata.permission,
1209
- false
1210
- );
1211
- if (memberHasPermission) await run(client, interaction);
1212
- }
1213
- };
1214
- var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
1215
- _active = true;
1216
- _ownerOnly = false;
1217
- _permission = 0 /* USER */;
1218
- _ephemeralReply = false;
1219
- /**
1220
- * Set the command as disabled.
1221
- *
1222
- * @public
1223
- * @returns {this}
1224
- */
1225
- disable() {
1226
- this._active = false;
1227
- return this;
1228
- }
1229
- /**
1230
- * Set the command as owner only.
1231
- *
1232
- * @public
1233
- * @returns {this}
1234
- */
1235
- setOwnerOnly() {
1236
- this._permission = 5 /* BOT_OWNER */;
1237
- this._ownerOnly = true;
1238
- return this;
1239
- }
1240
- /**
1241
- * Set the permission level required to run the command.
1242
- *
1243
- * @public
1244
- * @param {PermissionLevel} permission
1245
- * @returns {this}
1246
- */
1247
- setPermission(permission) {
1248
- this._permission = permission;
1249
- return this;
1250
- }
1251
- /**
1252
- * Set the interaction as ephemeral.
1253
- *
1254
- * @public
1255
- * @returns {this}
1256
- */
1257
- setEphemeralReply() {
1258
- this._ephemeralReply = true;
1259
- return this;
1260
- }
1261
- /**
1262
- * Build the builder
1263
- *
1264
- * @public
1265
- * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1266
- */
1267
- build() {
1268
- return {
1269
- data: this,
1270
- metadata: {
1271
- active: this._active,
1272
- ownerOnly: this._ownerOnly,
1273
- permission: this._permission,
1274
- ephemeralReply: this._ephemeralReply
1275
- }
1276
- };
1277
- }
1278
- };
1279
1321
 
1280
1322
  // src/core/components/component.base.ts
1281
1323
  var ComponentBuilder = class {
@@ -1378,6 +1420,6 @@ var Component = class {
1378
1420
  }
1379
1421
  };
1380
1422
 
1381
- 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 };
1382
1424
  //# sourceMappingURL=index.js.map
1383
1425
  //# sourceMappingURL=index.js.map