chat.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // chat container setup for maximum verwirrung weil ich kann das alles langsam nicht mehr junge die sprach macht kei sinn
  2. const chatContainer = document.getElementById('chat-container');
  3. const chatLog = document.getElementById('chat-log');
  4. const userInput = document.getElementById('user-input');
  5. let hasGreeted = false; // flag so we only say grǔtzi eimal und ned sächzgs mal junge das wäri fett weird
  6. // toggle chat open and closed again ????????????? i dont remember what i haben gesoffen hier
  7. function toggleChat() {
  8. if (chatContainer.classList.contains('open')) {
  9. chatContainer.classList.remove('open');
  10. setTimeout(() => {
  11. chatContainer.style.visibility = 'hidden';
  12. }, 400); // match delay with css so it doesnt look wie abfall
  13. } else {
  14. chatContainer.style.visibility = 'visible';
  15. chatContainer.classList.add('open');
  16. // the actuall saying grǔtzi miternaand gugus
  17. if (!hasGreeted) {
  18. displayMessage('Virtual Assistant', "Grǔtzi 🇨🇭 ! I'm your virtual assistant! Please tell me about your problem or what you need help with.");
  19. hasGreeted = true;
  20. }
  21. }
  22. }
  23. // send message when enter key is pressed because who will press a button to send a message ???? are you a psychopat ?
  24. userInput.addEventListener('keypress', function(event) {
  25. if (event.key === 'Enter') {
  26. sendMessage();
  27. }
  28. });
  29. // handle sending messages
  30. function sendMessage() {
  31. const userMessage = userInput.value.trim();
  32. if (userMessage) {
  33. displayMessage('You', userMessage);
  34. userInput.value = '';
  35. setTimeout(() => catReply(userMessage), 1000); // delay for realism so the "assistant" can "think" about the reply
  36. }
  37. }
  38. // put a message in the chat log will chat funktioniert ned ohni message history und so lol
  39. function displayMessage(sender, message) {
  40. const messageElement = document.createElement('div');
  41. messageElement.classList.add('chat-message');
  42. const senderSpan = document.createElement('span');
  43. senderSpan.classList.add('sender');
  44. senderSpan.classList.add(sender === 'You' ? 'user' : 'virtual-assistant');
  45. senderSpan.textContent = sender + ': ';
  46. const messageSpan = document.createElement('span');
  47. messageSpan.textContent = message;
  48. messageElement.appendChild(senderSpan);
  49. messageElement.appendChild(messageSpan);
  50. chatLog.appendChild(messageElement);
  51. chatLog.scrollTop = chatLog.scrollHeight;
  52. }
  53. // cat assistant category based matched replies
  54. function catReply(userMessage) {
  55. const keywords = {
  56. "help": ["meeeooow...? figure it out yourself! because that sounds like a you problem bahahahasdjkasadlkj 💀", "meeooww! welp too bad. help yourself bahasjdhaskjdhaskjdh", "mrrrow! idk either lol. go ask yourself maybe your smart if you use your brain instread of relying on a virtual assistant cat"],
  57. "problem": ["meeooow, eh thats normal here, should've chosen someone else to host your stuff ngl lol", "mrow, contact sysadminier maybe idk? i am just cat or a teaput ???? idk what i am help aaaaaaa", "mreeow, tell me more ig... if you want idc lol"],
  58. "default": ["meow", "meeooow!", "mew.", "mrow!", "meeow...", "meow, meow.", "mroww", "mlem"]
  59. };
  60. // generate a bs reply to fool user into thinking the cat assistant is actually doing something
  61. function generateScrambledReply() {
  62. const phrases = keywords["default"];
  63. let scrambled = [];
  64. const length = Math.floor(Math.random() * 3) + 3; // random length of reply 3-5 words
  65. for (let i = 0; i < length; i++) {
  66. const randomPhrase = phrases[Math.floor(Math.random() * phrases.length)];
  67. scrambled.push(randomPhrase);
  68. }
  69. return scrambled.join(" ");
  70. }
  71. // check for keywords in user message and decide what kind of blödsinn to say zu the schafseckel using the chat
  72. let reply;
  73. if (userMessage.toLowerCase().includes("help")) {
  74. reply = keywords["help"][Math.floor(Math.random() * keywords["help"].length)];
  75. } else if (userMessage.toLowerCase().includes("problem")) {
  76. reply = keywords["problem"][Math.floor(Math.random() * keywords["problem"].length)];
  77. } else {
  78. reply = generateScrambledReply(); // generate scrambled reply for "default" case
  79. }
  80. displayMessage('Virtual Assistant', reply);
  81. }