From 323e9e88a22d2afcec70b1c6dd0a1ba4d506155d Mon Sep 17 00:00:00 2001 From: Junseo Park Date: Sat, 27 Feb 2021 11:01:38 +0900 Subject: [PATCH] feat: added applications route --- components/Application.tsx | 19 +++++++++++++ pages/developers/applications/index.tsx | 38 +++++++++++++++++++++++++ pages/developers/index.tsx | 10 +++++++ types/index.ts | 6 ++++ utils/Query.ts | 9 +++++- 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 components/Application.tsx create mode 100644 pages/developers/applications/index.tsx create mode 100644 pages/developers/index.tsx diff --git a/components/Application.tsx b/components/Application.tsx new file mode 100644 index 0000000..32fde96 --- /dev/null +++ b/components/Application.tsx @@ -0,0 +1,19 @@ +import Link from 'next/link' +import DiscordAvatar from './DiscordAvatar' + +const Application = ({ type, id, name }:ApplicationProps):JSX.Element => { + return +
+ +

{name.slice(0, 7)}{name.length > 7 && '...'}

+
+ +} + +interface ApplicationProps { + type: 'bot' + id: string + name: string +} + +export default Application \ No newline at end of file diff --git a/pages/developers/applications/index.tsx b/pages/developers/applications/index.tsx new file mode 100644 index 0000000..d28b04b --- /dev/null +++ b/pages/developers/applications/index.tsx @@ -0,0 +1,38 @@ +import { NextPage, NextPageContext } from 'next' +import dynamic from 'next/dynamic' + +import { get } from '@utils/Query' +import { parseCookie } from '@utils/Tools' + +import { Bot, User } from '@types' + +const Application = dynamic(() => import('@components/Application')) +const Container = dynamic(() => import('@components/Container')) +const SEO = dynamic(() => import('@components/SEO')) + +const Applications: NextPage = ({ user }) => { + return + +

나의 봇

+

한국 디스코드봇 리스트 API를 활용하여 봇에 다양한 기능을 추가해보세요.

+
+ { + (user.bots as Bot[]).map(bot => ) + } +
+
+} + +interface ApplicationsProps { + user: User +} + +export const getServerSideProps = async (ctx: NextPageContext) => { + const parsed = parseCookie(ctx.req) + const user = await get.Authorization(parsed?.token) || '' + + return { + props: { user: await get.user.load(user) } + } +} +export default Applications \ No newline at end of file diff --git a/pages/developers/index.tsx b/pages/developers/index.tsx new file mode 100644 index 0000000..223cb93 --- /dev/null +++ b/pages/developers/index.tsx @@ -0,0 +1,10 @@ +import { NextPage } from 'next' +import { useRouter } from 'next/router' + +const Developers: NextPage = () => { + const router = useRouter() + router.push('/developers/applications') + return <> +} + +export default Developers \ No newline at end of file diff --git a/types/index.ts b/types/index.ts index 538f411..6ddf413 100644 --- a/types/index.ts +++ b/types/index.ts @@ -36,6 +36,12 @@ export interface User { bots: Bot[] | string[] } +export interface BotSpec { + id: string + webhook: string | null + token: string +} + export enum UserFlags { general = 0 << 0, staff = 1 << 0, diff --git a/utils/Query.ts b/utils/Query.ts index fa831f4..b9f5802 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -47,7 +47,7 @@ async function getBot(id: string, owners=true):Promise { const discordBot = await get.discord.user.load(res[0].id) await getMainGuild()?.members?.fetch(res[0].id).catch(e=> e) if(!discordBot) return null - res[0].flags = res[0].flags | (discordBot.flags && DiscordUserFlags.VERIFIED_BOT ? BotFlags.verifed : 0) | (res[0].trusted ? BotFlags.trusted : 0) + res[0].flags = res[0].flags | (discordBot.flags && DiscordUserFlags.VERIFIED_BOT ? BotFlags.verifed : 0) | (res[0].trusted ? BotFlags.trusted : 0) | (res[0].partnered ? BotFlags.partnered : 0) res[0].tag = discordBot.discriminator res[0].avatar = discordBot.avatar res[0].name = discordBot.username @@ -219,6 +219,12 @@ async function submitBot(id: string, data: AddBotSubmit):Promise serialize(row)) , { cacheMap: new TLRU({ maxStoreSize: 50, maxAgeMs: 60000 }) }), + botSpec: getBotSpec, list: { category: new DataLoader( async (key: string[]) =>