Hello, great scripters!
I need your help now.
I need to grab last 30 messages from the hub (no matter who wrote it (Bot or user)). I need to grab all the messages that were send to all users and was visible to all.
They must be written to a file like in main :
[12:25:37] hello every one.
[12:25:37] Hello, guy1! Welcome to our hub!
[12:25:37] :)
[12:25:47] Hi, guy1! How are you?
[12:26:01] I'm fine, thanx
[12:26:09] grrrrrrr
[12:26:09] grrrrrrrr
[12:27:09] grrrrrrrrr
[12:27:09] grrrrrrrrrr
[12:27:09] grrrrrrrrrrr
[12:27:14] <[GoodGuy]Sergik> lol. let's play CS
I want 30 messages (lines) be written to a file.
(If there are 30 lines in a file already then the oldest line(s) will be deleted and the new line(s) will be added after the existed lines in a files)
Thanx for attention!
Best regards,
NemeziS
try this one ..
--- HistoryIsSimple by Herodes v1
---- ---- ---- ---- ---- ---- ---- ---- ---- ----
-- very simple chat history script ..
--- !wazup shows the Chat History
tChatLines = {}
iMaxLines = 30
function ChatArrival(user, data)
data = string.sub( data, 1, -2)
if not string.find( data, "%b<>%s+[%!%?%+%%-%#]" ) then
local function resort(t) local r={}; for i,v in t do table.insert( r, v );end;return r;end;
if table.getn(tChatLines) > iMaxLines then
table.remove(tChatLines, 1);
end
table.insert( tChatLines, os.date("%x@%X").." [] "..data );
tChatLines = resort(tChatLines);
else
local s,e, cmd = string.find( data, "%b<>%s+[%!%?%+%%-%#](%S+)" )
if cmd == "wazup" then
local m = "\r\n\r\n========================\r\n"
for i,v in tChatLines do
m=m.." "..v.."\r\n"
end
m = m.."========================"
user:SendData( "ChatHistory", m)
end
end
end
Hi!
Thanx for quick answer! Could you convert this script to lua4 please?
And can you make a function to write 30 last chat lines in txt file? It will be fantastic! :)
Best regards,
NemeziS
QuoteOriginally posted by NemeziS
Hi!
Thanx for quick answer! Could you convert this script to lua4 please?
And can you make a function to write 30 last chat lines in txt file? It will be fantastic! :)
Best regards,
NemeziS
sorry no time for lua4 but there are lua4 chathistory scripts around .. also there are lua4 scripts that put stuff in a file.. ;)
Thanx, Herodes!
I found the script (I don't know is the autor):
maxhistory = 30
function Main()
chathistory = dofile("chathistory.dat") or {}
end
function DataArrival(user, data)
if strsub(data, 1, 1) == "<" then
local s, e, cmd = strfind(data, "^%b<> ([%!%+%?]%a+)")
if s then
if cmd == "!wassup" then
local n = getn(chathistory)
local str = ">> last "..n.." chat messages.."
for i = 1, n do str = str.."\n"..chathistory[i] end
user:SendData(str)
return 1
end
else
tinsert(chathistory, date("[%H:%M] ")..strsub(data, 1, -2))
if getn(chathistory) > maxhistory then tremove(chathistory, 1) end
savehistory()
end
end
end
function savehistory()
local f = openfile("chathistory.dat", "w+")
assert(f, "chathistory.dat")
write(f, "return {\n")
for i = 1, getn(chathistory) do
write(f, "\t"..format("%q", chathistory[i])..",\n")
end write(f, "}") closefile(f)
end
it writes 30 chat messages in a table. That's fine, but I also need to log Bot's messages (From "JokeR" or other specified botnames to All users). How can I make it?
Any idea? ;) Please, someone!
Just before I go to sleep .. I haven't tested .. check it out .. --- HistoryIsSimple by Herodes v2
---- ---- ---- ---- ---- ---- ---- ---- ---- ----
-- very simple chat history script ..
--- !wazup shows the Chat History
---- ---- ---- ---- ---- ---- ---- ---- ---- ----
-- added: dumping of chat lines to file possible ( on timer )
tChatLines = {} -- don't touch pls ..
iMaxLines = 30 -- how many lines to keep logged ..
bSaveToFile = true -- true:enables / false:disables the dumping of chatlines to file ..
sChatFile = "chatlines.txt" -- the filename in which the lines will be dumped ...
iInterval = 1 -- in minutes every how many minutes will the chatlines be dumped to the file..
function Main()
if bSaveToFile then
SetTimer( iInterval * 1000 * 60 )
StartTimer()
end
end
function OnTimer()
if bSaveToFile then
local m = ""
for i,v in tChatLines do m=m.."\n"..v; end;
local f=io.open( sChatFile, "w+" )
f:write(m); f:close();
end
end
function ChatArrival(user, data)
data = string.sub( data, 1, -2)
if not string.find( data, "%b<>%s+[%!%?%+%%-%#]" ) then
local function resort(t) local r={}; for i,v in t do table.insert( r, v );end;return r;end;
if table.getn(tChatLines) > iMaxLines then
table.remove(tChatLines, 1);
end
table.insert( tChatLines, os.date("%x@%X").." [] "..data );
tChatLines = resort(tChatLines);
else
local s,e, cmd = string.find( data, "%b<>%s+[%!%?%+%%-%#](%S+)" )
if cmd then
if cmd == "wazup" then
local m = "\r\n\r\n========================\r\n"
for i,v in tChatLines do
m=m.." "..v.."\r\n"
end
m = m.."========================"
user:SendData( "ChatHistory", m)
elseif user.iProfile == 0 then
if cmd=="stopsaves" then
OnTimer()
bSaveToFile = false
user:SendData( "ChatHistory", "Chat lines dumping to file is off")
elseif cmd=="startsaves" then
bSaveTofile = true
user:SendData( "ChatHistory", "Chat lines dumping to file is on")
else if cmd=="saveinterval" then
local s,e, interv = string.find( data, "%b<>%s+%S+%s+(%d)")
if interv then
iInterval = tonumber(interv)
user:SendData( "ChatHistory", "The chat lines will be saved to the file ("..sChatFile..") every "..iInterval.." minutes")
else
user:SendData( "ChatHistory", "Syntax error! Use: !saveinterval ")
end
end
end
return 1
end
end
end