highlights for discord

This commit is contained in:
ajvpot
2025-09-15 04:36:14 +02:00
parent 0aac045c1b
commit 4c7e7d8e1c
2 changed files with 42 additions and 5 deletions

View File

@@ -2,6 +2,8 @@
* Discord webhook integration utilities for posting and updating messages
*/
import { createNodeSearchUrl, processNodeMentionsForMarkdown } from '../../src/lib/node-utils';
export interface DiscordWebhookMessage {
content?: string;
username?: string;
@@ -184,13 +186,17 @@ export function formatMeshcoreMessageForDiscord(
}
): DiscordWebhookMessage {
const sender = decrypted?.sender || 'Unknown';
const text = decrypted?.text || '[Encrypted Message]';
const rawText = decrypted?.text || '[Encrypted Message]';
// Process node mentions (@[Node Name]) and convert to Discord markdown links
const processedText = processNodeMentionsForMarkdown(rawText);
// Calculate how many times the message was heard
const heardCount = message.origin_path_info ? message.origin_path_info.length : 0;
// Format the message content with the requested format
const content = `${text}\n-# _Heard ${heardCount} times by [MeshExplorer](https://map.w0z.is/messages)_`;
// Create URL to search page with node name prefilled and exact match enabled
const senderSearchUrl = createNodeSearchUrl(sender);
const content = `${processedText}\n-# _Heard ${heardCount} times_ | [Node Info](${senderSearchUrl})`;
// Generate profile picture URL using the new API
const profilePictureUrl = `https://map.w0z.is/api/meshcore/profilepicture.png?name=${encodeURIComponent(sender)}&v=3`;

View File

@@ -4,6 +4,7 @@ import { useConfig } from "./ConfigContext";
import { useMessageDecryption } from "@/hooks/useMessageDecryption";
import PathVisualization, { PathData } from "./PathVisualization";
import NodeLinkWithHover from "./NodeLinkWithHover";
import { findNodeMentions } from "@/lib/node-utils";
export interface ChatMessage {
message_id: string;
@@ -29,9 +30,39 @@ function formatLocalTime(utcString: string): string {
}
function ChatMessageContent({ text }: { text: string }) {
// Combined regex to match both URLs and @[node_name] patterns
const combinedRegex = /(https?:\/\/[^\s]+|@\[[^\]]+\])/g;
// Use utility function to find node mentions
const nodeMentions = findNodeMentions(text);
// If no node mentions, handle only URLs
if (nodeMentions.length === 0) {
const urlRegex = /(https?:\/\/[^\s]+)/g;
const parts = text.split(urlRegex);
return (
<>
{parts.map((part, index) => {
// Check if it's a URL
if (/^https?:\/\//.test(part)) {
return (
<a
key={index}
href={part}
target="_blank"
rel="nofollow noopener noreferrer"
className="text-blue-600 dark:text-blue-400 hover:underline"
>
{part}
</a>
);
}
return part;
})}
</>
);
}
// Process text with both URLs and node mentions
const combinedRegex = /(https?:\/\/[^\s]+|@\[[^\]]+\])/g;
const parts = text.split(combinedRegex);
return (