SHOW:
|
|
- or go back to the newest paste.
| 1 | API = require("buttonAPI")
| |
| 2 | local filesystem = require("filesystem")
| |
| 3 | local component = require("component")
| |
| 4 | local keyboard = require("keyboard")
| |
| 5 | local event = require("event")
| |
| 6 | local gpu = component.gpu | |
| 7 | - | local reactor = component.br_reactor |
| 7 | + | |
| 8 | --this is just a basic split function we'll use to split the messages | |
| 9 | - | local versionType = "NEW" |
| 9 | + | function split(data, pat) |
| 10 | local ret = {}
| |
| 11 | - | local DEBUG = false |
| 11 | + | for i in string.gmatch(data,pat) do |
| 12 | - | local debugList = {}
|
| 12 | + | table.insert(ret,i) |
| 13 | - | local debugVars = {}
|
| 13 | + | end |
| 14 | return ret | |
| 15 | end | |
| 16 | - | local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841,
|
| 16 | + | --config |
| 17 | - | black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB} |
| 17 | + | local nickname = "derpcraft" |
| 18 | - | -- set size of the screen for lvl 3 |
| 18 | + | local channel = "#derpcraft-mc" |
| 19 | - | gpu.setResolution(132,38) |
| 19 | + | |
| 20 | - | gpu.setBackground(colors.black) |
| 20 | + | local net = require("internet")
|
| 21 | - | gpu.fill(1, 1, 132, 38, " ") |
| 21 | + | local con = net.open("irc.esper.net",6667) --define server / port here, this will connect to the server
|
| 22 | if(con) then | |
| 23 | - | local sections = {}
|
| 23 | + | local line,png,linesplt,msgfrom = "" |
| 24 | - | local graphs = {}
|
| 24 | + | while(true) do |
| 25 | - | local infos = {}
|
| 25 | + | line = con:read() --read a line from the socket |
| 26 | print(line) | |
| 27 | linesplt = split(line,"[^:]+") | |
| 28 | - | -- defninitions |
| 28 | + | if #linesplt >= 2 and string.find(linesplt[2], "No Ident response") ~= nil then |
| 29 | - | reactor["stats"] = {}
|
| 29 | + | print("JOIN")
|
| 30 | - | local running = true |
| 30 | + | con:write("USER " .. nickname .. " 0 * :" .. nickname .. "\r\n") --con:write(msg) is used to send messages, con:read() will read a line
|
| 31 | - | local maxRF = 0 |
| 31 | + | con:write("NICK " .. nickname .. "\r\n") --for IRC, remember to append the \r\n on the end of all messages
|
| 32 | - | local reactorRodsLevel = {}
|
| 32 | + | con:write("JOIN :" .. channel .. "\r\n")
|
| 33 | - | local currentRodLevel = 0 |
| 33 | + | elseif linesplt[1] == "PING" or linesplt[1] == "PING " then |
| 34 | - | local currentRf = 0 |
| 34 | + | print("PING")
|
| 35 | - | local currentRfTick = 0 |
| 35 | + | png = split(line,"[^:]+") |
| 36 | - | local currenFuel = 0 |
| 36 | + | con:write("PONG :"..png[#png].."\r\n") --respond to pings so we don't get disconnected
|
| 37 | elseif string.find(linesplt[1], "PRIVMSG #") ~= nil then | |
| 38 | - | local minPowerRod = 0 |
| 38 | + | msgfrom = split(linesplt[1],"[^ ]+") |
| 39 | - | local maxPowerRod = 100 |
| 39 | + | msgfrom = msgfrom[3] |
| 40 | con:write("PRIVMSG "..msgfrom.." :"..linesplt[2].."\r\n")
| |
| 41 | end | |
| 42 | - | -- functions |
| 42 | + | end |
| 43 | else | |
| 44 | - | function toint(n) |
| 44 | + | print("Connection failed.")
|
| 45 | - | local s = tostring(n) |
| 45 | + | end |