File size: 1,585 Bytes
2ee9a6d |
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 |
-- Voltage Chatbot Lua Script
math.randomseed(os.time())
-- Memory system
local memory = {}
-- Knowledge base
local knowledge = {
greetings = {"Hello!", "Hi there!", "Hey!", "Greetings!"},
farewell = {"Goodbye!", "See you later!", "Take care!"},
weather = {"It looks sunny today!", "Might rain later, take an umbrella!"},
technology = {"AI is fascinating!", "Technology evolves rapidly!"},
activities = {"What do you like to do for fun?", "I enjoy chatting with you!"}
}
-- Function to get a response from a category
local function get_response(category)
if knowledge[category] then
return knowledge[category][math.random(#knowledge[category])]
else
return "I am not sure about that."
end
end
-- Function to update memory
local function update_memory(input)
for word in string.gmatch(input, "[%w']+") do
memory[word] = (memory[word] or 0) + 1
end
end
-- Function to find a matching category
local function match_category(input)
for category, phrases in pairs(knowledge) do
for _, phrase in ipairs(phrases) do
if string.find(string.lower(input), string.lower(phrase)) then
return category
end
end
end
return nil
end
-- Main chatbot loop
while true do
io.write("You: ")
local input = io.read()
if input:lower() == "exit" then break end
update_memory(input)
local category = match_category(input)
local response = category and get_response(category) or "I am still learning!"
print("Voltage: " .. response)
end
|