@open-discord-bots/framework 0.3.3 → 0.3.4

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.
@@ -123,7 +123,7 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
123
123
  }
124
124
  /**Get all servers the bot is part of. */
125
125
  async getGuilds(): Promise<discord.Guild[]> {
126
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
126
+ if (!this.initiated) throw new ODSystemError("ODClientManager() => Unable to use this method. Client isn't initiated yet.")
127
127
  if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
128
128
 
129
129
  return this.client.guilds.cache.map((guild) => guild)
@@ -146,15 +146,15 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
146
146
  /**Log-in with a discord auth token. Rejects returns `false` using 'softErrors' on failure. */
147
147
  login(softErrors?:boolean): Promise<boolean> {
148
148
  return new Promise(async (resolve,reject) => {
149
- if (!this.initiated) reject("Client isn't initiated yet!")
150
- if (!this.token) reject("Client doesn't have a token!")
149
+ if (!this.initiated) reject("ODClientManager.login() => Unable to use this method. Client isn't initiated yet.")
150
+ if (!this.token) reject("ODClientManager.login() => Unable to login, client does not have a token.")
151
151
 
152
152
  try {
153
153
  this.client.once("clientReady",async () => {
154
154
  this.ready = true
155
155
 
156
156
  //set slashCommandManager & contextMenuManager to client applicationCommandManager
157
- if (!this.client.application) throw new ODSystemError("Couldn't get client application for slashCommand & contextMenu managers!")
157
+ if (!this.client.application) throw new ODSystemError("ODClientManager.login() => Unable to fetch client application for slashCommand & contextMenu managers.")
158
158
  this.slashCommands.commandManager = this.client.application.commands
159
159
  this.contextMenus.commandManager = this.client.application.commands
160
160
  this.autocompletes.commandManager = this.client.application.commands
@@ -177,10 +177,10 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
177
177
  }
178
178
  })
179
179
  }
180
- /**A simplified shortcut to get a `discord.User` :) */
180
+ /**A simplified shortcut to get a `discord.User`. */
181
181
  async fetchUser(id:string): Promise<discord.User|null> {
182
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
183
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
182
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchUser() => Unable to use this method. Client isn't initiated yet.")
183
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchUser() => Unable to use this method. Client isn't ready and logged in yet.")
184
184
 
185
185
  try{
186
186
  return await this.client.users.fetch(id)
@@ -188,10 +188,10 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
188
188
  return null
189
189
  }
190
190
  }
191
- /**A simplified shortcut to get a `discord.Guild` :) */
191
+ /**A simplified shortcut to get a `discord.Guild`. */
192
192
  async fetchGuild(id:string): Promise<discord.Guild|null> {
193
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
194
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
193
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchGuild() => Unable to use this method. Client isn't initiated yet.")
194
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchGuild() => Unable to use this method. Client isn't ready and logged in yet.")
195
195
 
196
196
  try{
197
197
  return await this.client.guilds.fetch(id)
@@ -199,10 +199,10 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
199
199
  return null
200
200
  }
201
201
  }
202
- /**A simplified shortcut to get a `discord.Channel` :) */
202
+ /**A simplified shortcut to get a `discord.Channel`. */
203
203
  async fetchChannel(id:string): Promise<discord.Channel|null> {
204
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
205
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
204
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchChannel() => Unable to use this method. Client isn't initiated yet.")
205
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchChannel() => Unable to use this method. Client isn't ready and logged in yet.")
206
206
 
207
207
  try{
208
208
  return await this.client.channels.fetch(id)
@@ -210,10 +210,23 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
210
210
  return null
211
211
  }
212
212
  }
213
- /**A simplified shortcut to get a `discord.GuildBasedChannel` :) */
213
+ /**A simplified shortcut to get a `discord.TextChannel` (guild or DM). */
214
+ async fetchTextChannel(id:string): Promise<discord.TextChannel|discord.DMChannel|discord.PartialDMChannel|null> {
215
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchTextChannel() => Unable to use this method. Client isn't initiated yet.")
216
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchTextChannel() => Unable to use this method. Client isn't ready and logged in yet.")
217
+
218
+ try{
219
+ const channel = await this.client.channels.fetch(id)
220
+ if (!channel || (channel.type != discord.ChannelType.GuildText && channel.type != discord.ChannelType.DM)) return null
221
+ return channel
222
+ }catch{
223
+ return null
224
+ }
225
+ }
226
+ /**A simplified shortcut to get a `discord.GuildBasedChannel`. */
214
227
  async fetchGuildChannel(guildId:string|discord.Guild, id:string): Promise<discord.GuildBasedChannel|null> {
215
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
216
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
228
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchGuildChannel() => Unable to use this method. Client isn't initiated yet.")
229
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchGuildChannel() => Unable to use this method. Client isn't ready and logged in yet.")
217
230
 
218
231
  try{
219
232
  const guild = (guildId instanceof discord.Guild) ? guildId : await this.fetchGuild(guildId)
@@ -224,10 +237,10 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
224
237
  return null
225
238
  }
226
239
  }
227
- /**A simplified shortcut to get a `discord.TextChannel` :) */
240
+ /**A simplified shortcut to get a `discord.TextChannel`. */
228
241
  async fetchGuildTextChannel(guildId:string|discord.Guild, id:string): Promise<discord.TextChannel|null> {
229
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
230
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
242
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchGuildTextChannel() => Unable to use this method. Client isn't initiated yet.")
243
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchGuildTextChannel() => Unable to use this method. Client isn't ready and logged in yet.")
231
244
 
232
245
  try{
233
246
  const guild = (guildId instanceof discord.Guild) ? guildId : await this.fetchGuild(guildId)
@@ -239,10 +252,10 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
239
252
  return null
240
253
  }
241
254
  }
242
- /**A simplified shortcut to get a `discord.CategoryChannel` :) */
255
+ /**A simplified shortcut to get a `discord.CategoryChannel`. */
243
256
  async fetchGuildCategoryChannel(guildId:string|discord.Guild, id:string): Promise<discord.CategoryChannel|null> {
244
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
245
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
257
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchGuildCategoryChannel() => Unable to use this method. Client isn't initiated yet.")
258
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchGuildCategoryChannel() => Unable to use this method. Client isn't ready and logged in yet.")
246
259
 
247
260
  try{
248
261
  const guild = (guildId instanceof discord.Guild) ? guildId : await this.fetchGuild(guildId)
@@ -254,12 +267,11 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
254
267
  return null
255
268
  }
256
269
  }
257
- /**A simplified shortcut to get a `discord.GuildMember` :) */
270
+ /**A simplified shortcut to get a `discord.GuildMember`. */
258
271
  async fetchGuildMember(guildId:string|discord.Guild, id:string): Promise<discord.GuildMember|null> {
259
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
260
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
261
- if (typeof id != "string") throw new ODSystemError("TEMP ERROR => ODClientManager.fetchGuildMember() => id param isn't string")
262
-
272
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchGuildMember() => Unable to use this method. Client isn't initiated yet.")
273
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchGuildMember() => Unable to use this method. Client isn't ready and logged in yet.")
274
+
263
275
  try{
264
276
  const guild = (guildId instanceof discord.Guild) ? guildId : await this.fetchGuild(guildId)
265
277
  if (!guild) return null
@@ -268,12 +280,11 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
268
280
  return null
269
281
  }
270
282
  }
271
- /**A simplified shortcut to get a `discord.Role` :) */
283
+ /**A simplified shortcut to get a `discord.Role`. */
272
284
  async fetchGuildRole(guildId:string|discord.Guild, id:string): Promise<discord.Role|null> {
273
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
274
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
275
- if (typeof id != "string") throw new ODSystemError("TEMP ERROR => ODClientManager.fetchGuildRole() => id param isn't string")
276
-
285
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchGuildRole() => Unable to use this method. Client isn't initiated yet.")
286
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchGuildRole() => Unable to use this method. Client isn't ready and logged in yet.")
287
+
277
288
  try{
278
289
  const guild = (guildId instanceof discord.Guild) ? guildId : await this.fetchGuild(guildId)
279
290
  if (!guild) return null
@@ -282,30 +293,23 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
282
293
  return null
283
294
  }
284
295
  }
285
- /**A simplified shortcut to get a `discord.Message` :) */
286
- async fetchGuildChannelMessage(guildId:string|discord.Guild, channelId:string|discord.TextChannel, id:string): Promise<discord.Message<true>|null>
287
- async fetchGuildChannelMessage(channelId:discord.TextChannel, id:string): Promise<discord.Message<true>|null>
288
- async fetchGuildChannelMessage(guildId:string|discord.Guild|discord.TextChannel, channelId:string|discord.TextChannel|string, id?:string): Promise<discord.Message<true>|null> {
289
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
290
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
296
+ /**A simplified shortcut to get a `discord.Message`. */
297
+ async fetchChannelMessage(channelId:string|discord.TextChannel|discord.DMChannel, id:string): Promise<discord.Message<boolean>|null> {
298
+ if (!this.initiated) throw new ODSystemError("ODClientManager.fetchChannelMessage() => Unable to use this method. Client isn't initiated yet.")
299
+ if (!this.ready) throw new ODSystemError("ODClientManager.fetchChannelMessage() => Unable to use this method. Client isn't ready and logged in yet.")
291
300
 
292
301
  try{
293
- if (guildId instanceof discord.TextChannel && typeof channelId == "string"){
294
- const channel = guildId
295
- return await channel.messages.fetch(channelId)
296
- }else if (!(guildId instanceof discord.TextChannel) && id){
297
- const channel = (channelId instanceof discord.TextChannel) ? channelId : await this.fetchGuildTextChannel(guildId,channelId)
298
- if (!channel) return null
299
- return await channel.messages.fetch(id)
300
- }else return null
302
+ const channel = (channelId instanceof discord.TextChannel || channelId instanceof discord.DMChannel) ? channelId : await this.fetchTextChannel(channelId)
303
+ if (!channel) return null
304
+ return await channel.messages.fetch(id)
301
305
  }catch{
302
306
  return null
303
307
  }
304
308
  }
305
- /**A simplified shortcut to send a DM to a user :) */
309
+ /**A simplified shortcut to send a DM to a user. */
306
310
  async sendUserDm(user:string|discord.User, build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<false>> {
307
- if (!this.initiated) throw new ODSystemError("Client isn't initiated yet!")
308
- if (!this.ready) throw new ODSystemError("Client isn't ready yet!")
311
+ if (!this.initiated) throw new ODSystemError("ODClientManager.sendUserDm() => Unable to use this method. Client isn't initiated yet.")
312
+ if (!this.ready) throw new ODSystemError("ODClientManager.sendUserDm() => Unable to use this method. Client isn't ready and logged in yet.")
309
313
 
310
314
  try{
311
315
  const msgFlags: number[] = []
@@ -325,26 +329,26 @@ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstrai
325
329
  const finalMessage = Object.assign(msgData,{flags:msgFlags})
326
330
 
327
331
  if (user instanceof discord.User){
328
- if (user.bot) return {success:false,message:null}
332
+ if (user.bot) return {success:false}
329
333
  const channel = await user.createDM()
330
334
  const msg = await channel.send(finalMessage)
331
335
  return {success:true,message:msg}
332
336
  }else{
333
337
  const newUser = await this.fetchUser(user)
334
338
  if (!newUser) throw new Error()
335
- if (newUser.bot) return {success:false,message:null}
339
+ if (newUser.bot) return {success:false}
336
340
  const channel = await newUser.createDM()
337
341
  const msg = await channel.send(finalMessage)
338
342
  return {success:true,message:msg}
339
343
  }
340
344
  }catch{
341
345
  try{
342
- this.debug.console.log("Failed to send DM to user! ","warning",[
346
+ this.debug.console.log("ODClientManager.sendUserDm() => Failed to send DM. User may have DMs disabled for non-friends. ","warning",[
343
347
  {key:"id",value:(user instanceof discord.User ? user.id : user)},
344
348
  {key:"message-build",value:build.id.value}
345
349
  ])
346
350
  }catch{}
347
- return {success:false,message:null}
351
+ return {success:false}
348
352
  }
349
353
  }
350
354
  }
@@ -417,7 +421,7 @@ export class ODClientActivityManager {
417
421
 
418
422
  /**Update the client status */
419
423
  private updateClientActivity(type:ODClientActivityType,text:string){
420
- if (!this.client.client.user) throw new ODSystemError("Couldn't set client status: client.user == undefined")
424
+ if (!this.client.client.user) throw new ODSystemError("ODClientActivityManager.updateClientActivity() => Couldn't set client status: client.user is 'undefined'.")
421
425
  if (type == false){
422
426
  this.client.client.user.setActivity()
423
427
  return
@@ -217,7 +217,9 @@ export class ODError {
217
217
  }
218
218
  /**Create a more-detailed, non-colored version of this error to store it in the `debug.txt` file! */
219
219
  toDebugString(){
220
- return "[UNKNOWN OD ERROR]: "+this.error.message+" | origin: "+this.origin+"\n"+this.error.stack
220
+ const date = new Date()
221
+ const dstring = `${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
222
+ return "["+dstring+" UNKNOWN OPENDISCORD ERROR]: "+this.error.message+" | Error Origin: "+this.origin+" | Stacktrace:\n"+this.error.stack
221
223
  }
222
224
  }
223
225
 
@@ -89,7 +89,7 @@ export abstract class ODDatabase<IdList extends ODDatabaseIdConstraint = ODDatab
89
89
  abstract get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
90
90
  abstract get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
91
91
 
92
- /**Delete a specific category & key in the database */
92
+ /**Delete a specific category & key in the database. Returns `true` when deleted. */
93
93
  abstract delete<CategoryId extends keyof ODNoGeneric<IdList>>(category:CategoryId, key:string): ODOptionalPromise<boolean>
94
94
  abstract delete(category:string, key:string): ODOptionalPromise<boolean>
95
95
  abstract delete(category:string, key:string): ODOptionalPromise<boolean>
@@ -142,9 +142,6 @@ export interface ODSharedFuseList {
142
142
  /**Load the default Open Discord client activity initialization (& status refresh). */
143
143
  clientActivityInitiating:boolean,
144
144
 
145
- /**Load the default Open Discord priority levels. */
146
- priorityLoading:boolean,
147
-
148
145
  /**Load the default Open Discord slash commands. */
149
146
  slashCommandLoading:boolean,
150
147
  /**Load the default Open Discord slash command registerer (register slash cmds in discord). */
@@ -164,6 +161,11 @@ export interface ODSharedFuseList {
164
161
  /**Load the default Open Discord text commands. */
165
162
  textCommandLoading:boolean,
166
163
 
164
+ /**Load the default Open Discord message states. */
165
+ stateLoading:boolean,
166
+ /**Initiate the default Open Discord message states. */
167
+ stateInitiating:boolean,
168
+
167
169
  /**Load the default Open Discord button builders. */
168
170
  buttonBuildersLoading:boolean,
169
171
  /**Load the default Open Discord dropdown builders. */
@@ -298,8 +300,6 @@ export class ODSharedFuseManager extends ODFuseManager<ODSharedFuseList> {
298
300
  clientActivityLoading:true,
299
301
  clientActivityInitiating:true,
300
302
 
301
- priorityLoading:true,
302
-
303
303
  slashCommandLoading:true,
304
304
  slashCommandRegistering:true,
305
305
  forceSlashCommandRegistration:false,
@@ -310,6 +310,9 @@ export class ODSharedFuseManager extends ODFuseManager<ODSharedFuseList> {
310
310
  allowContextMenuRemoval:true,
311
311
  textCommandLoading:true,
312
312
 
313
+ stateLoading:true,
314
+ stateInitiating:true,
315
+
313
316
  buttonBuildersLoading:true,
314
317
  dropdownBuildersLoading:true,
315
318
  fileBuildersLoading:true,
@@ -107,13 +107,13 @@ export class ODPost<ChannelType extends discord.GuildBasedChannel> extends ODMan
107
107
  }
108
108
  /**Send a message to this channel using the Open Discord builder system */
109
109
  async send(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<true>> {
110
- if (!this.channel || !this.channel.isTextBased()) return {success:false,message:null}
110
+ if (!this.channel || !this.channel.isTextBased()) return {success:false}
111
111
  try{
112
112
  const finalMessage = this.getMessageFromBuildResult(build,"message")
113
113
  const sent = await this.channel.send(finalMessage)
114
114
  return {success:true,message:sent}
115
115
  }catch{
116
- return {success:false,message:null}
116
+ return {success:false}
117
117
  }
118
118
  }
119
119
  /**Get the final `messageCreateOptions` from a returned build result from builders/components. */
@@ -47,9 +47,7 @@ export type ODResponderSendResult<InGuild extends boolean> = {
47
47
  message:discord.Message<InGuild>
48
48
  } | {
49
49
  /**Did the message get sent successfully? */
50
- success:boolean,
51
- /**The message that got sent. */
52
- message:null
50
+ success:false
53
51
  }
54
52
 
55
53
  /**## ODResponderManager `class`
@@ -485,9 +483,9 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
485
483
  const sent = await this.interaction.channel.send(finalMessage)
486
484
  this.ignoreResponderTimeout = true
487
485
  return {success:true,message:sent}
488
- }else return {success:false,message:null}
486
+ }else return {success:false}
489
487
  }catch{
490
- return {success:false,message:null}
488
+ return {success:false}
491
489
  }
492
490
  }
493
491
  /**Defer this command. */
@@ -670,7 +668,7 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
670
668
  return {success:true,message:await sent.fetch()}
671
669
  }
672
670
  }catch{
673
- return {success:false,message:null}
671
+ return {success:false}
674
672
  }
675
673
  }
676
674
  /**Update the message of this button. */
@@ -687,7 +685,7 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
687
685
  return {success:true,message:await sent.fetch()}
688
686
  }
689
687
  }catch{
690
- return {success:false,message:null}
688
+ return {success:false}
691
689
  }
692
690
  }
693
691
  /**Defer this button. */
@@ -985,7 +983,7 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
985
983
  return {success:true,message:await sent.fetch()}
986
984
  }
987
985
  }catch{
988
- return {success:false,message:null}
986
+ return {success:false}
989
987
  }
990
988
  }
991
989
  /**Update the message of this dropdown. */
@@ -1002,7 +1000,7 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
1002
1000
  return {success:true,message:await sent.fetch()}
1003
1001
  }
1004
1002
  }catch{
1005
- return {success:false,message:null}
1003
+ return {success:false}
1006
1004
  }
1007
1005
  }
1008
1006
  /**Defer this dropdown. */
@@ -1229,7 +1227,7 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1229
1227
  this.ignoreResponderTimeout = true
1230
1228
  return {success:true,message:sent}
1231
1229
  }catch{
1232
- return {success:false,message:null}
1230
+ return {success:false}
1233
1231
  }
1234
1232
  }
1235
1233
  /**Update the message of this modal. */
@@ -1246,7 +1244,7 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1246
1244
  return {success:true,message:await sent.fetch()}
1247
1245
  }
1248
1246
  }catch{
1249
- return {success:false,message:null}
1247
+ return {success:false}
1250
1248
  }
1251
1249
  }
1252
1250
  /**Defer this modal. */
@@ -1414,7 +1412,7 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1414
1412
  return {success:true,message:await sent.fetch()}
1415
1413
  }
1416
1414
  }catch{
1417
- return {success:false,message:null}
1415
+ return {success:false}
1418
1416
  }
1419
1417
  }
1420
1418
  /**Update the message of this context menu. */
@@ -1427,7 +1425,7 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1427
1425
  return {success:true,message:await sent.fetch()}
1428
1426
  }else throw new ODSystemError("Unable to update context menu interaction!")
1429
1427
  }catch{
1430
- return {success:false,message:null}
1428
+ return {success:false}
1431
1429
  }
1432
1430
  }
1433
1431
  /**Defer this context menu. */