From 19c36877e7186c244d9c284e70e85a059f361de3 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 25 Jun 2025 14:03:45 -0700 Subject: basic rendering of discord hammertime tags --- src/renderer/src/App.tsx | 2 +- src/renderer/src/assets/base.css | 33 +++++++++++++++++++++++++++++++++ src/renderer/src/components/Message.tsx | 20 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 2297060..e458f89 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -46,7 +46,7 @@ function App(): React.JSX.Element { return () => { window.electron.ipcRenderer.removeListener('new-discord-message', listener) } - }, []) + }, [maxMessages]) return (
{ + const match = hammerTime.match(//) + if (!match) { + return 'Unknown Timestamp' + } + const timestamp = parseInt(match[1], 10) + if (isNaN(timestamp)) { + return 'Unknown Timestamp' + } + const date = new Date(timestamp * 1000) + return date.toLocaleString() +} + interface ParsedContent { html: string imageUrls: string[] @@ -39,6 +52,13 @@ const processRenderedContent = ( // Roles are a placeholder for now cause can't find a good way to get the names of them parsedContent = parsedContent.replace(/<@&?(\d+)>/g, '@RoleMention') parsedContent = parsedContent.replace(/@everyone/g, '@everyone') + parsedContent = parsedContent.replace(//g, (match) => { + return ( + '' + + hammerTimeToDateString(match) + + ' (your local time) ' + ) + }) // Replace Discord emote syntax <:name:id> and with img tags FIRST parsedContent = parsedContent.replace(/<(a?):([^:]+):(\d+)>/g, (_, animated, name, id) => { // Validate that we have a proper ID -- cgit v1.2.3