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 {
|
||||
client: Client
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -30,32 +30,36 @@ export class Base {
|
|||
return cached
|
||||
}
|
||||
}
|
||||
this.restFunc = endpoint.find(((v) => {
|
||||
v.name === init.endpoint
|
||||
}))
|
||||
// TODO: Make error for this
|
||||
if(this.restFunc) {
|
||||
const resp = await fetch(this.restFunc(...init.restURLfuncArgs), {
|
||||
headers: {
|
||||
Authorization: `Bot ${client.token}`
|
||||
}
|
||||
})
|
||||
const jsonParsed = await resp.json()
|
||||
|
||||
this.restFunc = endpoint.filter(v => v.name === init.endpoint)
|
||||
|
||||
const resp = await fetch(this.restFunc[0](init.restURLfuncArgs[0], init.restURLfuncArgs[1], init.restURLfuncArgs[2], init.restURLfuncArgs[3]), {
|
||||
headers: {
|
||||
Authorization: `Bot ${client.token}`
|
||||
}
|
||||
})
|
||||
|
||||
const jsonParsed = await resp.json()
|
||||
|
||||
cache.set(init.cacheName, cacheID, new this(client, jsonParsed))
|
||||
|
||||
return new this(client, jsonParsed)
|
||||
cache.set(init.cacheName, cacheID, new this(client, jsonParsed))
|
||||
|
||||
return new this(client, jsonParsed)
|
||||
}
|
||||
}
|
||||
|
||||
async refresh (client: Client, init: IInit) {
|
||||
const restFunc: ((...restURLfuncArgs: any) => string)[] = endpoint.filter(v => v.name === init.endpoint)
|
||||
|
||||
const resp = await fetch(restFunc[0](init.restURLfuncArgs[0], init.restURLfuncArgs[1], init.restURLfuncArgs[3], init.restURLfuncArgs[4]), {
|
||||
headers: {
|
||||
Authorization: `Bot ${client.token}`
|
||||
}
|
||||
})
|
||||
const jsonParsed = await resp.json()
|
||||
|
||||
Object.assign(this, jsonParsed)
|
||||
const restFunc: ((...restURLfuncArgs: string[]) => string) | undefined = endpoint.find(v => v.name === init.endpoint)
|
||||
// TODO: Make error for this
|
||||
if(restFunc) {
|
||||
const resp = await fetch(restFunc(...init.restURLfuncArgs), {
|
||||
headers: {
|
||||
Authorization: `Bot ${client.token}`
|
||||
}
|
||||
})
|
||||
const jsonParsed = await resp.json()
|
||||
|
||||
Object.assign(this, jsonParsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import { Role } from './role.ts'
|
|||
import { User } from './user.ts'
|
||||
|
||||
export class Member extends User {
|
||||
user: User
|
||||
nick?: string
|
||||
roles: Role[]
|
||||
joinedAt: string
|
||||
|
@ -18,7 +17,6 @@ export class Member extends User {
|
|||
|
||||
constructor (client: Client, data: MemberPayload) {
|
||||
super(client, data.user)
|
||||
this.user = this
|
||||
this.nick = data.nick
|
||||
this.roles = data.roles.map(v => new Role(client, v))
|
||||
this.joinedAt = data.joined_at
|
||||
|
|
|
@ -3,11 +3,7 @@ import { Guild } from '../structures/guild.ts'
|
|||
import { GatewayIntents } from '../types/gatewayTypes.ts'
|
||||
import { TOKEN } from './config.ts'
|
||||
import * as cache from '../models/cache.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"
|
||||
import { Member } from '../structures/member.ts'
|
||||
|
||||
const bot = new Client()
|
||||
|
||||
|
|
Loading…
Reference in a new issue