Advertisement
Mackan90096

MackOS Alpha [0.1] Release edition

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