Created
December 21, 2019 12:36
-
-
Save 12Me21/f8144602159b7048177f8ffd201caf6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Usage: | |
-- input chatlog files on stdin, outputs formatted logs on stdout | |
-- (name<tab>message\n), with all lines of multiline messages labelled with usernames | |
-- Pass a list of usernames to filter as arguments (optional) | |
-- iterator function, returns: name, message, room, time (in minutes) | |
function chatlines(file, ...) | |
local name, hour, minute, room | |
local names | |
if #{...}>0 then | |
names = {} | |
for _, v in ipairs({...}) do | |
names[v] = true | |
end | |
end | |
return function() | |
local space, name2, hour2, minute2, room2, message | |
repeat | |
local line = file:read() | |
if not line then return end | |
_, _, space, name2, hour2, minute2, room2, message = line:find("^(%s*)([A-Za-z0-9_]-)%[(%d%d):(%d%d)%](.): (.*)$") | |
if space then | |
name, hour, minute, room = name2, tonumber(hour2), tonumber(minute2), room2 | |
else | |
_, _, hour2, minute2, room2, name2, message = line:find("^ %[funmodule%]%[(%d%d):(%d%d)%](.): ([A-Za-z0-9_]-) (.*)$") | |
if hour2 then | |
name, hour, minute, room = name2, tonumber(hour2), tonumber(minute2), room2 | |
elseif line:sub(1,30)==" " then | |
message = line:sub(31) | |
else | |
message = line | |
end | |
end | |
until not names or names[name] | |
return name, message, room, hour*60 + minute | |
end | |
end | |
for name, message in chatlines(io.stdin, table.unpack(arg, 1)) do | |
print(name, message) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment