Read-Text problem
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Read-Text problem

Started by nErBoS, 13 October, 2003, 17:42:24

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

nErBoS

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
--## nErBoS Spot ##--

pHaTTy

Hmmm i dont understand Else what????

in the readtextfile
Resistance is futile!

pHaTTy

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
Resistance is futile!

nErBoS

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)"
--## nErBoS Spot ##--

pHaTTy

I dont understadn what you are trying to write to the file :S
Resistance is futile!

[ES]latinmusic

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

nErBoS

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 ??
--## nErBoS Spot ##--

plop

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

[ES]latinmusic

Yes line by line, test the plop script, if not work i will modify it later, now working, surry :p

nErBoS

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
--## nErBoS Spot ##--

[ES]latinmusic


SMF spam blocked by CleanTalk