Accepted Review (Helloyunho)

This commit is contained in:
yky4589 2020-10-25 17:02:24 +09:00
parent 3b8c961758
commit fedeef916c
3 changed files with 30 additions and 32 deletions

View file

@ -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,26 +30,29 @@ export class Base {
return cached
}
}
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]), {
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()
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]), {
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}`
}
@ -59,3 +62,4 @@ export class Base {
Object.assign(this, jsonParsed)
}
}
}

View file

@ -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

View file

@ -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()