request
 

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

request

Started by kbeh273300, 23 February, 2004, 01:48:32

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kbeh273300

can someone make a script that lets op's read and wright to and from a text file.what im looking for is to be able to let them say if they are checking users and find say good users i want them to be able to wright that users nick to a text file that the other op's with a command can then read.


!add     to add a good users nick to the list(gooduser.txt)

!show   to show the list of good users(gooduser.txt)
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

nErBoS

#1
Hi,

Hope it helps...

--Requested by kbeh273300
--Made by nErBoS

Bot = "FavUsers-Bot"

goodtext = "gooduser.txt" --It will be created in the script folder

function Main() 
frmHub:RegBot(Bot) 
end 

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+)")
		if (cmd=="!add") then
			if (user.bOperator) then
			s,e,cmd,goodusr = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (goodusr ~= nil) then
			appendto(goodtext) 
			write("\r\n"..goodusr.."\t"..user.sName) --It writes the user and the op who added
			writeto()
			user:SendPM(Bot, "The user "..goodusr.." was been added to the list GoodUser.")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !add . ")
			return 1
			end
			end
		elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end
		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

Best regards, nErBoS
--## nErBoS Spot ##--

kbeh273300

wow that was fast :)

il test it out right now


and thank you very much
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

kbeh273300

when i load the bot and type !add i get this [21:25] Syntax error, !add .  witch is ok but when i type this    !add testing it makes a script error and the bot doesnt respond.

Syntax error: attempt to concat global `gooduser' (a nil value)
stack traceback:
   1:  function `DataArrival' at line 21 [file `...esktop\New Folder (10)\scripts\FavUsers-Bot.lua']
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

kbeh273300

i fixed it.it was just a few spelling errors no big deal.

thank you very much nErBoS for the fast work on this one . :)
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

nErBoS

#5
Hi,

You are rigth when you see gooduser change it to goodusr :) ,may bad.

Best regards, nErBoS

PS:I have edited the post and corrected that.
--## nErBoS Spot ##--

DorianG

Sorry nErBoS, but i think that it is an error....

elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end

function Readtextfile(user, file)

nErBoS

hummm...

Why do you say that i am caliing the function readtextfile and this functions recives user and file.

Try to use a let me know :)

Best regards, nErBoS
--## nErBoS Spot ##--

DorianG

ok, is a good bot  ;)

Snooze

#9
Wow - I've been looking for this :D

Any change of adding so you can ad comments to that user -EX:

!add Snooze - Damn he should stop asking all those questions!

Result:

Snooze Damn he should stop asking all those questions! Added by: Snooze (Date)
;)

nErBoS

#10
Hi,

--Requested by kbeh273300
--Made by nErBoS

Bot = "FavUsers-Bot"

goodtext = "gooduser.txt" --It will be created in the script folder

function Main() 
frmHub:RegBot(Bot) 
end 

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+)")
		if (cmd=="!add") then
			if (user.bOperator) then
			s,e,cmd,goodusr, msg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s+(.*)")
			if (goodusr ~= nil) then
			appendto(goodtext) 
			write("\r\n"..goodusr.." "..msg..". Added by: "..user.sName.."("..GetDate()..")") --It writes the user and the op who added
			writeto()
			user:SendPM(Bot, "The user "..goodusr.." was been added to the list GoodUser.")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !add  . ")
			return 1
			end
			end
		elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end
		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

function Date()
	d = date("%d")
	mm = date("%m")
	y = date("%y")
	Date = d.."/"..mm.."/20"..y
	return Date
end

Is this what you want ???

Best regards, nErBoS
--## nErBoS Spot ##--

Snooze

DAMN your fast !!!

Its exactly what i had in mind :D



Thanks m8

You sure make it fun running a hub with the help your giving !!!! -

Keep up the good work ;)

kbeh273300

ok i have a request on the first one you made . can we add a few more command like  !findgu nick  = search the list for a user by nick.and say !regu nick  =removeing a user from the gooduser list.?

--Requested by kbeh273300
--Made by nErBoS

Bot = "FavUsers-Bot"

goodtext = "gooduser.txt" --It will be created in the script folder

function Main() 
frmHub:RegBot(Bot) 
end 

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+)")
		if (cmd=="!add") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			appendto(goodtext) 
			write("\r\n"..gooduser.."\t"..user.sName) --It writes the user and the op who added
			writeto()
			user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !add . ")
			return 1
			end
			end
		elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end
		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
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

nErBoS

Hi,

Let me know if it works OK...

--Requested by kbeh273300
--Made by nErBoS

Bot = "FavUsers-Bot"

goodtext = "gooduser.txt" --It will be created in the script folder

function Main() 
frmHub:RegBot(Bot) 
end 

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+)")
		if (cmd=="!add") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			appendto(goodtext) 
			write("\r\n"..gooduser.."\t"..user.sName) --It writes the user and the op who added
			writeto()
			user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !add . ")
			return 1
			end
			end
		elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end
		elseif (cmd=="!findgu") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			if (GetItemByName(gooduser) == nil) then
			user:SendPM(Bot, "The user "..gooduser.." isn't online.")
			else
			user:SendPM(Bot, "The user "..gooduser.." is online.")
			end
			else
			user:SendPM(Bot, "Syntax error, !findgu . ")
			end
			end
		elseif (cmd=="!regu") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			RemoveGoodUser(gooduser, goodtext)
			else
			user:SendPM(Bot, "Syntax error, !regu . ")
			end
			end
		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

function Writetextfile(file, array)
	writeto(file)
	for x=1,getn(array) do write(array[x].."\r\n") end
	writeto()
end

function RemoveGoodUser(user, file)
local tmp = ""
local temp = {}
readfrom(file)
   while 1 do
      local line = read()
      if (line == nil) then 
         break
      else
         local s, e, nick = strfind(line, "(%S*)%s%S*%s%S*")
         if (nick == user.sName) then
         else
            tmp = tmp .. line .. "\r\n"
         end
      end
   end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
user:SendPM(Bot, "Done..")
end

Best regards, nErBoS
--## nErBoS Spot ##--


nErBoS

Hi,

Snooze when i get a free time i will see that, i don?t have any expirence in working a script with a site, i will see what i can learn to help you out.

Best regards, nErBoS
--## nErBoS Spot ##--

kbeh273300

ok im getting a script error when i use the !regu cmd

Syntax error: attempt to index local `user' (a string value)
stack traceback:
   1:  function `RemoveGoodUser' at line 92 [file `...esktop\New Folder (10)\scripts\FavUsers-Bot.lua']
   2:  function `DataArrival' at line 52 [file `...esktop\New Folder (10)\scripts\FavUsers-Bot.lua']
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

nErBoS

Hi,

Try this...

--Requested by kbeh273300
--Made by nErBoS

Bot = "FavUsers-Bot"

goodtext = "gooduser.txt" --It will be created in the script folder

function Main() 
frmHub:RegBot(Bot) 
end 

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+)")
		if (cmd=="!add") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			appendto(goodtext) 
			write(gooduser.."\t"..user.sName.."\r\n") --It writes the user and the op who added
			writeto()
			user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !add . ")
			return 1
			end
			end
		elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end
		elseif (cmd=="!findgu") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			if (GetItemByName(gooduser) == nil) then
			user:SendPM(Bot, "The user "..gooduser.." isn't online.")
			return 1
			else
			user:SendPM(Bot, "The user "..gooduser.." is online.")
			return 1
			end
			else
			user:SendPM(Bot, "Syntax error, !findgu . ")
			return 1
			end
			end
		elseif (cmd=="!regu") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			RemoveGoodUser(gooduser, goodtext)
			user:SendPM(Bot, "Done..")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !regu . ")
			return 1
			end
			end
		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

function Writetextfile(file, array)
	writeto(file)
	for x=1,getn(array) do write(array[x].."\r\n") end
	writeto()
end

function RemoveGoodUser(user, file)
local tmp = ""
local temp = {}
readfrom(file)
   while 1 do
      local line = read()
      if (line == nil) then 
         break
      else
         local s, e, nick = strfind(line, "(%S*)%s%S*%s%S*")
         if (nick == user) then
         else
            tmp = tmp .. line .. "\r\n"
         end
      end
   end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end

Best regards, nErBoS
--## nErBoS Spot ##--


kbeh273300

working great now . your da man :)
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

kbeh273300

i guess i spoke to soon its not giveing the error and it says [19:18] Done..  when i use the !regu nick but then when i use the !show the user still shows on the list
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

nErBoS

#21
Hi,

Problay you have a a line blank in the midle of the gooduser.txt you have to delete that line, a little bug i will try to correct him.

Best regards, nErBoS
--## nErBoS Spot ##--

kbeh273300

yep i did have a blank line so i deleted it and its not giveing the error now but it still isnt removeing the user.

great job so far i thank you much for your time on this :)
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

nErBoS

Hi,

This will solve "i hope :) "..

--Requested by kbeh273300
--Made by nErBoS

Bot = "FavUsers-Bot"

goodtext = "gooduser.txt" --It will be created in the script folder

function Main() 
frmHub:RegBot(Bot) 
end 

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+)")
		if (cmd=="!add") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			appendto(goodtext) 
			write(gooduser.."\t"..user.sName.."\r\n") --It writes the user and the op who added
			writeto()
			user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !add . ")
			return 1
			end
			end
		elseif (cmd=="!show") then
			if (user.bOperator) then
			Readtextfile(user, goodtext)
			return 1
			end
		elseif (cmd=="!findgu") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			if (GetItemByName(gooduser) == nil) then
			user:SendPM(Bot, "The user "..gooduser.." isn't online.")
			return 1
			else
			user:SendPM(Bot, "The user "..gooduser.." is online.")
			return 1
			end
			else
			user:SendPM(Bot, "Syntax error, !findgu . ")
			return 1
			end
			end
		elseif (cmd=="!regu") then
			if (user.bOperator) then
			s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
			if (gooduser ~= nil) then
			RemoveGoodUser(gooduser, goodtext)
			user:SendPM(Bot, "Done..")
			return 1
			else
			user:SendPM(Bot, "Syntax error, !regu . ")
			return 1
			end
			end
		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

function Writetextfile(file, array)
	writeto(file)
	for x=1,getn(array) do write(array[x].."\r\n") end
	writeto()
end

function RemoveGoodUser(user, file)
local time = 0
local tmp = ""
local temp = {}
readfrom(file)
   while 1 do
      local line = read()
      if (time == 3) then
	 break
      else
      if (line == nil) then 
	 time = time + 1
      else
         local s, e, nick = strfind(line, "(%S+)%s+%S+")
         if (nick == user) then
	 time = 0
         else
            tmp = tmp .. line .. "\r\n"
	    time = 0
         end
      end
   end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end

Best regards, nErBoS
--## nErBoS Spot ##--

kbeh273300

looks like it still isnt removeing the user :(
no script errors tho :)
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

SMF spam blocked by CleanTalk