mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: using flags
This commit is contained in:
parent
fbfa9ddcf7
commit
2a6227ab83
@ -10,7 +10,7 @@ import { Bot, User } from '@types'
|
|||||||
import { git, Status } from '@utils/Constants'
|
import { git, Status } from '@utils/Constants'
|
||||||
import { get } from '@utils/Query'
|
import { get } from '@utils/Query'
|
||||||
import Day from '@utils/Day'
|
import Day from '@utils/Day'
|
||||||
import { checkPerm, formatNumber, parseCookie } from '@utils/Tools'
|
import { checkBotFlag, checkUserFlag, formatNumber, parseCookie } from '@utils/Tools'
|
||||||
|
|
||||||
import NotFound from '../404'
|
import NotFound from '../404'
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ const Bots: NextPage<BotsProps> = ({ data, date, user }) => {
|
|||||||
/>
|
/>
|
||||||
<h1 className='mb-2 mt-3 text-4xl font-bold'>
|
<h1 className='mb-2 mt-3 text-4xl font-bold'>
|
||||||
{data.name}{' '}
|
{data.name}{' '}
|
||||||
{data.trusted ? (
|
{checkBotFlag(data.flags, 'trusted') ? (
|
||||||
<Tooltip text='해당봇은 한국 디스코드봇 리스트에서 엄격한 기준을 통과한 봇입니다!' direction='left' size='large' href='/verification'>
|
<Tooltip text='해당봇은 한국 디스코드봇 리스트에서 엄격한 기준을 통과한 봇입니다!' direction='left' size='large' href='/verification'>
|
||||||
<span className='text-koreanbots-blue text-3xl'>
|
<span className='text-koreanbots-blue text-3xl'>
|
||||||
<i className='fas fa-award' />
|
<i className='fas fa-award' />
|
||||||
@ -92,7 +92,7 @@ const Bots: NextPage<BotsProps> = ({ data, date, user }) => {
|
|||||||
</span>
|
</span>
|
||||||
</LongButton>
|
</LongButton>
|
||||||
{
|
{
|
||||||
((data.owners as User[]).find(el => el.id === user.id) || checkPerm(user.perm, 'staff')) && <LongButton href={`/manage/${data.id}`}>
|
((data.owners as User[]).find(el => el.id === user.id) || checkUserFlag(user.flags, 'staff')) && <LongButton href={`/manage/${data.id}`}>
|
||||||
<h4>
|
<h4>
|
||||||
<i className='fas fa-cogs' /> 관리하기
|
<i className='fas fa-cogs' /> 관리하기
|
||||||
</h4>
|
</h4>
|
||||||
@ -120,7 +120,7 @@ const Bots: NextPage<BotsProps> = ({ data, date, user }) => {
|
|||||||
</div>
|
</div>
|
||||||
<div>{Day(date).fromNow(false)}</div>
|
<div>{Day(date).fromNow(false)}</div>
|
||||||
{
|
{
|
||||||
data.verified ?
|
checkBotFlag(data.flags, 'trusted') ?
|
||||||
<Tooltip direction='left' text='해당 봇은 디스코드측에서 인증된 봇입니다.'>
|
<Tooltip direction='left' text='해당 봇은 디스코드측에서 인증된 봇입니다.'>
|
||||||
<div>
|
<div>
|
||||||
<i className='fas fa-check text-discord-blurple' /> 디스코드 인증됨
|
<i className='fas fa-check text-discord-blurple' /> 디스코드 인증됨
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { josa } from 'josa'
|
|||||||
|
|
||||||
import { Bot, User } from '@types'
|
import { Bot, User } from '@types'
|
||||||
import * as Query from '@utils/Query'
|
import * as Query from '@utils/Query'
|
||||||
import { checkPerm } from '@utils/Tools'
|
import { checkUserFlag } from '@utils/Tools'
|
||||||
|
|
||||||
import NotFound from '../404'
|
import NotFound from '../404'
|
||||||
|
|
||||||
@ -50,14 +50,14 @@ const Users: NextPage<UserProps> = ({ data }) => {
|
|||||||
<span className='ml-0.5 text-gray-400 text-4xl font-semibold'>#{data.tag}</span>
|
<span className='ml-0.5 text-gray-400 text-4xl font-semibold'>#{data.tag}</span>
|
||||||
<br />
|
<br />
|
||||||
<div className='badges flex'>
|
<div className='badges flex'>
|
||||||
{checkPerm(data.perm, 'staff') && (
|
{checkUserFlag(data.flags, 'staff') && (
|
||||||
<Tooltip text='한국 디스코드봇 리스트 스탭입니다.' direction='left'>
|
<Tooltip text='한국 디스코드봇 리스트 스탭입니다.' direction='left'>
|
||||||
<div className='pr-5 text-koreanbots-blue text-2xl'>
|
<div className='pr-5 text-koreanbots-blue text-2xl'>
|
||||||
<i className='fas fa-hammer' />
|
<i className='fas fa-hammer' />
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{checkPerm(data.perm, 'bughunter') && (
|
{checkUserFlag(data.flags, 'bughunter') && (
|
||||||
<Tooltip text='버그를 많이 제보해주신 분입니다.' direction='left'>
|
<Tooltip text='버그를 많이 제보해주신 분입니다.' direction='left'>
|
||||||
<div className='pr-5 text-green-500 text-2xl'>
|
<div className='pr-5 text-green-500 text-2xl'>
|
||||||
<i className='fas fa-bug' />
|
<i className='fas fa-bug' />
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
export type UserPemissionFlags = 'general' | 'staff' | 'bughunter' | 'booster'
|
|
||||||
|
|
||||||
export interface Bot {
|
export interface Bot {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
@ -19,9 +17,6 @@ export interface Bot {
|
|||||||
git: string | null
|
git: string | null
|
||||||
url: string | null
|
url: string | null
|
||||||
discord: string | null
|
discord: string | null
|
||||||
verified: boolean
|
|
||||||
trusted: boolean
|
|
||||||
partnered: boolean
|
|
||||||
vanity: string | null
|
vanity: string | null
|
||||||
bg: string
|
bg: string
|
||||||
banner: string
|
banner: string
|
||||||
@ -33,11 +28,44 @@ export interface User {
|
|||||||
avatar: string
|
avatar: string
|
||||||
tag: string
|
tag: string
|
||||||
username: string
|
username: string
|
||||||
perm: number
|
flags: number
|
||||||
github: string
|
github: string
|
||||||
bots: Bot[] | 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 {
|
export interface BotList {
|
||||||
type: ListType
|
type: ListType
|
||||||
data: Bot[]
|
data: Bot[]
|
||||||
|
|||||||
@ -32,13 +32,6 @@ export const Status = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const perms = {
|
|
||||||
general: 0x0,
|
|
||||||
staff: 0x1,
|
|
||||||
bughunter: 0x4,
|
|
||||||
booster: 0x8,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const library = [
|
export const library = [
|
||||||
'discord.js',
|
'discord.js',
|
||||||
'Eris',
|
'Eris',
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import DataLoader from 'dataloader'
|
|||||||
import { User as DiscordUser } from 'discord.js'
|
import { User as DiscordUser } from 'discord.js'
|
||||||
import { Stream } from 'stream'
|
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 { categories } from './Constants'
|
||||||
|
|
||||||
import knex from './Knex'
|
import knex from './Knex'
|
||||||
@ -32,7 +32,6 @@ async function getBot(id: string, owners=true):Promise<Bot> {
|
|||||||
'url',
|
'url',
|
||||||
'category',
|
'category',
|
||||||
'status',
|
'status',
|
||||||
'verified',
|
|
||||||
'trusted',
|
'trusted',
|
||||||
'partnered',
|
'partnered',
|
||||||
'discord',
|
'discord',
|
||||||
@ -48,6 +47,7 @@ async function getBot(id: string, owners=true):Promise<Bot> {
|
|||||||
if (res[0]) {
|
if (res[0]) {
|
||||||
const discordBot = await get.discord.user.load(res[0].id)
|
const discordBot = await get.discord.user.load(res[0].id)
|
||||||
if(!discordBot) return null
|
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].tag = discordBot.discriminator
|
||||||
res[0].name = discordBot.username
|
res[0].name = discordBot.username
|
||||||
res[0].category = JSON.parse(res[0].category)
|
res[0].category = JSON.parse(res[0].category)
|
||||||
@ -69,7 +69,7 @@ async function getBot(id: string, owners=true):Promise<Bot> {
|
|||||||
|
|
||||||
async function getUser(id: string, bots = true):Promise<User> {
|
async function getUser(id: string, bots = true):Promise<User> {
|
||||||
const res = await knex('users')
|
const res = await knex('users')
|
||||||
.select(['id', 'perm', 'github'])
|
.select(['id', 'flags', 'perm', 'github'])
|
||||||
.where({ id })
|
.where({ id })
|
||||||
if (res[0]) {
|
if (res[0]) {
|
||||||
const owned = await knex('bots')
|
const owned = await knex('bots')
|
||||||
@ -151,7 +151,6 @@ async function getBotList(type: ListType, page = 1, query?: string):Promise<BotL
|
|||||||
if (!query) throw new Error('쿼리가 누락되었습니다.')
|
if (!query) throw new Error('쿼리가 누락되었습니다.')
|
||||||
count = (await knex.raw('SELECT count(*) FROM bots WHERE MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode)', [decodeURI(query)]))[0][0]['count(*)']
|
count = (await knex.raw('SELECT count(*) FROM bots WHERE MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode)', [decodeURI(query)]))[0][0]['count(*)']
|
||||||
res = (await knex.raw('SELECT id, votes, MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) as relevance FROM bots WHERE MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) ORDER BY relevance DESC, votes DESC LIMIT 16 OFFSET ?', [decodeURI(query), decodeURI(query), ((page ? Number(page) : 1) - 1) * 16]))[0]
|
res = (await knex.raw('SELECT id, votes, MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) as relevance FROM bots WHERE MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) ORDER BY relevance DESC, votes DESC LIMIT 16 OFFSET ?', [decodeURI(query), decodeURI(query), ((page ? Number(page) : 1) - 1) * 16]))[0]
|
||||||
console.log(res)
|
|
||||||
} else {
|
} else {
|
||||||
count = 1
|
count = 1
|
||||||
res = []
|
res = []
|
||||||
|
|||||||
@ -2,8 +2,8 @@ import { Readable } from 'stream'
|
|||||||
import { NextPageContext } from 'next'
|
import { NextPageContext } from 'next'
|
||||||
import cookie from 'cookie'
|
import cookie from 'cookie'
|
||||||
|
|
||||||
import { Bot, ImageOptions, UserPemissionFlags } from '@types'
|
import { BotFlags, ImageOptions, UserFlags } from '@types'
|
||||||
import { KoreanbotsEndPoints, Oauth, perms } from './Constants'
|
import { KoreanbotsEndPoints, Oauth } from './Constants'
|
||||||
import { NextRouter } from 'next/router'
|
import { NextRouter } from 'next/router'
|
||||||
|
|
||||||
export function formatNumber(value: number):string {
|
export function formatNumber(value: number):string {
|
||||||
@ -17,18 +17,24 @@ export function formatNumber(value: number):string {
|
|||||||
return shortValue+suffixes[suffixNum]
|
return shortValue+suffixes[suffixNum]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkPerm(base: number, required: number | UserPemissionFlags):boolean {
|
function checkFlag(base: number, required: number) {
|
||||||
required = typeof required === 'number' ? required : perms[required]
|
|
||||||
if (typeof required !== 'number' && !required) throw new Error('올바르지 않은 권한입니다.')
|
|
||||||
return (base & required) === required
|
return (base & required) === required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkUserFlag(base: number, required: number | keyof typeof UserFlags):boolean {
|
||||||
|
return checkFlag(base, typeof required === 'number' ? required : UserFlags[required])
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkBotFlag(base: number, required: number | keyof typeof BotFlags):boolean {
|
||||||
|
return checkFlag(base, typeof required === 'number' ? required : BotFlags[required])
|
||||||
|
}
|
||||||
|
|
||||||
export function makeImageURL(root:string, { format='png', size=256 }:ImageOptions):string {
|
export function makeImageURL(root:string, { format='png', size=256 }:ImageOptions):string {
|
||||||
return `${root}.${format}?size=${size}`
|
return `${root}.${format}?size=${size}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeBotURL(bot: { partnered?: boolean, trusted?: boolean, vanity?: string, id: string }): string {
|
export function makeBotURL({id, vanity, flags=0}: { flags?: number, vanity?:string, id: string }): string {
|
||||||
return `/bots/${(bot.partnered || bot.trusted) && bot.vanity ? bot.vanity : bot.id}`
|
return `/bots/${(checkBotFlag(flags, 'trusted') || checkBotFlag(flags, 'partnered')) && vanity ? vanity : id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serialize<T>(data: T): T {
|
export function serialize<T>(data: T): T {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user