function formatResponse(text) { return text // Escape HTML entities first .replace(/&/g, "&") .replace(//g, ">") // Bold: **text** .replace(/\*\*(.+?)\*\*/g, "$1") // Italic: *text* .replace(/\*(.+?)\*/g, "$1") // Dice notation: 🎲 lines get highlighted .replace(/^(🎲.*)$/gm, '$1') // Line breaks .replace(/\n\n/g, "
")
.replace(/\n/g, "
")
// Wrap in paragraph
.replace(/^(.*)$/, "
$1
"); } Hooks.on("chatMessage", async (chatLog, message, chatData) => { console.log(chatData); console.log(message); const response = await fetch('https://ai-dm-api.artisan.al/prompt', { //const response = await fetch('http://debianmacbookair:3000/prompt', { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message }) }); const data = await response.json(); console.log(data); await ChatMessage.create({ content: formatResponse(data.result), speaker: { alias: 'AI DM'}, style: CONST.CHAT_MESSAGE_STYLES.IC }); }) Hooks.once("ready", () => { console.log('Claude listening...'); });