From 2a6227ab838b6537f163a20166045b1112408949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Wed, 10 Feb 2021 18:51:55 +0900 Subject: [PATCH] feat: using flags --- pages/bots/[id].tsx | 8 ++++---- pages/users/[id].tsx | 6 +++--- types/index.ts | 40 ++++++++++++++++++++++++++++++++++------ utils/Constants.ts | 7 ------- utils/Query.ts | 7 +++---- utils/Tools.ts | 20 +++++++++++++------- 6 files changed, 57 insertions(+), 31 deletions(-) diff --git a/pages/bots/[id].tsx b/pages/bots/[id].tsx index 5802163..025a8fc 100644 --- a/pages/bots/[id].tsx +++ b/pages/bots/[id].tsx @@ -10,7 +10,7 @@ import { Bot, User } from '@types' import { git, Status } from '@utils/Constants' import { get } from '@utils/Query' import Day from '@utils/Day' -import { checkPerm, formatNumber, parseCookie } from '@utils/Tools' +import { checkBotFlag, checkUserFlag, formatNumber, parseCookie } from '@utils/Tools' import NotFound from '../404' @@ -60,7 +60,7 @@ const Bots: NextPage = ({ data, date, user }) => { />

{data.name}{' '} - {data.trusted ? ( + {checkBotFlag(data.flags, 'trusted') ? ( @@ -92,7 +92,7 @@ const Bots: NextPage = ({ data, date, user }) => { { - ((data.owners as User[]).find(el => el.id === user.id) || checkPerm(user.perm, 'staff')) && + ((data.owners as User[]).find(el => el.id === user.id) || checkUserFlag(user.flags, 'staff')) &&

관리하기

@@ -120,7 +120,7 @@ const Bots: NextPage = ({ data, date, user }) => {
{Day(date).fromNow(false)}
{ - data.verified ? + checkBotFlag(data.flags, 'trusted') ?
디스코드 인증됨 diff --git a/pages/users/[id].tsx b/pages/users/[id].tsx index 0ac8f0c..a1c293a 100644 --- a/pages/users/[id].tsx +++ b/pages/users/[id].tsx @@ -6,7 +6,7 @@ import { josa } from 'josa' import { Bot, User } from '@types' import * as Query from '@utils/Query' -import { checkPerm } from '@utils/Tools' +import { checkUserFlag } from '@utils/Tools' import NotFound from '../404' @@ -50,14 +50,14 @@ const Users: NextPage = ({ data }) => { #{data.tag}
- {checkPerm(data.perm, 'staff') && ( + {checkUserFlag(data.flags, 'staff') && (
)} - {checkPerm(data.perm, 'bughunter') && ( + {checkUserFlag(data.flags, 'bughunter') && (
diff --git a/types/index.ts b/types/index.ts index ed42811..eacf4a9 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,5 +1,3 @@ -export type UserPemissionFlags = 'general' | 'staff' | 'bughunter' | 'booster' - export interface Bot { id: string name: string @@ -19,9 +17,6 @@ export interface Bot { git: string | null url: string | null discord: string | null - verified: boolean - trusted: boolean - partnered: boolean vanity: string | null bg: string banner: string @@ -33,11 +28,44 @@ export interface User { avatar: string tag: string username: string - perm: number + flags: number github: string bots: Bot[] | string[] } +export enum UserFlags { + general = 0 << 0, + staff = 1 << 0, + bughunter = 1 << 1, + premium = 1 << 2 +} + +export enum BotFlags { + general = 0 << 0, + official = 1 << 0, + trusted = 1 << 2, + partnered = 1 << 3, + verifed = 1 << 4, + premium = 1 << 5, + hackerthon = 1 << 6 +} + +export enum DiscordUserFlags { + DISCORD_EMPLOYEE = 1 << 0, + DISCORD_PARTNER = 1 << 1, + HYPESQUAD_EVENTS = 1 << 2, + BUGHUNTER_LEVEL_1 = 1 << 3, + HOUSE_BRAVERY = 1 << 6, + HOUSE_BRILLIANCE = 1 << 7, + HOUSE_BALANCE = 1 << 8, + EARLY_SUPPORTER = 1 << 9, + TEAM_USER = 1 << 10, + SYSTEM = 1 << 12, + BUGHUNTER_LEVEL_2 = 1 << 14, + VERIFIED_BOT = 1 << 16, + VERIFIED_DEVELOPER = 1 << 17 +} + export interface BotList { type: ListType data: Bot[] diff --git a/utils/Constants.ts b/utils/Constants.ts index 61131b1..b3816dc 100644 --- a/utils/Constants.ts +++ b/utils/Constants.ts @@ -32,13 +32,6 @@ export const Status = { }, } -export const perms = { - general: 0x0, - staff: 0x1, - bughunter: 0x4, - booster: 0x8, -} - export const library = [ 'discord.js', 'Eris', diff --git a/utils/Query.ts b/utils/Query.ts index aef215a..fbf7241 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -5,7 +5,7 @@ import DataLoader from 'dataloader' import { User as DiscordUser } from 'discord.js' import { Stream } from 'stream' -import { Bot, User, ListType, BotList, TokenRegister } from '@types' +import { Bot, User, ListType, BotList, TokenRegister, BotFlags, DiscordUserFlags } from '@types' import { categories } from './Constants' import knex from './Knex' @@ -32,7 +32,6 @@ async function getBot(id: string, owners=true):Promise { 'url', 'category', 'status', - 'verified', 'trusted', 'partnered', 'discord', @@ -48,6 +47,7 @@ async function getBot(id: string, owners=true):Promise { if (res[0]) { const discordBot = await get.discord.user.load(res[0].id) if(!discordBot) return null + res[0].flags = res[0].flags | (discordBot.flags && DiscordUserFlags.VERIFIED_BOT ? BotFlags.verifed : 0) | res[0].trusted ? BotFlags.trusted : 0 res[0].tag = discordBot.discriminator res[0].name = discordBot.username res[0].category = JSON.parse(res[0].category) @@ -69,7 +69,7 @@ async function getBot(id: string, owners=true):Promise { async function getUser(id: string, bots = true):Promise { const res = await knex('users') - .select(['id', 'perm', 'github']) + .select(['id', 'flags', 'perm', 'github']) .where({ id }) if (res[0]) { const owned = await knex('bots') @@ -151,7 +151,6 @@ async function getBotList(type: ListType, page = 1, query?: string):Promise(data: T): T {