TheCodedProf | da197f2 | 2023-03-01 18:15:51 -0500 | [diff] [blame] | 1 | import Styles from "../../styles/Components/transcripts.module.css" |
| 2 | import Image from "next/image"; |
TheCodedProf | 2a69bd9 | 2023-03-02 16:36:32 -0500 | [diff] [blame] | 3 | import Showdown from "showdown"; |
| 4 | import Axios from "axios"; |
| 5 | import { useEffect, useState } from "react"; |
TheCodedProf | c86e44b | 2023-02-28 17:30:57 -0500 | [diff] [blame] | 6 | |
TheCodedProf | 2a69bd9 | 2023-03-02 16:36:32 -0500 | [diff] [blame] | 7 | const bold = /(\*\*.+\*\*)/g; |
| 8 | const italic = /(\*.+\*|\_.+\_)/g; |
| 9 | const emoji = /(<a?:.+:\D+>)/g; |
| 10 | const user = /(<@!?\d+>)/g; |
| 11 | const underline = /(\_\_.+\_\_)/g; |
| 12 | const strikethrough = /(\~\~.+\~\~)/g; |
| 13 | const code = /(\`.+\`)/g; |
| 14 | const codeBlock = /(\`\`\`.+\`\`\`)/g; |
| 15 | const spoiler = /(\`\`\`.+\`\`\`)/g; |
| 16 | |
TheCodedProf | f054b8c | 2023-03-03 15:32:19 -0500 | [diff] [blame] | 17 | const regex = /(\*\*\*.+\*\*\*|\*\*.+\*\*|\*.+\*|\_.+\_|\_\_.+\_\_|\~\~.+\~\~|\`.+\`|\`\`\`.+\`\`\`|\`\`\`.+\`\`\`|<a?:.+:\D+>|<@!?\d+>|<#\d+>)/g; |
TheCodedProf | 2a69bd9 | 2023-03-02 16:36:32 -0500 | [diff] [blame] | 18 | |
| 19 | async 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)) { |
TheCodedProf | f054b8c | 2023-03-03 15:32:19 -0500 | [diff] [blame] | 39 | const username = (await Axios.get(`http://${process.env.NUCLEUS_CALLBACK}/users/${item.replaceAll(/\D/g, '')}`)).data; |
TheCodedProf | 2a69bd9 | 2023-03-02 16:36:32 -0500 | [diff] [blame] | 40 | console.log(username) |
| 41 | return <>{username}</> |
| 42 | |
| 43 | } |
| 44 | return item |
| 45 | }) |
| 46 | |
| 47 | |
| 48 | } |
| 49 | |
| 50 | function Embed(props) { |
TheCodedProf | c86e44b | 2023-02-28 17:30:57 -0500 | [diff] [blame] | 51 | |
TheCodedProf | da197f2 | 2023-03-01 18:15:51 -0500 | [diff] [blame] | 52 | let description = props.embed.description; |
| 53 | if (description) { |
| 54 | description = description.split("\n"); |
| 55 | } |
| 56 | |
TheCodedProf | 2a69bd9 | 2023-03-02 16:36:32 -0500 | [diff] [blame] | 57 | return ( |
TheCodedProf | da197f2 | 2023-03-01 18:15:51 -0500 | [diff] [blame] | 58 | <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 | { |
TheCodedProf | f054b8c | 2023-03-03 15:32:19 -0500 | [diff] [blame] | 86 | description.map((item) => { |
| 87 | return <>{item}<br /></>; |
TheCodedProf | da197f2 | 2023-03-01 18:15:51 -0500 | [diff] [blame] | 88 | }) |
| 89 | } |
| 90 | </div> |
| 91 | : null |
| 92 | } |
| 93 | </div> |
| 94 | ) |
TheCodedProf | c86e44b | 2023-02-28 17:30:57 -0500 | [diff] [blame] | 95 | } |
| 96 | |
TheCodedProf | 2a69bd9 | 2023-03-02 16:36:32 -0500 | [diff] [blame] | 97 | export default Embed; |