From e8075ee7d51292b9233f9e4b3ccbb9ca1d783e3a Mon Sep 17 00:00:00 2001 From: Byungchul Kim <64084503+chul0721@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:03:41 +0900 Subject: [PATCH] feat: support webhook (#514) * feat: support webhook * feat: bot webhook * types: add enums for webhook * feat: update webhook status by param * feat: send webhook of server count change * feat: send webhook of vote * chore: add desc of faulty webhook * chore: set initial value * feat: add collection of clients * chore: simplify * feat: set webhook status dynamically * feat: webhook for discord * refactor: rename WebhookStatus.Paused * refactor: make webhookClients to one object * feat: webhook with fetch * feat: add warning prop to input component * feat: display red when warning * feat: check server count properly * feat: handle status codes * refactor: remove double fetch * chore: typo * feat: send failed message * fix: missing id on query * feat: limit response body * feat: use severlist bot to dm * feat: webhook for servers * feat: use env for ids * refactor: remove variables * fix: send discord log * fix: message * feat: include koreanbots in footer * fix: typo * refactor: export function as non default * feat: add verification * feat: add columns * feat: verify bot webhook * feat: verify server webhook * chore: rename key to secret * fix: stringify * chore: remove webhook related columns * refactor: use separate object for webhook * type: add webhook prop to bot / server * fix: implement webhook status * refactor: rename webhook to webhookURL * feat: select webhook props * feat: remove bot's private props * feat: remove server private fields * chore: use makeURLs * type: fix faildSince is type as string * refactor: rename to updateWebhook * chore: make props optional * feat: failedSince * feat: remove failedSince when success * fix: missing import * fix: typo * fix: convert missing prop * fix: typo * chore: remove unnecessary select * fix: missing systax * feat: sort docs * feat: use relay * fix: check status properly * chore: handle relay server error * remove awaits * fix: add base url * fix: typo * chore: remove red highlights * chore: change emoji --------- Co-authored-by: SKINMAKER Co-authored-by: skinmaker1345 --- .env.demo.local | 8 + components/Form/Input.tsx | 3 +- components/Form/Label.tsx | 11 + pages/api/v2/bots/[id]/index.ts | 17 +- pages/api/v2/bots/[id]/stats.ts | 14 +- pages/api/v2/bots/[id]/vote.ts | 16 +- pages/api/v2/servers/[id]/index.ts | 16 +- pages/api/v2/servers/[id]/vote.ts | 18 +- pages/bots/[id]/edit.tsx | 6 +- pages/developers/docs/[first]/[second].tsx | 8 +- pages/servers/[id]/edit.tsx | 6 +- migrate.sql => sql/migrate.sql | 0 sql/webhook.sql | 9 + types/index.ts | 23 ++ utils/DiscordBot.ts | 30 +-- utils/Query.ts | 57 ++++- utils/Webhook.ts | 241 +++++++++++++++++++++ utils/Yup.ts | 14 +- 18 files changed, 458 insertions(+), 39 deletions(-) rename migrate.sql => sql/migrate.sql (100%) create mode 100644 sql/webhook.sql create mode 100644 utils/Webhook.ts diff --git a/.env.demo.local b/.env.demo.local index 84a96af..89bc27c 100644 --- a/.env.demo.local +++ b/.env.demo.local @@ -15,6 +15,14 @@ DISCORD_SCOPE=SCOPE DISCORD_TOKEN=BOT_TOKEN DISCORD_CLIENT_INTENTS=32767 +GUILD_ID=653083797763522580 +REVIEW_GUILD_ID=906537041326637086 +REPORT_CHANNEL_ID=813255797823766568 +LOGGING_CHANNEL_ID=844006379823955978 +STATS_LOGGING_CHANNEL_ID=653227346962153472 +REVIEW_LOG_CHANNEL_ID=906551334063439902 +OPEN_REVIEW_LOG_CHANNEL_ID=1008376563731013643 + GITHUB_CLIENT_ID=GH_CLIENT_ID GITHUB_CLIENT_SECRET=GH_CLIENT_SECRET diff --git a/components/Form/Input.tsx b/components/Form/Input.tsx index 446e31f..2a3ea3b 100644 --- a/components/Form/Input.tsx +++ b/components/Form/Input.tsx @@ -4,7 +4,7 @@ const Input: React.FC = ({ name, placeholder, ...props }) => { return } @@ -12,6 +12,7 @@ const Input: React.FC = ({ name, placeholder, ...props }) => { interface InputProps { name: string placeholder?: string + warning?: boolean [key: string]: unknown } diff --git a/components/Form/Label.tsx b/components/Form/Label.tsx index 198b19e..6b75791 100644 --- a/components/Form/Label.tsx +++ b/components/Form/Label.tsx @@ -1,3 +1,5 @@ +import Tooltip from '@components/Tooltip' + const Label: React.FC = ({ For, children, @@ -7,6 +9,8 @@ const Label: React.FC = ({ grid = true, short = false, required = false, + warning = false, + warningText }) => { return + +