-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoodtrackerscript.js
More file actions
106 lines (92 loc) · 4.61 KB
/
moodtrackerscript.js
File metadata and controls
106 lines (92 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const chatbotMessages = [
"Hi there! I'm Bard, your AI companion. How are you feeling today?",
"Let's talk about what's on your mind. What can I help you with?",
"I'm here to listen. What's troubling you?",
"Tell me more about how you're feeling.",
"Is there anything specific you'd like to discuss?",
"I'm here to chat. What's on your mind?"
];
const emotionResponses = {
happy: {
message: "I'm glad to hear you're feeling happy! What's bringing you joy today?",
followUp: "Would you like to share what's making you happy?",
deeperQuestions: ["What are you looking forward to today?", "Can you describe a happy memory you have?", "What activities bring you joy?"]
},
sad: {
message: "I'm sorry to hear you're feeling sad. It's okay to not be okay. ",
followUp: "Is there anything specific that's making you feel sad today?",
deeperQuestions: ["Do you want to talk about what's bothering you?", "Is there anything I can do to help?", "Have you tried any relaxation techniques?"]
},
anxious: {
message: "It sounds like you're feeling anxious. Take some deep breaths. ",
followUp: "What's causing you to feel anxious right now?",
deeperQuestions: ["What can you do to calm yourself down?", "Have you tried any relaxation techniques?", "Is there anything I can do to help you feel more relaxed?"]
},
angry: {
message: "I understand you're feeling angry. It's okay to feel angry.",
followUp: "What happened that made you feel angry?",
deeperQuestions: ["How can you express your anger in a healthy way?", "What can you do to de-escalate the situation?", "Is there anything you can do to resolve the situation?"]
},
stressed: {
message: "It sounds like you're stressed. It's important to take breaks.",
followUp: "What's causing you stress right now?",
deeperQuestions: ["What are some stress-relieving activities you enjoy?", "Have you tried any relaxation techniques?", "Is there anything I can do to help you feel less stressed?"]
},
tired: {
message: "Feeling tired is tough. Rest is important.",
followUp: "Have you tried getting enough sleep lately?",
deeperQuestions: ["What time do you usually go to bed and wake up?", "Do you have any trouble falling asleep?", "Are you engaging in any activities that might be interfering with your sleep?"]
},
overwhelmed: {
message: "It seems like you're feeling overwhelmed. It's okay to ask for help.",
followUp: "What's making you feel overwhelmed right now?",
deeperQuestions: ["Can you break down the tasks that are overwhelming you?", "Have you considered delegating any tasks?", "What are some ways you can simplify your workload?"]
}
};
function sendMessage() {
const input = document.getElementById("chatInput").value.trim();
if (input) {
const chatbot = document.getElementById("chatbot");
chatbot.innerHTML += `<p><strong>You:</strong> ${input}</p>`;
const response = getBotResponse(input);
chatbot.innerHTML += `<p><strong>Bard:</strong> ${response.message}</p>`;
if (response.followUp) {
chatbot.innerHTML += `<p><strong>Bard:</strong> ${response.followUp}</p>`;
}
document.getElementById("chatInput").value = "";
chatbot.scrollTop = chatbot.scrollHeight;
} else {
alert("Please type a message.");
}
}
function getBotResponse(userInput) {
const lowerCaseInput = userInput.toLowerCase();
for (let emotion in emotionResponses) {
if (lowerCaseInput.includes(emotion)) {
return emotionResponses[emotion];
}
}
return {
message: chatbotMessages[Math.floor(Math.random() * chatbotMessages.length)],
};
}
function handleUserResponse(userInput, currentEmotion) {
const chatbot = document.getElementById("chatbot");
chatbot.innerHTML += `<p><strong>You:</strong> ${userInput}</p>`;
if (currentEmotion && emotionResponses[currentEmotion].deeperQuestions) {
const randomIndex = Math.floor(Math.random() * emotionResponses[currentEmotion].deeperQuestions.length);
const deeperQuestion = emotionResponses[currentEmotion].deeperQuestions[randomIndex];
chatbot.innerHTML += `<p><strong>Bard:</strong> ${deeperQuestion}</p>`;
} else {
const generalResponses = [
"I'm here to listen. Tell me more.",
"How else are you feeling today?",
"Is there anything else you'd like to talk about?",
"I'm here to support you. What's on your mind?"
];
const randomIndex = Math.floor(Math.random() * generalResponses.length);
chatbot.innerHTML += `<p><strong>Bard:</strong> ${generalResponses[randomIndex]}</p>`;
}
document.getElementById("chatInput").value = "";
chatbot.scrollTop = chatbot.scrollHeight;
}