From 799c40a68ccee19d9fa2129ff8b143f296d279cf Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 14:29:52 +0000 Subject: [PATCH 01/13] Add Message Editing --- website/src/App.tsx | 43 ++++++++++++++++++++++++++++++++++--- website/src/state.ts | 7 +++++- website/src/webhook.impl.ts | 8 +++---- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 896ec31..956abb0 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -32,6 +32,7 @@ function App() { const stateManager = useMemo(() => new DisplaySliceManager(dispatch), [dispatch]); const state = useSelector((state: RootState) => state.display.data) const webhookUrl = useSelector((state: RootState) => state.display.webhookUrl); + const messageLink = useSelector((state: RootState) => state.display.messageUrl); const response = useSelector((state: RootState) => state.display.webhookResponse); const [page, setPage] = useRouter(); const [postTitle, setPostTitle] = useState(""); @@ -53,6 +54,22 @@ function App() { return () => clearTimeout(getData) }, [webhookUrl]); + useEffect(() => { + const getData = setTimeout(() => localStorage.setItem("discord.builders__messageLink", messageLink), 1000) + return () => clearTimeout(getData) + }, [messageLink]); + + let parsed_msg_url: URL | null = null; + try { + parsed_msg_url = new URL(messageLink); + + if (parsed_msg_url.pathname.startsWith('/channels/') && parsed_msg_url.hostname === 'discord.com') { + parsed_msg_url.protocol = 'https:'; + } + + const parsed_query = new URLSearchParams(parsed_msg_url.search); + parsed_msg_url.search = parsed_query.toString(); + } catch (e) {} let parsed_url: URL | null = null; try { @@ -61,6 +78,9 @@ function App() { if (parsed_url.pathname.startsWith('/api/webhooks/') && parsed_url.hostname === 'discord.com') { parsed_url.protocol = 'https:'; parsed_url.pathname = '/api/v10/webhooks/' + parsed_url.pathname.slice('/api/webhooks/'.length); + if (parsed_msg_url != null) { + parsed_url.pathname += '/messages/'+parsed_msg_url.pathname.split('/').pop(); + } } const parsed_query = new URLSearchParams(parsed_url.search); @@ -75,7 +95,10 @@ function App() { const threadId = useMemo(() => getThreadId(webhookUrl), [webhookUrl]); const sendMessage = async () => { - const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state)) + var method_req; + if (parsed_msg_url != null) {method_req = "PATCH"} + else {method_req = "POST"} + const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state, method_req)) const status_code = req.status; if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})); @@ -95,7 +118,7 @@ function App() { if (!postTitle) return; dialog.current?.close(); - const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state, postTitle)) + const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state, "POST", postTitle)) const status_code = req.status; if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})); @@ -135,7 +158,7 @@ function App() { onChange={ev => dispatch(actions.setWebhookUrl(ev.target.value))}/> @@ -146,6 +169,20 @@ function App() { dispatch(actions.setThreadId(ev.target.value))} placeholder={"Optional. If you want to send the message to a thread, put the thread ID here."}/> +
+

Message Link

+
+
+ dispatch(actions.setMessageLink(ev.target.value))}/> +
+ +
+

Warning: The message must to be sent by the webhook that edits it.

+
+
diff --git a/website/src/state.ts b/website/src/state.ts index 4a52626..cd908df 100644 --- a/website/src/state.ts +++ b/website/src/state.ts @@ -52,7 +52,8 @@ export const displaySlice = createSlice({ initialState: () => ({ data: [] as Component[], webhookUrl: localStorage.getItem("discord.builders__webhookToken") || "", // Toolkit run this function so type is string - webhookResponse: null as object | null + webhookResponse: null as object | null, + messageUrl: localStorage.getItem("discord.builders__messageLink") || "" // Toolkit run this function so type is string }), reducers: { wrapKey(state, action: PayloadAction>) { @@ -150,6 +151,10 @@ export const displaySlice = createSlice({ state.webhookUrl = action.payload }, + setMessageLink(state, action: PayloadAction) { + state.messageUrl = action.payload + }, + setThreadId(state, action: PayloadAction) { try { const parsed_url = new URL(state.webhookUrl); diff --git a/website/src/webhook.impl.ts b/website/src/webhook.impl.ts index 0b88dec..5b14da7 100644 --- a/website/src/webhook.impl.ts +++ b/website/src/webhook.impl.ts @@ -58,7 +58,7 @@ export const webhookImplementation = { } }, - prepareRequest(state: Component[], thread_name?: string): RequestInit { + prepareRequest(state: Component[], method_req?: string, thread_name?: string): RequestInit { const files = this.scrapFiles(state); const data = JSON.stringify({ @@ -67,7 +67,7 @@ export const webhookImplementation = { thread_name, }); - if (!files.length) return {method: "POST", body: data, headers: {"Content-Type": "application/json"}} + if (!files.length) return {method: method_req, body: data, headers: {"Content-Type": "application/json"}} const form = new FormData(); form.append('payload_json', data); @@ -75,7 +75,7 @@ export const webhookImplementation = { const blob = window.uploadedFiles[filename]; form.append(`files[${idx}]`, blob, filename); }) - return {method: "POST", body: form, headers: {}} + return {method: method_req, body: form, headers: {}} }, getErrors(response: unknown) { @@ -91,4 +91,4 @@ export const webhookImplementation = { return components as Record; } -} \ No newline at end of file +} From 8e7d3823bb4824bf440a1f2c17c08a93cdadb3ef Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 17:39:11 +0000 Subject: [PATCH 02/13] Add loading the message for editing --- website/src/App.tsx | 27 +++++++++++++++++++++++++-- website/src/EmojiShow.tsx | 26 ++++++++++++++++---------- website/src/state.ts | 4 ++++ website/src/webhook.impl.ts | 2 +- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 956abb0..0a0a320 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -102,6 +102,29 @@ function App() { const status_code = req.status; if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})); + else if (status_code === 200) return dispatch(actions.setWebhookResponse({"status": "200 Success"})); + + const error_data = await req.json(); + + if (error_data?.code === 220001 && dialog.current !== null) { + dialog.current.showModal(); + dispatch(actions.setWebhookResponse(null)) + return; + } + + dispatch(actions.setWebhookResponse(error_data)) + } + + const getMessage = async () => { + const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state, "GET")) + + const status_code = req.status; + if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})) + else if (status_code === 200) { + let loaded_data = await req.json() + dispatch(actions.setComponentsData(loaded_data["components"])) + return dispatch(actions.setWebhookResponse({"status": "200 Success"})) + } const error_data = await req.json(); @@ -176,11 +199,11 @@ function App() { dispatch(actions.setMessageLink(ev.target.value))}/>
- -

Warning: The message must to be sent by the webhook that edits it.

+

Warning: The message must to be sent by the webhook that edits it and uploading a image or a file doesnt work with editing.

diff --git a/website/src/EmojiShow.tsx b/website/src/EmojiShow.tsx index 8796051..17d5b80 100644 --- a/website/src/EmojiShow.tsx +++ b/website/src/EmojiShow.tsx @@ -8,15 +8,21 @@ export const EmojiShow: EmojiShowType = ({emoji}) => { return getEmojiDataFromNative(emoji, 'twitter', data) }, []) - if (emoji.id !== null) return {`Discord + console.log(emoji) + if (typeof(emoji) == "undefined"){ + return null + } + else { + if (emoji.id !== null && typeof(emoji.id) !== "undefined") return {`Discord - return + return + } } diff --git a/website/src/state.ts b/website/src/state.ts index cd908df..54a12e9 100644 --- a/website/src/state.ts +++ b/website/src/state.ts @@ -155,6 +155,10 @@ export const displaySlice = createSlice({ state.messageUrl = action.payload }, + setComponentsData(state, action: PayloadAction) { + state.data = action.payload + }, + setThreadId(state, action: PayloadAction) { try { const parsed_url = new URL(state.webhookUrl); diff --git a/website/src/webhook.impl.ts b/website/src/webhook.impl.ts index 5b14da7..0760d72 100644 --- a/website/src/webhook.impl.ts +++ b/website/src/webhook.impl.ts @@ -67,7 +67,7 @@ export const webhookImplementation = { thread_name, }); - if (!files.length) return {method: method_req, body: data, headers: {"Content-Type": "application/json"}} + if (!files.length) return {method: method_req, body: ((method_req == "GET") ? null : data), headers: {"Content-Type": "application/json"}} const form = new FormData(); form.append('payload_json', data); From c9faea6d9b85666aa33025f3503847e9e0ee20f1 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 17:42:23 +0000 Subject: [PATCH 03/13] Remove console log that i forgot to remove --- website/src/EmojiShow.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/website/src/EmojiShow.tsx b/website/src/EmojiShow.tsx index 17d5b80..bf4e555 100644 --- a/website/src/EmojiShow.tsx +++ b/website/src/EmojiShow.tsx @@ -8,7 +8,6 @@ export const EmojiShow: EmojiShowType = ({emoji}) => { return getEmojiDataFromNative(emoji, 'twitter', data) }, []) - console.log(emoji) if (typeof(emoji) == "undefined"){ return null } From 865c9fc067e0a1414ad91673e867601ee77a07f7 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 19:04:44 +0000 Subject: [PATCH 04/13] Fixed duplication bug when loading a message --- website/src/App.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 0a0a320..6bc0164 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -37,6 +37,7 @@ function App() { const [page, setPage] = useRouter(); const [postTitle, setPostTitle] = useState(""); useHashRouter(); + console.log(state) const setFile = useCallback(webhookImplementation.setFile, []); const getFile = useCallback(webhookImplementation.getFile, []) @@ -122,7 +123,14 @@ function App() { if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})) else if (status_code === 200) { let loaded_data = await req.json() - dispatch(actions.setComponentsData(loaded_data["components"])) + dispatch(actions.setComponentsData([])) + for (const comp of loaded_data["components"]){ + let data_to_add = comp + if ("id" in data_to_add){ + delete data_to_add.id; + } + dispatch(actions.appendKey({"key":["data"],"value":data_to_add})) + } return dispatch(actions.setWebhookResponse({"status": "200 Success"})) } @@ -160,7 +168,7 @@ function App() { stateManager={stateManager} stateKey={stateKey} passProps={passProps} - className={Styles.preview} + className={Styles.input} errors={errors} /> From 25c76a3856e0cd9321559f41a83ee9e9ffc3c2c0 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 19:07:29 +0000 Subject: [PATCH 05/13] Again, forgot to remove console log --- website/src/App.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 6bc0164..ef75619 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -37,7 +37,6 @@ function App() { const [page, setPage] = useRouter(); const [postTitle, setPostTitle] = useState(""); useHashRouter(); - console.log(state) const setFile = useCallback(webhookImplementation.setFile, []); const getFile = useCallback(webhookImplementation.getFile, []) From 1b2e7091db6777051760908ce9bdb77379bee6e0 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 19:31:40 +0000 Subject: [PATCH 06/13] Remove the space in buttons after loading discord message with buttons that have no icon --- website/src/App.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/src/App.tsx b/website/src/App.tsx index ef75619..81d7416 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -59,6 +59,10 @@ function App() { return () => clearTimeout(getData) }, [messageLink]); + useEffect(() => { + document.querySelectorAll('._emoji_c7tgn_78').forEach(e => (e.childElementCount == 0) ? e.remove() : null); + }); + let parsed_msg_url: URL | null = null; try { parsed_msg_url = new URL(messageLink); From 9d95d3b409eddae3bb71b48a61aaa24d1934a69c Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 20:02:21 +0000 Subject: [PATCH 07/13] Fix Issue With sometimes disapearing emojis from buttons and crash if you attempt to move a loaded button with no icon outside of its component set --- website/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 81d7416..7279cb0 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -60,7 +60,7 @@ function App() { }, [messageLink]); useEffect(() => { - document.querySelectorAll('._emoji_c7tgn_78').forEach(e => (e.childElementCount == 0) ? e.remove() : null); + document.querySelectorAll('._emoji_c7tgn_78').forEach(e => (e.childElementCount == 0) ? e.style.display = "none" : e.style.display = ""); }); let parsed_msg_url: URL | null = null; From d743e3afb15991ad8ce00b621b67e166f1428556 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 23:23:28 +0000 Subject: [PATCH 08/13] Update Readme for steps with building --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 1bd97bd..e6a1683 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,25 @@ cd website && yarn dev Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +## 📦 Building + + +First, you need to have the steps above done: + +Build the website library: + +```bash +cd website && yarn build +``` + +Run the build server of the website: + +```bash +serve dist +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + ## ⚠️ Commercial use Although the `website/` project is licensed under the permissive MIT License, it depends on the `components-sdk/` package, which is **licensed under the PolyForm Noncommercial License 1.0.0**. From d6653d03511dfbf98c7b3a090417d9170bd123a5 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Tue, 13 May 2025 23:23:57 +0000 Subject: [PATCH 09/13] remove : --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6a1683..62e0e76 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the ## 📦 Building -First, you need to have the steps above done: +First, you need to have the steps above done Build the website library: From 668710af3b8484c66feb99562213fc4cb310b50b Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Wed, 14 May 2025 00:17:14 +0000 Subject: [PATCH 10/13] Add info on how to fix icons not loading on dev server (maybe only on linux) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 62e0e76..41bb704 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,13 @@ Run the development server of the website: cd website && yarn dev ``` +If icons from components-sdk are not loading for you +Comment this alias in website/vite.config.ts + +```bash +{find: /^components-sdk.*$/, replacement: resolve(__dirname, '../components-sdk/src')}, +``` + Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. ## 📦 Building From acfb5a5150406fa06b1d18abf20d9e48c0d12f1b Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Wed, 14 May 2025 00:18:09 +0000 Subject: [PATCH 11/13] Move the info --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 41bb704..c30f733 100644 --- a/README.md +++ b/README.md @@ -26,15 +26,14 @@ Run the development server of the website: cd website && yarn dev ``` -If icons from components-sdk are not loading for you -Comment this alias in website/vite.config.ts +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +If icons from components-sdk are not loading for you Comment this alias in website/vite.config.ts ```bash {find: /^components-sdk.*$/, replacement: resolve(__dirname, '../components-sdk/src')}, ``` -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. - ## 📦 Building From 4ea50cdd5da4e465ae63214e078e02a8d2dc7f00 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Wed, 14 May 2025 16:01:08 +0000 Subject: [PATCH 12/13] Added option to change username and avatar of the message --- website/src/App.tsx | 34 ++++++++++++++++++++++++++++++++-- website/src/state.ts | 12 +++++++++++- website/src/webhook.impl.ts | 5 ++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 7279cb0..3b29c98 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -34,6 +34,8 @@ function App() { const webhookUrl = useSelector((state: RootState) => state.display.webhookUrl); const messageLink = useSelector((state: RootState) => state.display.messageUrl); const response = useSelector((state: RootState) => state.display.webhookResponse); + const username = useSelector((state: RootState) => state.display.setusername); + const avatar = useSelector((state: RootState) => state.display.setavatar); const [page, setPage] = useRouter(); const [postTitle, setPostTitle] = useState(""); useHashRouter(); @@ -100,9 +102,22 @@ function App() { const sendMessage = async () => { var method_req; + let username_in = undefined; + let avatarurl_in = undefined; if (parsed_msg_url != null) {method_req = "PATCH"} - else {method_req = "POST"} - const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state, method_req)) + else { + method_req = "POST"; + if (username != "") username_in = username; + if (avatar != "") avatarurl_in = avatar; + } + const req = await fetch(String(parsed_url), webhookImplementation.prepareRequest(state, method_req, ...Array(1), username_in, avatarurl_in)) + + if (username == "" || avatar == ""){ + const req_2 = await fetch(String(webhookUrl), webhookImplementation.prepareRequest(state, "GET")) + let data_2 = await req_2.json() + if (username == "") dispatch(actions.setUsernameData(data_2["name"])) + if (avatar == "") dispatch(actions.setAvatarData("https://cdn.discordapp.com/avatars/"+data_2["id"]+"/"+data_2["avatar"]+".png")) + } const status_code = req.status; if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})); @@ -134,6 +149,9 @@ function App() { } dispatch(actions.appendKey({"key":["data"],"value":data_to_add})) } + dispatch(actions.setUsernameData(loaded_data["author"]["username"])) + dispatch(actions.setAvatarData("https://cdn.discordapp.com/avatars/"+loaded_data["author"]["id"]+"/"+loaded_data["author"]["avatar"]+".png")) + return dispatch(actions.setWebhookResponse({"status": "200 Success"})) } @@ -217,6 +235,18 @@ function App() {

Warning: The message must to be sent by the webhook that edits it and uploading a image or a file doesnt work with editing.

+
+
+
+

Username

+ dispatch(actions.setUsernameData(ev.target.value))} placeholder={((parsed_msg_url == null) ? 'Optional. If you want to change the username of the message.' : 'Cannot Change username in edit mode.')}/> +

Avatar Url

+ dispatch(actions.setAvatarData(ev.target.value))} placeholder={((parsed_msg_url == null) ? 'Optional. If you want to change the avatar of the message.' : 'Cannot Change avatar in edit mode.')}/> +
+
+

Warning: cant change name or profile when editing.

+
+
diff --git a/website/src/state.ts b/website/src/state.ts index 54a12e9..b2169b4 100644 --- a/website/src/state.ts +++ b/website/src/state.ts @@ -53,7 +53,9 @@ export const displaySlice = createSlice({ data: [] as Component[], webhookUrl: localStorage.getItem("discord.builders__webhookToken") || "", // Toolkit run this function so type is string webhookResponse: null as object | null, - messageUrl: localStorage.getItem("discord.builders__messageLink") || "" // Toolkit run this function so type is string + messageUrl: localStorage.getItem("discord.builders__messageLink") || "", // Toolkit run this function so type is string + setusername: "", + setavatar: "", }), reducers: { wrapKey(state, action: PayloadAction>) { @@ -155,6 +157,14 @@ export const displaySlice = createSlice({ state.messageUrl = action.payload }, + setUsernameData(state, action: PayloadAction) { + state.setusername = action.payload + }, + + setAvatarData(state, action: PayloadAction) { + state.setavatar = action.payload + }, + setComponentsData(state, action: PayloadAction) { state.data = action.payload }, diff --git a/website/src/webhook.impl.ts b/website/src/webhook.impl.ts index 0760d72..3358d1b 100644 --- a/website/src/webhook.impl.ts +++ b/website/src/webhook.impl.ts @@ -58,13 +58,16 @@ export const webhookImplementation = { } }, - prepareRequest(state: Component[], method_req?: string, thread_name?: string): RequestInit { + prepareRequest(state: Component[], method_req?: string, thread_name?: string, username?: string, avatar_url?: string): RequestInit { const files = this.scrapFiles(state); const data = JSON.stringify({ components: state, flags: 32768, thread_name, + username, + avatar_url, + }); if (!files.length) return {method: method_req, body: ((method_req == "GET") ? null : data), headers: {"Content-Type": "application/json"}} From f54e81f176b7ddde59f28c10c8606d9117c9adc8 Mon Sep 17 00:00:00 2001 From: Darko <48098927+Darko1green1LOrd@users.noreply.github.com> Date: Sun, 29 Jun 2025 11:25:49 +0000 Subject: [PATCH 13/13] Hopefully Fixed duplication bug when loading a message for now --- website/src/App.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 3b29c98..31e2f8b 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -127,7 +127,7 @@ function App() { if (error_data?.code === 220001 && dialog.current !== null) { dialog.current.showModal(); - dispatch(actions.setWebhookResponse(null)) + dispatch(actions.setWebhookResponse(null)); return; } @@ -140,9 +140,15 @@ function App() { const status_code = req.status; if (status_code === 204) return dispatch(actions.setWebhookResponse({"status": "204 Success"})) else if (status_code === 200) { - let loaded_data = await req.json() + let loaded_data = await req.json(); + let reg_check = /"id":(([1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9])|"[^"]*"),/gm; //Discord includes ids in the component but this doesnt like the ids (it causes duplicates), this is to remove them + try { + var fixed_data = JSON.parse(JSON.stringify(loaded_data).replaceAll(reg_check,"")); + } catch(err) { + console.error(err); + } dispatch(actions.setComponentsData([])) - for (const comp of loaded_data["components"]){ + for (const comp of fixed_data["components"]){ let data_to_add = comp if ("id" in data_to_add){ delete data_to_add.id;