Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- pastebin get XP2UPWgZ dischat
- std pb XP2UPWgZ dischat
- 'Enchat' derivative for posting to Discord (RogerBot)
- --]]
- local log,_log,chatlog
- local timedivisor = 2 --Must be same as other enchat clients. Can be used to limit scrambling due to using os.time
- local tArg = {...}
- local yourName = tArg[1]
- log = {} --Log formatted for view
- _log = {} --Log with all information
- chatlog = {} --Log with all pre-formatted information
- local commandTable --Contains all commands
- local scr_x, scr_y = term.getSize()
- local channel = 0 --Do not modify, it's changed anyway
- local modem, scroll, doScroll
- local endMode = 0 --0 is exit, 1 is restart
- local cfile --Current file. Defined later.
- local hasKrazy = false
- local enchatSettings = {
- fancyMsg = false, --Whether or not to colorize as you type
- doColorize = true, --Whether or not to use color formatting at all
- reverseScroll = false, --Reverses scrolling direction. But why would you want to do that?
- }
- local palate = {
- bg = colors.gray, --Default chat background color
- txt = colors.white, --Default chat text color
- chatbg = colors.white, --Chat prompt background color
- chattxt = colors.black, --Chat prompt text color
- }
- local colors_names = { --this has been modified to use the Paint colors rather than minecraft formatting
- ["0"] = colors.white,
- ["1"] = colors.orange,
- ["2"] = colors.magenta,
- ["3"] = colors.lightBlue,
- ["4"] = colors.yellow,
- ["5"] = colors.lime,
- ["6"] = colors.pink,
- ["7"] = colors.gray,
- ["8"] = colors.lightGray,
- ["9"] = colors.cyan,
- ["a"] = colors.purple,
- ["b"] = colors.blue,
- ["c"] = colors.brown,
- ["d"] = colors.green,
- ["e"] = colors.red,
- ["f"] = colors.black,
- }
- --going to add compatibility for ComputerCaft 1.63
- local _currentcolors = {
- txt = colors.white,
- bg = colors.black,
- }
- local termsetTextColor,termsetBackgroundColor = term.setTextColor,term.setBackgroundColor
- local termsetCursorPos,termclear,termclearLine,termwrite,termgetSize,termsetCursorBlink,termisColor = term.setCursorPos,term.clear,term.clearLine,term.write,term.getSize,term.setCursorBlink,term.isColor
- local tableinsert,tableconcat,tableunpack = table.insert,table.concat,table.unpack
- local termblit,termgetTextColor,termgetBackgroundColor,termgetCursorPos
- local parallelwaitForAny = parallel.waitForAny
- local termsetVisible
- if term.current then
- --termcurrent = term.current
- end
- local oldsettext = term.setTextColor
- local oldsetbg = term.setBackgroundColor
- if not term.blit then
- termsetTextColor = function(col)
- oldsettext(col)
- _currentcolors.txt = col
- end
- termsetBackgroundColor = function(col)
- oldsetbg(col)
- _currentcolors.bg = col
- end
- termgetTextColor = function()
- return _currentcolors.txt
- end
- termgetBackgroundColor = function()
- return _currentcolors.bg
- end
- termblit = function(txt,tx,bg)
- local pt,pb = _currentcolors.bg,_currentcolors.txt
- if type(txt) ~= "string" or type(tx) ~= "string" or type(bg) ~= "string" then
- error("expected 3 strings, got "..tableconcat({type(txt),type(tx),type(bg)},", "))
- end
- if not ((#txt == #tx) and #tx == #bg) then
- error("all three arguments must be of same length")
- end
- for p = 1, #txt do
- oldsettext(colors_names[tx:sub(p,p)])
- oldsetbg(colors_names[bg:sub(p,p)])
- termwrite(txt:sub(p,p))
- end
- oldsettext(pt)
- oldsettext(pb)
- end
- else
- termblit = term.blit
- termgetTextColor = term.getTextColor
- termgetBackgroundColor = term.getBackgroundColor
- termgetCursorPos = term.getCursorPos
- end
- local tableConcat = function(tbl,between)
- local output = ""
- for k,v in pairs(tbl) do
- output = output..k..between
- end
- return output:sub(1,-2)
- end
- local encode = function(txt) --converts string into a table of each character's byte code
- if type(txt) ~= "string" then return false, "requires string" end
- return {txt:byte(1,-1)}
- end
- local decode = function(tbl) --converts an encoded string into something useful.
- if type(tbl) ~= "table" then return false, "requires table" end
- return string.char(tableunpack(tbl))
- end
- local strcapsule = function(txt)
- return "\""..tostring(txt).."\""
- end
- local cwrite = function(txt,setY,doClearLine)
- local scr_x, scr_y = termgetSize()
- local x,y = termgetCursorPos()
- termsetCursorPos((scr_x/2)-(#txt/2),setY or y)
- if doClearLine then termclearLine() end
- write(txt)
- end
- local waitForModem = function()
- local mod
- while true do
- sleep(0.2)
- mod = peripheral.find("modem")
- if mod then
- return mod
- end
- end
- end
- if not peripheral.find("modem") then
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- termclear()
- cwrite("Enchat requires a modem.",3)
- cwrite("Add one, or press a key.",4)
- sleep(0.1)
- local outcome = parallelwaitForAny(function() os.pullEvent("key") end, waitForModem)
- modem = peripheral.find("modem")
- if not modem then
- termsetBackgroundColor(colors.black)
- termsetCursorPos(1,scr_y)
- termclearLine()
- sleep(0)
- return false
- end
- end
- local tsv = function(visible)
- if termcurrent then
- if termcurrent().setVisible then
- termcurrent().setVisible(visible)
- return true
- else
- return false
- end
- else
- return false
- end
- end
- local logadd = function(name,msg,newline,stopFormatting)
- chatlog[#chatlog+1] = {name,msg,newline,stopFormatting or false}
- end
- local deepCopy = function(tbl)
- local output = {}
- for k,v in pairs(tbl) do
- output[k] = v
- end
- return output
- end
- local explode = function(div,str)
- if (div=='') then return false end
- local pos,arr = 0,{}
- for st,sp in function() return string.find(str,div,pos,false) end do
- tableinsert(arr,string.sub(str,pos,st-1))
- pos = sp + 1
- end
- tableinsert(arr,string.sub(str,pos))
- return arr
- end
- local colors_strnames = { --primarily for use when coloring palate
- ["white"] = colors.white,
- ["orange"] = colors.orange,
- ["magenta"] = colors.magenta,
- ["lightpurple"] = colors.magenta,
- ["light purple"] = colors.magenta,
- ["lightblue"] = colors.lightBlue,
- ["light blue"] = colors.lightBlue,
- ["yellow"] = colors.yellow,
- ["piss"] = colors.yellow,
- ["lemon"] = colors.yellow,
- ["lime"] = colors.lime,
- ["lightgreen"] = colors.lime,
- ["light green"] = colors.lime,
- ["pink"] = colors.pink,
- ["lightish red"] = colors.pink,
- ["gray"] = colors.gray,
- ["grey"] = colors.gray,
- ["lightgray"] = colors.lightGray,
- ["lightgrey"] = colors.lightGray,
- ["light gray"] = colors.lightGray,
- ["light grey"] = colors.lightGray,
- ["cyan"] = colors.cyan,
- ["seawater"] = colors.cyan,
- ["purple"] = colors.purple,
- ["purble"] = colors.purple,
- ["blue"] = colors.blue,
- ["blu"] = colors.blue,
- ["brown"] = colors.brown,
- ["shit"] = colors.brown,
- ["green"] = colors.green,
- ["grass"] = colors.green,
- ["red"] = colors.red,
- ["blood"] = colors.red,
- ["black"] = colors.black,
- }
- for k,v in pairs(colors_names) do
- colors_strnames[k] = v
- end
- local function alterXY()
- local cx,cy = termgetCursorPos()
- if cx == scr_x then
- termsetCursorPos(1,cy+1)
- end
- end
- local blit_names = {}
- for k,v in pairs(colors_names) do
- blit_names[v] = k
- end
- local safeColor = function(col) --I could've done much better, but whatever
- if type(col) ~= "number" then
- return false
- else
- if col > 2^15 then
- return false
- else
- if not termisColor() then
- if (col ~= colors.white) and (col ~= colors.lightGray) and (col ~= colors.gray) and (col ~= colors.black) then
- return false
- end
- end
- end
- end
- return true
- end
- local blitWrap = function(text,txt,bg,noWrite)
- local wordNo = 1
- local words = explode(" ",text)
- local lines = 0
- local scr_x, scr_y = termgetSize()
- local cx,cy
- local startX,startY = termgetCursorPos()
- for a = 1, #text do
- cx,cy = termgetCursorPos()
- if text:sub(a,a) == " " and text:sub(a-1,a-1) ~= " " and a > 1 then
- wordNo = wordNo + 1
- if cx + #words[wordNo] > scr_x then
- termsetCursorPos(1,cy+1)
- lines = lines + 1
- end
- end
- cx,cy = termgetCursorPos()
- if text:sub(a,a) == "\n" then
- termsetCursorPos(1,cy+1)
- lines = lines + 1
- elseif not (cx == 1 and text:sub(a,a) == " ") then
- if noWrite == true then
- termsetCursorPos(cx+1,cy)
- else
- if safeColor(colors_names[txt:sub(a,a)]) then
- termblit(text:sub(a,a),txt:sub(a,a),bg:sub(a,a))
- else
- termwrite(text:sub(a,a))
- end
- end
- end
- if cx == scr_x then
- termsetCursorPos(1,cy+1)
- lines = lines + 1
- end
- end
- if noWrite == true then
- termsetCursorPos(startX,startY)
- end
- return lines
- end
- local tablefind = function(tbl,str)
- for a = 1, #tbl do
- if tbl[a] == str then
- return a
- end
- end
- end
- local codeNames = {
- ["r"] = "reset", -- Sets either the text (&) or background (~) colors to their original color.
- ["{"] = "stopFormatting", --Toggles formatting text off
- ["}"] = "startFormatting", --Toggles formatting text on
- ["k"] = "krazy" --Makes the font krazy!
- }
- local kraziez = {
- ["l"] = {
- "!",
- "l",
- "1",
- "|",
- "i",
- "I",
- ":",
- ";",
- },
- ["m"] = {
- "M",
- "W",
- "w",
- "m",
- "X",
- "N",
- "_",
- "%",
- "@",
- },
- ["all"] = {}
- }
- for a = 1, #kraziez["l"] do
- kraziez[kraziez["l"][a]] = kraziez["l"]
- end
- for k,v in pairs(kraziez) do
- for a = 1, #v do
- kraziez[kraziez[k][a]] = v
- end
- end
- if _VERSION then
- for a = 1, 255 do
- if (a ~= 32) and (a ~= 13) and (a ~= 10) then
- kraziez["all"][#kraziez["all"]+1] = string.char(a)
- end
- end
- else
- for a = 33, 126 do
- kraziez["all"][#kraziez["all"]+1] = string.char(a)
- end
- end
- local textToBlit = function(str) --returns output for term.blit, or blitWrap, with formatting codes for color selection. Modified for use specifically with Enchat.
- local p = 1
- local output = ""
- local txcolorout = ""
- local bgcolorout = ""
- local txcode = "&"
- local bgcode = "~"
- local isKrazy = false
- local doFormatting = true
- local usedformats = {}
- local txcol,bgcol = blit_names[termgetTextColor()], blit_names[termgetBackgroundColor()]
- local origTX,origBG = blit_names[termgetTextColor()], blit_names[termgetBackgroundColor()]
- local cx,cy
- local moveOn = function(tx,bg)
- if isKrazy and (str:sub(p,p) ~= " ") and doFormatting then
- if kraziez[str:sub(p,p)] then
- output = output..kraziez[str:sub(p,p)][math.random(1,#kraziez[str:sub(p,p)])]
- else
- output = output..kraziez.all[math.random(1,#kraziez.all)]
- end
- else
- output = output..str:sub(p,p)
- end
- txcolorout = txcolorout..(doFormatting and tx or origTX)
- bgcolorout = bgcolorout..(doFormatting and bg or origBG)
- end
- while p <= #str do
- if str:sub(p,p) == txcode then
- if colors_names[str:sub(p+1,p+1)] and doFormatting then
- txcol = str:sub(p+1,p+1)
- usedformats.txcol = true
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] then
- if str:sub(p+1,p+1) == "r" and doFormatting then
- txcol = blit_names[termgetTextColor()]
- isKrazy = false
- p = p + 1
- elseif str:sub(p+1,p+1) == "{" and doFormatting then
- doFormatting = false
- p = p + 1
- elseif str:sub(p+1,p+1) == "}" and (not doFormatting) then
- doFormatting = true
- p = p + 1
- elseif str:sub(p+1,p+1) == "k" and doFormatting then
- isKrazy = true
- usedformats.krazy = true
- p = p + 1
- else
- moveOn(txcol,bgcol)
- end
- else
- moveOn(txcol,bgcol)
- end
- p = p + 1
- elseif str:sub(p,p) == bgcode then
- if colors_names[str:sub(p+1,p+1)] and doFormatting then
- bgcol = str:sub(p+1,p+1)
- usedformats.bgcol = true
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] and (str:sub(p+1,p+1) == "r") and doFormatting then
- bgcol = blit_names[termgetBackgroundColor()]
- p = p + 1
- elseif str:sub(p+1,p+1) == "k" and doFormatting then
- isKrazy = false
- p = p + 1
- else
- moveOn(txcol,bgcol)
- end
- p = p + 1
- else
- moveOn(txcol,bgcol)
- p = p + 1
- end
- end
- return output, txcolorout, bgcolorout, usedformats
- end
- local funcread = function(repchar,rHistory,doFunc,noNewLine,writeFunc,cursorAdjFunc,doFuncEvent)
- local scr_x,scr_y = termgetSize()
- local sx,sy = termgetCursorPos()
- local cursor = 1
- local rCursor = #rHistory+1
- local output = ""
- termsetCursorBlink(true)
- local rite = writeFunc or termwrite
- while true do
- local evt,key = os.pullEvent()
- if evt == doFuncEvent then
- pleaseDoFunc = true
- elseif evt == "key" then
- if key == keys.enter then
- if not noNewLine then
- write("\n")
- end
- termsetCursorBlink(false)
- return output
- elseif key == keys.left then
- if cursor-1 >= 1 then
- cursor = cursor - 1
- end
- elseif key == keys.right then
- if cursor <= #output then
- cursor = cursor + 1
- end
- elseif key == keys.up then
- if rCursor > 1 then
- rCursor = rCursor - 1
- termsetCursorPos(sx,sy)
- rite((" "):rep(#output))
- output = rHistory[rCursor] or ""
- cursor = #output+1
- pleaseDoFunc = true
- end
- elseif key == keys.down then
- termsetCursorPos(sx,sy)
- rite((" "):rep(#output))
- if rCursor < #rHistory then
- rCursor = rCursor + 1
- output = rHistory[rCursor] or ""
- cursor = #output+1
- pleaseDoFunc = true
- else
- rCursor = #rHistory+1
- output = ""
- cursor = 1
- end
- elseif key == keys.backspace then
- if cursor > 1 and #output > 0 then
- output = output:sub(1,cursor-2)..output:sub(cursor)
- cursor = cursor - 1
- pleaseDoFunc = true
- end
- elseif key == keys.delete then
- if #output:sub(cursor,cursor) == 1 then
- output = output:sub(1,cursor-1)..output:sub(cursor+1)
- pleaseDoFunc = true
- end
- end
- elseif evt == "char" or evt == "paste" then
- output = output:sub(1,cursor-1)..key..output:sub(cursor+(#key-1))
- cursor = cursor + #key
- pleaseDoFunc = true
- end
- local pOut = (output or ""):sub(math.max( 1,(#textToBlit(output)+sx)-scr_x) )
- if pleaseDoFunc then
- pleaseDoFunc = false
- if type(doFunc) == "function" then
- doFunc(output)
- end
- termsetCursorPos(sx,sy)
- if repchar then
- rite(repchar:sub(1,1):rep(#pOut))
- else
- rite(pOut)
- end
- termwrite(" ")
- end
- termsetCursorPos(sx+cursorAdjFunc(pOut)+cursor-math.max( 1,(#textToBlit(output)+sx)-scr_x),sy)
- end
- end
- if yourName then
- if textToBlit(yourName) == "con" or textToBlit(yourName) == "*" then return printError("Not that name!") end
- end
- local writef = function(txt,noWrite)
- if enchatSettings.doColorize then
- local text, textCol, bgCol, usedformats = textToBlit(txt)
- local out = blitWrap(text,textCol,bgCol,noWrite)
- return out, #text, usedformats
- else
- return write(txt), #txt, {}
- end
- end
- local _ftlen = function(text)
- return #textToBlit(text)-#text
- end
- local clearLines = function(top, bottom)
- for a = top, bottom do
- termsetCursorPos(1,a)
- termclearLine()
- end
- end
- scroll = 1
- doScroll = true
- local urkrazy,_ = false
- local redrawScreen = function() --renders the chat and other things that change when scrolling.
- tsv(false)
- local prevX, prevY = termgetCursorPos()
- local _logold = _log
- _log,log = {},{}
- for a = 1, #chatlog do
- if not chatlog[a][3] then
- _log[#_log+1] = {"",false}
- end
- if chatlog[a][4] == true then
- _log[#_log+1] = {"<"..chatlog[a][1].."> "..chatlog[a][2],false}
- else
- _log[#_log+1] = {"<"..chatlog[a][1].."> "..chatlog[a][2],true}
- end
- end
- if not doScroll then
- scroll = scroll + (#_log - #_logold)
- end
- for a = 1, #_log-(scroll-1) do
- log[#log+1] = _log[a]
- end
- termsetCursorPos(1,1)
- termsetBackgroundColor(palate.bg)
- termsetTextColor(palate.txt)
- termwrite(string.rep(" ",scr_x*(scr_y-2)))
- local midPoint = {
- scr_x / 2,
- scr_y / 2,
- }
- local yoffset = 0
- clearLines(1,scr_y-2)
- termsetCursorPos(1,scr_y)
- termclearLine()
- local indent = 1 --in case any line is greater than the length of the screen
- local indentIn = 0 --in the same case, mid writing
- for a = 1, #log do
- if log[a][2] then
- indent = indent + writef(log[a][1],true)
- else
- indent = indent + math.floor(#log[a][1]/scr_x)
- end
- end
- hasKrazy = false
- for a = 1, #log do
- termsetCursorPos(1,((((scr_y-1)+a-#log))-indent)+indentIn)
- if log[a][2] then
- indentIn = indentIn + writef(log[a][1],true)
- _,_,urkrazy = writef(log[a][1],false)
- hasKrazy = hasKrazy or (urkrazy.krazy or false)
- else
- indentIn = indentIn + math.floor((#log[a][1])/scr_x)
- termwrite(log[a][1])
- end
- end
- termsetCursorPos(scr_x,scr_y)
- if doScroll then writef("&8.") else termwrite(" ") end
- termsetCursorPos(prevX,prevY)
- tsv(true)
- end
- local handleCommand = function(commie)
- commie = commie or {}
- local command = commie[1] or ""
- local argument = commie
- if #commie > 0 then
- table.remove(argument,1)
- argument = tableconcat(argument," ") or ""
- else
- argument = ""
- end
- local commandTable
- commandTable = {
- ["exit"] = function() --why would you want to leave??
- endMode = 0
- return "exit"
- end,
- ["heil"] = function() --please don't tell me that you're offended, or I'll get offended
- local heilTable = {
- "Cobra",
- "this",
- "LDD",
- "unto me",
- "dan200",
- "myself",
- "!",
- "oeed",
- "Exerro",
- "Kepler",
- "Danny",
- "Bagel",
- "Roger",
- "King Porky",
- }
- local hailer
- if argument ~= "" then hailer = argument else hailer = heilTable[math.random(1,#heilTable)] end
- local mess = "Heil "..hailer.."!"
- os.queueEvent("enchat_send", yourName, mess)
- logadd("con","You heiled "..hailer.."!",false)
- redrawScreen()
- end,
- ["help"] = function() --I would call it "man", but there's only so much you can write about a two-argument function
- local a = false
- for k,v in pairs(commandTable) do
- strtime = tostring(math.floor(os.time()/timedivisor))
- logadd("*","&0/&4"..k,a)
- a = true
- end
- redrawScreen()
- end,
- ["clear"] = function() --*accidentally clears inventory* FUCK
- _log = {}
- log = {}
- chatlog = {}
- redrawScreen()
- end,
- ["ping"] = function() --what do you mean this command is useless
- logadd("*",(argument ~= "") and argument or "Pong!",false)
- redrawScreen()
- end,
- ["update"] = function()
- local url
- url = "https://pastebin.com/raw/XP2UPWgZ"
- if shell then
- cfile = shell.getRunningProgram()
- else
- logadd("con","&4Download where?",true)
- scroll = 1
- redrawScreen()
- termsetCursorPos(1,scr_y-1)
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(palate.chattxt)
- termclearLine()
- write(":")
- termsetBackgroundColor(palate.chatbg)
- cfile = read()
- end
- if fs.isReadOnly(cfile) then
- logadd("*","Unable to update to &4read-only directory.&r",true)
- redrawScreen()
- return
- end
- if not http then
- logadd("*","&4HTTP is disabled.&r Ask an admin to enable it.",true)
- redrawScreen()
- return
- else
- if not http.checkURL(url) then
- logadd("*","&4It appears the download URL is whitelisted.&r &cPlease slap your admin in their stupid face.",true)
- redrawScreen()
- return
- end
- end
- --termsetBackgroundColor(palate.bg)
- --termsetTextColor((palate.txt ~= colors.yellow) and colors.yellow or colors.black)
- --cwrite("Downloading...",scr_y,true)
- logadd("con","&4Downloading...",true)
- scroll = 1
- redrawScreen()
- local data = http.get(url)
- if not data then
- logadd("*","&4Couldn't connect to Pastebin.&r Sorry.",true)
- redrawScreen()
- return
- else
- local file = fs.open(cfile,"w")
- file.write(data.readAll())
- file.close()
- --cwrite("Yay! Relaunching.",scr_y,true)
- logadd("con","&4Yay! Relaunching.",true)
- scroll = 1
- redrawScreen()
- sleep(1)
- --os.queueEvent("enchat_send", "con", yourName.."&r~r redownloaded the program.")
- sleep(0)
- endMode = 1
- return "restart"
- end
- end,
- ["whoami"] = function()
- if argument:lower() == "now" then
- logadd("*","You are still \""..yourName.."&r~r\"!",true)
- else
- logadd("*","You are \""..yourName.."&r~r\"!",true)
- end
- redrawScreen()
- end,
- ["nick"] = function()
- if argument ~= "" then
- if argument ~= yourName then
- if #textToBlit(argument) < 20 then
- --os.queueEvent("enchat_send", "con", tostring(yourName.."&r~r is now known as "..strcapsule(argument)))
- logadd("*",yourName.."&r~r is now known as "..argument,false)
- yourName = tostring(argument)
- else
- logadd("*","&4Maximum 20 non-formatting characters!",false)
- end
- else
- logadd("*","&4That's already your name.",false)
- end
- else
- logadd("*","&4/nick <newname>",true)
- end
- redrawScreen()
- end,
- ["palate"] = function()
- if argument:gsub("%s","") == "" then
- logadd("*","&4/palate "..tableConcat(palate,"/").." <color code>",false)
- else
- argument = explode(" ",argument)
- if #argument == 1 then
- if argument[1]:gsub("%s",""):lower() == "reset" then
- palate = {
- bg = colors.gray,
- txt = colors.white,
- chatbg = colors.white,
- chattxt = colors.black,
- }
- logadd("*","&4You cleansed your palate.",false)
- else
- logadd("*","&4Give me a color code next time.",false)
- end
- else
- if #argument > 2 then
- argument = {argument[1], tableconcat(argument," ",2)}
- end
- argument[1] = argument[1]:lower()
- local newcol = argument[2]:lower()
- if not palate[argument[1]] then
- logadd("*","&4That's not a valid palate choice.")
- else
- if not colors_strnames[newcol] then
- logadd("*","&4That isn't a valid color code. (0-f)")
- else
- palate[argument[1]] = colors_strnames[newcol]
- logadd("*","You have such a sense of style.",false)
- end
- end
- end
- end
- redrawScreen()
- end,
- }
- if commandTable[command] then
- return commandTable[command]()
- else
- return false
- end
- end
- local doAndBack = function(func)
- local backColor = termgetBackgroundColor()
- local textColor = termgetTextColor()
- local curX, curY = termgetCursorPos()
- local results = {func()}
- termsetBackgroundColor(backColor)
- termsetTextColor(textColor)
- termsetCursorPos(curX,curY)
- return tableunpack(results)
- end
- local renderAll = function()
- termsetBackgroundColor(palate.bg)
- termsetTextColor(palate.txt)
- termclear()
- local mHistory = {""}
- local msg = nil
- while true do
- repeat
- local msgPrompt = function()
- termsetCursorPos(1,scr_y-1)
- termsetBackgroundColor(palate.chatbg)
- termsetTextColor(colors.lightGray)
- termclearLine()
- write(">")
- termsetTextColor(palate.chattxt)
- end
- msgPrompt()
- msg = enchatSettings.fancyMsg and funcread(nil,mHistory,msgPrompt,true,function(text)
- termsetBackgroundColor(palate.chatbg)
- local _,_,u = writef(text)
- hasKrazy=hasKrazy or (u.krazy or false)
- termsetCursorPos(1,scr_y)
- termsetBackgroundColor(palate.bg)
- termwrite((" "):rep(scr_x-2))
- end,_ftlen,"redrawprompt") or read(nil,mHistory)
- if msg ~= mHistory[#mHistory] and msg:gsub("%s","") ~= "" then
- tableinsert(mHistory,msg)
- end
- until string.gsub(msg,"%s","") ~= ""
- if string.sub(msg,1,1) == "/" then
- local comm = explode("%s",tostring(msg):sub(2))
- local result = handleCommand(comm)
- if result == "exit" then
- --os.queueEvent("enchat_send", "con", yourName.."&r~r has left.")
- sleep(0)
- return "exit"
- elseif result == "restart" then
- sleep(0)
- return "restart"
- elseif result == false then
- logadd("con","No such command.",false)
- redrawScreen()
- end
- else
- local strtime = tostring(math.floor(os.time()/timedivisor))
- logadd(yourName,msg,false)
- redrawScreen()
- os.queueEvent("enchat_send", yourName, msg)
- end
- end
- end
- local httppost = function(tUrl,tForm,tHeader)
- httphandle = http.post("http://smaller.hol.es/proxy.php?url="..tUrl,tForm,tHeader)
- resp = httphandle.readAll()
- httphandle.close()
- return resp
- end
- local sendMessages = function()
- while true do
- local event, name, message = os.pullEvent("enchat_send",key)
- local str
- if #name > 0 then
- str = "**"..name.."**: "..message
- else
- str = message
- end
- header = {
- ['ContentType'] = "application/json",
- ['User-Agent'] = "DiscordBot (KrakenBot)",
- }
- httppost("https://discordapp.com/api/webhooks/300730487968759809/p7L4gBv51CAioatwMCTANd42bgDmb6QcL3rbD1-r1sYORqXFDMkb8SX85KN6GMcNocW3","content="..str,header)
- end
- end
- if termisColor() then
- colormode = true
- grayAllowed = true
- else
- colormode = false
- if _VERSION then
- grayAllowed = true
- else
- grayAllowed = false
- end
- end
- termsetBackgroundColor(colors.gray)
- termclear()
- termsetCursorPos(1,1)
- if not yourName then
- write("\n")
- local posX, posY = termgetCursorPos()
- local prevX,prevY = 1,1
- local namePrompt = function()
- termsetCursorPos(prevX,prevY)
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(colors.black)
- termclearLine()
- write(">")
- end
- repeat
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- termsetCursorPos(posX,posY)
- termclearLine()
- cwrite("Enter your name:\n",posY)
- prevX,prevY = termgetCursorPos()
- termsetTextColor(colors.lightGray)
- --cwrite("Color codes:",scr_y-3)
- --cwrite("(&text,~backg.)",scr_y-2)
- termsetCursorPos((scr_x/2)-8,scr_y-1)
- termsetBackgroundColor(colors.gray)
- termclearLine()
- --blitWrap(textToBlit("~0&f0~1&01~22~33~44~55~66~77~88~99~aa~bb~cc~dd~ee~ff"))
- termsetCursorPos(prevX,prevY)
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(colors.black)
- termclearLine()
- write(">")
- yourName = enchatSettings.fancyMsg and funcread(nil,{},namePrompt,false,writef,_ftlen) or read()
- until true
- end
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- local getScrolling = function()
- local oldScroll
- scroll = 1
- doScroll = true
- while true do
- local _,dir,x,y = os.pullEvent("mouse_scroll")
- oldScroll = scroll
- if dir == (enchatSettings.reverseScroll and 1 or -1) then
- if scroll < #_log-1 then
- scroll = scroll + 1
- doScroll = false
- end
- elseif dir == (enchatSettings.reverseScroll and -1 or 1) then
- if scroll > 1 then
- scroll = scroll - 1
- if scroll == 1 then
- doScroll = true
- end
- end
- end
- if oldScroll ~= scroll then
- os.queueEvent("didScroll",scroll)
- end
- end
- end
- --os.queueEvent("enchat_send", "con", yourName.."&r~r moseyed on over.")
- local funcList = {
- sendMessages,
- renderAll,
- getScrolling,
- }
- parallelwaitForAny(tableunpack(funcList))
- if endMode == 1 then
- if shell then
- shell.run(strcapsule(cfile),strcapsule(encKey),strcapsule(yourName))
- else
- loadfile(cfile)(encKey,yourName)
- end
- else
- if modem then modem.close(channel) end
- termsetCursorPos(1,scr_y)
- termsetBackgroundColor(colors.black)
- termclearLine()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement