mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 06:20:24 +00:00
Chore: improved bot review api (#484)
This commit is contained in:
parent
0593105fd5
commit
f74f668e3e
21
pages/api/v2/management/bots/submits/[id]/history.ts
Normal file
21
pages/api/v2/management/bots/submits/[id]/history.ts
Normal 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
|
||||||
@ -7,7 +7,9 @@ const guildID = '653083797763522580'
|
|||||||
const reportChannelID = '813255797823766568'
|
const reportChannelID = '813255797823766568'
|
||||||
const loggingChannelID = '844006379823955978'
|
const loggingChannelID = '844006379823955978'
|
||||||
const statsLoggingChannelID = '653227346962153472'
|
const statsLoggingChannelID = '653227346962153472'
|
||||||
const botReviewLogChannelID = '844044961975500840'
|
|
||||||
|
const reviewGuildID = '906537041326637086'
|
||||||
|
const botReviewLogChannelID = '906551334063439902'
|
||||||
|
|
||||||
DiscordBot.on('ready', async () => {
|
DiscordBot.on('ready', async () => {
|
||||||
console.log('I\'m Ready')
|
console.log('I\'m Ready')
|
||||||
@ -18,9 +20,10 @@ DiscordBot.on('ready', async () => {
|
|||||||
DiscordBot.login(process.env.DISCORD_TOKEN)
|
DiscordBot.login(process.env.DISCORD_TOKEN)
|
||||||
|
|
||||||
export const getMainGuild = () => DiscordBot.guilds.cache.get(guildID)
|
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 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 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 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> => {
|
export const discordLog = async (type: string, issuerID: string, embed?: Discord.MessageEmbed, attachment?: { content: string, format: string}, content?: string): Promise<void> => {
|
||||||
|
|||||||
@ -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 }))))
|
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) {
|
async function denyBotSubmission(id: string, date: number, reason?: string) {
|
||||||
await knex('submitted').update({ state: 2, reason: reason || null }).where({ state: 0, id, date })
|
await knex('submitted').update({ state: 2, reason: reason || null }).where({ state: 0, id, date })
|
||||||
}
|
}
|
||||||
@ -815,6 +820,7 @@ export const get = {
|
|||||||
BotAuthorization,
|
BotAuthorization,
|
||||||
ServerAuthorization,
|
ServerAuthorization,
|
||||||
botSubmitList: getBotSubmitList,
|
botSubmitList: getBotSubmitList,
|
||||||
|
botSubmitHistory: getBotSubmitHistory,
|
||||||
serverOwners: fetchServerOwners
|
serverOwners: fetchServerOwners
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user