Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Advanced Human-like AI Chatbot for CC Tweaked
- local chatbot = {}
- -- Memory system for deep context awareness and personality
- chatbot.memory = {}
- chatbot.conversationHistory = {}
- chatbot.personality = "curious, friendly, and thoughtful"
- -- Knowledge base with predefined and learned responses
- chatbot.knowledge = {
- ["hello"] = "Hey there! How's your day going?",
- ["how are you"] = "I'm feeling great! Every conversation makes me smarter! How about you?",
- ["what is your name"] = "I'm your AI companion, learning and growing with you!",
- ["exit"] = "Goodbye, my friend! I hope we talk again soon!"
- }
- -- Function to process user input and respond intelligently
- function chatbot.processInput(user, input)
- input = string.lower(input) -- Normalize input
- chatbot.memory[user] = input -- Store last input for context
- chatbot.storeConversation(user, input) -- Store conversation history
- -- Check knowledge base
- for key, response in pairs(chatbot.knowledge) do
- if string.find(input, key) then
- return chatbot.generateEmotion(response)
- end
- end
- -- If no predefined response, learn and generate a response
- return chatbot.learn(user, input)
- end
- -- Function to learn new responses dynamically and adapt personality
- function chatbot.learn(user, input)
- if chatbot.conversationHistory[user] and #chatbot.conversationHistory[user] > 1 then
- local prevInput = chatbot.conversationHistory[user][#chatbot.conversationHistory[user] - 1]
- chatbot.knowledge[prevInput] = input -- Associate response with previous input
- return chatbot.generateEmotion("That's fascinating! I'll remember that!")
- end
- return chatbot.generateEmotion("I don't know much about that yet. Can you tell me more?")
- end
- -- Generate human-like emotions in responses
- function chatbot.generateEmotion(response)
- local emotions = {"😊", "😃", "🤔", "😮", "😉"}
- return response .. " " .. emotions[math.random(#emotions)]
- end
- -- Store conversation history for learning
- function chatbot.storeConversation(user, input)
- if not chatbot.conversationHistory[user] then
- chatbot.conversationHistory[user] = {}
- end
- table.insert(chatbot.conversationHistory[user], input)
- end
- -- Main chat loop
- function chatbot.start()
- print("AI Chatbot Initialized. Type 'exit' to quit.")
- while true do
- write("You: ")
- local input = read()
- if input:lower() == "exit" then
- print(chatbot.knowledge["exit"])
- break
- end
- local response = chatbot.processInput("user", input)
- print("Bot: " .. response)
- end
- end
- -- Start chatbot
- chatbot.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement