Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Variables ]]--
- version = "BETA 2.5.6"
- screenX, screenY = term.getSize()
- loadingBar = false
- running = true
- progress = false
- pastebin_url = "vi275s3k"
- isBeta = true
- path = shell.dir()
- programPath = shell.getRunningProgram()
- -- Tables
- local t_mic = {
- ".::.",
- "///\\\\\\",
- "||||||",
- "HH |||||| HH",
- "HH==========HH",
- "HH==========HH",
- "HH ###### HH",
- "HH #### HH",
- "HH ## HH",
- "HH HH",
- "\\\\ //",
- "\\\\ //",
- "___\\/___ ",
- }
- local logo = {
- " 9999 9999 7 7 8 ",
- "9 9 8 8 ",
- "9 9 7 77 7 8888 8888 888 88 ",
- "9 9 7 7 7 8 8 8 8 8 8 8 ",
- "9 9 7 7 7 8 8 8888 8 8 8 ",
- "9 9 7 7 7 8 8 8 8 8 8 ",
- " 9999 9999 7 7 7 8888 8888 8 888",
- }
- local appkeys = {"GU7GAL-HLW2TGXR4J","P99XV4-6Y359T8584","5KGYY5-YE2JLLG74H"}
- --[[ End of Variables ]]--
- --[[ Functions ]]--
- -- Draw a line at _yPos
- function line(_yPos)
- term.setCursorPos(1, _yPos)
- if term.isColor and term.isColor() then
- for i = 1, screenX do
- paintutils.drawPixel(i, _yPos, colors.white)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- else
- for i = 1, screenX do
- write("-")
- end
- end
- end
- -- Print text centered at line _yPos
- function printC(text, _yPos)
- term.setCursorPos((screenX - #text)/2, _yPos)
- write(text)
- end
- -- Clear screen and set cursor pos
- function cScreen(swidth, sheight)
- if term.isColor and term.isColor() then
- term.setBackgroundColor(colors.white)
- end
- term.clear()
- term.setCursorPos(swidth, sheight)
- end
- -- Wait for key pressing
- function waitForExitKey()
- t = "Press x to go back"
- term.setCursorPos(screenX - #t, 4)
- write(t)
- while true do
- _, key = os.pullEvent("key")
- if key == keys.x then break end
- end
- end
- -- Print a progress bar
- function progressBar()
- local function doWrite(char)
- term.setCursorPos(3, 6)
- write("Loading "..char)
- sleep(0.1)
- end
- while true do
- doWrite("|")
- doWrite("/")
- doWrite("-")
- doWrite("\\")
- end
- end
- -- Split a paragraph into single lines
- function splitLine( text )
- local swidth = term.getSize()
- local function split( str, regex )
- local t = { }
- local fpat = "(.-)"..regex
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- local currLine = ""
- local words = split( text, " " )
- local t = {}
- for i = 1, #words do
- if #currLine + #words[i] + 1 > swidth then
- table.insert( t, currLine )
- currLine = words[i].." "
- else
- currLine = currLine..words[i].." "
- end
- if i == #words then
- table.insert( t, currLine )
- end
- end
- return t
- end
- -- Get the answer from Wolfram Alpha
- function getMessage(_input)
- _input = textutils.urlEncode(_input)
- http.request("http://api.wolframalpha.com/v2/query?appid="..appkeys[math.random(1,#appkeys)].."&input=".._input.."&format=plaintext")
- parallel.waitForAny(progressBar,
- function()
- repeat sEvent, url, sourceText = os.pullEvent() until sEvent == "http_success" or sEvent == "http_failure"
- end)
- if sEvent == "http_success" then
- local respondedText = sourceText.readAll()
- text = {}
- mainTable = {}
- index = 1
- for content in respondedText:gmatch "<plaintext>(.-)</plaintext>" do
- table.insert(text, content)
- text[index] = string.gsub(text[index],"'","'")
- text[index] = string.gsub(text[index],""","\"")
- text[index] = string.gsub(text[index],"&","&")
- text[index] = string.gsub(text[index],"<","<")
- text[index] = string.gsub(text[index],">",">")
- index = index + 1
- end
- cScreen(1,1)
- line(1) printC("CCiri V "..version, 2) line(3)
- if text[1] ~= nil then
- screenx = term.getSize()
- for i = 1, #text do
- if #text[i] >= screenx-5 then
- k = splitLine(text[i])
- for l = 1, #k do
- table.insert(mainTable, k[l])
- end
- else
- table.insert(mainTable, text[i])
- end
- end
- return true, mainTable
- else
- printC("Output: No answer found", 7)
- waitForExitKey()
- return false, nil
- end
- elseif sEvent == "http_failure" then
- cScreen(1,1)
- line(1) printC("CCiri V "..version, 2) line(3)
- write("Couldn't contact server")
- waitForExitKey()
- return false, nil
- end
- end
- -- Print the answer
- function printMessage(_table)
- yPos = 1
- while true do
- cScreen(1,1)
- line(1) printC("CCiri V "..version, 2) line(3)
- write("Input: "..input, 5)
- t = "Press x to go back"
- term.setCursorPos(screenX - #t, 4)
- write(t)
- for i = 6, screenY do
- term.setCursorPos(1, i)
- term.clearLine()
- if not _table[i + yPos - 6] then
- break
- else
- if string.find(_table[i + yPos - 6], "\n") then
- _table[i + yPos - 6] = string.sub(_table[i + yPos - 6], 1, string.find(_table[i + yPos - 6], "\n") - 1)
- .. " " ..
- string.sub(_table[i + yPos - 6], string.find(_table[i + yPos - 6], "\n") + 1)
- end
- write(_table[i + yPos - 6])
- end
- end
- e, button = os.pullEvent()
- if e == "mouse_scroll" and term.isColor() then
- if button == 1 and yPos < #_table - (screenY - 6) then
- -- Down
- yPos = yPos + 1
- elseif button == -1 and yPos > 1 then
- yPos = yPos - 1
- end
- elseif e == "key" then
- if button == keys.down and yPos < #_table - (screenY - 6) then
- -- Down
- yPos = yPos + 1
- elseif button == keys.up and yPos > 1 then
- --Up
- yPos = yPos - 1
- elseif button == keys.x then
- break
- end
- end
- end
- sleep(0.1)
- end
- -- Check for Updates
- function checkForUpdate()
- intBar:setMessage( "Starting up..." )
- sleep(1)
- intBar:triggerUpdate( "1/4 Checking for updates..." )
- sleep(0.5)
- if http then
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( pastebin_url ))
- if response then
- v = response.readLine()
- v = response.readLine()
- content = "--[[ Variables ]]--\n"..v.."\n"..response.readAll()
- v = string.sub(v, 12, -2)
- response.close()
- if v == version then
- intBar:triggerUpdate( "2/4 No update required" )
- sleep(0.75)
- intBar:triggerUpdate()
- sleep(0.5)
- intBar:triggerUpdate( "4/4 Done." )
- else
- intBar:triggerUpdate( "2/4 Update found ("..v..")" )
- t = "Click Y to update, N to continue"
- term.setCursorPos((screenX-#t)/2, screenY-2)
- write(t)
- repeat _, k = os.pullEvent("key") until k == keys.y or k == keys.n
- term.setCursorPos(1, screenY-2) term.clearLine()
- if k == keys.y then
- version = v
- intBar:triggerUpdate( "3/4 Updating... Please wait" )
- fileName = fs.getName(shell.getRunningProgram())
- file = fs.open(path.."/"..fileName, "w")
- file.write(content)
- file.close()
- sleep(1)
- intBar:triggerUpdate( "4/4 Done." )
- sleep(1)
- return true
- elseif k == keys.n then
- intBar:triggerUpdate( "3/4 Update canceled.")
- sleep(0.75)
- intBar:triggerUpdate( "4/4 Done." )
- sleep(1)
- return false
- end
- end
- else
- write("Failed to connect to pastebin.")
- return false
- end
- else
- intBar:triggerUpdate()
- intBar:triggerUpdate( "3/4 HTTP api is disabled" )
- sleep(1)
- intBar:triggerUpdate( "4/4 Done." )
- end
- sleep(2)
- end
- os.unloadAPI(path.."/CCiri_Files/load")
- os.loadAPI(path.."/CCiri_Files/load")
- -- Load bar API by TheOriginalBit
- if term.isColor and term.isColor() then -- this allows it to work on CC1.3 AND CC1.4
- intBar = load.init( load.LOGO_IS_LOAD, logo, 4, nil, screenY - 5, colors.red, "Starting...", " ", "CCiri " .. version )
- else
- intBar = load.init( load.ASCII, logo, 4, nil, screenY - 5, "Starting...", " ", "CCiri".. version )
- end
- local function loadBar()
- intBar:run( true )
- end
- parallel.waitForAll( loadBar, checkForUpdate )
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.white)
- term.clear()
- -- Startup
- while running do
- cScreen(1, 1)
- line(1) printC("CCiri V "..version, 2) line(3) line(17) line(19)
- for i = 1, #t_mic do
- term.setCursorPos((screenX - #t_mic[i])/2, i+3)
- write(t_mic[i])
- end
- term.setCursorPos(1,18)
- write("> ")
- input = read()
- cScreen(1,1)
- line(1) printC("CCiri V "..version, 2) line(3)
- write("Input: "..input, 5)
- progress, tab = getMessage(input)
- if progress then printMessage(tab) end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement