Hi, i need more help :)
Could someone check if there is something wrong with the function ReadRelease ? i'm able to write, but the Read function does not return correct.. tks in advance.
------------------------------------------------------
function WriteRelease(user, data, cmd)
arg = GetArgs(data)
if arg == nil then
arg = "Sem coment?rios no Hub."
user:SendData(sBot, arg)
return 1
end
local handle = io.open("Data/CLP.GuestBook.dat","a")
timedate = os.date()
handle.write(handle,timedate.." - "..user.sName..": "..arg.."?")
SendPmToOps(sChatBot,"DC:CLP - Novo coment?rio no GuestBook do Hub por: "..user.sName.."")
SendToAll(sBot,"DC:CLP - Novo coment?rio no GuestBook do Hub, digite: !livro para ler o(s) coment?rio(s).")
handle:close()
end
function ReadRelease(user, data, cmd)
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
handle = io.open("Data/CLP.GuestBook.dat","r")
if (handle) then
line = handle.read(handle,"*a")
line=string.sub(line,1,string.len(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(sBot,linearray[i])
end
handle:close()
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
end
end
------------------------------------------------------
Change this
handle.write(handle,timedate.." - "..user.sName..": "..arg.."?")
to this handle:write(handle,timedate.." - "..user.sName..": "..arg.."?")
And this line = handle.read(handle,"*a")
to this line = handle:read()
Then should be ok :)
darn, some minutes late ;)
Hehe jiten, still get some syntax errors on this one !
Write function --> script.lua:1199: bad argument #1 to `write' (string expected, got userdata)
Read function --> script.lua:1213: `for' limit must be a number
Can u post the whole script so that I can have a better look at it?
sBot = "?per"
sChatBot ="Moita"
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
string.gsub(inString, matcher, function (w) table.insert(_WORDS,w) end)
return _WORDS
end
function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
_,_,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd=="!livro") then
ReadRelease(user, data, cmd)
return 1
else
if (cmd=="!escrever") then
WriteRelease(user, data, cmd)
return 1
end
end
end
function GetArgs(data)
s,e,arg = string.find( data, "%b<>%s+%S+%s+(.+)" )
return arg
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function WriteRelease(user, data, cmd)
arg = GetArgs(data)
if arg == nil then
arg = "Sem coment?rios no Hub."
user:SendData(sBot, arg)
return 1
end
handle = io.open("Data/CLP.GuestBook.dat","a")
timedate = os.date()
handle:write(handle,timedate.." - "..user.sName..": "..arg.."?")
SendPmToOps(sChatBot,"DC:CLP - Novo coment?rio no GuestBook do Hub por: "..user.sName.."")
SendToAll(sBot,"DC:CLP - Novo coment?rio no GuestBook do Hub, digite: !livro para ler o(s) coment?rio(s).")
handle:close()
end
function ReadRelease(user, data, cmd)
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
handle = io.open("Data/CLP.GuestBook.dat","r")
if (handle) then
line = handle:read()
line=string.sub(line,1,string.len(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(sBot,linearray[i])
end
handle:close()
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
end
end
Here you go:
--Converted to LUA 5 by jiten
sBot = "?per"
sChatBot ="Moita"
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
string.gsub(inString, matcher, function (w) table.insert(_WORDS,w) end)
return _WORDS
end
function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
_,_,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd=="!livro") then
ReadRelease(user, data, cmd)
return 1
else
if (cmd=="!escrever") then
WriteRelease(user, data, cmd)
return 1
end
end
end
function GetArgs(data)
s,e,arg = string.find( data, "%b<>%s+%S+%s+(.+)" )
return arg
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
function WriteRelease(user, data, cmd)
arg = GetArgs(data)
if arg == nil then
arg = "Sem coment?rios no Hub."
user:SendData(sBot, arg)
return 1
end
local handle = io.open("Data/CLP.GuestBook.dat","a+")
assert(handle, "Data/CLP.GuestBook.dat")
timedate = os.date()
handle:write(timedate.." - "..user.sName..": "..arg.."?")
SendPmToOps(sChatBot,"DC:CLP - Novo coment?rio no GuestBook do Hub por: "..user.sName.."")
SendToAll(sBot,"DC:CLP - Novo coment?rio no GuestBook do Hub, digite: !livro para ler o(s) coment?rio(s).")
handle:close()
end
function ReadRelease(user, data, cmd)
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
handle = io.open("Data/CLP.GuestBook.dat","r")
if (handle) then
line = handle:read()
line=string.sub(line,1,string.len(line)-1)
linearray=tokenize(line,"?")
for i=1,table.getn(linearray) do
user:SendPM(sBot,linearray[i])
end
handle:close()
user:SendPM(sBot, ":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:")
end
end
running perfect :) tks again []'s
yw, no probs :)