Advertisement
Mackan90096

MackOS Alpha [0.1]

Mar 13th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.44 KB | None | 0 0
  1.  
  2.  
  3. --[[
  4.   __  __            _     ____   _____
  5.  |  \/  |          | |   / __ \ / ____|
  6.  | \  / | __ _  ___| | _| |  | | (___  
  7.  | |\/| |/ _` |/ __| |/ / |  | |\___ \
  8.  | |  | | (_| | (__|   <| |__| |____) |
  9.  |_|  |_|\__,_|\___|_|\_\\____/|_____/
  10.  
  11. Welcome to MackOS!
  12. Author: Mackan90096
  13. Version: Alpha [0.1] Build: Tester Edition.
  14. Created: 13 Mar 2013
  15.  
  16. License:
  17.  
  18. COPYRIGHT NOTICE
  19. Copyright © 2013 Max Thor a.k.a Mackan90096 [thormax5@gmail.com]
  20. If you wish to use any of these function(s) or code snippets, contact Mackan90096 on the
  21. ComputerCraft Forums. (www.computercraft.info/forums2)
  22.                                        
  23. --]]
  24.  
  25. local debugMode = true -- Set to false to prevent exiting to craftOS
  26. local pullEvent = os.pullEvent
  27. os.pullEvent = os.pullEventRaw
  28.  
  29.  
  30.  
  31. Version = "Alpha [0.1]"
  32. credCol = 32
  33. firstCol = 1
  34. secCol = 2048
  35. Author  = "Mackan90096"
  36. ErrCol1 = 16384
  37. calcCol = 128
  38.  
  39.  
  40.  
  41. function start()
  42. term.clear()
  43. term.setTextColor(firstCol)
  44. term.setCursorPos(1,1)
  45. textutils.slowPrint("Welcome to MackOs version " ..Version)
  46. term.setCursorPos(1,3)
  47. print("What would you like to do?")
  48. term.setCursorPos(1,4)
  49. print("[1] Login")
  50. term.setCursorPos(1,5)
  51. print("[2] Register")
  52. term.setCursorPos(1,6)
  53. print("[3] Reboot Computer")
  54. term.setCursorPos(1,7)
  55. print("[4] Shutdown Computer")
  56. term.setCursorPos(1,8)
  57. print("[5] Generate a password")
  58. term.setCursorPos(1,9)
  59. print("[6] Credits")
  60. term.setCursorPos(1,11)
  61. write("Input a number: ")
  62. local input = read()
  63. if input == "1" then
  64. login()
  65. elseif input == "2"  then
  66. register()
  67. elseif input == "3" then
  68. term.clear()
  69. term.setCursorPos(1,1)
  70. print("Rebooting in 2 seconds!")
  71. sleep(2)
  72. os.reboot()
  73. elseif input == "4" then
  74. term.clear()
  75. term.setCursorPos(1,1)
  76. print("Shutting down in 2 seconds!")
  77. sleep(2)
  78. os.shutdown()
  79. elseif input == "5" then
  80. term.clear()
  81. term.setCursorPos(1,1)
  82. print("Opening passgen")
  83. sleep(1)
  84. term.clear()
  85. passgen()
  86. elseif input == "6" then
  87. term.clear()
  88. term.setCursorPos(1,1)
  89. print("Opening credits")
  90. sleep(1)
  91. term.clear()
  92. credits()
  93. else
  94. term.clear()
  95. term.setCursorPos(1,1)
  96. print("Cant understand!")
  97. sleep(1)
  98. term.clear()
  99. start()
  100. end
  101. end
  102.  
  103. function credits()
  104. term.clear()
  105. term.setCursorPos(1,1)
  106. term.setTextColor(credCol)
  107. print("Credits")
  108. term.setCursorPos(1,3)
  109. print("Programs and apis:")
  110. term.setCursorPos(1,5)
  111. print("CCalendar - TheOriginalBIT")
  112. term.setCursorPos(1,6)
  113. print("Passgen -  Conn332")
  114. term.setCursorPos(1,7)
  115. print("CCleverbot - 1lann and GravityScore")
  116. term.setCursorPos(1,9)
  117. print("Help in development:")
  118. term.setCursorPos(1,11)
  119. print("All the great people that helped me on the forums! - You know who you are :)")
  120. term.setCursorPos(1,13)
  121. write("To return type anything and hit enter: ")
  122. local input = read()
  123. if input == "1" then
  124. term.clear()
  125. start()
  126. else
  127. term.clear()
  128. start()
  129. end
  130. end
  131.  
  132. function passgen()
  133. function clear()
  134.   term.clear()
  135.   term.setCursorPos(1,1)
  136. end
  137. function center(text,y,mode)
  138.   w,h = term.getSize()
  139.   term.setCursorPos((w/2)-(#text/2),y)
  140.   if mode == nil then mode = "print" end
  141.   if mode == "write" then
  142.     write(text)
  143.   else
  144.     print(text)
  145.   end
  146. end
  147. clear()
  148. write "Length: "
  149. local length = read()
  150. if tonumber(length) == false then
  151.   print("Use a number please")
  152.   sleep(2)
  153.   error()
  154. else
  155.   length = tonumber(length)
  156. end
  157. if length > 51 then
  158.         print("Please enter a length 50 characters or below")
  159.         sleep(2)
  160.         error()
  161. end
  162. lower = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
  163. upper = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
  164. special = {'!','@','#','$','%','^','&','*'}
  165. numbers = {'0','1','2','3','4','5','6','7','8','9'}
  166. mode = {"usnl","usln","ulsn","unsl","unls","ulns","nusl", "nsul", "sunl", "snul","lsnu","lsun","luns","lusn","lnsu","lnus" ,"nu", "un", "sn", "ns", "us", "su", "u", "s", "n"}
  167. clear()
  168. center("Modes: Upper[u], special[s], number[n], lower[l]",2)
  169. print()
  170. print()
  171. write "write all modes you want (no commas): "
  172. local l = false
  173. local u = false
  174. local s = false
  175. local n = false
  176. mds = ""
  177. while true do
  178.   event, key = os.pullEvent("key")
  179.   if key == 22 then
  180.     if u == false then
  181.       u = true
  182.       term.setCursorPos(1,7)
  183.       print"Upper"
  184.           mds = mds.."u"
  185.     else
  186.       u = false
  187.       term.setCursorPos(1,7)
  188.       term.clearLine()
  189.           mds = mds:gsub( "u", "" )
  190.     end
  191.   elseif key == 31 then
  192.     if s == false then
  193.       s = true
  194.       term.setCursorPos(1,8)
  195.       print"Special"
  196.           mds = mds.."s"
  197.     else
  198.       s = false
  199.       term.setCursorPos(1,8)
  200.       term.clearLine()
  201.           mds = mds:gsub("s","")
  202.     end
  203.   elseif key == 49 then
  204.     if n == false then
  205.       n = true
  206.       term.setCursorPos(1,9)
  207.       print"Number"
  208.           mds = mds.."n"
  209.     else
  210.       n = false
  211.       term.setCursorPos(1,9)
  212.       term.clearLine()
  213.           mds = mds:gsub("n", "")
  214.     end
  215.   elseif key == 38 then
  216.     if l == false then
  217.       l = true
  218.       term.setCursorPos(1,10)
  219.       print"Lower"
  220.           mds = mds.."l"
  221.     else
  222.       l = false
  223.       term.setCursorPos(1,10)
  224.       term.clearLine()
  225.           mds = mds:gsub("l", "")
  226.     end
  227.   elseif key == 28 and (l or n or s or u) then
  228.     break
  229.   end
  230. end
  231. mds = string.lower(mds)
  232. local test = false
  233. for i=1, #mode do
  234.   if mds == mode[i] then
  235.     test = true
  236.     break
  237.   end
  238. end
  239. if test == false then
  240.   print("Invalid mode: "..mds)
  241. end
  242. modes = {}
  243. message = ""
  244. if l == true and n == true and s == true and u == true then
  245.   for i=1, length do
  246.     num = math.random(4)
  247.     if num == 1 then
  248.       message = message..lower[math.random(#lower)]
  249.     elseif num == 2 then
  250.       message = message..upper[math.random(#upper)]
  251.     elseif num == 3 then
  252.       message = message..special[math.random(#special)]
  253.     elseif num == 4 then
  254.       message = message..numbers[math.random(#numbers)]
  255.     end
  256.   end
  257. elseif n == true and s == true and u == true then
  258.   for i=1, length do
  259.     num = math.random(3)
  260.     if num == 1 then
  261.       message = message..upper[math.random(#upper)]
  262.     elseif num == 2 then
  263.       message = message..special[math.random(#special)]
  264.     elseif num == 3 then
  265.       message = message..numbers[math.random(#numbers)]
  266.     end
  267.   end
  268. elseif n == true and s == true and l == true then
  269.   for i=1, length do
  270.     num = math.random(3)
  271.     if num == 1 then
  272.       message = message..special[math.random(#special)]
  273.     elseif num == 2 then
  274.       message = message..numbers[math.random(#numbers)]
  275.     elseif num == 3 then
  276.       message = message..lower[math.random(#lower)]
  277.     end
  278.   end
  279. else if n == true and s == true then
  280.   for i=1, length do
  281.     num = math.random(2)
  282.     if num == 1 then
  283.       message = message..numbers[math.random(#numbers)]
  284.     elseif num == 2 then
  285.       message = message..special[math.random(#special)]
  286.     end
  287.   end
  288. elseif l == true and u == true and s == true then
  289.   for i=1, length do
  290.     num = math.random(3)
  291.     if num == 1 then
  292.       message = message..upper[math.random(#upper)]
  293.     elseif num == 2 then
  294.       message = message..lower[math.random(#lower)]
  295.     elseif num == 3 then
  296.       message = message..special[math.random(#special)]
  297.     end
  298.   end
  299. elseif s == true and u == true then
  300.   for i=1, length do
  301.     num = math.random(2)
  302.     if num == 1 then
  303.       message = message..special[math.random(#special)]
  304.     else
  305.       message = message..upper[math.random(#upper)]
  306.     end
  307.   end
  308. elseif l == true and n == true and u == true then
  309.   for i=1, length do
  310.     num = math.random(3)
  311.     if num == 1 then
  312.       message = message..upper[math.random(#upper)]
  313.     elseif num == 2 then
  314.       message = message..numbers[math.random(#numbers)]
  315.     elseif num == 3 then
  316.       message = message..lower[math.random(#lower)]
  317.     end
  318.   end
  319. elseif u == true and n == true then
  320.   for i=1, length do
  321.     num = math.random()
  322.     if num == 1 then
  323.       message = message..upper[math.random(#upper)]
  324.     else
  325.       message = message..numbers[math.random(#numbers)]
  326.     end
  327.   end
  328. elseif l == true and n == true then
  329.   for i=1, length do
  330.     num = math.random(2)
  331.     if num == 1 then
  332.       message = message..numbers[math.random(#numbers)]
  333.     elseif num == 2 then
  334.       message = message..lower[math.random(#lower)]
  335.     end
  336.   end
  337. elseif l == true and s == true then
  338.   for i=1, length do
  339.     num = math.random(2)
  340.     if num == 1 then
  341.       message = message..special[math.random(#special)]
  342.     elseif num == 2 then
  343.       message = message..lower[math.random(#lower)]
  344.     end
  345.   end
  346. elseif l == true and u == true then
  347.   for i=1, length do
  348.     num = math.random(2)
  349.     if num == 1 then
  350.       message = message..upper[math.random(#upper)]
  351.     elseif num == 2 then
  352.       message = message..lower[math.random(#lower)]
  353.     end
  354.   end
  355. elseif l == true then
  356.   for i=1, length do
  357.     message = message..lower[math.random(#lower)]
  358.   end
  359. elseif n == true then
  360.   for i=1, length do
  361.     message = message..numbers[math.random(#numbers)]
  362.   end
  363. elseif s == true then
  364.   for i=1, length do
  365.     message = message..special[math.random(#special)]
  366.   end
  367. elseif u == true then
  368.   for i=1, length do
  369.     message = message..upper[math.random(#upper)]
  370.   end
  371. end
  372. end
  373. clear()
  374. center("Your Password is: ", 4)
  375. center(message,6)
  376. sleep(10)
  377. term.clear()
  378. start()
  379. end
  380.  
  381. function register()
  382. term.clear()
  383. term.setCursorPos(1,1)
  384. print("Registering")
  385. term.setCursorPos(1,3)
  386. write("Username: ")
  387. local usrName = read()
  388. term.setCursorPos(1,4)
  389. write("Password: ")
  390. local pass = read("*")
  391. fs.makeDir("users")
  392. if not fs.exists("users/"..usrName) then
  393. local file = fs.open("users/"..usrName, "a")
  394. file.writeLine(pass)
  395. file.close()
  396. sleep(0.5)
  397. term.clear()
  398. term.setCursorPos(1,1)
  399. print("Registered!")
  400. sleep(0.5)
  401. term.clear()
  402. start()
  403. elseif fs.exists("users/"..usrName) then
  404. term.clear()
  405. term.setCursorPos(1,1)
  406. print("Username already in use!")
  407. sleep(1)
  408. term.clear()
  409. start()
  410. end
  411. end
  412.  
  413. function login()
  414. term.clear()
  415. term.setCursorPos(1,1)
  416. print("Logging in")
  417. term.setCursorPos(1,3)
  418. write("Username: ")
  419. usrName = read()
  420. write("Password: ")
  421. local pass = read("*")
  422. file = fs.open("users/"..usrName,"r")
  423. if not fs.exists("users/"..usrName) then
  424. term.clear()
  425. term.setCursorPos(1,1)
  426. print("Login failed")
  427. sleep(1)
  428. term.clear()
  429. start()
  430. elseif fs.exists("users/"..usrName) then
  431. local fileData = {}
  432. local line = file.readLine()
  433. repeat
  434. table.insert(fileData, line)
  435. line = file.readLine()
  436. until line == nil -- readLine()
  437. file.close()
  438. local passFromFile = fileData[1]
  439. if pass == passFromFile then
  440. term.clear()
  441. term.setCursorPos(1,1)
  442. print("Login succeded!")
  443. sleep(1)
  444. term.clear()
  445. start2()
  446. else
  447. term.clear()
  448. term.setCursorPos(1,1)
  449. print("Login failed!")
  450. sleep(1)
  451. term.clear()
  452. start()
  453. end
  454. end
  455. end
  456.  
  457. function start2()
  458. term.clear()
  459. term.setTextColor(secCol)
  460. term.setCursorPos(1,1)
  461. print("Running MackOs version " ..Version)
  462. term.setCursorPos(1,2)
  463. print("Logged in as " ..usrName)
  464. term.setCursorPos(1,3)
  465. print("To exit any function use CTRL+R")
  466. term.setCursorPos(1,5)
  467. print("[1] Logout")
  468. term.setCursorPos(1,6)
  469. print("[2] Calculator")
  470. term.setCursorPos(1,7)
  471. print("[3] Games")
  472. term.setCursorPos(1,8)
  473. print("[4] Delete account")
  474. term.setCursorPos(1,9)
  475. print("[5] Exit to CraftOs")
  476. term.setCursorPos(1,10)
  477. print("[6] Calendar (Made by TheOiginalBIT")
  478. term.setCursorPos(1,11)
  479. print("[7] Credits")
  480. local input = read()
  481. if input == "1" then
  482. term.clear()
  483. term.setCursorPos(1,1)
  484. print("Logging out")
  485. sleep(1)
  486. term.clear()
  487. start()
  488. elseif input == "2" then
  489. term.clear()
  490. term.setCursorPos(1,1)
  491. print("Starting Calulator")
  492. sleep(1)
  493. term.clear()
  494. sleep(0.1)
  495. calc()
  496. elseif input == "3" then
  497. term.clear()
  498. term.setCursorPos(1,1)
  499. print("Opening games")
  500. sleep(1)
  501. term.clear()
  502. games()
  503. elseif input == "4" then
  504. term.clear()
  505. term.setCursorPos(1,1)
  506. print("Opening delete function")
  507. sleep(1)
  508. term.clear()
  509. delacc()
  510. elseif input == "5" and debugMode then
  511. os.pullEvent = pullEvent
  512. term.clear()
  513. term.setCursorPos(1,1)
  514. print("You can press ctrl+t now")
  515. while true do os.pullEvent() end
  516. elseif input == "6" then
  517. term.clear()
  518. print("Starting calendar by TheOriginalBIT")
  519. sleep(1)
  520. term.clear()
  521. calendar(false, false, 0.5)
  522. elseif input == "7" then
  523. term.clear()
  524. term.setCursorPos(1,1)
  525. print("Opening credits")
  526. sleep(1)
  527. term.clear()
  528. credits2()
  529. else
  530. term.clear()
  531. error1()
  532. end
  533. end
  534.  
  535. function credits2()
  536. term.clear()
  537. term.setCursorPos(1,1)
  538. term.setTextColor(credCol)
  539. print("Credits")
  540. term.setCursorPos(1,3)
  541. print("Programs and apis:")
  542. term.setCursorPos(1,5)
  543. print("CCalendar - TheOriginalBIT")
  544. term.setCursorPos(1,6)
  545. print("Passgen -  Conn332")
  546. term.setCursorPos(1,7)
  547. print("CCleverbot - 1lann and GravityScore")
  548. term.setCursorPos(1,9)
  549. print("Help in development:")
  550. term.setCursorPos(1,11)
  551. print("All the great people that helped me on the forums! - You know who you are :)")
  552. term.setCursorPos(1,13)
  553. write("To return type anything and hit enter: ")
  554. local input = read()
  555. if input == "1" then
  556. term.clear()
  557. start2()
  558. else
  559. term.clear()
  560. start2()
  561. end
  562. end
  563.  
  564.  
  565.  
  566.  
  567. --[[
  568. Author: TheOriginalBIT
  569. Version: CUSTOM FOR Mackos
  570. Created: 13 Mar 2013
  571.  
  572. License:
  573.  
  574. COPYRIGHT NOTICE
  575. Copyright © 2013 Joshua Asbury a.k.a TheOriginalBIT [theoriginalbit@gmail.com]
  576.  
  577. Permission is hereby granted only to Mackan90096 to distribute this software as a part of Mackos. If you wish to use this program please contact TheOriginalBIT on the ComputerCraft forums
  578. ]]--
  579.  
  580. function calendar(shorthand, ampm, refreshRate)
  581.   if not os.day then
  582.     print("Sorry but you don't seem to be running the version of ComputerCraft that this program requires (1.48+)")
  583.     return
  584.   end
  585.  
  586.   local useShorthand = (shorthand == true) or false
  587.   local useAmPm = (ampm == true) or false
  588.   local refreshRate = (type(refreshRate) == "number") and refreshRate or 0.05
  589.  
  590.   -- initialise variables
  591.   local currentYear = 1
  592.   local currentMonth = 1
  593.   local currentDay = 1
  594.   local isLeapYear = (currentYear % 4 == 0 and (currentYear % 100 > 0 or  currentYear % 400 == 0))
  595.   local yearPrefix = "AS (After Spawn)"
  596.  
  597.   local monthsTable = {
  598.     {month="January", days=31, shorthand="JAN"},
  599.     {month="February", days=28, shorthand="FEB"},
  600.     {month="March", days=31, shorthand="MAR"},
  601.     {month="April", days=30, shorthand="APR"},
  602.     {month="May", days=31, shorthand="MAY"},
  603.     {month="June", days=30, shorthand="JUNE"},
  604.     {month="July", days=31, shorthand="JULY"},
  605.     {month="August", days=31, shorthand="AUG"},
  606.     {month="September", days=30, shorthand="SEPT"},
  607.     {month="October", days=31, shorthand="OCT"},
  608.     {month="November", days=30, shorthand="NOV"},
  609.     {month="December", days=31, shorthand="DEC"},
  610.   }
  611.  
  612.   local daysTable = {
  613.     {day="Monday", shorthand="MON"},
  614.     {day="Tuesday", shorthand="TUE"},
  615.     {day="Wednesday", shorthand="WED"},
  616.     {day="Thursday", shorthand="THU"},
  617.     {day="Friday", shorthand="FRI"},
  618.     {day="Saturday", shorthand="SAT"},
  619.     {day="Sunday", shorthand="SUN"},
  620.   }
  621.  
  622.   local function updateLeapYear(year)
  623.     isLeapYear = (currentYear % 4 == 0 and (currentYear % 100 > 0 or  currentYear % 400 == 0))
  624.   end
  625.  
  626.   local function updateYear(days)
  627.     currentYear = math.floor(days/(isLeapYear and 366 or 365)+1)
  628.     updateLeapYear(year)
  629.   end
  630.  
  631.   local function updateMonth(days)
  632.     local shiftedDays = days%366
  633.     local d = 0
  634.     for i = 1, #monthsTable do
  635.       local before = d
  636.       if i == 2 and isLeapYear then
  637.         d = d + 29
  638.       else
  639.         d = d + monthsTable[i].days
  640.       end
  641.       if shiftedDays >= before and shiftedDays <= d then
  642.         currentMonth = i
  643.         return
  644.       end
  645.     end
  646.   end
  647.  
  648.   local function updateDay(days)
  649.     local shiftedDays = days%366
  650.     for i = 1, currentMonth - 1 do
  651.       shiftedDays = shiftedDays - monthsTable[i].days
  652.     end
  653.     currentDay = shiftedDays
  654.   end
  655.  
  656.   local function hexToCol(hex)
  657.     local num = tonumber(hex, 16)
  658.     return num ~= nil and 2^num or nil
  659.   end
  660.  
  661.   local function cwrite(msg, y, offset)
  662.     local sw,sh=term.getSize()
  663.     term.setCursorPos(sw/2-#msg/2+(#msg%2 and 0 or 1), (y or (sh/2)) + (offset or 0))
  664.     write(msg)
  665.   end
  666.  
  667.   while true do
  668.     term.clear()
  669.     local dayCount = os.day()
  670.     updateYear(dayCount)
  671.     updateMonth(dayCount)
  672.     updateDay(dayCount)
  673.     cwrite("The time is: "..textutils.formatTime(os.time(), not useAmPm),nil,-2)
  674.     cwrite("The date is: "..currentDay.." "..(useShorthand and monthsTable[currentMonth].shorthand or monthsTable[currentMonth].month).." "..string.format("%.4d",currentYear),nil,2)
  675.  
  676.     os.startTimer(refreshRate)
  677.     os.pullEvent("timer")
  678.   end
  679. end
  680.  
  681.  
  682.  
  683.  
  684. function calc()
  685. term.setTextColor(calcCol)
  686. term.clear()
  687. term.setCursorPos(1,1)
  688. print("Do you want to Add, Subtract, Divide or Multiply?")
  689. op = read()
  690. print("")
  691. print("What is the first number to be operated on?")
  692. num1 = tonumber(read())
  693. print("")
  694. print("And the second number?")
  695. num2 = tonumber(read())
  696. print("")
  697. if op == "add" then
  698. result = num1+num2
  699. print(result)
  700. sleep(5)
  701. term.clear()
  702. start2()
  703. elseif op == "multiply" then
  704. result = num1*num2
  705. print(result)
  706. sleep(5)
  707. term.clear()
  708. start2()
  709. elseif op == "subtract" then
  710. result = num1-num2
  711. print(result)
  712. sleep(5)
  713. term.clear()
  714. start2()
  715. elseif op == "divide" then
  716. result = num1/num2
  717. print(result)
  718. sleep(5)
  719. term.clear()
  720. start2()
  721. else
  722. term.clear()
  723. term.setCursorPos(1,1)
  724. print("You failed! Try again.")
  725. sleep(1)
  726. term.clear()
  727. start2()
  728. end
  729. end
  730.  
  731.  
  732. function games()
  733. term.clear()
  734. term.setCursorPos(1,1)
  735. print("Welcome to the games!")
  736. term.setCursorPos(1,3)
  737. print("Wich game would you like to play?")
  738. term.setCursorPos(1,5)
  739. print("[1] CCleverbot -- Made by 1lan and GravityScore")
  740. term.setCursorPos(1,7)
  741. write("Input a number: ")
  742. local input = read()
  743. if input == "1" then
  744. term.clear()
  745. term.setCursorPos(1,1)
  746. print("Starting CCleverbot")
  747. sleep(1)
  748. term.clear()
  749. ccbot()
  750. else
  751. term.clear()
  752. term.setCursorPos(1,1)
  753. print("Not a game!")
  754. sleep(1)
  755. term.clear()
  756. start2()
  757. end
  758. end
  759.  
  760. function error1()
  761. term.clear()
  762. term.setTextColor(ErrCol1)
  763. term.setCursorPos(1,1)
  764. print("Oh Noes!, Something went wrong!")
  765. term.setCursorPos(1,2)
  766. print("Either is this not implemented yet")
  767. term.setCursorPos(1,3)
  768. print("or there was an error in the code or")
  769. term.setCursorPos(1,4)
  770. print("you do not have the permission to acces the")
  771. term.setCursorPos(1,5)
  772. print("item(s) you requested")
  773. term.setCursorPos(1,7)
  774. print("If you think this is an error")
  775. term.setCursorPos(1,8)
  776. print("please contact " ..Author)
  777. term.setCursorPos(1,10)
  778. write("[1] Reboot [2] Go back to the start screen: ")
  779. local input = read()
  780. if input == "1" then
  781. os.reboot()
  782. elseif input == "2" then
  783. term.clear()
  784. start()
  785. end
  786. end
  787.  
  788. function delacc()
  789. term.clear()
  790. term.setCursorPos(1,1)
  791. print("Really delete account? Y/N")
  792. local input = read()
  793. if input == "y" then
  794. term.clear()
  795. delacc2()
  796. elseif input == "n" then
  797. start2()
  798. else
  799. term.clear()
  800. error1()
  801. end
  802. end
  803.  
  804. function delacc2()
  805. term.clear()
  806. term.setCursorPos(1,1)
  807. write("Your username: ")
  808. local usrName = read()
  809. sleep(1)
  810. fs.delete("users/"..usrName)
  811. term.clear()
  812. term.setCursorPos(1,1)
  813. print("Deleting account")
  814. sleep(1)
  815. term.clear()
  816. start()
  817. end
  818.  
  819. function ccbot()
  820. --  
  821. --  CCleverBot
  822. --  Made by 1lann and GravityScore
  823. --  
  824.  
  825.  
  826. --  Variables
  827.  
  828. local version = "1.1"
  829.  
  830. local responseURL = "http://firewolf.dyndns.org:8080/ccleverbot/response.php"
  831. local event_updateChat = "ccleverbot_updateChatEvent"
  832. local event_continue = "ccleverbot_continueEvent"
  833. local event_exit = "ccleverbot_exitEvent"
  834.  
  835. local chatHistory = {}
  836. local chatLog = {}
  837. local w, h = term.getSize()
  838.  
  839. --  Drawing
  840.  
  841. local function centerPrint(text, y)
  842.         if type(text) == "table" then for _, v in pairs(text) do centerPrint(v) end
  843.         else
  844.                 local x, y = term.getCursorPos()
  845.                 term.setCursorPos((w + 2)/2 - text:len()/2, ny or y)
  846.                 print(text)
  847.         end
  848. end
  849.  
  850. local function drawChat(chatData, offset, thinking, scrolled)
  851.         local a, b = false, false
  852.         for i = 1, 10 do
  853.                 term.setCursorPos(3, 16 - i)
  854.                 term.clearLine()
  855.         end
  856.  
  857.         for i = 1, 10 do
  858.                 local c = chatData[#chatData + 1 - i + offset]
  859.  
  860.                 if #chatData + 1 - i + offset < 1 then break end
  861.                 term.setCursorPos(3, 16 - i)
  862.  
  863.                 if thinking and i == 1 then
  864.                         term.setTextColor(colors.lightGray)
  865.                         write("...")
  866.                         offset = offset + 1
  867.                 else
  868.                         if c[2] == "user" then
  869.                                 term.setTextColor(colors.black)
  870.                                 write(c[1])
  871.                         else
  872.                                 term.setTextColor(colors.lightBlue)
  873.                                 if i == 1 and scrolled ~= true then
  874.                                         a = true
  875.                                 elseif i == 2 and scrolled ~= true then
  876.                                         b = true
  877.                                 else
  878.                                         write(c[1])
  879.                                 end
  880.                         end
  881.                 end
  882.         end
  883.  
  884.         if a then
  885.                 term.setTextColor(colors.lightBlue)
  886.                 if b then
  887.                         term.setCursorPos(3, 14)
  888.                         textutils.slowWrite(chatData[#chatData - 1][1])
  889.                 end
  890.  
  891.                 term.setCursorPos(3, 15)
  892.                 textutils.slowWrite(chatData[#chatData][1])
  893.         end
  894.  
  895.         os.queueEvent(event_continue)
  896. end
  897.  
  898.  
  899. --  Interface
  900.  
  901. local function interface()
  902.         local scrollPos = 0
  903.         local updateChatLog = nil
  904.         while true do
  905.                 local e, p1, p2 = os.pullEvent()
  906.                 if e == event_updateChat then
  907.                         updateChatLog = textutils.unserialize(p1)
  908.                         scrollPos = 0
  909.                         drawChat(updateChatLog, 0, p2)
  910.                 elseif e == event_exit then
  911.                         return
  912.                 elseif e == "mouse_scroll" then
  913.                         if scrollPos + p1 <= 0 and updateChatLog then
  914.                                 if #updateChatLog > 10 and #updateChatLog >= (scrollPos+p1)*-1+10 then
  915.                                         scrollPos = scrollPos+p1
  916.                                         local scrollChat = {}
  917.                                         for i = 10, 1, -1 do
  918.                                                 scrollChat[i] = updateChatLog[#updateChatLog-(10-i)+scrollPos]
  919.                                         end
  920.                                         local x, y = term.getCursorPos()
  921.                                         drawChat(scrollChat, 0, nil, true)
  922.                                         term.setCursorPos(x, y)
  923.                                         term.setTextColor(colors.gray)
  924.                                 end
  925.                         end
  926.                 end
  927.         end
  928. end
  929.  
  930.  
  931. --  Input
  932.  
  933. local function input()
  934.         while true do
  935.                 -- Read
  936.                 term.setCursorPos(3, 17)
  937.                 term.setTextColor(colors.gray)
  938.                 term.clearLine()
  939.                 write("> ")
  940.                 local inputData = read(nil, chatHistory):gsub("^%s*(.-)%s*$", "%1")
  941.                 table.insert(chatHistory, inputData)
  942.                 if inputData == "/exit" then
  943.                         os.queueEvent(event_exit)
  944.                         return
  945.                 end
  946.  
  947.                 -- Parse input
  948.                 if inputData == "" then inputData = "Hello." end
  949.                 inputData = inputData:sub(1, 1):upper() .. inputData:sub(2, -1)
  950.                 if not inputData:sub(-1, -1):find("[\.\?!,]") then inputData = inputData .. "." end
  951.                 if inputData:len() > 45 and not inputData:sub(1, 45):find(" ") then
  952.                         inputData = inputData:sub(1, 45) .. " " .. inputData:sub(46, -1)
  953.                 end
  954.  
  955.                 -- Clear
  956.                 term.setCursorPos(3, 17)
  957.                 term.clearLine()
  958.                 write("> ")
  959.  
  960.                 if inputData:len() > 46 then
  961.                         local spaceData = {}
  962.                         local loopNum = 0
  963.                         while true do
  964.                                 loopNum = inputData:find(" ", loopNum + 1, 1, true)
  965.                                 table.insert(spaceData, loopNum)
  966.                                 if type(loopNum) ~= "number" then
  967.                                         table.insert(spaceData, 47)
  968.                                         break
  969.                                 end
  970.                         end
  971.  
  972.                         for k, v in ipairs(spaceData) do
  973.                                 if v > 46 then
  974.                                         chatLog[#chatLog + 1] = {inputData:sub(1, spaceData[k - 1] - 1), "user"}
  975.                                         chatLog[#chatLog + 1] = {inputData:sub(spaceData[k - 1] + 1, -1), "user"}
  976.                                         break
  977.                                 end
  978.                         end
  979.                 else
  980.                         chatLog[#chatLog + 1] = {inputData, "user"}
  981.                 end
  982.  
  983.                 os.queueEvent(event_updateChat, textutils.serialize(chatLog), true)
  984.  
  985.                 -- Get response
  986.                 local response = http.post(responseURL, "input=" .. textutils.urlEncode(inputData))
  987.                 if response then
  988.                         local responseData = response.readAll()
  989.                         if responseData:len() > 46 then
  990.                                 local spaceData = {}
  991.                                 local loopNum = 0
  992.                                 while true do
  993.                                         loopNum = responseData:find(" ", loopNum + 1, 1, true)
  994.                                         table.insert(spaceData, loopNum)
  995.                                         if type(loopNum) ~= "number" then
  996.                                                 table.insert(spaceData, 47)
  997.                                                 break
  998.                                         end
  999.                                 end
  1000.  
  1001.                                 for k, v in ipairs(spaceData) do
  1002.                                         if v > 46 then
  1003.                                                 chatLog[#chatLog + 1] = {responseData:sub(1, spaceData[k - 1] - 1), "bot"}
  1004.                                                 chatLog[#chatLog + 1] = {responseData:sub(spaceData[k - 1]+1, -1), "bot"}
  1005.                                                 break
  1006.                                         end
  1007.                                 end
  1008.                         else
  1009.                                 chatLog[#chatLog + 1] = {responseData, "bot"}
  1010.                         end
  1011.                 else
  1012.                         chatLog[#chatLog + 1] = {"CCBot: An error has ocurred!", "bot"}
  1013.                 end
  1014.  
  1015.                 os.queueEvent(event_updateChat, textutils.serialize(chatLog))
  1016.                 os.pullEvent(event_continue)
  1017.         end
  1018. end
  1019.  
  1020.  
  1021. --  Main
  1022.  
  1023. local function main()
  1024.         -- Top logo
  1025.         term.setBackgroundColor(colors.white)
  1026.         term.clear()
  1027.         term.setCursorPos(19, 2)
  1028.  
  1029.         term.setTextColor(colors.lightBlue)
  1030.         write("CClever")
  1031.         term.setTextColor(colors.lime)
  1032.         write("B")
  1033.         term.setTextColor(colors.yellow)
  1034.         write("o")
  1035.         term.setTextColor(colors.red)
  1036.         write("t  ")
  1037.         term.setTextColor(colors.lightGray)
  1038.         write(version)
  1039.         term.setTextColor(colors.gray)
  1040.         term.setCursorPos(1, 3)
  1041.         centerPrint("- www.cleverbot.com -")
  1042.  
  1043.         -- Run
  1044.         parallel.waitForAll(input, interface)
  1045. end
  1046.  
  1047. -- Check
  1048. if not http then
  1049.         print("HTTP API Needs to be Enabled!")
  1050.         print("CCleverBot heavily orties on it!")
  1051.         error()
  1052. end
  1053.  
  1054. -- Run
  1055. local _, err = pcall(main)
  1056. if err then
  1057.         term.setTextColor(colors.white)
  1058.         term.setBackgroundColor(colors.black)
  1059.         term.clear()
  1060.         term.setCursorPos(1, 1)
  1061.         print("Error!")
  1062.         print(err)
  1063.         print("\nPress any key to exit...")
  1064.         os.pullEvent("key")
  1065.         start2()
  1066. end
  1067.  
  1068. -- Exit
  1069. term.setTextColor(colors.white)
  1070. term.setBackgroundColor(colors.black)
  1071. term.clear()
  1072. term.setCursorPos(1, 1)
  1073. centerPrint("Thank You for Using CCleverBot " .. version)
  1074. centerPrint("Made by 1lann and GravityScore")
  1075.  
  1076. end
  1077.  
  1078. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement