Merge pull request #410 from koreanbots/master

Feat: shards, using datadog
This commit is contained in:
Junseo Park 2021-06-03 22:40:06 +09:00 committed by GitHub
commit 6432e9ba1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 540 additions and 181 deletions

View File

@ -1,12 +1,12 @@
{
"name": "client-next",
"name": "koreanbots",
"version": "2.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "node --require dd-trace/init next dev",
"pre-build": "git init && git submodule init && git submodule update --remote",
"build": "npm run pre-build && next build",
"start": "next start | (sleep 1; wget http://localhost:3000/api/v2 -O /dev/null)",
"start": "next start | (sleep 1; wget http://localhost:3000/api/v2/management/load -O /dev/null)",
"lint": "eslint --ext ts,tsx .",
"prettier": "prettier --write **/*",
"lint:fix": "eslint --ext ts,tsx . --fix",
@ -16,10 +16,10 @@
"dependencies": {
"@fortawesome/fontawesome-free": "5.15.3",
"@hcaptcha/react-hcaptcha": "0.3.6",
"@sentry/nextjs": "6.4.1",
"@sentry/node": "6.4.1",
"@sentry/react": "6.4.1",
"@sentry/tracing": "6.4.1",
"@sentry/nextjs": "6.5.1",
"@sentry/node": "6.5.1",
"@sentry/react": "6.5.1",
"@sentry/tracing": "6.5.1",
"abort-controller": "3.0.0",
"autoprefixer": "10.2.5",
"badgen": "3.2.2",
@ -27,6 +27,7 @@
"csrf": "3.1.0",
"dataloader": "2.0.0",
"dayjs": "1.10.5",
"dd-trace": "0.34.0",
"difflib": "0.2.4",
"discord.js": "12.5.3",
"emoji-mart": "3.0.1",
@ -52,13 +53,13 @@
"react-adsense": "0.1.0",
"react-dom": "17.0.2",
"react-hotkeys": "2.0.0",
"react-responsive-modal": "6.0.1",
"react-responsive-modal": "6.1.0",
"react-select": "4.3.1",
"react-showdown": "2.3.0",
"react-sortable-hoc": "2.0.0",
"react-use-clipboard": "1.0.7",
"sanitize-html": "2.4.0",
"tailwindcss": "2.1.2",
"tailwindcss": "2.1.4",
"tlru": "1.0.2",
"twemoji": "13.1.0",
"url-regex-safe": "2.0.2",
@ -74,18 +75,18 @@
"@types/jest": "26.0.23",
"@types/josa": "3.0.2",
"@types/jsonwebtoken": "8.5.1",
"@types/node": "14.17.1",
"@types/node": "14.17.2",
"@types/node-emoji": "1.8.1",
"@types/node-fetch": "2.5.10",
"@types/nprogress": "0.2.0",
"@types/rc-tooltip": "3.7.3",
"@types/react": "17.0.8",
"@types/react": "17.0.9",
"@types/react-select": "4.0.15",
"@types/sanitize-html": "2.3.1",
"@types/twemoji": "12.1.1",
"@types/url-regex-safe": "1.0.0",
"@typescript-eslint/eslint-plugin": "4.25.0",
"@typescript-eslint/parser": "4.25.0",
"@typescript-eslint/eslint-plugin": "4.26.0",
"@typescript-eslint/parser": "4.26.0",
"eslint": "7.27.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-jsx-a11y": "6.4.1",

View File

@ -39,7 +39,7 @@ const BotStats = RequestHandler()
const botInfo = await get.bot.load(bot)
if(!botInfo) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.', version: 1 })
if(botInfo.id !== bot) return ResponseWrapper(res, { code: 403, version: 1 })
const d = await update.updateServer(botInfo.id, validated.servers)
const d = await update.updateServer(botInfo.id, validated.servers, undefined)
if(d===1 || d===2) return ResponseWrapper(res, { code: 403, message: `서버 수를 ${[null, '1만', '100만'][d]} 이상으로 설정하실 수 없습니다. 문의해주세요.`, version: 1 })
get.bot.clear(bot)
await getStatsLoggingChannel().send(`[BOT/STATS] <@${botInfo.id}> (${botInfo.id})\n${makeDiscordCodeblock(`${botInfo.servers > validated.servers ? '-' : '+'} ${botInfo.servers} -> ${validated.servers} (${botInfo.servers > validated.servers ? '▼' : '▲'}${Math.abs(validated.servers - botInfo.servers)})`, 'diff')}`, (new MessageEmbed().setDescription(`${botInfo.name} - <@${botInfo.id}> ([${botInfo.id}](${KoreanbotsEndPoints.URL.bot(botInfo.id)}))`)))

View File

@ -49,12 +49,12 @@ const BotStats = RequestHandler().post(limiter)
ResponseWrapper(res, { code: 400, errors: e.errors })
return null
})
if(!validated) return
const botInfo = await get.bot.load(req.query.id)
if(!botInfo) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
if(botInfo.id !== bot) return ResponseWrapper(res, { code: 403 })
const d = await update.updateServer(botInfo.id, validated.servers)
const d = await update.updateServer(botInfo.id, validated.servers, validated.shards)
if(d===1 || d===2) return ResponseWrapper(res, { code: 403, message: `서버 수를 ${[null, '1만', '100만'][d]} 이상으로 설정하실 수 없습니다. 문의해주세요.` })
get.bot.clear(req.query.id)
await getStatsLoggingChannel().send(`[BOT/STATS] <@${botInfo.id}> (${botInfo.id})\n${makeDiscordCodeblock(`${botInfo.servers > validated.servers ? '-' : '+'} ${botInfo.servers} -> ${validated.servers} (${botInfo.servers > validated.servers ? '▼' : '▲'}${Math.abs(validated.servers - botInfo.servers)})`, 'diff')}`, (new MessageEmbed().setDescription(`${botInfo.name} - <@${botInfo.id}> ([${botInfo.id}](${KoreanbotsEndPoints.URL.bot(botInfo.id)}))`)))

View File

@ -1,9 +1,7 @@
import { NextApiHandler } from 'next'
import { getMainGuild } from '@utils/DiscordBot'
import RequestHandler from '@utils/RequestHandler'
const HelloWorld: NextApiHandler = RequestHandler().all(async (req, res) => {
getMainGuild() // Load Discord Bot
const HelloWorld: NextApiHandler = RequestHandler().all(async (_req, res) => {
res.status(200).json({ happy: 'hacking' })
})

View File

@ -0,0 +1,11 @@
import { NextApiHandler } from 'next'
import { getMainGuild } from '@utils/DiscordBot'
import RequestHandler from '@utils/RequestHandler'
const LoadAPI: NextApiHandler = RequestHandler().get(async (req, res) => {
getMainGuild() // Load Discord Bot
res.status(200).json({ load: 'success' })
})
export default LoadAPI

View File

@ -179,6 +179,14 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
<i className='fas fa-users' />
</div>
<div>{data.servers || 'N/A'}</div>
{
data.shards && data.servers > 1500 && <>
<div>
<i className='fas fa-sitemap' />
</div>
<div>{data.shards}</div>
</>
}
<div>
<i className='fas fa-calendar-day' />
</div>

View File

@ -13,6 +13,7 @@ export interface Bot {
prefix: string
votes: number
servers: number
shards: number
intro: string
desc: string
category: Category[]

View File

@ -25,6 +25,7 @@ async function getBot(id: string, owners=true):Promise<Bot> {
'prefix',
'votes',
'servers',
'shards',
'intro',
'desc',
'web',
@ -280,12 +281,14 @@ async function updateBot(id: string, data: ManageBot) {
/**
* @returns 1 - Limit of 100k servers
* @returns 2 - Limit of 10M servers
* @returns 3 - Limit of 100 shards
*/
async function updateServer(id: string, servers: number) {
async function updateServer(id: string, servers: number, shards: number) {
const bot = await get.bot.load(id)
if(bot.servers < 10000 && servers >= 10000) return 1
if(bot.servers < 1000000 && servers >= 1000000) return 2
await knex('bots').update({ servers }).where({ id })
else if(bot.servers < 1000000 && servers >= 1000000) return 2
if(bot.shards < 200 && shards >= 200) return 3
await knex('bots').update({ servers: servers === undefined ? bot.servers : servers, shards: shards === undefined ? bot.shards : shards }).where({ id })
return
}

View File

@ -194,11 +194,18 @@ export const BotStatUpdateSchema: Yup.SchemaOf<BotStatUpdate> = Yup.object({
servers: Yup.number()
.positive('서버 수는 양수여야합니다.')
.integer('서버 수는 정수여야합니다.')
.required()
.max(1000000000000)
.nullable(),
shards: Yup.number()
.positive('샤드 수는 양수여야합니다.')
.integer('샤드 수는 정수여야합니다.')
.max(10000)
.nullable(),
})
export interface BotStatUpdate {
servers: number
shards: number
}
export const ReportSchema: Yup.SchemaOf<Report> = Yup.object({

646
yarn.lock

File diff suppressed because it is too large Load Diff