Offline-Message script
 

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

Offline-Message script

Started by bolamix, 10 March, 2005, 06:29:45

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bolamix

This script allows you to send messages to offline users; the messages will then be sent to said users when they connect to the hub.
-- offlinemsg.lua, created by amutex 11.01.2003
-- thx to nathanos for the fine pm-parsing
-- bits and pieces added and deleted by bolamix over time, kudos to all scripters who helped!
-- attempted conversion to lua5 by bolamix Feb. 27 2005
-- successful conversion to lua5 by Jelf March 9 2005
-- usage: send a PM to the bot with   

path = "messages" -- name of the folder where the message files will be stored
ext = ".msg" -- extension for the message files
command = "+note"
botname = frmHub:GetHubBotName() -- or use whatever botname you want then uncomment the following 3 lines
--function main
-- 	frmHub:RegBot( botname )
--end

os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"")

function Get2Args(data)
	s,e,whoTo,from,cmd,arg,arg2 = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(%S+)%s+(.*)")
	return arg,arg2
end

function ToArrival(user, data)
	s,e,whoTo = string.find(data,"$To:%s+(%S+)")
	if (whoTo == botname) then
		s,e,whoTo,from,cmd = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
		if (cmd == command) then
			arg,arg2 = Get2Args(data)
			local f,e = io.open(path.."/"..arg..ext,"a+")
			if f then
			    f:write(""..user.sName.." sent you this message on "..GetDate().." at "..GetTime().." : "..arg2)
				user:SendPM(botname,"Message stored. It will be sent to "..arg.." next time he/she logs in.")
				f:close()
			end
		end
	end
end

function NewUserConnected(curUser)
	local handle = io.open(path.."/"..curUser.sName ..ext,"r")
	if (handle ~= nil) then
		local line = handle:read() 
		curUser:SendPM("#Offline_Message", line)
		handle:close()
	 	os.remove(path.."/"..curUser.sName..ext)
	else
	end
end

OpConnected = NewUserConnected

function GetTime()
	h = os.date("%H")
	m = os.date("%M")
	Time = h..":"..m
	return Time
end

function GetDate()
	d = os.date("%d")
	mm = os.date("%m")
	y = os.date("%y")
	Date = mm.."/"..d.."/"..y
	return Date
end
Enjoy ;)
Sharing is of the essence!

Live music >> Aiwadirock! live music hub
PtokaX knowledge >> The PtokaX Wiki

dkt

#1
nice script working fine...but the message is shown in main...that too above motd...so i dont think u can easily find out or see ur offline message !!!
can the script be modified to get the offline message in pm on hub connect ?
if yes thn how ?

Also one more thing u have to pm Ptokax bot for sending an offline message..can this script be modified to by just typing in main chat ??

jiten

QuoteOriginally posted by dkt
nice script working fine...but the message is shown in main...
That's strange.
As you can see in the red line it sends the Offline message in PM:
function NewUserConnected(curUser)
	local handle = io.open(path.."/"..curUser.sName ..ext,"r")
	if (handle ~= nil) then
		local line = handle:read() 
		[COLOR=red]curUser:SendPM("#Offline_Message", line)[/COLOR] 
		handle:close()
	 	os.remove(path.."/"..curUser.sName..ext)
	else
	end
end
Tomorrow, I'll have a look at this one.

Cheers

jiten

#3
Here you go:
-- LUA 5 version - heavily modified by jiten

-- offlinemsg.lua, created by amutex 11.01.2003
-- thx to nathanos for the fine pm-parsing
-- bits and pieces added and deleted by bolamix over time, kudos to all scripters who helped!
-- attempted conversion to lua5 by bolamix Feb. 27 2005
-- successful conversion to lua5 by Jelf March 9 2005
-- usage: send a PM to the bot with   

sBot = frmHub:GetHubBotName()		-- sBot = "yourbotname"
Command = "mail"			-- Offline message command
Path = "messages"			-- Name of the folder where the message files will be stored
Ext = ".msg"				-- Extension for the message files

Main = function()
	if sBot ~= frmHub:GetHubBotName() then frmHub:RegBot(sBot) end
	os.execute("mkdir ".."\""..string.gsub(Path, "/", "\\").."\"")
end

ChatArrival = function(sUser,data)
	local data = string.sub(data, 1, -2)
	local s,e,cmd = string.find(data,"%b<>%s+[%!%?%+%#](%S+)")
	if (string.sub(data,1,1) == "<") or (string.sub(data,1,5+string.len(sBot)) == "$To: "..sBot) then
		if cmd then
			local tCmds = {
			[Command] =	function(user,data)
						local s,e,usr,msg = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(.*)")
						if (usr == nil or msg == nil) then
							sUser:SendData(sBot, "*** Syntax Error: Type !"..Command.."  ")
						else
							local f = io.open(Path.."/"..usr..Ext,"a+")
							if f then
								f:write(""..user.sName.." sent you this message on "..os.date("%d:%m:%y").." at "..os.date("%H:%M")..": "..msg)
								user:SendPM(sBot,"Message stored. It will be sent to "..usr.." next time he/she logs in.")
								f:close()
							end
						end
					end,
			}
			if tCmds[cmd] then return tCmds[cmd](sUser,data),1 end
		end
	end
end

ToArrival = ChatArrival

NewUserConnected = function(sUser)
	local f = io.open(Path.."/"..sUser.sName..Ext)
	if f then
		local line = f:read() f:close()
		sUser:SendPM(sBot,line) line = nil
	 	os.remove(Path.."/"..sUser.sName..Ext)
	end
end

OpConnected = NewUserConnected
*EDIT* small fix

htb222

Nice script, and it works too!
Cheers

SMF spam blocked by CleanTalk