Advertisement
LDDestroier

OurChat Reloaded (unofficial)

Oct 15th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- pastebin get NQVPiSWZ ourchat-rl
  2. -- std pb NQVPiSWZ ourchat-rl
  3.  
  4. tMess = {}
  5. tArg = {...}
  6. scr_x, scr_y = term.getSize()
  7.  
  8. playerNames = {} --list of player names to keep track of nicknames
  9.  
  10. chat = peripheral.find("chatbox_admin")
  11. if not chat then
  12.     chat = peripheral.find("chatbox")
  13.     if not chat then
  14.         chat = peripheral.find("chat_box")
  15.         if not chat then
  16.             error("Requires a chatbox.")
  17.         end
  18.     end
  19. end
  20.  
  21. function send(data)
  22.     local a = http.post("http://minechat.x10host.com/index.php?words="..textutils.urlEncode(data))
  23.     return a
  24. end
  25.  
  26. commands = {
  27.     ["me"] = function()
  28.         if string.len(arg1) > 0 then
  29.             send( "* "..playerNames[playername].." "..arg1 )
  30.         else
  31.             chat.tell(playername, "/me <whatever>")
  32.         end
  33.     end,
  34.     ["nick"] = function()
  35.         if not playerNames[playername] then
  36.             playerNames[playername] = playername
  37.         end
  38.         if string.len(arg1) > 0 then
  39.             playerNames[playername] = "'"..arg1.."'"
  40.             send( "* "..playerNames[playername].." is now known as "..arg1 )
  41.         else
  42.             chat.tell(playername, "/nick <newname>")
  43.         end
  44.     end,
  45.     ["help"] = function()
  46.         chat.tell(playername, "Available commands:")
  47.         local sCommands = "*"
  48.         for sCommand, fnCommand in pairs( commands ) do
  49.             sCommands = sCommands .. " ##:" .. sCommand
  50.         end
  51.         chat.tell(playername, sCommands)
  52.     end,
  53.     ["insult"] = function() --the insult command is a very useful utility in making children cry
  54.         insults = {
  55.             "USERNAME can go eat a bag of shiza.",
  56.             "USERNAME is fat and ugly and really, really stupid.",
  57.             "USERNAME is a fat sack o' crap.",
  58.             "If USERNAME was admin...eh, I don't want to think of such things...",
  59.             "No one is more pathetic than USERNAME.",
  60.             "USERNAME is known to suck more than Kirby.",
  61.             "USERNAME was the inspiration of Bubsy 3D.",
  62.             "USERNAME's IQ is his age...times two!",
  63.             "USERNAME's programming skills rival that of the Software Toolworks.",
  64.             "Down with USERNAME, the killer of kings!",
  65.             "USERNAME can go suck it!",
  66.             "Stop being so adversarial, USERNAME!",
  67.             "USERNAME cannot beat Air Man!",
  68.             "USERNAME likes Daikatana and Bubsy.",
  69.             "USERNAME is like King Midas, except with coagulated blood rather than gold.",
  70.             "USERNAME's mother was a hampster, and his father smells of elderberry!",
  71.             "Ni!",
  72.             "USERNAME is a dishonorable Ferrengi p'tach!",
  73.             "Pepperoni is too spicy for USERNAME.",
  74.         }
  75.         send(string.gsub(insults[math.random(1,#insults)],"USERNAME",arg1))
  76.     end,
  77.     ["kill"] = function() --a useless command, I admit. But funny.
  78.         if #arg1 < 1 then
  79.             send(playerNames[playername].." was killed.")
  80.         else
  81.             send(arg1.." was killed.")
  82.         end
  83.     end,
  84.     ["whois"] = function()
  85.         local names = seperateMethods(playerNames)
  86.         for a = 1, #names do
  87.             if names[2] == "'"..arg1.."'" then
  88.                 chat.tell(playername, arg1.." is actually '"..names[2].."'")
  89.                 break
  90.             end
  91.         end
  92.     end,
  93.     ["id"] = function()
  94.         send(playerNames[playername].." is not a computer.")
  95.     end,
  96. }
  97.  
  98. local function seperateMethods(input)
  99.     output={}
  100.     for key,value in pairs(input) do
  101.         table.insert(output, {key,value})
  102.     end
  103.     return output
  104. end
  105.  
  106. function b()
  107.     while true do
  108.         ev, side, playername, mess = os.pullEvent("chat_message")
  109.         if not playerNames[playername] then
  110.             playerNames[playername] = playername
  111.         end
  112.         local sCommand = string.match( mess, ":([a-z]+)" )
  113.         if sCommand then
  114.             local fnCommand = commands[sCommand]
  115.             if fnCommand then
  116.                 if string.find(mess," ") then
  117.                     arg1 = string.sub(mess,string.find(mess," ")+1)
  118.                     ab = fnCommand(arg1)
  119.                 else
  120.                     arg1 = ""
  121.                     ab = fnCommand()
  122.                 end
  123.                 if ab == true then
  124.                     return true
  125.                 end
  126.             else
  127.                 chat.tell(playername, "Bad command!")
  128.             end
  129.         else
  130.             fullMess = "<"..playerNames[playername].."> "..mess
  131.             tMess[#tMess+1] = fullMess
  132.             send( fullMess )
  133.         end
  134.     end
  135. end
  136.  
  137. function clearLines(top, bottom)
  138.     for a = top, bottom do
  139.         term.setCursorPos(1,a)
  140.         term.clearLine()
  141.     end
  142. end
  143.  
  144. function a()
  145.     while true do
  146.         local b = http.post("http://minechat.x10host.com/index.php?true=true")
  147.         if b then
  148.             b = b.readAll()
  149.         else
  150.             error("Server not found. :(")
  151.         end
  152.         if (b ~= tMess[#tMess]) and (b ~= fullMess) then
  153.             tMess[#tMess+1] = b
  154.             chat.say(tMess[#tMess])
  155.         end
  156.     end
  157. end
  158.  
  159. function showListofAllNames()
  160.     while true do
  161.         term.clear()
  162.         term.setCursorPos(1,1)
  163.         for a = 1, #tMess do
  164.             print(tMess[a])
  165.         end
  166.         repeat
  167.             oldPlayerNames = playerNames
  168.             sleep(0.5)
  169.         until oldPlayerNames ~= playerNames
  170.     end
  171.        
  172. end
  173.  
  174. parallel.waitForAny(a, b, showListofAllNames)
  175. term.setCursorPos(1,1)
  176. term.clear()
  177. print("Thank you for using OurChat!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement