clearing a text file?
 

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

clearing a text file?

Started by buttmonkey, 11 May, 2004, 19:04:27

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

buttmonkey

hello all, im presuming this problem should be easy however i have no real LUA scripting skills more PHP skills :(

basically i have made a PHP form that outputs a text file.. users will use this form to fill out a complaint if they have been banned/kicked

then anyone in the hub can use a command to bring up the text file (which currently looks like this)

- [Name]buttmonkey
- [Email]drinks@my.house
- [Kick Reason]No Porn allowed AT ALL
- [Complaint]blah blah

when viewed in the hub

all that works fine.. however i have no clue how i could delete anything from the text file (using a hub command) hopefully seperatly or clearing out the whole text file. can anyone give me any hints or point me to any scripts/chunk of scripts that could help me?

(i use the ascii art bot to display the text files.. its easier for me ;) )

plop

you can fully remove a file with.
remove("filename.txt")
2 remove seperate lines it's easyest 2 load the file line for line and stuff it in a table.
next walk thru the table and remove what you don't want.
and finaly save the table again by overwriting the old 1.
there should be enough scripts on the board 2 help you with that, but if needed i'll give a hint later.

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 <----<<

buttmonkey

#2
so far so good.. i used your hint like this:

remove("complaints.txt")
writeto("complaints.txt") 
write("") 
end


and file gets deleted and a empty file is put in its place (prolly not the best way but its works)

now i went about making a command to do so (in this case !delcomplaints)

it works fine.. however im assuming im missing some command to halt the script in its tracks or maybe i should reorganise the whole thing around better.. but after doing the !complaints command (to show the complaints) it also does the equivlant of doing !delcomplaints at the same time (therefore pming the user with the complaints list then emptynig the complaints file).. !delcomplaints by itself works though

heres the code:

--Artbot 1.0 made by: [NL]MrBuitenhuizen
--Artbot has most of the scripting lines from > :
-->ShowInfo v1.0 by latinmusic == poweroperator 18/04/2003
-->Based on TrickerBot 2 by ?Ptaczek? 
-->Based on a few lines of DirtyBot made by Dirty Finger)
--nov 2003 = start empty rule idea by Plop 
--thnx to the people who made the Art txt files
--you need to have the directory "art" in your txt directory
--have fun with it

BotName = "-=Gamer=-" 
cmd = "!delcomplaints"
Files = { 
["!complaints"] = "complaints.txt", 
} 

function Main() 
--frmHub:RegBot(BotName) 
end
function DataArrival(user, data)
if ( strsub(data, 1, 1) == "<" ) then 
s,e,msg = strfind(data, "%b<> ([ -z]*)") 
for key, value in Files do 
if ( strfind( strlower(msg), key) ) then 
txtToShow, x = gsub(value, "%b[]", user.sName)
Show(user, TheFile) 
if (cmd=="!delcomplaints") then 
delcomplaints(user,data) 
end
end
end
end 
end
function Show(user, TheFile) 
readfrom(txtToShow, "r") 
local message = "\r\n"
while 1 do 
local line = read() 
if line == nil then break 
else 
message = message..line.."\r\n" 
end 
end 
SendPmToNick(user.sName, BotName, message ) -- send bot's message
readfrom()
return 1; 
end
function delcomplaints(user, TheFile)
remove("complaints.txt")
writeto("complaints.txt") 
write("") 
end


can anyone also show me the proper way to make the commands for ops only?

i assume this would work?

function delcomplaints(user, TheFile)
if user.bOperator then
remove("complaints.txt")


i seem to be breaking something all over the script every time i try something new.. a while back it seemed to be all working (except for the deleting of the text file after !complaints) including the op only command.. now the !delcomplaints command dosnt seem to be working >:|

can anyone help?

plop

give this 1 a try.
i added several comments in it 2 show what i changed.
--Artbot 1.0 made by: [NL]MrBuitenhuizen
--Artbot has most of the scripting lines from > :
-->ShowInfo v1.0 by latinmusic == poweroperator 18/04/2003
-->Based on TrickerBot 2 by ?Ptaczek? 
-->Based on a few lines of DirtyBot made by Dirty Finger)
--nov 2003 = start empty rule idea by Plop 
--thnx to the people who made the Art txt files
--you need to have the directory "art" in your txt directory
--have fun with it

BotName = "-=Gamer=-" 
cmd = "!delcomplaints"
Files = { 
["!complaints"] = "complaints.txt", 
} 

function Main() 
--frmHub:RegBot(BotName) 
end

function DataArrival(user, data)
   if ( strsub(data, 1, 1) == "<" ) then 
      s,e,msg = strfind(data, "%b<> ([ -z]*)") 
      for key, value in Files do 
         if ( strfind( strlower(msg), key) ) then 
            txtToShow, x = gsub(value, "%b[]", user.sName)
            Show(user, TheFile) 
            return 1
         end
      end
      -- here i added the string find as it's needed 2 grab the command if give by a op
      s,e,cmd = strfind(data, "%b<>%s+(%S+)")
      if (cmd=="!delcomplaints") and user.bOperator then  -- checking if the command is typed and if the user who does is a OP
         delcomplaints() 
         user:SendData(BotName, "The complaints file has been removed!|")
         return 1
      end
   end 
end

function Show(user, TheFile) 
   readfrom(txtToShow, "r") 
   local message = "\r\n"
   while 1 do 
      local line = read() 
      if line == nil then 
         break 
      else 
         message = message..line.."\r\n" 
      end 
   end 
   SendPmToNick(user.sName, BotName, message ) -- send bot's message
   readfrom()
   return 1
end

function delcomplaints()
   remove("complaints.txt")
   writeto("complaints.txt") 
   write("") 
   writeto() --- you forgot 2 close the file
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 <----<<

buttmonkey

thankyoooou very muchly plop :)

the script worked perfectly except for the delcomplaints command but everything seems to be working perfectly

it looks like i fixed the delcomplaints command by:

     s,e,cmd = strfind(data, "%b<>%s+(%S+)") <----- removing this line
      if (cmd=="!delcomplaints") and user.bOperator then  -- checking if the command is typed and if the user who does is a OP
         delcomplaints() 
         user:SendData(BotName, "The complaints file has been removed!|")
         return 1

not sure if it will effect anything but normal users cannot use delcomplaint and the file is cleared so it seems fine

thanks again

pHaTTy

hmm but this is not neccasary really lol

   remove("complaints.txt") --//why remove if ya readding, might as well just blank it

function delcomplaints()
   writeto("complaints.txt") 
   write("") 
   writeto() --- you forgot 2 close the file
end
Resistance is futile!

SMF spam blocked by CleanTalk