Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ...use with responsibility.
- --
- -- Get with
- -- pastebin get n3K9Nt3D fakechat
- -- std PB n3K9Nt3D fakechat
- local names = { --Add names to quickly switch between using PageUP and PageDOWN
- {
- name = "&o&6Jesus",
- prefix = "<",
- suffix = "> ",
- },
- {
- name = "&dServer",
- prefix = "&d[",
- suffix = "&d] ",
- msgprefix = "&d",
- realname = "But nobody"
- },
- {
- name = "&eBagel&6Bot",
- prefix = "<",
- suffix = "> ",
- },
- {
- name = "Lr_",
- prefix = "<",
- suffix = "> ",
- },
- {
- name = "dan200",
- prefix = "<",
- suffix = "> ",
- },
- }
- local sHistories = {}
- local cname = 1
- local tArg = {...}
- local channel = 1251 --default 1251
- local sHistory = {}
- local scr_x, scr_y = term.getSize()
- local modems
- local setModems = function()
- modems = {peripheral.find("modem")}
- for a = 1, #modems do
- if modems[a].isWireless() then
- modem = modems[a]
- modem.open(channel)
- return
- end
- end
- modem = nil
- end
- setModems()
- if (not commands) and (not modem) then
- return printError("You need a modem! Or a command computer!")
- end
- if commands then isServer = true else isServer = false end
- if (not commands) and (not modem) then
- error("This requires a command computer.")
- end
- local prefix = ""
- local suffix = ""
- local dnb = function(phunk, ...)
- local t,b = term.getTextColor(), term.getBackgroundColor()
- local x,y = term.getCursorPos()
- local output = {phunk(...)}
- term.setCursorPos(x,y)
- term.setTextColor(t)
- term.setBackgroundColor(b)
- return unpack(output)
- end
- local prevnames = {}
- local colnames = {
- ["0"] = "black",
- ["1"] = "dark_blue",
- ["2"] = "dark_green",
- ["3"] = "dark_aqua",
- ["4"] = "dark_red",
- ["5"] = "dark_purple",
- ["6"] = "gold",
- ["7"] = "gray",
- ["8"] = "dark_gray",
- ["9"] = "blue",
- ["a"] = "green",
- ["b"] = "aqua",
- ["c"] = "red",
- ["d"] = "light_purple",
- ["e"] = "yellow",
- ["f"] = "white",
- }
- local colors_names = { --for use with colors api, you see
- ["0"] = colors.black,
- ["1"] = colors.blue,
- ["2"] = colors.green,
- ["3"] = colors.cyan,
- ["4"] = colors.red,
- ["5"] = colors.purple,
- ["6"] = colors.orange,
- ["7"] = colors.lightGray,
- ["8"] = colors.gray,
- ["9"] = colors.blue, --they don't translate perfectly, okay??
- ["a"] = colors.lime,
- ["b"] = colors.lightBlue,
- ["c"] = colors.red,
- ["d"] = colors.magenta,
- ["e"] = colors.yellow,
- ["f"] = colors.white,
- }
- local codeNames = { --just for checking
- ["k"] = "obfuscate",
- ["o"] = "italic",
- ["l"] = "bold",
- ["m"] = "strikethrough",
- ["n"] = "underline",
- ["r"] = "reset",
- }
- local filterColors = function(str,doprint)
- local p = 1
- local output = ""
- local code = "&"
- local col = "f"
- local prevT,prevB = term.getTextColor(), term.getBackgroundColor()
- while p <= #str do
- if str:sub(p,p) == code then
- if colors_names[str:sub(p+1,p+1)] then
- col = str:sub(p+1,p+1)
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] then
- if str:sub(p+1,p+1) == "r" then
- col = "f"
- end
- p = p + 1
- else
- if doprint then
- if term.isColor() then
- term.setTextColor(colors_names[col])
- end
- write(str:sub(p,p))
- end
- end
- p = p + 1
- else
- output = output..str:sub(p,p)
- if doprint then
- if term.isColor() then
- term.setTextColor(colors_names[col])
- end
- write(str:sub(p,p))
- end
- p = p + 1
- end
- end
- term.setTextColor(prevT)
- term.setBackgroundColor(prevB)
- return output
- end
- local renderReadBar = function(doReturn)
- local cx,cy = term.getCursorPos()
- local cb,ct = term.getBackgroundColor(), term.getTextColor()
- term.setCursorPos(1,scr_y)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- filterColors(prefix.."&r"..names[cname].prefix.."&r"..names[cname].name.."&r"..names[cname].suffix.."&r"..suffix,true)
- term.setCursorPos(1,scr_y-1)
- if not doReturn then
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- term.setTextColor(colors.white)
- else
- term.setCursorPos(cx,cy)
- term.setBackgroundColor(cb)
- term.setTextColor(ct)
- end
- end
- local colorFormat = function(str)
- local color = "f"
- local obfuscated = false
- local bold = false
- local strikethrough = false
- local underline = false
- local italic = false
- local code = "&" --ONE CHARACTER
- local pos = 1
- local opos = 1
- local output = {}
- while pos <= #str do
- output[opos] = {}
- if str:sub(pos,pos) == code and pos < #str then
- local changed = false
- if colnames[str:sub(pos+1,pos+1)] then
- color = str:sub(pos+1,pos+1)
- changed = true
- else
- if str:sub(pos+1,pos+1) == "r" then
- color = "f"
- obfuscated = false
- bold = false
- strikethrough = false
- underline = false
- italic = false
- changed = true
- end
- if str:sub(pos+1,pos+1) == "k" then
- obfuscated = true
- changed = true
- end
- if str:sub(pos+1,pos+1) == "l" then
- bold = true
- changed = true
- end
- if str:sub(pos+1,pos+1) == "m" then
- strikethrough = true
- changed = true
- end
- if str:sub(pos+1,pos+1) == "n" then
- underline = true
- changed = true
- end
- if str:sub(pos+1,pos+1) == "o" then
- italic = true
- changed = true
- end
- end
- if changed then
- output[opos].text = ""
- pos = pos + 2
- else
- output[opos].text = str:sub(pos,pos)
- pos = pos + 1
- end
- else
- output[opos].text = str:sub(pos,pos)
- pos = pos + 1
- end
- output[opos].color = colnames[color]
- output[opos].obfuscated = obfuscated
- output[opos].bold = bold
- output[opos].strikethrough = strikethrough
- output[opos].underline = underline
- output[opos].italic = italic
- opos = opos + 1
- end
- return textutils.serialiseJSON(output)
- end
- local players = { --Add playernames here if you want to filter who receives messages
- "dan200",
- "EldidiStroyrr",
- }
- local doFilter = false --If true, filters according to 'players' table
- local send = function(name,msg,np,ns,realname,doprint)
- local compiled --compiled message, not compiled program
- local filtmsg = filterColors(msg)
- if filtmsg:sub(1,3) == "___" then --should this be a client option? hmm...
- if filtmsg == "___join" then
- compiled = "&e"..filterColors(realname).." joined the game."
- elseif filtmsg == "___notjoin" then
- compiled = "&e"..filterColors(realname).." hasn't joined the game."
- elseif filtmsg == "___leave" then
- compiled = "&e"..filterColors(realname).." left the game."
- elseif filtmsg == "___notleave" then
- compiled = "&e"..filterColors(realname).." hasn't left the game."
- elseif filtmsg:sub(1,8) == "___medal" then
- compiled = realname.."&r has made the achievement &a["..msg:sub(10).."&a]"
- else
- compiled = msg:sub(4)
- end
- else
- compiled = prefix.."&r"..np.."&r"..name.."&r"..ns.."&r"..suffix.."&r"..msg
- end
- compiled = colorFormat(compiled)
- if doFilter then
- for a = 1, #players do
- commands.tellraw(players[a],compiled)
- end
- else
- commands.tellraw("@a",compiled)
- end
- end
- local netsend = function(n,m,p,s,mp,rn) --name, message, prefix, suffix
- local data = {
- name = n,
- realname = rn or n,
- msg = mp..m,
- prefix = p or "<",
- suffix = s or "> ",
- }
- if modem then modem.transmit(channel,channel,data) end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- local name
- if tArg[1] then
- name = tArg[1]
- if name:gsub(" ","") ~= "" and prevnames[#prevnames] ~= name then
- table.insert(prevnames,name)
- end
- else
- print("Enter a name:")
- write(">")
- dnb(function() write("\n\nUse PageUP and PageDOWN to switch names.\nDo '/exit' to exit.\nDo '___join' or '___leave' to simulate doing either.\nPrefix any other message with '___' to do raw chat.\n\nUse responsibly") if term.isColor() then print(".") else print(", and it'd be preferable to use a golden computer. Not required, but...") end end)
- name = read(nil,prevnames)
- if name:gsub(" ","") ~= "" and prevnames[#prevnames] ~= name then
- table.insert(prevnames,name)
- end
- end
- if name:gsub(" ","") == "" then name = "Scabby cunt" end --enter in a fucking name
- table.insert(names,1,{
- name = name,
- prefix = "<",
- suffix = "> ",
- realname = name
- })
- local insend = function(n,m,p,s,mp,rn) --name, message, prefix, suffix. Sends a message inwards to simulate receiving a message from a client
- local data = {
- name = n,
- realname = rn or n,
- msg = mp..m,
- prefix = p or "<",
- suffix = s or "> ",
- }
- os.queueEvent("modem_message","top",channel,channel,data,0)
- end
- local client = function() --this is where you enter in your awesome messages! it also happens to be where *you* enter in your shitty messages
- while true do
- term.setBackgroundColor(colors.black) --dats rasist
- term.clear()
- renderReadBar()
- write(">")
- local msg = read(nil,sHistories[cname] or {"I like to eat pubes I find in urinals.","One of my hobbies is to kick small dogs and see how far they go.","Have you reddit","My child-sized skin suit it starting to smell."})
- if msg:gsub(" ","") == "/exit" then
- return
- end
- if msg:gsub(" ","") ~= "" then
- if not sHistories[cname] then
- sHistories[cname] = {msg}
- else
- if sHistories[cname][#sHistories[cname]] ~= msg then
- sHistories[cname][#sHistories[cname]+1] = msg
- end
- end
- end
- if isServer then --if you are a command computer, fuck that netsend() function!!! that's for pussies!!
- if msg:gsub(" ","") ~= "" then
- local sdata = {
- names[cname].name,
- msg,
- prefix..names[cname].prefix or "<",
- suffix..names[cname].suffix or "> ",
- names[cname].msgprefix or "",
- }
- if type(names[cname].realname) == "string" then
- table.insert(sdata,names[cname].realname)
- end
- insend(unpack(sdata))
- end
- else --if you're a client, studies have shown that you're the type of fuck who makes positive acronyms out of insults that are thrown your way
- local sdata = {
- names[cname].name,
- msg,
- prefix..names[cname].prefix or "<",
- suffix..names[cname].suffix or "> ",
- names[cname].msgprefix or "",
- }
- if type(names[cname].realname) == "string" then
- table.insert(sdata,names[cname].realname)
- end
- netsend(unpack(sdata))
- end
- end
- end
- local renderHistory = function() --this shows all the latest and greatest (optional) messages sent by fakechat clients!
- local y = scr_y-2
- local r = "&r"
- term.setBackgroundColor(colors.black)
- for a = #sHistory, #sHistory-(scr_y-2), -1 do
- if not sHistory[a] then break end
- term.setCursorPos(1,y)
- term.clearLine()
- filterColors(sHistory[a].p..r..sHistory[a].n..r..sHistory[a].s..r..sHistory[a].m,true)
- y = y - 1
- end
- end
- local server = function() --now THIS is what I call a quality function! servers are where it's at! *it* being command computers, of course...
- while true do
- local evt = {os.pullEvent("modem_message")}
- if type(evt[5]) == "table" then
- local i = evt[5]
- if type(i.name) == "string" and type(i.msg) == "string" and type(i.prefix) == "string" and type(i.suffix) == "string" and type(i.realname) == "string" then
- table.insert(sHistory,{n=i.name, m=i.msg, p=i.prefix, s=i.suffix})
- send( i.name, i.msg, i.prefix, i.suffix, i.realname, true)
- dnb(function() return renderHistory() end)
- end
- end
- end
- end
- moreModems = function() --keep them modems loaded!
- while true do
- setModems()
- sleep(0)
- end
- end
- switchNames = function() --in case you happen to be named harry kuntz, and want to change that right away
- local evt, key, rerender
- while true do
- rerender = false
- evt, key = os.pullEvent("key")
- if key == keys.pageUp then
- cname = cname - 1
- rerender = true
- elseif key == keys.pageDown then
- cname = cname + 1
- rerender = true
- end
- if cname <= 0 then
- cname = #names
- elseif cname > #names then
- cname = 1
- end
- if rerender then renderReadBar(true) end
- end
- end
- local funclist = { --this is the funciest list I've ever laid eyes upon
- client,
- moreModems,
- switchNames,
- }
- if isServer then table.insert(funclist,server) end --clients are not servers, you thick idiot
- parallel.waitForAny(unpack(funclist)) --execute the SHIT out of this!
- term.setCursorPos(1,scr_y)
- term.setBackgroundColor(colors.black)
- term.clearLine() --the last line is always the hardest...*sniffle*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement