mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 22:10:24 +00:00
Merge pull request #410 from koreanbots/master
Feat: shards, using datadog
This commit is contained in:
commit
6432e9ba1e
27
package.json
27
package.json
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "client-next",
|
"name": "koreanbots",
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "node --require dd-trace/init next dev",
|
||||||
"pre-build": "git init && git submodule init && git submodule update --remote",
|
"pre-build": "git init && git submodule init && git submodule update --remote",
|
||||||
"build": "npm run pre-build && next build",
|
"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 .",
|
"lint": "eslint --ext ts,tsx .",
|
||||||
"prettier": "prettier --write **/*",
|
"prettier": "prettier --write **/*",
|
||||||
"lint:fix": "eslint --ext ts,tsx . --fix",
|
"lint:fix": "eslint --ext ts,tsx . --fix",
|
||||||
@ -16,10 +16,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "5.15.3",
|
"@fortawesome/fontawesome-free": "5.15.3",
|
||||||
"@hcaptcha/react-hcaptcha": "0.3.6",
|
"@hcaptcha/react-hcaptcha": "0.3.6",
|
||||||
"@sentry/nextjs": "6.4.1",
|
"@sentry/nextjs": "6.5.1",
|
||||||
"@sentry/node": "6.4.1",
|
"@sentry/node": "6.5.1",
|
||||||
"@sentry/react": "6.4.1",
|
"@sentry/react": "6.5.1",
|
||||||
"@sentry/tracing": "6.4.1",
|
"@sentry/tracing": "6.5.1",
|
||||||
"abort-controller": "3.0.0",
|
"abort-controller": "3.0.0",
|
||||||
"autoprefixer": "10.2.5",
|
"autoprefixer": "10.2.5",
|
||||||
"badgen": "3.2.2",
|
"badgen": "3.2.2",
|
||||||
@ -27,6 +27,7 @@
|
|||||||
"csrf": "3.1.0",
|
"csrf": "3.1.0",
|
||||||
"dataloader": "2.0.0",
|
"dataloader": "2.0.0",
|
||||||
"dayjs": "1.10.5",
|
"dayjs": "1.10.5",
|
||||||
|
"dd-trace": "0.34.0",
|
||||||
"difflib": "0.2.4",
|
"difflib": "0.2.4",
|
||||||
"discord.js": "12.5.3",
|
"discord.js": "12.5.3",
|
||||||
"emoji-mart": "3.0.1",
|
"emoji-mart": "3.0.1",
|
||||||
@ -52,13 +53,13 @@
|
|||||||
"react-adsense": "0.1.0",
|
"react-adsense": "0.1.0",
|
||||||
"react-dom": "17.0.2",
|
"react-dom": "17.0.2",
|
||||||
"react-hotkeys": "2.0.0",
|
"react-hotkeys": "2.0.0",
|
||||||
"react-responsive-modal": "6.0.1",
|
"react-responsive-modal": "6.1.0",
|
||||||
"react-select": "4.3.1",
|
"react-select": "4.3.1",
|
||||||
"react-showdown": "2.3.0",
|
"react-showdown": "2.3.0",
|
||||||
"react-sortable-hoc": "2.0.0",
|
"react-sortable-hoc": "2.0.0",
|
||||||
"react-use-clipboard": "1.0.7",
|
"react-use-clipboard": "1.0.7",
|
||||||
"sanitize-html": "2.4.0",
|
"sanitize-html": "2.4.0",
|
||||||
"tailwindcss": "2.1.2",
|
"tailwindcss": "2.1.4",
|
||||||
"tlru": "1.0.2",
|
"tlru": "1.0.2",
|
||||||
"twemoji": "13.1.0",
|
"twemoji": "13.1.0",
|
||||||
"url-regex-safe": "2.0.2",
|
"url-regex-safe": "2.0.2",
|
||||||
@ -74,18 +75,18 @@
|
|||||||
"@types/jest": "26.0.23",
|
"@types/jest": "26.0.23",
|
||||||
"@types/josa": "3.0.2",
|
"@types/josa": "3.0.2",
|
||||||
"@types/jsonwebtoken": "8.5.1",
|
"@types/jsonwebtoken": "8.5.1",
|
||||||
"@types/node": "14.17.1",
|
"@types/node": "14.17.2",
|
||||||
"@types/node-emoji": "1.8.1",
|
"@types/node-emoji": "1.8.1",
|
||||||
"@types/node-fetch": "2.5.10",
|
"@types/node-fetch": "2.5.10",
|
||||||
"@types/nprogress": "0.2.0",
|
"@types/nprogress": "0.2.0",
|
||||||
"@types/rc-tooltip": "3.7.3",
|
"@types/rc-tooltip": "3.7.3",
|
||||||
"@types/react": "17.0.8",
|
"@types/react": "17.0.9",
|
||||||
"@types/react-select": "4.0.15",
|
"@types/react-select": "4.0.15",
|
||||||
"@types/sanitize-html": "2.3.1",
|
"@types/sanitize-html": "2.3.1",
|
||||||
"@types/twemoji": "12.1.1",
|
"@types/twemoji": "12.1.1",
|
||||||
"@types/url-regex-safe": "1.0.0",
|
"@types/url-regex-safe": "1.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "4.25.0",
|
"@typescript-eslint/eslint-plugin": "4.26.0",
|
||||||
"@typescript-eslint/parser": "4.25.0",
|
"@typescript-eslint/parser": "4.26.0",
|
||||||
"eslint": "7.27.0",
|
"eslint": "7.27.0",
|
||||||
"eslint-config-prettier": "8.3.0",
|
"eslint-config-prettier": "8.3.0",
|
||||||
"eslint-plugin-jsx-a11y": "6.4.1",
|
"eslint-plugin-jsx-a11y": "6.4.1",
|
||||||
|
|||||||
@ -39,7 +39,7 @@ const BotStats = RequestHandler()
|
|||||||
const botInfo = await get.bot.load(bot)
|
const botInfo = await get.bot.load(bot)
|
||||||
if(!botInfo) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.', version: 1 })
|
if(!botInfo) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.', version: 1 })
|
||||||
if(botInfo.id !== bot) return ResponseWrapper(res, { code: 403, 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 })
|
if(d===1 || d===2) return ResponseWrapper(res, { code: 403, message: `서버 수를 ${[null, '1만', '100만'][d]} 이상으로 설정하실 수 없습니다. 문의해주세요.`, version: 1 })
|
||||||
get.bot.clear(bot)
|
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)}))`)))
|
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)}))`)))
|
||||||
|
|||||||
@ -49,12 +49,12 @@ const BotStats = RequestHandler().post(limiter)
|
|||||||
ResponseWrapper(res, { code: 400, errors: e.errors })
|
ResponseWrapper(res, { code: 400, errors: e.errors })
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
if(!validated) return
|
if(!validated) return
|
||||||
const botInfo = await get.bot.load(req.query.id)
|
const botInfo = await get.bot.load(req.query.id)
|
||||||
if(!botInfo) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
if(!botInfo) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
||||||
if(botInfo.id !== bot) return ResponseWrapper(res, { code: 403 })
|
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]} 이상으로 설정하실 수 없습니다. 문의해주세요.` })
|
if(d===1 || d===2) return ResponseWrapper(res, { code: 403, message: `서버 수를 ${[null, '1만', '100만'][d]} 이상으로 설정하실 수 없습니다. 문의해주세요.` })
|
||||||
get.bot.clear(req.query.id)
|
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)}))`)))
|
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)}))`)))
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { NextApiHandler } from 'next'
|
import { NextApiHandler } from 'next'
|
||||||
import { getMainGuild } from '@utils/DiscordBot'
|
|
||||||
import RequestHandler from '@utils/RequestHandler'
|
import RequestHandler from '@utils/RequestHandler'
|
||||||
|
|
||||||
const HelloWorld: NextApiHandler = RequestHandler().all(async (req, res) => {
|
const HelloWorld: NextApiHandler = RequestHandler().all(async (_req, res) => {
|
||||||
getMainGuild() // Load Discord Bot
|
|
||||||
res.status(200).json({ happy: 'hacking' })
|
res.status(200).json({ happy: 'hacking' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
11
pages/api/v2/management/load.ts
Normal file
11
pages/api/v2/management/load.ts
Normal 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
|
||||||
@ -179,6 +179,14 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
<i className='fas fa-users' /> 서버수
|
<i className='fas fa-users' /> 서버수
|
||||||
</div>
|
</div>
|
||||||
<div>{data.servers || 'N/A'}</div>
|
<div>{data.servers || 'N/A'}</div>
|
||||||
|
{
|
||||||
|
data.shards && data.servers > 1500 && <>
|
||||||
|
<div>
|
||||||
|
<i className='fas fa-sitemap' /> 샤드수
|
||||||
|
</div>
|
||||||
|
<div>{data.shards}</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
<div>
|
<div>
|
||||||
<i className='fas fa-calendar-day' /> 봇 생성일
|
<i className='fas fa-calendar-day' /> 봇 생성일
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -13,6 +13,7 @@ export interface Bot {
|
|||||||
prefix: string
|
prefix: string
|
||||||
votes: number
|
votes: number
|
||||||
servers: number
|
servers: number
|
||||||
|
shards: number
|
||||||
intro: string
|
intro: string
|
||||||
desc: string
|
desc: string
|
||||||
category: Category[]
|
category: Category[]
|
||||||
|
|||||||
@ -25,6 +25,7 @@ async function getBot(id: string, owners=true):Promise<Bot> {
|
|||||||
'prefix',
|
'prefix',
|
||||||
'votes',
|
'votes',
|
||||||
'servers',
|
'servers',
|
||||||
|
'shards',
|
||||||
'intro',
|
'intro',
|
||||||
'desc',
|
'desc',
|
||||||
'web',
|
'web',
|
||||||
@ -280,12 +281,14 @@ async function updateBot(id: string, data: ManageBot) {
|
|||||||
/**
|
/**
|
||||||
* @returns 1 - Limit of 100k servers
|
* @returns 1 - Limit of 100k servers
|
||||||
* @returns 2 - Limit of 10M 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)
|
const bot = await get.bot.load(id)
|
||||||
if(bot.servers < 10000 && servers >= 10000) return 1
|
if(bot.servers < 10000 && servers >= 10000) return 1
|
||||||
if(bot.servers < 1000000 && servers >= 1000000) return 2
|
else if(bot.servers < 1000000 && servers >= 1000000) return 2
|
||||||
await knex('bots').update({ servers }).where({ id })
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -194,11 +194,18 @@ export const BotStatUpdateSchema: Yup.SchemaOf<BotStatUpdate> = Yup.object({
|
|||||||
servers: Yup.number()
|
servers: Yup.number()
|
||||||
.positive('서버 수는 양수여야합니다.')
|
.positive('서버 수는 양수여야합니다.')
|
||||||
.integer('서버 수는 정수여야합니다.')
|
.integer('서버 수는 정수여야합니다.')
|
||||||
.required()
|
.max(1000000000000)
|
||||||
|
.nullable(),
|
||||||
|
shards: Yup.number()
|
||||||
|
.positive('샤드 수는 양수여야합니다.')
|
||||||
|
.integer('샤드 수는 정수여야합니다.')
|
||||||
|
.max(10000)
|
||||||
|
.nullable(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export interface BotStatUpdate {
|
export interface BotStatUpdate {
|
||||||
servers: number
|
servers: number
|
||||||
|
shards: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ReportSchema: Yup.SchemaOf<Report> = Yup.object({
|
export const ReportSchema: Yup.SchemaOf<Report> = Yup.object({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user