Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Wojbie's #ComputerCraft Irc Channel Monitor
- --Simply run and watch chat go by
- --change user and userSide below to set settings
- -- Copyright (c) 2013-2021 Wojbie (wojbie@wojbie.net)
- -- Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met:
- -- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- -- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- -- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- -- 4. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
- -- 5. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
- -- NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY NUCLEAR FACILITY.
- local zone={Hour=1,Min=0,Sec=0} --provide offset from time thats printed.
- local user=nil --Username to send redstone signal if mentioned (String).
- local userSide=nil --Side to send signal(top, bottom, left, right, front and back)
- local tArgs={...}
- local i=1
- local filter=false
- while #tArgs>0 do
- if tArgs[1] == "-f" then
- filter=true
- i=i+1
- table.remove(tArgs,1)
- elseif tArgs[1] and tArgs[2] then
- local nope=true
- for i,k in pairs(redstone.getSides()) do
- if tArgs[2]==k then
- user=table.remove(tArgs,1)
- userSide=table.remove(tArgs,1)
- nope=false
- break
- end
- end
- if nope then table.remove(tArgs,1) end
- else table.remove(tArgs,1) end
- end
- if user then user=string.lower(user) end--easyer to work on that later
- if filter then print("Filter on") end
- if user then print("On pings for ",user," emits redstone signal on ",userSide," side") rs.setOutput(userSide,false) end
- sleep(1)
- local Startup="http://sbnc.khobbits.co.uk/log/logs/100/computercraft.html"
- local Update="http://sbnc.khobbits.co.uk/log/logs/10/computercraft.html"
- local UpdateRate=1
- --patterns
- local patcutoff="<p>If you want your channel logged here, contact KHobbits on #lain @ Esper.<br />()"
- local patmaincut="<span class='(.-)'><span class='timestamp'>(.-)</span><br /></span>"
- local patsystem="%[(%d-):(%d-):(%d-)%] </span><span style=\"color:(.-);\">(.*)"
- local patsystem2="%[(%d-):(%d-):(%d-)%] (.*)"
- local patuser="%[(%d-):(%d-):(%d-)%] </span><span><</span><span style=\"color:(.-);\">(.-)</span><span>>(.*)"
- --html unescaping http://stackoverflow.com/a/14899740
- local gsub, char = string.gsub, string.char
- local entityMap = {["lt"]="<",["gt"]=">",["amp"]="&",["quot"]='"',["apos"]="'",["nbsp"]=" "}
- local entitySwap = function(orig,n,s)
- return entityMap[s] or n=="#" and char(s) or orig
- end
- function unescape(str)
- return gsub( str, '(&(#?)([%d%a]+);)', entitySwap )
- end
- local All={}
- local colors, Standard, bgColor
- if term.isColour() then
- colors={green=colours.lime,purple=colours.purple,teal=colours.lightBlue,navy=colours.blue,fuchsia=colours.pink,red=colours.red,gray=colours.lightGrey}
- Standard = colours.white
- bgColor = colours.black
- else
- colors={green=colours.white,purple=colours.white,teal=colours.white,navy=colours.white,fuchsia=colours.white,red=colours.white,gray=colours.white}
- Standard = colours.white
- bgColor = colours.black
- end
- local function download(A)
- handle=http.get(A)
- if not handle then return nil end
- local out=handle.readAll()
- handle.close()
- return out
- end
- local function inlines(A)
- local out={}
- local cut=string.match(A,patcutoff)
- --Cutting in lines
- A=string.sub(A,cut or 1)
- for i,k in string.gmatch(A,patmaincut)do --getting in lines
- table.insert(out,{["system"]=i=="chatline-hideable",["content"]=k})
- end
- return out
- end
- local function timezone(Hour,Min,Sec) --add time correction onto timestamp
- local function loop(A,B) local p=0 while A<0 do A=A+B p=p-1 end while A>B-1 do A=A-B p=p+1 end return A,p end
- local p=0
- Sec,p=loop(tonumber(Sec)+zone.Sec,60)
- Min,p=loop(tonumber(Min)+zone.Min+p,60)
- Hour=loop(tonumber(Hour)+zone.Hour+p,24)
- return string.format ("[%02d:%02d]",Hour,Min)
- --return string.format ("[%02d:%02d:%02d]",Hour,Min,Sec) --"["..Hour..":"..Min..":"..Sec.."]"
- end
- local function process(A) --process one table line into better one
- local ta,tb,tc
- ta,tb,tc,A.color,A.user,A.data = string.match(A.content,patuser)
- if not ta then ta,tb,tc,A.color,A.data = string.match(A.content,patsystem) end
- if not ta then ta,tb,tc,A.data = string.match(A.content,patsystem2) end
- A.mtime=timezone(ta,tb,tc)
- A.data=unescape(A.data)
- return A
- end
- local function findlast(A,B)
- if not B then B="impossible" end
- local out={}
- local fin=A[#A].content
- for i=#A,1,-1 do
- if A[i].content==B then return out,fin end
- table.insert(out,1,process(A[i]))
- end
- table.insert(out,1,{["system"]=true,["mtime"]=out[1].mtime,["color"]="red",["data"]="* Possible loss of few lines of log before this message."})
- return out,fin
- end
- local function printline(A)
- write( "\n" )
- term.setTextColor(Standard)
- write(A.mtime)
- if A.user then write(" <") end
- if A.color then term.setTextColor(colors[A.color]) end
- if A.user then write(A.user) term.setTextColor(Standard) write(">") else write(" ") end
- write(A.data)
- end
- local function printAll(A,filter,ding)
- for i,k in pairs(A) do
- if not (filter and k.system) then
- printline(k)
- if ding and user then
- local data=string.lower(k.data)
- if (k.user and user~=string.lower(k.user)) and not string.match(data,"* "..user) and string.match(data,user) then rs.setOutput(userSide, true) end
- end
- end
- end
- end
- local function AddTab(A,B)
- for i,k in pairs(B) do table.insert(A,k) end
- end
- local file,new=nil
- while true do
- file=download(Startup)
- if file then break end
- sleep(1)
- end
- local All,last = findlast(inlines(file),last)
- printAll(All,filter)
- local tick=os.startTimer(UpdateRate)
- while true do
- local sEvent, param = os.pullEvent()
- if sEvent =="timer" then
- if param==tick then
- if user then rs.setOutput(userSide,false) end
- while true do
- file=download(Update)
- if file then break end
- sleep(1)
- end
- new,last = findlast(inlines(file),last)
- AddTab(All,new)
- printAll(new,filter,true)
- tick=os.startTimer(UpdateRate)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement