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
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: "..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
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
i don't see a bot here
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
@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
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: "..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
One main function is enough :-)
I have just checked, main must be written this way: Main
Otherwise it is not recognized.
if i'd want a description for the bot, how can i add that?
+savemessage test in PM to the bot doesn't produce anything ....
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.
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
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
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
Perfect.... Thanks again.... E
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.
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
how can i use this script without have to PM the bot?
so that i just can type +msg in the main chat?
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