commit c249783683fc002a4f0eb7179397cc23b0e4ee47 Author: Matt Huntington Date: Thu Mar 26 00:01:52 2026 -0400 basic diff --git a/module.json b/module.json new file mode 100644 index 0000000..dffa7fb --- /dev/null +++ b/module.json @@ -0,0 +1,18 @@ +{ + "id": "claude-gm", + "title": "Claude GM", + "description": "Routes chat messages to a Claude Code relay server for AI Game Master responses.", + "version": "0.1.0", + "compatibility": { + "minimum": "12", + "verified": "13" + }, + "authors": [ + { + "name": "Matt Huntington" + } + ], + "esmodules": [ + "scripts/claude-gm.js" + ] +} diff --git a/scripts/claude-gm.js b/scripts/claude-gm.js new file mode 100644 index 0000000..cec3ab3 --- /dev/null +++ b/scripts/claude-gm.js @@ -0,0 +1,39 @@ +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('http://192.168.1.183:3000/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...'); +});