A script where users can leave "mails" to other users both online and offline ..
I know that its been build into a few multibots, but what im looking for is a standalone version of this function.
Any help will be great !
**snooze
u mean somethign like what in gekko hmmm
Mail = "Daemon"
mcmd = "!"
function NewUserConnected(user)
Mailer(user)
end
function OpConnected(user)
Mailer(user)
end
function Mailer(user)
handle2=openfile("messages/"..user.sName..".msg","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(Bot,linearray[i])
end
closefile(handle2)
end
a,b=remove("messages/"..user.sName..".msg")
end
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd ==mcmd.."checkmail" then
Mailer(user)
elseif (cmd==mcmd.."mail") then
s,e,cmd,arg,arg2 = strfind(data,"%s+(%S+)%s+(%S+)%s+(.*)")
if arg == nil or arg2 == nil then
user:SendData(Mail,"What you gonna send?")
return 1
else
local handle=openfile("messages/"..arg..".msg","a")
write(handle,"("..user.sName..") :"..arg2.."?")
user:SendPM(Mail,"Message sent")
closefile(handle)
mailing = GetItemByName(arg)
if mailing == nil then
else
mailing:SendPM(Mail,"You have mail, use checkmail to read it")
end
end
end
end
end
later,,
Hehe - thats exactly what i had in mind, pH?tt? ;)
Thanks for sharing ..
QuoteOriginally posted by Snooze
Hehe - thats exactly what i had in mind, pH?tt? ;)
Thanks for sharing ..
eheh np ;)
Umm... i hate to ask for more, but i were trying to write a nice !delmail command for this.
Could you help me out again ?
**Snooze
QuoteOriginally posted by Snooze
Umm... i hate to ask for more, but i were trying to write a nice !delmail command for this.
Could you help me out again ?
**Snooze
as soon as its been read its deleted or you want it chaged so it stored all of em?
Damn - i just thought of two nice feature ..
!mailops - sends a mail to all ops.
!mailnews - sends a msg to all regged users
Just two nice ways for all ops and users to get the latest news ..
If you could help me with this i would be forever greatfull :D
**Snooze
Hmm... when im testing it, it do not delete the msg after being read ..
Could i be missing a part of the script ?
**Snoozes
dunno maybe
Mail = "Daemon"
mcmd = "!"
function NewUserConnected(user)
Mailer(user)
end
function OpConnected(user)
Mailer(user)
end
function Mailer(user)
handle2=openfile("messages/"..user.sName..".msg","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(Bot,linearray[i])
end
closefile(handle2)
end
end
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd ==mcmd.."checkmail" then
Mailer(user)
elseif cmd == mcmd.."delmail" then
a,b=remove("messages/"..user.sName..".msg")
user:SendPM(Mail,"All your mail has been erased")
return 1
elseif (cmd==mcmd.."mail") then
s,e,cmd,arg,arg2 = strfind(data,"%s+(%S+)%s+(%S+)%s+(.*)")
if arg == nil or arg2 == nil then
user:SendData(Mail,"What you gonna send?")
return 1
else
local handle=openfile("messages/"..arg..".msg","a")
write(handle,"("..user.sName..") :"..arg2.."?")
user:SendPM(Mail,"Message sent")
closefile(handle)
mailing = GetItemByName(arg)
if mailing == nil then
else
mailing:SendPM(Mail,"You have mail, use checkmail to read it")
end
end
end
end
end
later,,
Hmm...
i used this little part to make a function
function DelMail(user, data)
remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Mail,"All your mail has been erased")
return 1
end
But i keep getting this error
Syntax Error: bad argument #1 to `gsub' (string expected, got nil)
When calling the function ??
Any idea ??
**Snooze
Arrrhhhhh .... been fighting with this for more than a "few" hours now.
All i want to do is delete the f*cking mail
Im using a function that looks like this:
function DelMail(user,data)
a,b=remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Bot,"All your mail(s) has been erased.")
return 1
end
even tried:
function DelMail(user,data)
a,b=remove("skbot/skmail/Snooze.msg")
user:SendPM(Bot,"All your mail(s) has been erased.")
return 1
end
But all i get is this:
Syntax Error: bad argument #1 to `strsub' (string expected, got nil)
So i did some searching on this forum, but with no luck..
The best i could find were that this would delete a file:
Remove(filename)
But even that didnt get me past that error :(
So .. what im looking for is an explenation for that error im getting as i have no idea about what it mean
Any help will be great :)
The Newbie
**Snooze
Check your vars before you pass. The strsub error is coming from here:
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
What if the files exists but it is empty? So.
line = read(handle2,"*a")
if(line) then
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(Bot,linearray[i])
end
endif
closefile(handle2)
Next problem is the Remove function. It returns nothing and lua IS case sensetive.
Remove("skbot/skmail/"..user.sName..".msg")
Is correct as long as the directory exists and you have altered the directory names in all other references in the script.
-NotRabidWombat
This is driving me nutz ..
To give you some more to work with :
Start of function DataArrival(user,data)
function DataArrival(user,data)
if strsub(data, 1, 1) == "<" or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
cmd = strlower(cmd)
down the line of commands comes this:
elseif (cmd==prefix.."delmail") then
DeleteMail(user,data)
function DeleteMail(user,data) looks like like this:
function DeleteMail(user,data)
a,b=Remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Bot,"All your mail(s) has been erased.")
return 1
end
And the local path for the "mail"
scripts/skbot/skmail/
In the skmail folder i have a "mail" named "Snooze.msg"
with that running i get this error msg:
Syntax Error: attempt to call global `Remove' (a nil value)
<---Feeling really dumb :( But i just cant figure it out..
case sensitive means Remove isn't the same as remove.
btw if a == nil then you can show the user that he didn't have any msg's.
b shows that error msg.
plop
Great :D
Im getting closer !!
function DelMail(user)
if (a==nil) then
user:SendPM(Bot,"You have no mails to delete.")
return 1
else
a,b=remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Bot,"All your mail has been erased")
return 1
end
end
It's now returning the (a==nill) part though it's not true - there IS a Snooze.msg at the end of that path..
+ im now getting a new error
Error:
Syntax Error: table index is nil
Well... the good news is that im getting better ... :) (though very slowly)
**Snooze
your checking if a == nil before actualy checking if the file can be deleted, so a whill always be nil.
move the remove all the way up.
plop
Ok... I think this is what you wanted me to do :
function DelMail(user,data)
if (a ~= nil) then
a,b=remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Bot,"All your mail has been erased")
return 1
else
user:SendPM(Bot,"You have no mails to delete.")
return 1
end
end
Right ??
If so, im still getting the same result :'(
If i understod your correctly, "a" checks if there is a file to be deleted, right ?
Then what does the "b" do ?
**Snooze
Oops !!!!
This might work better :D
function DelMail(user,data)
a,b=remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Bot,"All your mail has been erased")
return 1
end
That worked (when i had removed the other "function remove(something)" from the script :O
<-- Blushing
Sorry guys and thanks for all the help - Im sure that i would just have delete the whole script had it not been for all your guys at this forum :D
**Snooze
QuoteOriginally posted by Snooze
Ok... I think this is what you wanted me to do :
function DelMail(user,data)
if (a ~= nil) then
a,b=remove("skbot/skmail/"..user.sName..".msg")
user:SendPM(Bot,"All your mail has been erased")
return 1
else
user:SendPM(Bot,"You have no mails to delete.")
return 1
end
end
Right ??
If so, im still getting the same result :'(
If i understod your correctly, "a" checks if there is a file to be deleted, right ?
Then what does the "b" do ?
**Snooze
a,b = remove(filename.
a gets a vallue the moment the file is deleted.
b gets the error msg if the delete failed.
a,b=remove(filename)
if a ~= nil then
user:SendPM(Bot, "your file was deleted")
else
user:SendPM(Bot, "there were no files 2 be deleted. error msg: "..b)
end
plop
Thanks plop :D
Well.. thats the best part of this ... i just keep learning new stuff every day :D
**Snooze
QuoteOriginally posted by Snooze
Thanks plop :D
Well.. thats the best part of this ... i just keep learning new stuff every day :D
**Snooze
yw.
plop
One of my Ops asked if i could add an !mailop command that would send the same msg too all regged Ops.
I guess its more or less the same function i think i just need a way to "pull" all the Ops (level 0+1) from the reg list ?
I've searched the forum, but came up empty on a way to do it, so any help would be really nice :)
**Snooze