Hi,
I have a problem... I don't get this. I always have done code like this in LUA 4, in 5 it doesn't work somehow. Can someone explain what is wrong?
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
if (user.iProfile == 3 or user.iProfile == 2) 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
return 1
elseif user.iProfile == -1 or user.bOperator then
user:SendPM(botname, "*** Command is only for [REG] and [VIP] profile!")
return 1
end
end
end
end
Thanx
try this
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
if (user.iProfile == 3 or user.iProfile == 2) 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
return 1
else
user:SendPM(botname, "*** Command is only for [REG] and [VIP] profile!")
return 1
end
end
end
end
I already tried that... but thanx for your help. It is not working. I will post the whole script, it's very irritating this...
-- offlinemsg.lua, created by amutex 11.01.2003
-- converted to LUA 5 by jiten
-- thanks to dessamator for the rightclick hint :]
-- 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 = "!mail"
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
if (user.iProfile == 3 or user.iProfile == 2) 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
else
user:SendPM(botname,"*** Command is only for [REG] and [VIP] profile!")
-- return 1
-- elseif user.iProfile == -1 or user.bOperator then
-- user:SendPM(botname,"*** Command is only for [REG] and [VIP] profile!")
return 1
end
end
end
end
function NewUserConnected(curUser)
UserCmds(curUser)
local handle = io.open(path.."/"..curUser.sName ..ext,"r")
if (handle ~= nil) then
local line = handle:read()
curUser:SendPM(frmHub:GetHubBotName(), 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
function UserCmds(curUser)
if (curUser.iProfile == 3 or curUser.iProfile == 2) then
curUser:SendData("$UserCommand 1 2 offline\\Offline Message$$To: "..botname.." From: %[mynick] $<%[mynick]> !mail %[line:Nick] %[line:Message]||")
end
end
Btw, the rightclicker seems to work fine... (function UserCmds)
PostMan 0.3 LUA5 http://www.aokol.u-szeged.hu/postman03.lua very nice
Thanx... I'm going to use thatone. But I still don't understand why the script above couldn't be edited the way I did.
If someone knows, please let me know. I want to learn from it!
-- offlinemsg.lua, created by amutex 11.01.2003
-- converted to LUA 5 by jiten
-- thanks to dessamator for the rightclick hint :]
-- 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
-- heavily touched by Herodes ... this shortened the script a lot ..
path = "messages" -- name of the folder where the message files will be stored
ext = ".msg" -- extension for the message files
command = "!mail"
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 ToArrival(user, data)
if ( string.sub( data, 1, string.len(botname) + 5) == "$To: "..botname ) then
local s,e, cmd, args = string.find ( data, "%$%b<>%s+(%S+)%s*(.*)|")
if (cmd == command) then
if (user.iProfile == 3 or user.iProfile == 2) then
local s,e,arg1,arg2 = string.find ( args, ("(%S+)%s+(.*)") )
-- SendToAll( arg1.." == "..arg2 )
if (arg1 and arg2) then
if (arg1 ~= user.sName) then
local what = string.rep(" -", 50).." - Message by : "..user.sName.."\n - Sent on: "..os.date("%m/%d/%y").."\n - Sent at: "..os.date("%H:%M").."\n"..string.rep(" -", 50).."\n"..arg2.."\n\n"
local filename = path.."/"..arg1..ext
AppendToFile(filename, what)
user:SendPM(botname,"Message stored. It will be sent to "..arg1.." next time he/she logs in.")
return 1
else user:SendPM( botname, "Trying to msg yourself ain't ya?"); return 1
end
else user:SendPM( botname, "Syntax Error!"); return 1
end
else
user:SendPM(botname,"*** Command is only for [REG] and [VIP] profile!")
return 1
end
end
end
end
function AppendToFile(filename, what) -- Thx NightLitch
local file = io.open(filename, "a+") -- "a+"
file:write (what)
file:close()
end
function NewUserConnected(curUser)
if (curUser.iProfile == 3 or curUser.iProfile == 2) then
curUser:SendData("$UserCommand 1 2 offline\\Offline Message$$To: "..botname.." From: %[mynick] $<%[mynick]> !mail %[line:Nick] %[line:Message]||")
end
local handle = io.open(path.."/"..curUser.sName ..ext,"r")
if handle then
local line = handle:read("*a")
handle:close()
os.remove(path.."/"..curUser.sName..ext)
curUser:SendPM(botname, line)
end
end
OpConnected = NewUserConnected
Sorry for totaly fixing it .. you can always add new features to it ;)
the problem was ( i think ) a problem with your string.finds ..
I also noticed that you weren't using local variables .. that ( apart from putting more load on the mem, in bigger scripts especially ) is making your code prone to errors...
I believe that the io functions needed some work too. Check NightLitch's thread on the io system in the How-To section of the board I bet you'll find many usefull info there.
this above script is tested and working .. see what changes I made in the scirpt and compare to the version you were working with ..
[*edit*] Notice the "-- SendToAll( arg1.." == "..arg2 )" part ? ;) this is a very common way to debug values or script logic...
Nice one, Herodes ;)
So it had some bugs and I didn't know about about them...
Best regards,
jiten
you're welcome jiten .. I still think this script can go further ..
It may not delete the messages after they've been viewed and it may require the user to delete it ( or have an index file to know how long the message had been there so that it can also auto-prune messages.. )
just spitting ideas.. ;)
Thanx Herodes,
It was a little late yesterday and I almost fall in sleep on my keyboard. I looked @ it also yesterday, but couldn't think anymore. :P
Well... I will take your advice with me, and take a very good look (off course) @ this script!
Again, thanx!
Ok,
now I do have another problem...
Check:
[16:00:21] *** Connected
[16:00:22] This hub is running PtokaX DC Hub 0.3.3.0 build 16.06 (UpTime: 0 days, 0 hours, 0 minutes)
[16:00:22] *** Stored password sent...
[16:00:22] Private message from ?Bot-Player?: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Message by : [VIP]Thundar
- Sent on: 03/26/05
- Sent at: 16:01
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fsdfssdf
[16:00:22] *** Joins: [SU]TTB
[16:00:22] *** Joins: ?Bot-Player?
[16:00:22] *** Joins: [VIP]Thundar
[16:00:22] *** Joins: ?OP-Chat?
[16:00:22] motd
The message is send now, before the BOT is regged... What can I do about that? Is delay an option?
Try replacing this
--function Main()
-- frmHub:RegBot( botname )
--end
with this:
function Main()
frmHub:RegBot( botname )
end
Best regards.
Hi
Thanx for your reply, but the reason because it is not regged, is because it is the PtokaX bot I use...
botname = frmHub:GetHubBotName() -- or use whatever botname you want then uncomment the following 3 lines
--function Main()
-- frmHub:RegBot( botname )
--end
Maybe you know something else to solve this problem?
Have u ticked "Popup messages from users that are not online" and unticked "Ignore messages from users that are not online" in File - Settings - Advanced ?
Maybe, that's the reason.
By the way, have u tried uncommenting the Main function, just like I advised? It may work.
Best regards.
Hi,
QuoteHave u ticked "Popup messages from users that are not online" and unticked "Ignore messages from users that are not online" in File - Settings - Advanced ?
Maybe, that's the reason.
Now it works :D
QuoteBy the way, have u tried uncommenting the Main function, just like I advised? It may work.
I did...
Now it works... I have to let ppl in the hub tick that option standard on... It isn't standard enabled...
Thanx for your reply!
yw