From f74f668e3ea4d55fe4ae62a56aa39ae75791a5b5 Mon Sep 17 00:00:00 2001 From: Junseo Park Date: Sun, 13 Feb 2022 11:49:17 +0900 Subject: [PATCH] Chore: improved bot review api (#484) --- .../management/bots/submits/[id]/history.ts | 21 +++++++++++++++++++ utils/DiscordBot.ts | 7 +++++-- utils/Query.ts | 6 ++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 pages/api/v2/management/bots/submits/[id]/history.ts diff --git a/pages/api/v2/management/bots/submits/[id]/history.ts b/pages/api/v2/management/bots/submits/[id]/history.ts new file mode 100644 index 0000000..f6580e1 --- /dev/null +++ b/pages/api/v2/management/bots/submits/[id]/history.ts @@ -0,0 +1,21 @@ +import { NextApiRequest } from 'next' + +import RequestHandler from '@utils/RequestHandler' +import ResponseWrapper from '@utils/ResponseWrapper' +import { get } from '@utils/Query' +import { DiscordBot } from '@utils/DiscordBot' + +const BotSubmit = RequestHandler() + .get(async (req: ApiRequest, res) => { + const bot = await get.BotAuthorization(req.headers.authorization) + if(bot !== DiscordBot.user.id) return ResponseWrapper(res, { code: 403 }) + return ResponseWrapper(res, { code: 200, data: await get.botSubmitHistory(req.query.id) }) + }) + +interface ApiRequest extends NextApiRequest { + query: { + id: string + } +} + +export default BotSubmit \ No newline at end of file diff --git a/utils/DiscordBot.ts b/utils/DiscordBot.ts index 5e0b5ce..91cce5d 100644 --- a/utils/DiscordBot.ts +++ b/utils/DiscordBot.ts @@ -7,7 +7,9 @@ const guildID = '653083797763522580' const reportChannelID = '813255797823766568' const loggingChannelID = '844006379823955978' const statsLoggingChannelID = '653227346962153472' -const botReviewLogChannelID = '844044961975500840' + +const reviewGuildID = '906537041326637086' +const botReviewLogChannelID = '906551334063439902' DiscordBot.on('ready', async () => { console.log('I\'m Ready') @@ -18,9 +20,10 @@ DiscordBot.on('ready', async () => { DiscordBot.login(process.env.DISCORD_TOKEN) export const getMainGuild = () => DiscordBot.guilds.cache.get(guildID) +export const getReviewGuild = () => DiscordBot.guilds.cache.get(reviewGuildID) export const getReportChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(reportChannelID) as Discord.TextChannel export const getLoggingChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(loggingChannelID) as Discord.TextChannel -export const getBotReviewLogChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(botReviewLogChannelID) as Discord.TextChannel +export const getBotReviewLogChannel = (): Discord.TextChannel => getReviewGuild().channels.cache.get(botReviewLogChannelID) as Discord.TextChannel export const getStatsLoggingChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(statsLoggingChannelID) as Discord.TextChannel export const discordLog = async (type: string, issuerID: string, embed?: Discord.MessageEmbed, attachment?: { content: string, format: string}, content?: string): Promise => { diff --git a/utils/Query.ts b/utils/Query.ts index ca8219b..8274ab2 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -660,6 +660,11 @@ async function getBotSubmitList() { return await Promise.all(res.map(b => get.botSubmit.load(JSON.stringify({ id: b.id, date: b.date })))) } +async function getBotSubmitHistory(id: string): Promise { + const res = await knex('submitted').select(['id', 'date']).where({ id }) + return await Promise.all(res.map(b => get.botSubmit.load(JSON.stringify({ id: b.id, date: b.date })))) +} + async function denyBotSubmission(id: string, date: number, reason?: string) { await knex('submitted').update({ state: 2, reason: reason || null }).where({ state: 0, id, date }) } @@ -815,6 +820,7 @@ export const get = { BotAuthorization, ServerAuthorization, botSubmitList: getBotSubmitList, + botSubmitHistory: getBotSubmitHistory, serverOwners: fetchServerOwners }