You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
function formatResponse(text) {
|
|
return text
|
|
// Escape HTML entities first
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
// Bold: **text**
|
|
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
|
|
// Italic: *text*
|
|
.replace(/\*(.+?)\*/g, "<em>$1</em>")
|
|
// Dice notation: 🎲 lines get highlighted
|
|
.replace(/^(🎲.*)$/gm, '<span style="color: #c9a33e; font-weight: bold;">$1</span>')
|
|
// Line breaks
|
|
.replace(/\n\n/g, "</p><p>")
|
|
.replace(/\n/g, "<br>")
|
|
// Wrap in paragraph
|
|
.replace(/^(.*)$/, "<p>$1</p>");
|
|
}
|
|
|
|
Hooks.on("createChatMessage", async (chatData, options, userId) => {
|
|
console.log(chatData);
|
|
if (chatData.speaker?.alias === 'AI DM' || chatData.isRoll) return
|
|
})
|
|
Hooks.on("chatMessage", async (chatLog, message, chatData) => {
|
|
|
|
const response = await fetch('https://ai-dm-api.artisan.al/prompt', {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ content: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...');
|
|
});
|