Advertisement
minimite

cleverbotclient

Mar 15th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 KB | None | 0 0
  1. if term.isColor() then
  2.   promptColor = colors.cyan
  3.   infoColor = colors.yellow
  4.   normalColor = colors.white
  5. else
  6.   promptColor = colors.white
  7.   infoColor = colors.white
  8.   normalColor = colors.white
  9. end
  10.  
  11. if not fs.exists("cleverbot") then
  12.   shell.run("pastebin", "get", "Dv9x1ppc", "cleverbot")
  13. end
  14.  
  15. term.setTextColor(infoColor)
  16. write("What's your name? ")
  17. term.setTextColor(normalColor)
  18. local name = read()
  19. if type(name) ~= "string" then
  20.   name = "You"
  21. end
  22. if name == "" then
  23.   name = "You"
  24. end
  25.  
  26. term.clear()
  27. term.setCursorPos(1,1)
  28. term.setTextColor(promptColor)
  29. print("Cleverbot Client")
  30. term.setTextColor(normalColor)
  31.  
  32. os.loadAPI("cleverbot")
  33. local bot = cleverbot.Cleverbot.new()
  34. local ignore = false
  35. term.setTextColor(infoColor)
  36. print("Send '_quit_' to leave, and '_conv_' to save conversation")
  37. term.setTextColor(normalColor)
  38. print("")
  39. while true do
  40.   ignore = false
  41.   term.setTextColor(infoColor)
  42.   write(name .. ": ")
  43.   term.setTextColor(normalColor)
  44.   local message = read()
  45.   if message == "_quit_" then
  46.     error()
  47.   elseif message == "_conv_" then
  48.     ignore = true
  49.     open = fs.open("_conv_", "w")
  50.     open.writeLine("--Cleverbot Conversation--")
  51.     open.writeLine("--http://pastebin.com/Px9N7si4--")
  52.     open.writeLine("")
  53.     open.writeLine("--Begin Conversation--")
  54.     local num = 0
  55.     for k, v in pairs(bot.conversation) do
  56.       num = num + 1
  57.       if tonumber(num) % 2 == 0 then
  58.         open.writeLine("Cleverbot: " .. v)
  59.       else
  60.         open.writeLine(name .. ": " .. v)
  61.       end
  62.     end
  63.     if textutils.serialize(bot.conversation):gsub("\n", "") == "{}" then
  64.       open.writeLine("No conversation found!")
  65.     end
  66.     open.writeLine("--End Conversation--")
  67.     open.close()
  68.     open = nil
  69.        term.setTextColor(infoColor)
  70.     print("Saved conversation as '_conv_'")
  71.        term.setTextColor(normalColor)
  72.   elseif string.lower(message):gsub("!", "") == "atenefyr sucks" then
  73.     printError("No, he doesn't! Nobody heard that..")
  74.     ignore = true
  75.   elseif string.lower(message):gsub(".", "") == "atenefyr sucks" then
  76.     printError("No, he doesn't! Nobody heard that..")
  77.     ignore = true
  78.   end
  79.   if not ignore then
  80.     local response = bot:send(message)
  81.     term.setTextColor(promptColor)
  82.     write("Cleverbot: ")
  83.     term.setTextColor(normalColor)
  84.     write(response .. "\n")
  85.   else
  86.     ignore = false
  87.   end
  88.   sleep(0.1)
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement