Chore: improved bot review api (#484)

This commit is contained in:
Junseo Park 2022-02-13 11:49:17 +09:00 committed by GitHub
parent 0593105fd5
commit f74f668e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -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

View File

@ -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<void> => {

View File

@ -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<SubmittedBot[]> {
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
}