Roles#fetch -> Roles#fetchAll & jsdoc
This commit is contained in:
		
							parent
							
								
									b13cdbe480
								
							
						
					
					
						commit
						b324263a7b
					
				
					 4 changed files with 32 additions and 13 deletions
				
			
		|  | @ -71,7 +71,7 @@ export interface ClientOptions { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Discord Client. |  * Harmony Client. Provides high-level interface over the REST and WebSocket API. | ||||||
|  */ |  */ | ||||||
| export class Client extends HarmonyEventEmitter<ClientEvents> { | export class Client extends HarmonyEventEmitter<ClientEvents> { | ||||||
|   /** REST Manager - used to make all requests */ |   /** REST Manager - used to make all requests */ | ||||||
|  | @ -148,9 +148,9 @@ export class Client extends HarmonyEventEmitter<ClientEvents> { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /** Get Shard 0's Gateway */ | ||||||
|   get gateway(): Gateway { |   get gateway(): Gateway { | ||||||
|     // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
 |     return this.shards.list.get('0')! | ||||||
|     return this.shards.list.get('0') as Gateway |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   applicationID?: string |   applicationID?: string | ||||||
|  | @ -289,7 +289,10 @@ export class Client extends HarmonyEventEmitter<ClientEvents> { | ||||||
|    * @param token Your token. This is required if not given in ClientOptions. |    * @param token Your token. This is required if not given in ClientOptions. | ||||||
|    * @param intents Gateway intents in array. This is required if not given in ClientOptions. |    * @param intents Gateway intents in array. This is required if not given in ClientOptions. | ||||||
|    */ |    */ | ||||||
|   async connect(token?: string, intents?: GatewayIntents[]): Promise<Client> { |   async connect( | ||||||
|  |     token?: string, | ||||||
|  |     intents?: Array<GatewayIntents | keyof typeof GatewayIntents> | ||||||
|  |   ): Promise<Client> { | ||||||
|     token ??= this.token |     token ??= this.token | ||||||
|     if (token === undefined) throw new Error('No Token Provided') |     if (token === undefined) throw new Error('No Token Provided') | ||||||
|     this.token = token |     this.token = token | ||||||
|  | @ -301,7 +304,9 @@ export class Client extends HarmonyEventEmitter<ClientEvents> { | ||||||
|     } else if (intents === undefined && this.intents !== undefined) { |     } else if (intents === undefined && this.intents !== undefined) { | ||||||
|       intents = this.intents |       intents = this.intents | ||||||
|     } else if (intents !== undefined && this.intents === undefined) { |     } else if (intents !== undefined && this.intents === undefined) { | ||||||
|       this.intents = intents |       this.intents = intents.map((e) => | ||||||
|  |         typeof e === 'string' ? GatewayIntents[e] : e | ||||||
|  |       ) | ||||||
|     } else throw new Error('No Gateway Intents were provided') |     } else throw new Error('No Gateway Intents were provided') | ||||||
| 
 | 
 | ||||||
|     this.rest.token = token |     this.rest.token = token | ||||||
|  |  | ||||||
|  | @ -43,6 +43,11 @@ export interface CommandClientOptions extends ClientOptions { | ||||||
|   caseSensitive?: boolean |   caseSensitive?: boolean | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * Harmony Client with extended functionality for Message based Commands parsing and handling. | ||||||
|  |  * | ||||||
|  |  * See SlashClient (`Client#slash`) for more info about Slash Commands. | ||||||
|  |  */ | ||||||
| export class CommandClient extends Client implements CommandClientOptions { | export class CommandClient extends Client implements CommandClientOptions { | ||||||
|   prefix: string | string[] |   prefix: string | string[] | ||||||
|   mentionPrefix: boolean |   mentionPrefix: boolean | ||||||
|  | @ -372,7 +377,9 @@ export class CommandClient extends Client implements CommandClientOptions { | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** Command decorator */ | /** | ||||||
|  |  * Command decorator. Decorates the function with optional metadata as a Command registered upon constructing class. | ||||||
|  |  */ | ||||||
| export function command(options?: CommandOptions) { | export function command(options?: CommandOptions) { | ||||||
|   return function (target: CommandClient | Extension, name: string) { |   return function (target: CommandClient | Extension, name: string) { | ||||||
|     if (target._decoratedCommands === undefined) target._decoratedCommands = {} |     if (target._decoratedCommands === undefined) target._decoratedCommands = {} | ||||||
|  |  | ||||||
|  | @ -300,6 +300,8 @@ export class CommandsLoader { | ||||||
|   /** |   /** | ||||||
|    * Load a Command from file. |    * Load a Command from file. | ||||||
|    * |    * | ||||||
|  |    * NOTE: Relative paths resolve from cwd | ||||||
|  |    * | ||||||
|    * @param filePath Path of Command file. |    * @param filePath Path of Command file. | ||||||
|    * @param exportName Export name. Default is the "default" export. |    * @param exportName Export name. Default is the "default" export. | ||||||
|    */ |    */ | ||||||
|  | @ -344,6 +346,8 @@ export class CommandsLoader { | ||||||
|   /** |   /** | ||||||
|    * Load commands from a Directory. |    * Load commands from a Directory. | ||||||
|    * |    * | ||||||
|  |    * NOTE: Relative paths resolve from cwd | ||||||
|  |    * | ||||||
|    * @param path Path of the directory. |    * @param path Path of the directory. | ||||||
|    * @param options Options to configure loading. |    * @param options Options to configure loading. | ||||||
|    */ |    */ | ||||||
|  |  | ||||||
|  | @ -22,14 +22,17 @@ export class RolesManager extends BaseManager<RolePayload, Role> { | ||||||
|     this.guild = guild |     this.guild = guild | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** Fetch a Guild Role (from API) */ |   /** Fetch All Guild Roles */ | ||||||
|   async fetch(id: string): Promise<Role> { |   async fetchAll(): Promise<Role[]> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest.api.guilds[this.guild.id].roles.get | ||||||
|         .get(GUILD_ROLE(this.guild.id, id)) |         .then(async (data: RolePayload[]) => { | ||||||
|         .then(async (data) => { |           const roles: Role[] = [] | ||||||
|           await this.set(id, data as RolePayload) |           for (const raw of data) { | ||||||
|           resolve(((await this.get(id)) as unknown) as Role) |             await this.set(raw.id, raw) | ||||||
|  |             roles.push(new Role(this.client, raw, this.guild)) | ||||||
|  |           } | ||||||
|  |           resolve(roles) | ||||||
|         }) |         }) | ||||||
|         .catch((e) => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue