Hi all,
Have a problem with this bot
Bot = "Text-Bot"
rules = "rules.txt"
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
s,e,cmd = strfind( data, "%b<>%s+(%S+)%s*")
cmd=strsub(cmd,1,strlen(cmd)-1)
if (cmd=="!rules") then
rules = Readtextfile(rules)
user:SendPM(Bot, rules)
rules = nil
return 1
end
end
end
function Readtextfile(file)
local text = ""
local line
local ret, err = readfrom(file)
if (ret) then
while 1 do
line = read()
if not line then
break
else
text = text..line.."\r\n"
end
end
readfrom()
else
text = ""
Writetextfile(file, text)
end
return text
end
function Writetextfile(file, text)
writeto(file)
write(text)
writeto()
end
When the comand is call for the first time , it works, the bot sends the text, but when called on a second time the command appears in the main chat and the bot doesn?t sends the text and on the script editor e have this error
"Syntax Error: bad argument #1 to `readfrom' (string expected, got nil)"
Can anyone help me ???
Best regrads, nErBoS
Hmmm i dont understand Else what????
in the readtextfile
Hmmm si this what ur trying to do for that function
function Readtextfile(file)
local text = ""
local line
local ret, err = readfrom(file)
if (ret) then
while 1 do
line = read()
if not line then
text = ""
Writetextfile(file, text)
return text
else
text = text..line.."\r\n"
end
end
readfrom()
end
The readtext function that i posted i goted from glory securitaz !!
I used your function the first time i called the bot doesn?t sends the text back at the second time that i called i get the same error that i have gotten before "Syntax Error: bad argument #1 to `readfrom' (string expected, got nil)"
I dont understadn what you are trying to write to the file :S
Yo have some errors present, i have no time for explanations now, use this code.
Bot = "Text-Bot"
rules = "rules.txt"
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
s,e,cmd = strfind( data, "%b<>%s+(%S+)%s*")
cmd=strsub(cmd,1,strlen(cmd)-1)
if (cmd=="!rules") then
Readtextfile(user, rules)
end
end
end
function Readtextfile(user, rules)
local handle = openfile(rules, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
user:SendPM(Bot, line)
line = read(handle)
end
closefile(handle)
end
end
Ok [ES]latinmusic that script works but the bot sends the text line by line how can i do to make the bot send all !!
For eg the script you gave sends this:
xxxxxx
yyyyy
zzzzzzzz
i would like to do this:
xxxxxx
yyyyyy
zzzzzzzzzz
Can be done ??
not tested but should work like you want
Bot = "Text-Bot"
rules = "rules.txt"
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
s,e,cmd = strfind( data, "%b<>%s+(%S+)%s*")
cmd=strsub(cmd,1,strlen(cmd)-1)
if (cmd=="!rules") then
Readtextfile(user, rules)
end
end
end
function Readtextfile(user, rules)
local filecontents = ""
local handle = openfile(rules, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents.." |")
end
end
plop
Yes line by line, test the plop script, if not work i will modify it later, now working, surry :p
Yes working great i made this little modificacion to work on all files you want !!
Bot = "Text-Bot"
rules = "rules.txt"
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
s,e,cmd = strfind( data, "%b<>%s+(%S+)%s*")
cmd=strsub(cmd,1,strlen(cmd)-1)
if (cmd=="!rules") then
Readtextfile(user, rules)
return 1
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
Many thanks to all for the help !!
Best regards, nErBoS
Great!