mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: handle unknown user
This commit is contained in:
parent
49bf059f4f
commit
3e44a86e89
@ -31,10 +31,10 @@ const Avatar = RequestHandler()
|
||||
if(!validated) return
|
||||
|
||||
const user = await get.discord.user.load(id)
|
||||
if(!user) return ResponseWrapper(res, { code: 400, message: '올바르지 않은 유저입니다.' })
|
||||
|
||||
let img = await get.images.user.load(DiscordEnpoints.CDN.user(id, user.avatar, { format: validated.ext === 'gif' && !user.avatar.startsWith('a_') ? 'png' : validated.ext }))
|
||||
if(!user.avatar || !img) {
|
||||
let img: Buffer
|
||||
if(!user || !user.avatar) img = await get.images.user.load(DiscordEnpoints.CDN.default(Math.floor(Math.random() * 6), { format: 'png', size: validated.size }))
|
||||
else img = await get.images.user.load(DiscordEnpoints.CDN.user(id, user.avatar, { format: validated.ext === 'gif' && !user.avatar.startsWith('a_') ? 'png' : validated.ext }))
|
||||
if(!img) {
|
||||
img = await get.images.user.load(DiscordEnpoints.CDN.default(user.discriminator, { format: 'png', size: validated.size }))
|
||||
ext = 'png'
|
||||
}
|
||||
|
||||
@ -80,8 +80,8 @@ async function getUser(id: string, bots = true):Promise<User> {
|
||||
.select(['id'])
|
||||
.where('owners', 'like', `%${id}%`)
|
||||
const discordUser = await get.discord.user.load(id)
|
||||
res[0].tag = discordUser.discriminator
|
||||
res[0].username = discordUser.username
|
||||
res[0].tag = discordUser?.discriminator || '0000'
|
||||
res[0].username = discordUser?.username || 'Unknown User'
|
||||
if (bots) {
|
||||
res[0].bots = await Promise.all(owned.map(async b => await get._rawBot.load(b.id)))
|
||||
res[0].bots = res[0].bots.filter((el: Bot | null) => el).map((row: User) => ({ ...row }))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user