Last 30 messages
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Last 30 messages

Started by NemeziS, 07 April, 2005, 12:17:37

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NemeziS

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
--LUA forever! =)

Herodes

#1
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

NemeziS

#2
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
--LUA forever! =)

Herodes

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.. ;)

NemeziS

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?
--LUA forever! =)

NemeziS

#5
Any idea?  ;) Please, someone!
--LUA forever! =)

Herodes

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

SMF spam blocked by CleanTalk