Messages for offline users
 

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

Messages for offline users

Started by Endless, 18 May, 2004, 11:18:56

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Endless

I've been looking around on this board and can't seem to find what I'm looking for, and I'm no good on lua so even if I did find exactly what I need, I may have overlooked it.  I hope this doesn't seem like too tall an order...

I'm trying to find a script for ptokax that will let me or any other user send a pm to a specified user when he connects.  I tried plop's offline message script, but I was really looking for something less complicated.  I don't want an inbox for the user, just to send them a private message the next time they connect, one time.

Something like, I type to a bot: "!postmsg User4 I have a file for you, search blah.jpg", and next time that user comes online, they get a pm from the bot saying "Message from Endless: I have a file for you, search blah.jpg".  The message is only given to them them once, and they don't need to type something like !readmsg #, etc. Being able to handle mulitple messages would be cool too, like this:

Message from User50, : I figured you may be interested in this: http://fakelink.com
Message from Endless, : I have a file for you, search blah.jpg
Message from User10, : I found those files you needed, I've got them shared now

Does a script like this already exist?

Thanks to anyone who can help :-)

Endless

Yokozuna

This is a part of a script I use:


BOTNAME1 
"Messagebot" -- change to a name of your choice
PREFIX 
"+" -- change if you use ! or something else as command prefix

function NewUserConnected(curUser)
	
DeliverMessage(curUser)
end

function OpConnected(curUser)
	
DeliverMessage(curUser)
end

function Savemessage(user,data)
	
if (
strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1then
	
	
data strsub(data,1,strlen(data)-1)
	
	
local s,e,cmd strfind(data,"%b<>%s+(%S+)")
	
	
if (
cmd == PREFIX.."savemessage"then
	
	
	
s,e,arg,arg2 strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
	
	
	
local handle openfile("messages/"..arg..".msg","a")
	
	
	
write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."\tfrom "..user.sName.." : "..arg2.."?")
	
	
	
closefile(handle)
	
	
	
user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
	
	
end
	
end
end

function tokenize(inString,token)
	
WORDS = { }
	
local matcher "([^?"..token.."]+)"
	
gsub(inString,matcher,function(wtinsert(WORDS,w)end)
	
return 
WORDS
end

function DeliverMessage(curUser)
	
handle2 openfile("messages/"..curUser.sName..".msg","r")
	
if 
handle2 ~= nil then
	
	
line read(handle2,"*a")
	
	
s,e,from strfind(line,"from%s(%S+)")
	
	
line strsub(line,1,strlen(line)-1
	
	
linearray tokenize(line,"?")
	
	
for 
1,linearray.do
	
	
	
curUser:SendPM(BOTNAME1,linearray[i])
	
	
end
	
	
closefile(handle2)
	
	
a,remove("messages/"..curUser.sName..".msg")
	
	
if 
not from then
	
	
	
return 
1
	
	
end
	
	
sender GetItemByName(from)
	
	
if 
sender then
	
	
	
sender:SendPM(BOTNAME1,"Your offline message has been delivered to "..curUser.sName.." !")
	
	
else
	
	
	
local handle openfile("messages/"..from..".msg","a")
	
	
	
write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").." : Offline message has been delivered to "..curUser.sName.."?")
	
	
	
closefile(handle)
	
	
end
	
end
end


Syntax is +savemessage user message
It must be sent as a PM to the bot !
The sending user will be notified when the offline message has been delivered.



Yokozuna

sander815

i don't see a bot here

plop

QuoteOriginally posted by Yokozuna
This is a part of a script I use:

Yokozuna
don't post a part of a script, specialy not when the credits are missing.
beside that you forgot the function Main().

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Yokozuna

@sander

Sory, you are right.

Add

function main()
      frmHub:RegBot(BOTNAME1)
end


@plop
This script is part of a complete hubscript made by myself. This part is based on a old script made by amutex and nathanos, but I have changed it so it it notifies the users when the message is delivered !
You are right that I should have included the original credits, but I simply copied and pasted it from my scripteditor in PtokaX


Yokozuna

sander815

like this?:
caus ei still don't see it




BOTNAME1 
"--Messagebot--" -- change to a name of your choice
PREFIX 
"+" -- change if you use ! or something else as command prefix
function main() 
frmHub:RegBot(BOTNAME1
end 

function NewUserConnected(curUser)
    
DeliverMessage(curUser)
end

function OpConnected(curUser)
    
DeliverMessage(curUser)
end
function main() 
frmHub:RegBot(BOTNAME1
end 
function Savemessage(user,data)
    if (
strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1then
        data 
strsub(data,1,strlen(data)-1)
        
local s,e,cmd strfind(data,"%b<>%s+(%S+)")
        if (
cmd == PREFIX.."savemessage"then
            s
,e,arg,arg2 strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
            
local handle openfile("messages/"..arg..".msg","a")
            
write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."tfrom "..user.sName.." : "..arg2.."?")
            
closefile(handle)
            
user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
        
end
    end
end

function tokenize(inString,token)
    
WORDS = { }
    
local matcher "([^?"..token.."]+)"
    
gsub(inString,matcher,function(wtinsert(WORDS,w)end)
    return 
WORDS
end

function DeliverMessage(curUser)
    
handle2 openfile("messages/"..curUser.sName..".msg","r")
    if 
handle2 ~= nil then
        line 
read(handle2,"*a")
        
s,e,from strfind(line,"from%s(%S+)")
        
line strsub(line,1,strlen(line)-1
        
linearray tokenize(line,"?")
        for 
1,linearray.do
            
curUser:SendPM(BOTNAME1,linearray[i])
        
end
        closefile
(handle2)
        
a,remove("messages/"..curUser.sName..".msg")
        if 
not from then
            
return 1
        end
        sender 
GetItemByName(from)
        if 
sender then
            sender
:SendPM(BOTNAME1,"Your offline message has been delivered to "..curUser.sName.." !")
        else
            
local handle openfile("messages/"..from..".msg","a")
            
write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").." : Offline message has been delivered to "..curUser.sName.."?")
            
closefile(handle)
        
end
    end
end


Yokozuna

One main function is enough :-)

I have just checked, main must be written this way: Main
Otherwise it is not recognized.

sander815

if i'd want a description for the bot, how can i add that?

sander815

+savemessage test in PM to the bot doesn't produce anything ....

Yokozuna

#9
Sorry, another error on my side

Add

function DataArrival(user,data)
    Savemessage(user,data)
end

to get it work.
And you need a directory named messages in your scripting directory of PtokaX !
I will post the whole debugged script with the description you have asked for in some minutes.

Yokozuna

#10
Here is the debugged script:

-- Thanks to amutex and nathanos for the original offline messages bot
-- modifications made by Yokozuna
PREFIX = "+" -- change if you use ! or something else as command prefix
BOTNAME1 = "--Messagebot--" -- change to a name of your choice
BOTDESCR = "Offline Messages" -- change to someting you like
BOTTAG = ""
BOTSPEED = "BOT"
BOTEMAIL = ""
BOTSHARE = "0"
SBOTINFO = "$MyINFO $ALL "..BOTNAME1.." "..BOTDESCR..BOTTAG.."$ $"..BOTSPEED..strchar(1).."$"..BOTEMAIL.."$"..BOTSHARE.."$"

function Main() 
	frmHub:RegBot(BOTNAME1)
	UpdateBotInfo()
end 

function DataArrival(user,data)
	Savemessage(user,data)
	SendBotInfo(curUser)
end

function NewUserConnected(curUser)
	DeliverMessage(curUser)
	SendBotInfo(curUser)
end

function OpConnected(curUser)
	DeliverMessage(curUser)
end

function UpdateBotInfo()
	SBOTINFO = "$MyINFO $ALL "..BOTNAME1.." "..BOTDESCR..BOTTAG.."$ $"..BOTSPEED..strchar(1).."$"..BOTEMAIL.."$"..BOTSHARE.."$"
end

function SendBotInfo(curUser)
	SendToAll(SBOTINFO)
end

function Savemessage(user,data)
    if (strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
        data = strsub(data,1,strlen(data)-1)
        local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
        if (cmd == PREFIX.."savemessage") then
            s,e,arg,arg2 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
            local handle = openfile("messages/"..arg..".msg","a")
            write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."\tfrom "..user.sName.." : "..arg2.."?")
            closefile(handle)
            user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
        end
    end
end

function tokenize(inString,token)
    WORDS = { }
    local matcher = "([^?"..token.."]+)"
    gsub(inString,matcher,function(w) tinsert(WORDS,w)end)
    return WORDS
end

function DeliverMessage(curUser)
    handle2 = openfile("messages/"..curUser.sName..".msg","r")
    if handle2 ~= nil then
        line = read(handle2,"*a")
        s,e,from = strfind(line,"from%s(%S+)")
        line = strsub(line,1,strlen(line)-1) 
        linearray = tokenize(line,"?")
        for i = 1,linearray.n do
            curUser:SendPM(BOTNAME1,linearray[i])
        end
        closefile(handle2)
        a,b = remove("messages/"..curUser.sName..".msg")
        if not from then
            return 1
        end
        sender = GetItemByName(from)
        if sender then
            sender:SendPM(BOTNAME1,"Your offline message has been delivered to "..curUser.sName.." !")
        else
            local handle = openfile("messages/"..from..".msg","a")
            write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").." : Offline message has been delivered to "..curUser.sName.."?")
            closefile(handle)
        end
    end
end

Make sure you have a directory named messages in your scripts directory of PtokaX !

I have tested it on my side and didn't get any error.


Yokozuna

Endless

This is PERFECT, Yokozuna.   Exactly what I was looking for and it's working great.

I have one question, I wanted to shorten the command a little, so I changed it to "msg", is below the only part I would have to change?  because I saw several other instances of "savemessage" and I'm not sure if they need to be changed too.

function Savemessage(user,data)
    if (strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
        data = strsub(data,1,strlen(data)-1)
        local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
        if (cmd == PREFIX.."msg") then


And thanks again!

Endless

Yokozuna

QuoteI have one question, I wanted to shorten the command a little, so I changed it to "msg", is below the only part I would have to change? because I saw several other instances of "savemessage" and I'm not sure if they need to be changed too.

function Savemessage(user,data)
if (strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd == PREFIX.."msg") then

Yes, it is the only part you need to change.



Yokozuna

Endless

Perfect.... Thanks again.... E

QuikThinker

Can any1 use this script or just OPs coz if possible i'd like it so it IS just the OPs, Masters & VIPs that can use it?

Quik.

Yokozuna

Hi there

Anyone can use this command.

If you want to change the script in a way that only special users are allowed to use it, do the following:

Change the function

function Savemessage(user,data)
    if (strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
        data = strsub(data,1,strlen(data)-1)
        local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
        if (cmd == PREFIX.."savemessage") then
            s,e,arg,arg2 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
            local handle = openfile("messages/"..arg..".msg","a")
            write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."\tfrom "..user.sName.." : "..arg2.."?")
            closefile(handle)
            user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
        end
    end
end

to this

function Savemessage(user,data)
	if (strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
		data = strsub(data,1,strlen(data)-1)
		local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
		if (cmd == PREFIX.."savemessage") then
			userok = 0
			for every, profile in PROFILES do
				if user.iProfile == tonumber(profile) then
					userok = 1
				end
			end
			if userok == 1 then
	        		s,e,arg,arg2 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
				local handle = openfile("messages/"..arg..".msg","a")
				write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."\tfrom "..user.sName.." : "..arg2.."?")
				closefile(handle)
				user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
			end
		end
	end
end

and add this:
PROFILES = { "0","1","2" } -- add the profiles here that are allowed to use the script
at the beginning of the script

That is all  :)



Yokozuna

OneHero

how can i use this script without have to PM the bot?

so that i just can type +msg in the main chat?

nErBoS

Hi,

Change this....

function Savemessage(user,data)
    if (strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
        data = strsub(data,1,strlen(data)-1)
        local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
        if (cmd == PREFIX.."savemessage") then
            s,e,arg,arg2 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
            local handle = openfile("messages/"..arg..".msg","a")
            write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."\tfrom "..user.sName.." : "..arg2.."?")
            closefile(handle)
            user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
        end
    end
end

to this...

function Savemessage(user,data)
    if (strsub(data,1,1) == "<" or strsub(data,1,strlen(BOTNAME1)+5) == "$To: "..BOTNAME1) then
        data = strsub(data,1,strlen(data)-1)
        local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
        if (cmd == PREFIX.."savemessage") then
            s,e,arg,arg2 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+([%S%s]+)")
            local handle = openfile("messages/"..arg..".msg","a")
            write(handle,date("%d").."."..date("%m").."."..date("%Y").." at "..date("%T").."\tfrom "..user.sName.." : "..arg2.."?")
            closefile(handle)
            user:SendPM(BOTNAME1,"Your offline message for "..arg.." has been saved and will be delivered as soon as "..arg.." logs in again. You will be notified when the message has been delivered.")
        end
    end
end

Best regards, nErBoS
--## nErBoS Spot ##--

SMF spam blocked by CleanTalk