mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 22:30:23 +00:00
style: prettier
This commit is contained in:
parent
145bbe47ea
commit
b4b62445ec
@ -1,37 +1,37 @@
|
|||||||
export interface Bot {
|
export interface Bot {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
tag: string
|
tag: string
|
||||||
avatar: string
|
avatar: string
|
||||||
status: Status
|
status: Status
|
||||||
lib: Library
|
lib: Library
|
||||||
prefix: string
|
prefix: string
|
||||||
votes: number
|
votes: number
|
||||||
servers: number
|
servers: number
|
||||||
intro: string
|
intro: string
|
||||||
desc: string
|
desc: string
|
||||||
category: Category[]
|
category: Category[]
|
||||||
web?: string
|
web?: string
|
||||||
git?: string
|
git?: string
|
||||||
url?: string
|
url?: string
|
||||||
discord?: string
|
discord?: string
|
||||||
verified: boolean
|
verified: boolean
|
||||||
trusted: boolean
|
trusted: boolean
|
||||||
partnered: boolean
|
partnered: boolean
|
||||||
vanity: string | null
|
vanity: string | null
|
||||||
bg: string
|
bg: string
|
||||||
banner: string
|
banner: string
|
||||||
owners: User[] | string[]
|
owners: User[] | string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
id: string
|
id: string
|
||||||
avatar: string
|
avatar: string
|
||||||
tag: string
|
tag: string
|
||||||
username: string
|
username: string
|
||||||
perm: number
|
perm: number
|
||||||
github: string
|
github: string
|
||||||
bots: Bot[] | string[]
|
bots: Bot[] | string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Status = 'online' | 'offline' | 'dnd' | 'idle' | 'streaming'
|
export type Status = 'online' | 'offline' | 'dnd' | 'idle' | 'streaming'
|
||||||
|
|||||||
@ -2,12 +2,18 @@ import DataLoader from 'dataloader'
|
|||||||
import * as Query from './Query'
|
import * as Query from './Query'
|
||||||
|
|
||||||
const Fetch = {
|
const Fetch = {
|
||||||
bot: new DataLoader(async (ids:string[]) => await Promise.all(ids.map((el:string)=> Query.getBot(el))), {
|
bot: new DataLoader(
|
||||||
batchScheduleFn: callback => setTimeout(callback, 1000)
|
async (ids: string[]) => await Promise.all(ids.map((el: string) => Query.getBot(el))),
|
||||||
}),
|
{
|
||||||
user: new DataLoader(async (ids:string[]) => await Promise.all(ids.map((el:string)=> Query.getUser(el))), {
|
batchScheduleFn: callback => setTimeout(callback, 1000),
|
||||||
batchScheduleFn: callback => setTimeout(callback, 1000)
|
}
|
||||||
}),
|
),
|
||||||
|
user: new DataLoader(
|
||||||
|
async (ids: string[]) => await Promise.all(ids.map((el: string) => Query.getUser(el))),
|
||||||
|
{
|
||||||
|
batchScheduleFn: callback => setTimeout(callback, 1000),
|
||||||
|
}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Fetch
|
export default Fetch
|
||||||
|
|||||||
@ -17,29 +17,60 @@ export const knex = knsexy({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export async function getBot(id: string, owners=true):Promise<Bot> {
|
export async function getBot(id: string, owners = true): Promise<Bot> {
|
||||||
const res = await knex('bots').select(['id', 'owners', 'lib', 'prefix', 'votes', 'servers', 'intro', 'desc', 'web', 'git', 'url', 'category', 'status', 'name', 'avatar', 'tag', 'verified', 'trusted', 'partnered', 'discord', 'boosted', 'state', 'vanity', 'bg', 'banner']).where({ id }).orWhere({ vanity: id, boosted: 1 })
|
const res = await knex('bots')
|
||||||
if(res[0]) {
|
.select([
|
||||||
|
'id',
|
||||||
|
'owners',
|
||||||
|
'lib',
|
||||||
|
'prefix',
|
||||||
|
'votes',
|
||||||
|
'servers',
|
||||||
|
'intro',
|
||||||
|
'desc',
|
||||||
|
'web',
|
||||||
|
'git',
|
||||||
|
'url',
|
||||||
|
'category',
|
||||||
|
'status',
|
||||||
|
'name',
|
||||||
|
'avatar',
|
||||||
|
'tag',
|
||||||
|
'verified',
|
||||||
|
'trusted',
|
||||||
|
'partnered',
|
||||||
|
'discord',
|
||||||
|
'boosted',
|
||||||
|
'state',
|
||||||
|
'vanity',
|
||||||
|
'bg',
|
||||||
|
'banner',
|
||||||
|
])
|
||||||
|
.where({ id })
|
||||||
|
.orWhere({ vanity: id, boosted: 1 })
|
||||||
|
if (res[0]) {
|
||||||
res[0].category = JSON.parse(res[0].category)
|
res[0].category = JSON.parse(res[0].category)
|
||||||
res[0].owners = JSON.parse(res[0].owners)
|
res[0].owners = JSON.parse(res[0].owners)
|
||||||
if(owners) res[0].owners = res[0].owners.map(async (u: string) => await getUser(u))
|
if (owners) res[0].owners = res[0].owners.map(async (u: string) => await getUser(u))
|
||||||
res[0].owners = await Promise.all(res[0].owners.filter((el: User|null)=> el))
|
res[0].owners = await Promise.all(res[0].owners.filter((el: User | null) => el))
|
||||||
res[0].vanity = res[0].vanity && ( res[0].boosted || res[0].trusted || res[0].partnered )
|
res[0].vanity = res[0].vanity && (res[0].boosted || res[0].trusted || res[0].partnered)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res[0] || null
|
return res[0] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUser(id: string, bots=true):Promise<User> {
|
export async function getUser(id: string, bots = true): Promise<User> {
|
||||||
const res = await knex('users').select(['id', 'avatar', 'tag', 'username', 'perm', 'github']).where({ id })
|
const res = await knex('users')
|
||||||
if(res[0]) {
|
.select(['id', 'avatar', 'tag', 'username', 'perm', 'github'])
|
||||||
const owned = await knex('bots').select(['id']).where('owners', 'like', `%${id}%`)
|
.where({ id })
|
||||||
if(bots) res[0].bots = owned.map(async b=> await getBot(b.id, false))
|
if (res[0]) {
|
||||||
else res[0].bots = owned.map(async b=> b.id)
|
const owned = await knex('bots')
|
||||||
res[0].bots = await Promise.all(res[0].bots.filter((el:Bot|null)=> el))
|
.select(['id'])
|
||||||
|
.where('owners', 'like', `%${id}%`)
|
||||||
|
if (bots) res[0].bots = owned.map(async b => await getBot(b.id, false))
|
||||||
|
else res[0].bots = owned.map(async b => b.id)
|
||||||
|
res[0].bots = await Promise.all(res[0].bots.filter((el: Bot | null) => el))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res[0] || null
|
return res[0] || null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user