| import Styles from "../../styles/Components/transcripts.module.css" |
| import Image from "next/image"; |
| import Showdown from "showdown"; |
| import Axios from "axios"; |
| import { useEffect, useState } from "react"; |
| |
| 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+>|<#\d+>)/g; |
| |
| 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(`${process.env.NUCLEUS_CALLBACK}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 ( |
| <div className={Styles.embed} style={{borderColor: props.color ?? "#F27878"}}> |
| { |
| props.embed.author ? |
| <div className={Styles.embedAuthor}> |
| { |
| props.embed.author.iconURL ? |
| <Image src={props.embed.author.iconURL} alt=""/> : |
| null |
| } |
| { |
| props.embed.author.url ? |
| <a href={props.embed.author.url}> |
| {props.embed.author?.name ?? ""} |
| </a> : |
| <p>{props.embed.author?.name ?? ""}</p> |
| } |
| </div> : |
| null |
| } |
| { |
| props.embed.title ? |
| <div className={Styles.embedTitle}>{props.embed.title}</div> : |
| null |
| } |
| { |
| props.embed.description ? |
| <div className={Styles.embedDescription}> |
| { |
| description.map((item) => { |
| return <>{item}<br /></>; |
| }) |
| } |
| </div> |
| : null |
| } |
| </div> |
| ) |
| } |
| |
| export default Embed; |