Advertisement
Thecodeeasar

Lil timmy

Sep 25th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // Define the bot named Lil Timmy
  2. class LilTimmy {
  3. constructor() {
  4. this.name = "Lil Timmy";
  5. this.birthDate = new Date("2020-09-25T20:07:00");
  6. this.responses = [
  7. "That's interesting!",
  8. "Tell me more!",
  9. "I see what you mean.",
  10. "Wow, really?",
  11. "Can you explain that further?",
  12. "I'm not sure about that. What do you think?"
  13. ];
  14. }
  15.  
  16. // Method to introduce himself
  17. introduce() {
  18. const birthDateString = this.birthDate.toLocaleString('en-US', {
  19. year: 'numeric',
  20. month: 'long',
  21. day: 'numeric',
  22. hour: '2-digit',
  23. minute: '2-digit',
  24. hour12: true
  25. });
  26. return `Hi! I'm ${this.name}. I was born on ${birthDateString}.`;
  27. }
  28.  
  29. // Method to generate a random response based on user input
  30. generateResponse(userInput) {
  31. // Basic NLP to analyze user input (for demonstration)
  32. const keywords = userInput.toLowerCase().split(" ");
  33.  
  34. // Check for specific keywords to tailor responses (simple example)
  35. if (keywords.includes("hello") || keywords.includes("hi")) {
  36. return "Hello there! How can I assist you today?";
  37. } else if (keywords.includes("help")) {
  38. return "Sure! What do you need help with?";
  39. } else if (keywords.includes("bye")) {
  40. return "Goodbye! Have a great day!";
  41. } else {
  42. // Return a random response if no specific keywords are found
  43. return this.responses[Math.floor(Math.random() * this.responses.length)];
  44. }
  45. }
  46. }
  47.  
  48. // Create an instance of the bot
  49. const lilTimmyBot = new LilTimmy();
  50.  
  51. // Function to simulate chat interaction
  52. function chatWithLilTimmy(userInput) {
  53. console.log(lilTimmyBot.introduce()); // Introduce bot
  54. console.log(lilTimmyBot.generateResponse(userInput)); // Generate response based on user input
  55. }
  56.  
  57. // Example usage
  58. chatWithLilTimmy("Hi Lil Timmy, can you help me?");
  59. chatWithLilTimmy("What do you think about AI?");
  60. chatWithLilTimmy("Goodbye!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement