@open-discord-bots/framework 0.4.8 → 0.5.0

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/api/main.js CHANGED
@@ -44,7 +44,7 @@ export class ODMain {
44
44
  constructor(managers, project) {
45
45
  this.project = project;
46
46
  this.versions = managers.versions;
47
- this.versions.add(ODVersion.fromString("opendiscord:api", "v0.4.8"));
47
+ this.versions.add(ODVersion.fromString("opendiscord:api", "v0.5.0"));
48
48
  this.versions.add(ODVersion.fromString("opendiscord:livestatus", "v2.0.0"));
49
49
  this.debugfile = managers.debugfile;
50
50
  this.console = managers.console;
@@ -351,7 +351,9 @@ export declare class ODDropdownResponderInstanceValues {
351
351
  /**Get the selected users. */
352
352
  getUserValues(): Promise<discord.User[]>;
353
353
  /**Get the selected channels. */
354
- getChannelValues(): Promise<discord.GuildBasedChannel[]>;
354
+ getChannelValues(): Promise<discord.Channel[]>;
355
+ /**Get the selected mentionables. */
356
+ getMentionableValues(): Promise<(discord.User | discord.Role)[]>;
355
357
  }
356
358
  /**## ODDropdownResponderInstance `class`
357
359
  * This is an Open Discord dropdown responder instance.
@@ -458,6 +460,25 @@ export declare class ODModalResponderInstanceValues {
458
460
  /**Get the value of a text field. */
459
461
  getTextField(name: string, required: true): string;
460
462
  getTextField(name: string, required: false): string | null;
463
+ /**Get the state of a single checkbox field. */
464
+ getSingleCheckbox(name: string): boolean;
465
+ /**Get the selected checkboxes of a checkbox group. */
466
+ getCheckboxGroup(name: string): string[];
467
+ /**Get the selected value of a radio group. */
468
+ getRadioGroup(name: string, required: true): string;
469
+ getRadioGroup(name: string, required: false): string | null;
470
+ /**Get the selected values of a string/text dropdown. */
471
+ getStringDropdownValues(name: string): string[];
472
+ /**Get the selected values of a role dropdown. */
473
+ getRoleDropdownValues(name: string): Promise<discord.Role[]>;
474
+ /**Get the selected values of a user dropdown. */
475
+ getUserDropdownValues(name: string): Promise<discord.User[]>;
476
+ /**Get selected values of a channel dropdown. */
477
+ getChannelDropdownValues(name: string): Promise<discord.Channel[]>;
478
+ /**Get the selected values of a mentionable dropdown. */
479
+ getMentionableDropdownValues(name: string): Promise<(discord.User | discord.Role)[]>;
480
+ /**Get the uploaded files of a modal file upload component. */
481
+ getUploadedFiles(name: string): Promise<discord.Attachment[]>;
461
482
  }
462
483
  /**## ODModalResponderInstance `class`
463
484
  * This is an Open Discord modal responder instance.
@@ -781,6 +781,8 @@ export class ODDropdownResponderInstanceValues {
781
781
  }
782
782
  /**Get the selected values. */
783
783
  getStringValues() {
784
+ if (this.type != "string" || !this.interaction.isStringSelectMenu())
785
+ throw new ODSystemError("ODDropdownResponderInstanceValues:getStringValues() dropdown type isn't 'role'!");
784
786
  try {
785
787
  return this.interaction.values;
786
788
  }
@@ -791,16 +793,20 @@ export class ODDropdownResponderInstanceValues {
791
793
  }
792
794
  /**Get the selected roles. */
793
795
  async getRoleValues() {
794
- if (this.type != "role")
795
- throw new ODSystemError("ODDropdownResponderInstanceValues:getRoleValues() dropdown type isn't role!");
796
+ if (this.type != "role" || !this.interaction.isRoleSelectMenu())
797
+ throw new ODSystemError("ODDropdownResponderInstanceValues:getRoleValues() dropdown type isn't 'role'!");
796
798
  try {
797
799
  const result = [];
798
- for (const id of this.interaction.values) {
799
- if (!this.interaction.guild)
800
- break;
801
- const role = await this.interaction.guild.roles.fetch(id);
802
- if (role)
800
+ if (!this.interaction.guild)
801
+ return result;
802
+ for (const role of this.interaction.roles.toJSON()) {
803
+ if (role instanceof discord.Role)
803
804
  result.push(role);
805
+ else {
806
+ const fetchedRole = await this.interaction.guild.roles.fetch(role.id);
807
+ if (fetchedRole)
808
+ result.push(fetchedRole);
809
+ }
804
810
  }
805
811
  return result;
806
812
  }
@@ -811,16 +817,10 @@ export class ODDropdownResponderInstanceValues {
811
817
  }
812
818
  /**Get the selected users. */
813
819
  async getUserValues() {
814
- if (this.type != "role")
815
- throw new ODSystemError("ODDropdownResponderInstanceValues:getUserValues() dropdown type isn't user!");
820
+ if (this.type != "user" || !this.interaction.isUserSelectMenu())
821
+ throw new ODSystemError("ODDropdownResponderInstanceValues:getUserValues() dropdown type isn't 'user'!");
816
822
  try {
817
- const result = [];
818
- for (const id of this.interaction.values) {
819
- const user = await this.interaction.client.users.fetch(id);
820
- if (user)
821
- result.push(user);
822
- }
823
- return result;
823
+ return this.interaction.users.toJSON();
824
824
  }
825
825
  catch (err) {
826
826
  process.emit("uncaughtException", err);
@@ -829,16 +829,18 @@ export class ODDropdownResponderInstanceValues {
829
829
  }
830
830
  /**Get the selected channels. */
831
831
  async getChannelValues() {
832
- if (this.type != "role")
833
- throw new ODSystemError("ODDropdownResponderInstanceValues:getChannelValues() dropdown type isn't channel!");
832
+ if (this.type != "channel" || !this.interaction.isChannelSelectMenu())
833
+ throw new ODSystemError("ODDropdownResponderInstanceValues:getChannelValues() dropdown type isn't 'channel'!");
834
834
  try {
835
835
  const result = [];
836
- for (const id of this.interaction.values) {
837
- if (!this.interaction.guild)
838
- break;
839
- const guild = await this.interaction.guild.channels.fetch(id);
840
- if (guild)
841
- result.push(guild);
836
+ for (const channel of this.interaction.channels.toJSON()) {
837
+ if (channel instanceof discord.BaseChannel)
838
+ result.push(channel);
839
+ else {
840
+ const fetchedChannel = await this.interaction.client.channels.fetch(channel.id);
841
+ if (fetchedChannel)
842
+ result.push(fetchedChannel);
843
+ }
842
844
  }
843
845
  return result;
844
846
  }
@@ -847,6 +849,31 @@ export class ODDropdownResponderInstanceValues {
847
849
  throw new ODSystemError("ODDropdownResponderInstanceValues:getChannelValues() invalid values!");
848
850
  }
849
851
  }
852
+ /**Get the selected mentionables. */
853
+ async getMentionableValues() {
854
+ if (this.type != "mentionable" || !this.interaction.isMentionableSelectMenu())
855
+ throw new ODSystemError("ODDropdownResponderInstanceValues:getMentionableValues() dropdown type isn't 'mentionable'!");
856
+ try {
857
+ const result = [];
858
+ result.push(...this.interaction.users.toJSON());
859
+ if (!this.interaction.guild)
860
+ return result;
861
+ for (const role of this.interaction.roles.toJSON()) {
862
+ if (role instanceof discord.Role)
863
+ result.push(role);
864
+ else {
865
+ const fetchedRole = await this.interaction.guild.roles.fetch(role.id);
866
+ if (fetchedRole)
867
+ result.push(fetchedRole);
868
+ }
869
+ }
870
+ return result;
871
+ }
872
+ catch (err) {
873
+ process.emit("uncaughtException", err);
874
+ throw new ODSystemError("ODDropdownResponderInstanceValues:getMentionableValues() invalid values!");
875
+ }
876
+ }
850
877
  }
851
878
  /**## ODDropdownResponderInstance `class`
852
879
  * This is an Open Discord dropdown responder instance.
@@ -1089,16 +1116,149 @@ export class ODModalResponderInstanceValues {
1089
1116
  }
1090
1117
  getTextField(name, required) {
1091
1118
  try {
1092
- const data = this.interaction.fields.getField(name, discord.ComponentType.TextInput);
1093
- if (!data && required)
1094
- throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field not found!");
1095
- return (data) ? data.value : null;
1119
+ const data = this.interaction.fields.getTextInputValue(name);
1120
+ if (data.length < 1 && required)
1121
+ throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field required, found empty!");
1122
+ return (data.length < 1) ? data : null;
1096
1123
  }
1097
1124
  catch (err) {
1098
1125
  process.emit("uncaughtException", err);
1099
1126
  throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field not found!");
1100
1127
  }
1101
1128
  }
1129
+ /**Get the state of a single checkbox field. */
1130
+ getSingleCheckbox(name) {
1131
+ try {
1132
+ return this.interaction.fields.getCheckbox(name);
1133
+ }
1134
+ catch (err) {
1135
+ process.emit("uncaughtException", err);
1136
+ throw new ODSystemError("ODModalResponderInstanceValues:getSingleCheckbox() field not found!");
1137
+ }
1138
+ }
1139
+ /**Get the selected checkboxes of a checkbox group. */
1140
+ getCheckboxGroup(name) {
1141
+ try {
1142
+ return [...this.interaction.fields.getCheckboxGroup(name)];
1143
+ }
1144
+ catch (err) {
1145
+ process.emit("uncaughtException", err);
1146
+ throw new ODSystemError("ODModalResponderInstanceValues:getCheckboxGroup() field not found!");
1147
+ }
1148
+ }
1149
+ getRadioGroup(name, required) {
1150
+ try {
1151
+ const data = this.interaction.fields.getRadioGroup(name);
1152
+ if (typeof data !== "string" && required)
1153
+ throw new ODSystemError("ODModalResponderInstanceValues:getRadioGroup() field required, found empty!");
1154
+ return data;
1155
+ }
1156
+ catch (err) {
1157
+ process.emit("uncaughtException", err);
1158
+ throw new ODSystemError("ODModalResponderInstanceValues:getRadioGroup() field not found!");
1159
+ }
1160
+ }
1161
+ /**Get the selected values of a string/text dropdown. */
1162
+ getStringDropdownValues(name) {
1163
+ try {
1164
+ return [...this.interaction.fields.getStringSelectValues(name)];
1165
+ }
1166
+ catch (err) {
1167
+ process.emit("uncaughtException", err);
1168
+ throw new ODSystemError("ODModalResponderInstanceValues:getStringDropdownValues() field not found!");
1169
+ }
1170
+ }
1171
+ /**Get the selected values of a role dropdown. */
1172
+ async getRoleDropdownValues(name) {
1173
+ try {
1174
+ const result = [];
1175
+ if (!this.interaction.guild)
1176
+ return result;
1177
+ for (const role of (this.interaction.fields.getSelectedRoles(name)?.toJSON() ?? [])) {
1178
+ if (!role)
1179
+ continue;
1180
+ else if (role instanceof discord.Role)
1181
+ result.push(role);
1182
+ else {
1183
+ const fetchedRole = await this.interaction.guild.roles.fetch(role.id);
1184
+ if (fetchedRole)
1185
+ result.push(fetchedRole);
1186
+ }
1187
+ }
1188
+ return result;
1189
+ }
1190
+ catch (err) {
1191
+ process.emit("uncaughtException", err);
1192
+ throw new ODSystemError("ODModalResponderInstanceValues:getRoleDropdownValues() field not found!");
1193
+ }
1194
+ }
1195
+ /**Get the selected values of a user dropdown. */
1196
+ async getUserDropdownValues(name) {
1197
+ try {
1198
+ const result = (this.interaction.fields.getSelectedUsers(name)?.toJSON() ?? []);
1199
+ return result;
1200
+ }
1201
+ catch (err) {
1202
+ process.emit("uncaughtException", err);
1203
+ throw new ODSystemError("ODModalResponderInstanceValues:getUserDropdownValues() field not found!");
1204
+ }
1205
+ }
1206
+ /**Get selected values of a channel dropdown. */
1207
+ async getChannelDropdownValues(name) {
1208
+ try {
1209
+ const result = [];
1210
+ for (const channel of (this.interaction.fields.getSelectedChannels(name)?.toJSON() ?? [])) {
1211
+ if (channel instanceof discord.BaseChannel)
1212
+ result.push(channel);
1213
+ else {
1214
+ const fetchedChannel = await this.interaction.client.channels.fetch(channel.id);
1215
+ if (fetchedChannel)
1216
+ result.push(fetchedChannel);
1217
+ }
1218
+ }
1219
+ return result;
1220
+ }
1221
+ catch (err) {
1222
+ process.emit("uncaughtException", err);
1223
+ throw new ODSystemError("ODModalResponderInstanceValues:getChannelDropdownValues() field not found!");
1224
+ }
1225
+ }
1226
+ /**Get the selected values of a mentionable dropdown. */
1227
+ async getMentionableDropdownValues(name) {
1228
+ try {
1229
+ const result = [];
1230
+ result.push(...(this.interaction.fields.getSelectedUsers(name)?.toJSON() ?? []));
1231
+ if (!this.interaction.guild)
1232
+ return result;
1233
+ for (const role of (this.interaction.fields.getSelectedRoles(name)?.toJSON() ?? [])) {
1234
+ if (!role)
1235
+ continue;
1236
+ else if (role instanceof discord.Role)
1237
+ result.push(role);
1238
+ else {
1239
+ const fetchedRole = await this.interaction.guild.roles.fetch(role.id);
1240
+ if (fetchedRole)
1241
+ result.push(fetchedRole);
1242
+ }
1243
+ }
1244
+ return result;
1245
+ }
1246
+ catch (err) {
1247
+ process.emit("uncaughtException", err);
1248
+ throw new ODSystemError("ODModalResponderInstanceValues:getMentionableDropdownValues() field not found!");
1249
+ }
1250
+ }
1251
+ /**Get the uploaded files of a modal file upload component. */
1252
+ async getUploadedFiles(name) {
1253
+ try {
1254
+ const result = (this.interaction.fields.getUploadedFiles(name)?.toJSON() ?? []);
1255
+ return result;
1256
+ }
1257
+ catch (err) {
1258
+ process.emit("uncaughtException", err);
1259
+ throw new ODSystemError("ODModalResponderInstanceValues:getUploadedFiles() field not found!");
1260
+ }
1261
+ }
1102
1262
  }
1103
1263
  /**## ODModalResponderInstance `class`
1104
1264
  * This is an Open Discord modal responder instance.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-discord-bots/framework",
3
3
  "author": "DJj123dj",
4
- "version": "0.4.8",
4
+ "version": "0.5.0",
5
5
  "description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",