blob: 43b1ac49df11800ab1f511d415df0759669d57ad [file] [log] [blame]
TheCodedProfda197f22023-03-01 18:15:51 -05001import Styles from "../../styles/Components/transcripts.module.css"
2import Image from "next/image";
TheCodedProf2a69bd92023-03-02 16:36:32 -05003import Showdown from "showdown";
4import Axios from "axios";
5import { useEffect, useState } from "react";
TheCodedProfc86e44b2023-02-28 17:30:57 -05006
TheCodedProf2a69bd92023-03-02 16:36:32 -05007const bold = /(\*\*.+\*\*)/g;
8const italic = /(\*.+\*|\_.+\_)/g;
9const emoji = /(<a?:.+:\D+>)/g;
10const user = /(<@!?\d+>)/g;
11const underline = /(\_\_.+\_\_)/g;
12const strikethrough = /(\~\~.+\~\~)/g;
13const code = /(\`.+\`)/g;
14const codeBlock = /(\`\`\`.+\`\`\`)/g;
15const spoiler = /(\`\`\`.+\`\`\`)/g;
16
TheCodedProff054b8c2023-03-03 15:32:19 -050017const regex = /(\*\*\*.+\*\*\*|\*\*.+\*\*|\*.+\*|\_.+\_|\_\_.+\_\_|\~\~.+\~\~|\`.+\`|\`\`\`.+\`\`\`|\`\`\`.+\`\`\`|<a?:.+:\D+>|<@!?\d+>|<#\d+>)/g;
TheCodedProf2a69bd92023-03-02 16:36:32 -050018
19async function parse(text) {
20 const splitText = text.split(regex);
21 console.log(splitText)
22 return await splitText.map( async (item, index) => {
23 if (item.match(bold)) {
24 return <b key={index}>{item.replaceAll(/\*\*/g, '')}</b>
25 }
26 if (item.match(underline)) {
27 return <u key={index}>{item.replaceAll(/\_\_/g, '')}</u>
28 }
29 if (item.match(italic)) {
30 return <i key={index}>{item.replaceAll(/\*/g, '')}</i>
31 }
32 if (item.match(code)) {
33 return <code key={index}>{item.replaceAll(/\`/g, '')}</code>
34 }
35 if (item.match(emoji)) {
36 return <Image key={index} src={`https://cdn.discord.com/emojis/${item.replaceAll(/\D/g, '')}`} width={20} height={20} alt="" />
37 }
38 if (item.match(user)) {
TheCodedProff054b8c2023-03-03 15:32:19 -050039 const username = (await Axios.get(`http://${process.env.NUCLEUS_CALLBACK}/users/${item.replaceAll(/\D/g, '')}`)).data;
TheCodedProf2a69bd92023-03-02 16:36:32 -050040 console.log(username)
41 return <>{username}</>
42
43 }
44 return item
45 })
46
47
48}
49
50function Embed(props) {
TheCodedProfc86e44b2023-02-28 17:30:57 -050051
TheCodedProfda197f22023-03-01 18:15:51 -050052 let description = props.embed.description;
53 if (description) {
54 description = description.split("\n");
55 }
56
TheCodedProf2a69bd92023-03-02 16:36:32 -050057 return (
TheCodedProfda197f22023-03-01 18:15:51 -050058 <div className={Styles.embed} style={{borderColor: props.color ?? "#F27878"}}>
59 {
60 props.embed.author ?
61 <div className={Styles.embedAuthor}>
62 {
63 props.embed.author.iconURL ?
64 <Image src={props.embed.author.iconURL} alt=""/> :
65 null
66 }
67 {
68 props.embed.author.url ?
69 <a href={props.embed.author.url}>
70 {props.embed.author?.name ?? ""}
71 </a> :
72 <p>{props.embed.author?.name ?? ""}</p>
73 }
74 </div> :
75 null
76 }
77 {
78 props.embed.title ?
79 <div className={Styles.embedTitle}>{props.embed.title}</div> :
80 null
81 }
82 {
83 props.embed.description ?
84 <div className={Styles.embedDescription}>
85 {
TheCodedProff054b8c2023-03-03 15:32:19 -050086 description.map((item) => {
87 return <>{item}<br /></>;
TheCodedProfda197f22023-03-01 18:15:51 -050088 })
89 }
90 </div>
91 : null
92 }
93 </div>
94 )
TheCodedProfc86e44b2023-02-28 17:30:57 -050095}
96
TheCodedProf2a69bd92023-03-02 16:36:32 -050097export default Embed;