Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if term.isColor() then
- promptColor = colors.cyan
- infoColor = colors.yellow
- normalColor = colors.white
- else
- promptColor = colors.white
- infoColor = colors.white
- normalColor = colors.white
- end
- if not fs.exists("cleverbot") then
- shell.run("pastebin", "get", "Dv9x1ppc", "cleverbot")
- end
- term.setTextColor(infoColor)
- write("What's your name? ")
- term.setTextColor(normalColor)
- local name = read()
- if type(name) ~= "string" then
- name = "You"
- end
- if name == "" then
- name = "You"
- end
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(promptColor)
- print("Cleverbot Client")
- term.setTextColor(normalColor)
- os.loadAPI("cleverbot")
- local bot = cleverbot.Cleverbot.new()
- local ignore = false
- term.setTextColor(infoColor)
- print("Send '_quit_' to leave, and '_conv_' to save conversation")
- term.setTextColor(normalColor)
- print("")
- while true do
- ignore = false
- term.setTextColor(infoColor)
- write(name .. ": ")
- term.setTextColor(normalColor)
- local message = read()
- if message == "_quit_" then
- error()
- elseif message == "_conv_" then
- ignore = true
- open = fs.open("_conv_", "w")
- open.writeLine("--Cleverbot Conversation--")
- open.writeLine("--http://pastebin.com/Px9N7si4--")
- open.writeLine("")
- open.writeLine("--Begin Conversation--")
- local num = 0
- for k, v in pairs(bot.conversation) do
- num = num + 1
- if tonumber(num) % 2 == 0 then
- open.writeLine("Cleverbot: " .. v)
- else
- open.writeLine(name .. ": " .. v)
- end
- end
- if textutils.serialize(bot.conversation):gsub("\n", "") == "{}" then
- open.writeLine("No conversation found!")
- end
- open.writeLine("--End Conversation--")
- open.close()
- open = nil
- term.setTextColor(infoColor)
- print("Saved conversation as '_conv_'")
- term.setTextColor(normalColor)
- elseif string.lower(message):gsub("!", "") == "atenefyr sucks" then
- printError("No, he doesn't! Nobody heard that..")
- ignore = true
- elseif string.lower(message):gsub(".", "") == "atenefyr sucks" then
- printError("No, he doesn't! Nobody heard that..")
- ignore = true
- end
- if not ignore then
- local response = bot:send(message)
- term.setTextColor(promptColor)
- write("Cleverbot: ")
- term.setTextColor(normalColor)
- write(response .. "\n")
- else
- ignore = false
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement