Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- __ __ _ ____ _____
- | \/ | | | / __ \ / ____|
- | \ / | __ _ ___| | _| | | | (___
- | |\/| |/ _` |/ __| |/ / | | |\___ \
- | | | | (_| | (__| <| |__| |____) |
- |_| |_|\__,_|\___|_|\_\\____/|_____/
- Welcome to MackOS!
- Author: Mackan90096
- Version: Alpha [0.1] Build: Release.
- Created: 14 Mar 2013
- License:
- COPYRIGHT NOTICE
- Copyright © 2013 Max Thor a.k.a Mackan90096 [thormax5@gmail.com]
- If you wish to use any of these function(s) or code snippets, contact Mackan90096 on the
- ComputerCraft Forums. (www.computercraft.info/forums2)
- --]]
- local debugMode = true -- Set to false to prevent exiting to craftOS
- local pullEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- Version = "Alpha [0.1]"
- credCol = 32
- firstCol = 1
- secCol = 2048
- Author = "Mackan90096"
- ErrCol1 = 16384
- calcCol = 128
- function start()
- term.clear()
- term.setTextColor(firstCol)
- term.setCursorPos(1,1)
- textutils.slowPrint("Welcome to MackOs version " ..Version)
- term.setCursorPos(1,3)
- print("What would you like to do?")
- term.setCursorPos(1,4)
- print("[1] Login")
- term.setCursorPos(1,5)
- print("[2] Register")
- term.setCursorPos(1,6)
- print("[3] Reboot Computer")
- term.setCursorPos(1,7)
- print("[4] Shutdown Computer")
- term.setCursorPos(1,8)
- print("[5] Generate a password")
- term.setCursorPos(1,9)
- print("[6] Credits")
- term.setCursorPos(1,11)
- write("Input a number: ")
- local input = read()
- if input == "1" then
- login()
- elseif input == "2" then
- register()
- elseif input == "3" then
- term.clear()
- term.setCursorPos(1,1)
- print("Rebooting in 2 seconds!")
- sleep(2)
- os.reboot()
- elseif input == "4" then
- term.clear()
- term.setCursorPos(1,1)
- print("Shutting down in 2 seconds!")
- sleep(2)
- os.shutdown()
- elseif input == "5" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening passgen")
- sleep(1)
- term.clear()
- passgen()
- elseif input == "6" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening credits")
- sleep(1)
- term.clear()
- credits()
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Cant understand!")
- sleep(1)
- term.clear()
- start()
- end
- end
- function credits()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(credCol)
- print("Credits")
- term.setCursorPos(1,3)
- print("Programs and apis:")
- term.setCursorPos(1,5)
- print("CCalendar - TheOriginalBIT")
- term.setCursorPos(1,6)
- print("Passgen - Conn332")
- term.setCursorPos(1,7)
- print("CCleverbot - 1lann and GravityScore")
- term.setCursorPos(1,9)
- print("Help in development:")
- term.setCursorPos(1,11)
- print("All the great people that helped me on the forums! - You know who you are :)")
- term.setCursorPos(1,13)
- write("To return type anything and hit enter: ")
- local input = read()
- if input == "1" then
- term.clear()
- start()
- else
- term.clear()
- start()
- end
- end
- function passgen()
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function center(text,y,mode)
- w,h = term.getSize()
- term.setCursorPos((w/2)-(#text/2),y)
- if mode == nil then mode = "print" end
- if mode == "write" then
- write(text)
- else
- print(text)
- end
- end
- clear()
- write "Length: "
- local length = read()
- if tonumber(length) == false then
- print("Use a number please")
- sleep(2)
- error()
- else
- length = tonumber(length)
- end
- if length > 51 then
- print("Please enter a length 50 characters or below")
- sleep(2)
- error()
- end
- 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'}
- 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'}
- special = {'!','@','#','$','%','^','&','*'}
- numbers = {'0','1','2','3','4','5','6','7','8','9'}
- 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"}
- clear()
- center("Modes: Upper[u], special[s], number[n], lower[l]",2)
- print()
- print()
- write "write all modes you want (no commas): "
- local l = false
- local u = false
- local s = false
- local n = false
- mds = ""
- while true do
- event, key = os.pullEvent("key")
- if key == 22 then
- if u == false then
- u = true
- term.setCursorPos(1,7)
- print"Upper"
- mds = mds.."u"
- else
- u = false
- term.setCursorPos(1,7)
- term.clearLine()
- mds = mds:gsub( "u", "" )
- end
- elseif key == 31 then
- if s == false then
- s = true
- term.setCursorPos(1,8)
- print"Special"
- mds = mds.."s"
- else
- s = false
- term.setCursorPos(1,8)
- term.clearLine()
- mds = mds:gsub("s","")
- end
- elseif key == 49 then
- if n == false then
- n = true
- term.setCursorPos(1,9)
- print"Number"
- mds = mds.."n"
- else
- n = false
- term.setCursorPos(1,9)
- term.clearLine()
- mds = mds:gsub("n", "")
- end
- elseif key == 38 then
- if l == false then
- l = true
- term.setCursorPos(1,10)
- print"Lower"
- mds = mds.."l"
- else
- l = false
- term.setCursorPos(1,10)
- term.clearLine()
- mds = mds:gsub("l", "")
- end
- elseif key == 28 and (l or n or s or u) then
- break
- end
- end
- mds = string.lower(mds)
- local test = false
- for i=1, #mode do
- if mds == mode[i] then
- test = true
- break
- end
- end
- if test == false then
- print("Invalid mode: "..mds)
- end
- modes = {}
- message = ""
- if l == true and n == true and s == true and u == true then
- for i=1, length do
- num = math.random(4)
- if num == 1 then
- message = message..lower[math.random(#lower)]
- elseif num == 2 then
- message = message..upper[math.random(#upper)]
- elseif num == 3 then
- message = message..special[math.random(#special)]
- elseif num == 4 then
- message = message..numbers[math.random(#numbers)]
- end
- end
- elseif n == true and s == true and u == true then
- for i=1, length do
- num = math.random(3)
- if num == 1 then
- message = message..upper[math.random(#upper)]
- elseif num == 2 then
- message = message..special[math.random(#special)]
- elseif num == 3 then
- message = message..numbers[math.random(#numbers)]
- end
- end
- elseif n == true and s == true and l == true then
- for i=1, length do
- num = math.random(3)
- if num == 1 then
- message = message..special[math.random(#special)]
- elseif num == 2 then
- message = message..numbers[math.random(#numbers)]
- elseif num == 3 then
- message = message..lower[math.random(#lower)]
- end
- end
- else if n == true and s == true then
- for i=1, length do
- num = math.random(2)
- if num == 1 then
- message = message..numbers[math.random(#numbers)]
- elseif num == 2 then
- message = message..special[math.random(#special)]
- end
- end
- elseif l == true and u == true and s == true then
- for i=1, length do
- num = math.random(3)
- if num == 1 then
- message = message..upper[math.random(#upper)]
- elseif num == 2 then
- message = message..lower[math.random(#lower)]
- elseif num == 3 then
- message = message..special[math.random(#special)]
- end
- end
- elseif s == true and u == true then
- for i=1, length do
- num = math.random(2)
- if num == 1 then
- message = message..special[math.random(#special)]
- else
- message = message..upper[math.random(#upper)]
- end
- end
- elseif l == true and n == true and u == true then
- for i=1, length do
- num = math.random(3)
- if num == 1 then
- message = message..upper[math.random(#upper)]
- elseif num == 2 then
- message = message..numbers[math.random(#numbers)]
- elseif num == 3 then
- message = message..lower[math.random(#lower)]
- end
- end
- elseif u == true and n == true then
- for i=1, length do
- num = math.random()
- if num == 1 then
- message = message..upper[math.random(#upper)]
- else
- message = message..numbers[math.random(#numbers)]
- end
- end
- elseif l == true and n == true then
- for i=1, length do
- num = math.random(2)
- if num == 1 then
- message = message..numbers[math.random(#numbers)]
- elseif num == 2 then
- message = message..lower[math.random(#lower)]
- end
- end
- elseif l == true and s == true then
- for i=1, length do
- num = math.random(2)
- if num == 1 then
- message = message..special[math.random(#special)]
- elseif num == 2 then
- message = message..lower[math.random(#lower)]
- end
- end
- elseif l == true and u == true then
- for i=1, length do
- num = math.random(2)
- if num == 1 then
- message = message..upper[math.random(#upper)]
- elseif num == 2 then
- message = message..lower[math.random(#lower)]
- end
- end
- elseif l == true then
- for i=1, length do
- message = message..lower[math.random(#lower)]
- end
- elseif n == true then
- for i=1, length do
- message = message..numbers[math.random(#numbers)]
- end
- elseif s == true then
- for i=1, length do
- message = message..special[math.random(#special)]
- end
- elseif u == true then
- for i=1, length do
- message = message..upper[math.random(#upper)]
- end
- end
- end
- clear()
- center("Your Password is: ", 4)
- center(message,6)
- sleep(10)
- term.clear()
- start()
- end
- function register()
- term.clear()
- term.setCursorPos(1,1)
- print("Registering")
- term.setCursorPos(1,3)
- write("Username: ")
- local usrName = read()
- term.setCursorPos(1,4)
- write("Password: ")
- local pass = read("*")
- fs.makeDir("users")
- if not fs.exists("users/"..usrName) then
- local file = fs.open("users/"..usrName, "a")
- file.writeLine(pass)
- file.close()
- sleep(0.5)
- term.clear()
- term.setCursorPos(1,1)
- print("Registered!")
- sleep(0.5)
- term.clear()
- start()
- elseif fs.exists("users/"..usrName) then
- term.clear()
- term.setCursorPos(1,1)
- print("Username already in use!")
- sleep(1)
- term.clear()
- start()
- end
- end
- function login()
- term.clear()
- term.setCursorPos(1,1)
- print("Logging in")
- term.setCursorPos(1,3)
- write("Username: ")
- usrName = read()
- write("Password: ")
- local pass = read("*")
- file = fs.open("users/"..usrName,"r")
- if not fs.exists("users/"..usrName) then
- term.clear()
- term.setCursorPos(1,1)
- print("Login failed")
- sleep(1)
- term.clear()
- start()
- elseif fs.exists("users/"..usrName) then
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData, line)
- line = file.readLine()
- until line == nil -- readLine()
- file.close()
- local passFromFile = fileData[1]
- if pass == passFromFile then
- term.clear()
- term.setCursorPos(1,1)
- print("Login succeded!")
- sleep(1)
- term.clear()
- start2()
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Login failed!")
- sleep(1)
- term.clear()
- start()
- end
- end
- end
- function start2()
- term.clear()
- term.setTextColor(secCol)
- term.setCursorPos(1,1)
- print("Running MackOs version " ..Version)
- term.setCursorPos(1,2)
- print("Logged in as " ..usrName)
- term.setCursorPos(1,3)
- print("To exit any function use CTRL+R")
- term.setCursorPos(1,5)
- print("[1] Logout")
- term.setCursorPos(1,6)
- print("[2] Calculator")
- term.setCursorPos(1,7)
- print("[3] Games")
- term.setCursorPos(1,8)
- print("[4] Delete account")
- term.setCursorPos(1,9)
- print("[5] Exit to CraftOs")
- term.setCursorPos(1,10)
- print("[6] Calendar (Made by TheOriginalBIT")
- term.setCursorPos(1,11)
- print("[7] Credits")
- term.setCursorPos(1,12)
- print("[8] Send me an email")
- term.setCursorPos(1,13)
- print("[9] File Explorer (kindof)")
- term.setCursorPos(1,14)
- print("[10] Whats new")
- local input = read()
- if input == "1" then
- term.clear()
- term.setCursorPos(1,1)
- print("Logging out")
- sleep(1)
- term.clear()
- start()
- elseif input == "2" then
- term.clear()
- term.setCursorPos(1,1)
- print("Starting Calulator")
- sleep(1)
- term.clear()
- sleep(0.1)
- calc()
- elseif input == "3" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening games")
- sleep(1)
- term.clear()
- games()
- elseif input == "4" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening delete function")
- sleep(1)
- term.clear()
- delacc()
- elseif input == "5" and debugMode then
- os.pullEvent = pullEvent
- term.clear()
- term.setCursorPos(1,1)
- print("You can press ctrl+t now")
- while true do os.pullEvent() end
- elseif input == "6" then
- term.clear()
- print("Starting calendar by TheOriginalBIT")
- sleep(1)
- term.clear()
- calendar(false, false, 0.5)
- elseif input == "7" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening credits")
- sleep(1)
- term.clear()
- credits2()
- elseif input == "8" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening mail function")
- sleep(1)
- term.clear()
- email()
- elseif input == "9" then
- term.clear()
- fileFunctions()
- elseif input == "10" then
- term.clear()
- term.setCursorPos(1,1)
- print("Opening Whats New")
- sleep(1)
- term.clear()
- new2()
- else
- term.clear()
- error1()
- end
- end
- function Edit()
- term.clear()
- term.setCursorPos(1,1)
- write("What file would you like to edit?: ")
- fileName = read()
- sleep(1)
- term.clear()
- if fileName == "startup" then
- term.clear()
- term.setCursorPos(1,1)
- print("You do not have acces to this!")
- sleep(1)
- term.clear()
- fileFunctions()
- else
- term.clear()
- shell.run("edit "..fileName)
- fileFunctions()
- end
- end
- function copy()
- term.clear()
- term.setCursorPos(1,1)
- write("What file would you like to move?: ")
- source = read()
- write("To where?: ")
- path2 = read()
- sleep(1)
- term.clear()
- if source == "startup" then
- term.clear()
- term.setCursorPos(1,1)
- print("You do not have acces to this!")
- sleep(1)
- term.clear()
- fileFunctions()
- else
- term.clear()
- shell.run("cp "..source ..path2)
- term.clear()
- term.setCursorPos(1,1)
- print("Copied "..source "to" ..path2)
- sleep(1)
- term.clear()
- fileFunctions()
- end
- end
- function reName()
- term.clear()
- term.setCursorPos(1,1)
- write("What file would you like to rename?: ")
- file1 = read()
- write("To what?: ")
- newName = read()
- sleep(1)
- term.clear()
- if file1 == "startup" then
- term.clear()
- term.setCursorPos(1,1)
- print("You do not have acces to this!")
- sleep(1)
- term.clear()
- fileFunctions()
- else
- term.clear()
- shell.run("rename "..file1 ..newName)
- term.clear()
- term.setCursorPos(1,1)
- print("Renamed " ..file1)
- print("to " ..newName)
- sleep(1)
- term.clear()
- fileFunctions()
- end
- end
- function fileFunctions()
- term.clear()
- term.setCursorPos(1,1)
- print("File Functions")
- term.setCursorPos(1,3)
- print("[1] Edit a file")
- term.setCursorPos(1,4)
- print("[2] Copy a file")
- term.setCursorPos(1,5)
- print("[3] Rename a file")
- term.setCursorPos(1,6)
- print("[4] Go back")
- term.setCursorPos(1,8)
- write("Please input a number: ")
- local input = read()
- if input == "1" then
- Edit()
- elseif input == "2" then
- term.clear()
- copy()
- elseif input == "3" then
- term.clear()
- reName()
- elseif input == "4" then
- term.clear()
- start2()
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Can't understand!")
- sleep(1)
- term.clear()
- fileFunctions()
- end
- end
- function new2()
- term.clear()
- term.setCursorPos(1,1)
- print("[0.1]:")
- term.setCursorPos(1,2)
- print("Initial release")
- term.setCursorPos(1,4)
- write("To exit type anything and press enter: ")
- local input = read()
- if input == "1" then
- term.clear()
- start2()
- else
- term.clear()
- start2()
- end
- end
- function credits2()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(credCol)
- print("Credits")
- term.setCursorPos(1,3)
- print("Programs and apis:")
- term.setCursorPos(1,5)
- print("CCalendar - TheOriginalBIT")
- term.setCursorPos(1,6)
- print("Passgen - Conn332")
- term.setCursorPos(1,7)
- print("CCleverbot - 1lann and GravityScore")
- term.setCursorPos(1,9)
- print("Help in development:")
- term.setCursorPos(1,11)
- print("All the great people that helped me on the forums! - You know who you are :)")
- term.setCursorPos(1,13)
- write("To return type anything and hit enter: ")
- local input = read()
- if input == "1" then
- term.clear()
- start2()
- else
- term.clear()
- start2()
- end
- end
- --[[
- Author: TheOriginalBIT
- Version: CUSTOM FOR Mackos
- Created: 13 Mar 2013
- License:
- COPYRIGHT NOTICE
- Copyright © 2013 Joshua Asbury a.k.a TheOriginalBIT [theoriginalbit@gmail.com]
- 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
- ]]--
- function calendar(shorthand, ampm, refreshRate)
- if not os.day then
- print("Sorry but you don't seem to be running the version of ComputerCraft that this program requires (1.48+)")
- return
- end
- local useShorthand = (shorthand == true) or false
- local useAmPm = (ampm == true) or false
- local refreshRate = (type(refreshRate) == "number") and refreshRate or 0.05
- -- initialise variables
- local currentYear = 1
- local currentMonth = 1
- local currentDay = 1
- local isLeapYear = (currentYear % 4 == 0 and (currentYear % 100 > 0 or currentYear % 400 == 0))
- local yearPrefix = "AS (After Spawn)"
- local monthsTable = {
- {month="January", days=31, shorthand="JAN"},
- {month="February", days=28, shorthand="FEB"},
- {month="March", days=31, shorthand="MAR"},
- {month="April", days=30, shorthand="APR"},
- {month="May", days=31, shorthand="MAY"},
- {month="June", days=30, shorthand="JUNE"},
- {month="July", days=31, shorthand="JULY"},
- {month="August", days=31, shorthand="AUG"},
- {month="September", days=30, shorthand="SEPT"},
- {month="October", days=31, shorthand="OCT"},
- {month="November", days=30, shorthand="NOV"},
- {month="December", days=31, shorthand="DEC"},
- }
- local daysTable = {
- {day="Monday", shorthand="MON"},
- {day="Tuesday", shorthand="TUE"},
- {day="Wednesday", shorthand="WED"},
- {day="Thursday", shorthand="THU"},
- {day="Friday", shorthand="FRI"},
- {day="Saturday", shorthand="SAT"},
- {day="Sunday", shorthand="SUN"},
- }
- local function updateLeapYear(year)
- isLeapYear = (currentYear % 4 == 0 and (currentYear % 100 > 0 or currentYear % 400 == 0))
- end
- local function updateYear(days)
- currentYear = math.floor(days/(isLeapYear and 366 or 365)+1)
- updateLeapYear(year)
- end
- local function updateMonth(days)
- local shiftedDays = days%366
- local d = 0
- for i = 1, #monthsTable do
- local before = d
- if i == 2 and isLeapYear then
- d = d + 29
- else
- d = d + monthsTable[i].days
- end
- if shiftedDays >= before and shiftedDays <= d then
- currentMonth = i
- return
- end
- end
- end
- local function updateDay(days)
- local shiftedDays = days%366
- for i = 1, currentMonth - 1 do
- shiftedDays = shiftedDays - monthsTable[i].days
- end
- currentDay = shiftedDays
- end
- local function hexToCol(hex)
- local num = tonumber(hex, 16)
- return num ~= nil and 2^num or nil
- end
- local function cwrite(msg, y, offset)
- local sw,sh=term.getSize()
- term.setCursorPos(sw/2-#msg/2+(#msg%2 and 0 or 1), (y or (sh/2)) + (offset or 0))
- write(msg)
- end
- while true do
- term.clear()
- local dayCount = os.day()
- updateYear(dayCount)
- updateMonth(dayCount)
- updateDay(dayCount)
- cwrite("The time is: "..textutils.formatTime(os.time(), not useAmPm),nil,-2)
- cwrite("The date is: "..currentDay.." "..(useShorthand and monthsTable[currentMonth].shorthand or monthsTable[currentMonth].month).." "..string.format("%.4d",currentYear),nil,2)
- os.startTimer(refreshRate)
- os.pullEvent("timer")
- end
- end
- function calc()
- term.setTextColor(calcCol)
- term.clear()
- term.setCursorPos(1,1)
- print("Do you want to Add, Subtract, Divide or Multiply?")
- op = read()
- print("")
- print("What is the first number to be operated on?")
- num1 = tonumber(read())
- print("")
- print("And the second number?")
- num2 = tonumber(read())
- print("")
- if op == "add" then
- result = num1+num2
- print(result)
- sleep(5)
- term.clear()
- start2()
- elseif op == "multiply" then
- result = num1*num2
- print(result)
- sleep(5)
- term.clear()
- start2()
- elseif op == "subtract" then
- result = num1-num2
- print(result)
- sleep(5)
- term.clear()
- start2()
- elseif op == "divide" then
- result = num1/num2
- print(result)
- sleep(5)
- term.clear()
- start2()
- else
- term.clear()
- term.setCursorPos(1,1)
- print("You failed! Try again.")
- sleep(1)
- term.clear()
- start2()
- end
- end
- function games()
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to the games!")
- term.setCursorPos(1,3)
- print("Wich game would you like to play?")
- term.setCursorPos(1,5)
- print("[1] CCleverbot -- Made by 1lan and GravityScore")
- term.setCursorPos(1,7)
- write("Input a number: ")
- local input = read()
- if input == "1" then
- term.clear()
- term.setCursorPos(1,1)
- print("Starting CCleverbot")
- sleep(1)
- term.clear()
- ccbot()
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Not a game!")
- sleep(1)
- term.clear()
- start2()
- end
- end
- function error1()
- term.clear()
- term.setTextColor(ErrCol1)
- term.setCursorPos(1,1)
- print("Oh Noes!, Something went wrong!")
- term.setCursorPos(1,2)
- print("Either is this not implemented yet")
- term.setCursorPos(1,3)
- print("or there was an error in the code or")
- term.setCursorPos(1,4)
- print("you do not have the permission to acces the")
- term.setCursorPos(1,5)
- print("item(s) you requested")
- term.setCursorPos(1,7)
- print("If you think this is an error")
- term.setCursorPos(1,8)
- print("please contact " ..Author)
- term.setCursorPos(1,10)
- write("[1] Reboot [2] Go back to the start screen: ")
- local input = read()
- if input == "1" then
- os.reboot()
- elseif input == "2" then
- term.clear()
- start()
- end
- end
- function delacc()
- term.clear()
- term.setCursorPos(1,1)
- print("Really delete account? Y/N")
- local input = read()
- if input == "y" then
- term.clear()
- delacc2()
- elseif input == "n" then
- start2()
- else
- term.clear()
- error1()
- end
- end
- function delacc2()
- term.clear()
- term.setCursorPos(1,1)
- write("Your username: ")
- local usrName = read()
- sleep(1)
- fs.delete("users/"..usrName)
- term.clear()
- term.setCursorPos(1,1)
- print("Deleting account")
- sleep(1)
- term.clear()
- start()
- end
- function email()
- term.clear()
- write("Name: ")
- name = read()
- write("Message: ")
- msg = read()
- email = name.."\n"..msg
- http.post(
- "http://mackos.netai.net/scripts/email.php?message="..textutils.urlEncode(tostring(email))
- )
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- print("Email sent!")
- sleep(1)
- term.clear()
- start2()
- end
- function ccbot()
- --
- -- CCleverBot
- -- Made by 1lann and GravityScore
- --
- -- Variables
- local version = "1.1"
- local responseURL = "http://firewolf.dyndns.org:8080/ccleverbot/response.php"
- local event_updateChat = "ccleverbot_updateChatEvent"
- local event_continue = "ccleverbot_continueEvent"
- local event_exit = "ccleverbot_exitEvent"
- local chatHistory = {}
- local chatLog = {}
- local w, h = term.getSize()
- -- Drawing
- local function centerPrint(text, y)
- if type(text) == "table" then for _, v in pairs(text) do centerPrint(v) end
- else
- local x, y = term.getCursorPos()
- term.setCursorPos((w + 2)/2 - text:len()/2, ny or y)
- print(text)
- end
- end
- local function drawChat(chatData, offset, thinking, scrolled)
- local a, b = false, false
- for i = 1, 10 do
- term.setCursorPos(3, 16 - i)
- term.clearLine()
- end
- for i = 1, 10 do
- local c = chatData[#chatData + 1 - i + offset]
- if #chatData + 1 - i + offset < 1 then break end
- term.setCursorPos(3, 16 - i)
- if thinking and i == 1 then
- term.setTextColor(colors.lightGray)
- write("...")
- offset = offset + 1
- else
- if c[2] == "user" then
- term.setTextColor(colors.black)
- write(c[1])
- else
- term.setTextColor(colors.lightBlue)
- if i == 1 and scrolled ~= true then
- a = true
- elseif i == 2 and scrolled ~= true then
- b = true
- else
- write(c[1])
- end
- end
- end
- end
- if a then
- term.setTextColor(colors.lightBlue)
- if b then
- term.setCursorPos(3, 14)
- textutils.slowWrite(chatData[#chatData - 1][1])
- end
- term.setCursorPos(3, 15)
- textutils.slowWrite(chatData[#chatData][1])
- end
- os.queueEvent(event_continue)
- end
- -- Interface
- local function interface()
- local scrollPos = 0
- local updateChatLog = nil
- while true do
- local e, p1, p2 = os.pullEvent()
- if e == event_updateChat then
- updateChatLog = textutils.unserialize(p1)
- scrollPos = 0
- drawChat(updateChatLog, 0, p2)
- elseif e == event_exit then
- return
- elseif e == "mouse_scroll" then
- if scrollPos + p1 <= 0 and updateChatLog then
- if #updateChatLog > 10 and #updateChatLog >= (scrollPos+p1)*-1+10 then
- scrollPos = scrollPos+p1
- local scrollChat = {}
- for i = 10, 1, -1 do
- scrollChat[i] = updateChatLog[#updateChatLog-(10-i)+scrollPos]
- end
- local x, y = term.getCursorPos()
- drawChat(scrollChat, 0, nil, true)
- term.setCursorPos(x, y)
- term.setTextColor(colors.gray)
- end
- end
- end
- end
- end
- -- Input
- local function input()
- while true do
- -- Read
- term.setCursorPos(3, 17)
- term.setTextColor(colors.gray)
- term.clearLine()
- write("> ")
- local inputData = read(nil, chatHistory):gsub("^%s*(.-)%s*$", "%1")
- table.insert(chatHistory, inputData)
- if inputData == "/exit" then
- os.queueEvent(event_exit)
- return
- end
- -- Parse input
- if inputData == "" then inputData = "Hello." end
- inputData = inputData:sub(1, 1):upper() .. inputData:sub(2, -1)
- if not inputData:sub(-1, -1):find("[\.\?!,]") then inputData = inputData .. "." end
- if inputData:len() > 45 and not inputData:sub(1, 45):find(" ") then
- inputData = inputData:sub(1, 45) .. " " .. inputData:sub(46, -1)
- end
- -- Clear
- term.setCursorPos(3, 17)
- term.clearLine()
- write("> ")
- if inputData:len() > 46 then
- local spaceData = {}
- local loopNum = 0
- while true do
- loopNum = inputData:find(" ", loopNum + 1, 1, true)
- table.insert(spaceData, loopNum)
- if type(loopNum) ~= "number" then
- table.insert(spaceData, 47)
- break
- end
- end
- for k, v in ipairs(spaceData) do
- if v > 46 then
- chatLog[#chatLog + 1] = {inputData:sub(1, spaceData[k - 1] - 1), "user"}
- chatLog[#chatLog + 1] = {inputData:sub(spaceData[k - 1] + 1, -1), "user"}
- break
- end
- end
- else
- chatLog[#chatLog + 1] = {inputData, "user"}
- end
- os.queueEvent(event_updateChat, textutils.serialize(chatLog), true)
- -- Get response
- local response = http.post(responseURL, "input=" .. textutils.urlEncode(inputData))
- if response then
- local responseData = response.readAll()
- if responseData:len() > 46 then
- local spaceData = {}
- local loopNum = 0
- while true do
- loopNum = responseData:find(" ", loopNum + 1, 1, true)
- table.insert(spaceData, loopNum)
- if type(loopNum) ~= "number" then
- table.insert(spaceData, 47)
- break
- end
- end
- for k, v in ipairs(spaceData) do
- if v > 46 then
- chatLog[#chatLog + 1] = {responseData:sub(1, spaceData[k - 1] - 1), "bot"}
- chatLog[#chatLog + 1] = {responseData:sub(spaceData[k - 1]+1, -1), "bot"}
- break
- end
- end
- else
- chatLog[#chatLog + 1] = {responseData, "bot"}
- end
- else
- chatLog[#chatLog + 1] = {"CCBot: An error has ocurred!", "bot"}
- end
- os.queueEvent(event_updateChat, textutils.serialize(chatLog))
- os.pullEvent(event_continue)
- end
- end
- -- Main
- local function main()
- -- Top logo
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setCursorPos(19, 2)
- term.setTextColor(colors.lightBlue)
- write("CClever")
- term.setTextColor(colors.lime)
- write("B")
- term.setTextColor(colors.yellow)
- write("o")
- term.setTextColor(colors.red)
- write("t ")
- term.setTextColor(colors.lightGray)
- write(version)
- term.setTextColor(colors.gray)
- term.setCursorPos(1, 3)
- centerPrint("- www.cleverbot.com -")
- -- Run
- parallel.waitForAll(input, interface)
- end
- -- Check
- if not http then
- print("HTTP API Needs to be Enabled!")
- print("CCleverBot heavily orties on it!")
- error()
- end
- -- Run
- local _, err = pcall(main)
- if err then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- print("Error!")
- print(err)
- print("\nPress any key to exit...")
- os.pullEvent("key")
- start2()
- end
- -- Exit
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint("Thank You for Using CCleverBot " .. version)
- centerPrint("Made by 1lann and GravityScore")
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement