feat: handle unknown user

This commit is contained in:
wonderlandpark 2021-03-13 22:06:42 +09:00
parent 49bf059f4f
commit 3e44a86e89
2 changed files with 6 additions and 6 deletions

View File

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

View File

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