worked on transcripts
diff --git a/Components/Transcripts/Embed.js b/Components/Transcripts/Embed.js
index dca30b2..b163da8 100644
--- a/Components/Transcripts/Embed.js
+++ b/Components/Transcripts/Embed.js
@@ -1,15 +1,72 @@
import Styles from "../../styles/Components/transcripts.module.css"
import Image from "next/image";
-import JSDom from "jsdom";
+import Showdown from "showdown";
+import Axios from "axios";
+import { useEffect, useState } from "react";
-function embed(props) {
+const bold = /(\*\*.+\*\*)/g;
+const italic = /(\*.+\*|\_.+\_)/g;
+const emoji = /(<a?:.+:\D+>)/g;
+const user = /(<@!?\d+>)/g;
+const underline = /(\_\_.+\_\_)/g;
+const strikethrough = /(\~\~.+\~\~)/g;
+const code = /(\`.+\`)/g;
+const codeBlock = /(\`\`\`.+\`\`\`)/g;
+const spoiler = /(\`\`\`.+\`\`\`)/g;
+
+const regex = /(\*\*\*.+\*\*\*|\*\*.+\*\*|\*.+\*|\_.+\_|\_\_.+\_\_|\~\~.+\~\~|\`.+\`|\`\`\`.+\`\`\`|\`\`\`.+\`\`\`|<a?:.+:\D+>|<@!?\d+>)/g;
+
+const converter = new Showdown.Converter();
+
+async function parse(text) {
+ const splitText = text.split(regex);
+ console.log(splitText)
+ return await splitText.map( async (item, index) => {
+ if (item.match(bold)) {
+ return <b key={index}>{item.replaceAll(/\*\*/g, '')}</b>
+ }
+ if (item.match(underline)) {
+ return <u key={index}>{item.replaceAll(/\_\_/g, '')}</u>
+ }
+ if (item.match(italic)) {
+ return <i key={index}>{item.replaceAll(/\*/g, '')}</i>
+ }
+ if (item.match(code)) {
+ return <code key={index}>{item.replaceAll(/\`/g, '')}</code>
+ }
+ if (item.match(emoji)) {
+ return <Image key={index} src={`https://cdn.discord.com/emojis/${item.replaceAll(/\D/g, '')}`} width={20} height={20} alt="" />
+ }
+ if (item.match(user)) {
+ const username = (await Axios.get(`http://localhost:10000/users/${item.replaceAll(/\D/g, '')}`)).data;
+ console.log(username)
+ return <>{username}</>
+
+ }
+ return item
+ })
+
+
+}
+
+function Embed(props) {
let description = props.embed.description;
if (description) {
description = description.split("\n");
}
- return ( // added it
+ const [newDesc, setNewDesc] = useState([]);
+
+ useEffect(() => {
+ async function stuff() {
+ const parsed = await parse(props.embed.description);
+ setNewDesc(newDesc => [...newDesc, parsed]);
+ }
+ stuff();
+ })
+
+ return (
<div className={Styles.embed} style={{borderColor: props.color ?? "#F27878"}}>
{
props.embed.author ?
@@ -38,18 +95,8 @@
props.embed.description ?
<div className={Styles.embedDescription}>
{
- description.map(i => {// idk how to do make this work
- i = i
- .replaceAll(/<a?:.+:\D+>/g, (match, id) => {
- return <Image src={`https://cdn.discordapp.com/emojis/${id}.png`} alt=""/>
- })
- .replaceAll(/\*\*.+\*\*/g, (match, text) => {
- return <b>{text}</b>
- })
- .replaceAll(/\*.+\*/g, (match, text) => {
- return <i>{text}</i>
- })
- return <>{new JSDom.JSDOM(i)}<br/></> // CANT FIND A DOM PARSER THAT WORKS
+ newDesc.map((item) => {
+ return item;
})
}
</div>
@@ -59,4 +106,4 @@
)
}
-export default embed;
\ No newline at end of file
+export default Embed;
diff --git a/package.json b/package.json
index 294b01a..f85ee32 100644
--- a/package.json
+++ b/package.json
@@ -39,6 +39,7 @@
"react-tiny-popover": "^7.0.1",
"redux": "^4.1.1",
"redux-thunk": "^2.3.0",
+ "showdown": "^2.1.0",
"theme-ui": "^0.12.0",
"tls": "^0.0.1",
"tsparticles": "^2.5.3"
diff --git "a/pages/nucleus/transcript/\133code\135/human.js" "b/pages/nucleus/transcript/\133code\135/human.js"
new file mode 100644
index 0000000..d84a78f
--- /dev/null
+++ "b/pages/nucleus/transcript/\133code\135/human.js"
@@ -0,0 +1,31 @@
+import Axios from 'axios';
+
+const t = () => { return <></>}
+export default t
+export async function getServerSideProps(ctx) {
+ if(!ctx.params.code) {
+ return {
+ redirect: {
+ destination: '/nucleus/transcript/about',
+ permanent: true
+ }
+ }
+ }
+ let code;
+ try {
+ code = (await Axios.get(`http://localhost:10000/transcript/${ctx.params.code}`))
+ } catch (e) {
+ return {
+ redirect: {
+ destination: '/nucleus/transcript/invalid',
+ permanent: true
+ }
+ }
+ }
+ return {
+ redirect: {
+ destination: `http://api.coded.codes/nucleus/transcript/${ctx.params.code}/human`,
+ permanent: true
+ }
+ }
+}
\ No newline at end of file
diff --git a/pages/nucleus/transcript/index.js "b/pages/nucleus/transcript/\133code\135/index.js"
similarity index 93%
rename from pages/nucleus/transcript/index.js
rename to "pages/nucleus/transcript/\133code\135/index.js"
index eab0221..4b2389f 100644
--- a/pages/nucleus/transcript/index.js
+++ "b/pages/nucleus/transcript/\133code\135/index.js"
@@ -1,6 +1,6 @@
import Axios from 'axios';
import React from 'react';
-import Message from '../../../Components/Transcripts/Message';
+import Message from '../../../../Components/Transcripts/Message';
function Index(props) {
return <div style={{overflowY: "scroll", overflowX: "hidden"}}>
@@ -34,7 +34,7 @@
export default Index;
export async function getServerSideProps(ctx) {
- if(!ctx.query.code) {
+ if(!ctx.params.code) {
return {
redirect: {
destination: '/nucleus/transcript/about',
@@ -44,7 +44,7 @@
}
let code;
try {
- code = (await Axios.get(`http://localhost:10000/transcript/${ctx.query.code}`))
+ code = (await Axios.get(`http://localhost:10000/transcript/${ctx.params.code}`))
} catch (e) {
return {
redirect: {
diff --git "a/pages/nucleus/transcript/\133code\135/raw.js" "b/pages/nucleus/transcript/\133code\135/raw.js"
new file mode 100644
index 0000000..8c5436e
--- /dev/null
+++ "b/pages/nucleus/transcript/\133code\135/raw.js"
@@ -0,0 +1,32 @@
+import Axios from 'axios';
+
+const t = () => { return <></>}
+export default t
+export async function getServerSideProps(ctx) {
+ console.log(ctx.req.url)
+ if(!ctx.params.code) {
+ return {
+ redirect: {
+ destination: '/nucleus/transcript/about',
+ permanent: true
+ }
+ }
+ }
+ let code;
+ try {
+ code = (await Axios.get(`http://localhost:10000/transcript/${ctx.params.code}`))
+ } catch (e) {
+ return {
+ redirect: {
+ destination: '/nucleus/transcript/invalid',
+ permanent: true
+ }
+ }
+ }
+ return {
+ redirect: {
+ destination: `http://localhost:10000/transcript/${ctx.params.code}`,
+ permanent: true
+ }
+ }
+}
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 154a476..dbf855d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2791,6 +2791,11 @@
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==
+commander@^9.0.0:
+ version "9.5.0"
+ resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
+ integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==
+
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -5048,6 +5053,13 @@
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
+showdown@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/showdown/-/showdown-2.1.0.tgz#1251f5ed8f773f0c0c7bfc8e6fd23581f9e545c5"
+ integrity sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==
+ dependencies:
+ commander "^9.0.0"
+
side-channel@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"