Accepted Review (Helloyunho)
This commit is contained in:
		
							parent
							
								
									3b8c961758
								
							
						
					
					
						commit
						fedeef916c
					
				
					 3 changed files with 30 additions and 32 deletions
				
			
		|  | @ -12,9 +12,9 @@ interface IInit { | ||||||
| export class Base { | export class Base { | ||||||
|   client: Client |   client: Client | ||||||
|   static useCache?: boolean = true |   static useCache?: boolean = true | ||||||
|   static restFunc: ((...restURLfuncArgs: any) => string)[] |   static restFunc?: ((...restURLfuncArgs: string[]) => string) | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, _data: any) { |   constructor (client: Client, _data?: any) { | ||||||
|     this.client = client |     this.client = client | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -30,26 +30,29 @@ export class Base { | ||||||
|         return cached |         return cached | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 |     this.restFunc = endpoint.find(((v) => { | ||||||
|     this.restFunc = endpoint.filter(v => v.name === init.endpoint) |       v.name === init.endpoint | ||||||
| 
 |     })) | ||||||
|     const resp = await fetch(this.restFunc[0](init.restURLfuncArgs[0], init.restURLfuncArgs[1], init.restURLfuncArgs[2], init.restURLfuncArgs[3]), { |     // TODO: Make error for this
 | ||||||
|  |     if(this.restFunc) { | ||||||
|  |       const resp = await fetch(this.restFunc(...init.restURLfuncArgs), { | ||||||
|         headers: { |         headers: { | ||||||
|           Authorization: `Bot ${client.token}` |           Authorization: `Bot ${client.token}` | ||||||
|         } |         } | ||||||
|       }) |       }) | ||||||
| 
 |  | ||||||
|       const jsonParsed = await resp.json() |       const jsonParsed = await resp.json() | ||||||
| 
 | 
 | ||||||
|       cache.set(init.cacheName, cacheID, new this(client, jsonParsed)) |       cache.set(init.cacheName, cacheID, new this(client, jsonParsed)) | ||||||
|    |    | ||||||
|       return new this(client, jsonParsed) |       return new this(client, jsonParsed) | ||||||
|     } |     } | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   async refresh (client: Client, init: IInit) { |   async refresh (client: Client, init: IInit) { | ||||||
|     const restFunc: ((...restURLfuncArgs: any) => string)[] = endpoint.filter(v => v.name === init.endpoint) |     const restFunc: ((...restURLfuncArgs: string[]) => string) | undefined = endpoint.find(v => v.name === init.endpoint) | ||||||
| 
 |     // TODO: Make error for this
 | ||||||
|     const resp = await fetch(restFunc[0](init.restURLfuncArgs[0], init.restURLfuncArgs[1], init.restURLfuncArgs[3], init.restURLfuncArgs[4]), { |     if(restFunc) { | ||||||
|  |       const resp = await fetch(restFunc(...init.restURLfuncArgs), { | ||||||
|         headers: { |         headers: { | ||||||
|           Authorization: `Bot ${client.token}` |           Authorization: `Bot ${client.token}` | ||||||
|         } |         } | ||||||
|  | @ -58,4 +61,5 @@ export class Base { | ||||||
|    |    | ||||||
|       Object.assign(this, jsonParsed) |       Object.assign(this, jsonParsed) | ||||||
|     } |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,7 +8,6 @@ import { Role } from './role.ts' | ||||||
| import { User } from './user.ts' | import { User } from './user.ts' | ||||||
| 
 | 
 | ||||||
| export class Member extends User { | export class Member extends User { | ||||||
|   user: User |  | ||||||
|   nick?: string |   nick?: string | ||||||
|   roles: Role[] |   roles: Role[] | ||||||
|   joinedAt: string |   joinedAt: string | ||||||
|  | @ -18,7 +17,6 @@ export class Member extends User { | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: MemberPayload) { |   constructor (client: Client, data: MemberPayload) { | ||||||
|     super(client, data.user) |     super(client, data.user) | ||||||
|     this.user = this |  | ||||||
|     this.nick = data.nick |     this.nick = data.nick | ||||||
|     this.roles = data.roles.map(v => new Role(client, v)) |     this.roles = data.roles.map(v => new Role(client, v)) | ||||||
|     this.joinedAt = data.joined_at |     this.joinedAt = data.joined_at | ||||||
|  |  | ||||||
|  | @ -3,11 +3,7 @@ import { Guild } from '../structures/guild.ts' | ||||||
| import { GatewayIntents } from '../types/gatewayTypes.ts' | import { GatewayIntents } from '../types/gatewayTypes.ts' | ||||||
| import { TOKEN } from './config.ts' | import { TOKEN } from './config.ts' | ||||||
| import * as cache from '../models/cache.ts' | import * as cache from '../models/cache.ts' | ||||||
| import { Member } from "../structures/member.ts" | import { Member } from '../structures/member.ts' | ||||||
| import { User } from "../structures/user.ts" |  | ||||||
| import endpoint from "../types/endpoint.ts" |  | ||||||
| import { Base } from "../structures/base.ts" |  | ||||||
| import { GuildChannel } from "../structures/guildChannel.ts" |  | ||||||
| 
 | 
 | ||||||
| const bot = new Client() | const bot = new Client() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue