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 ;) )
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
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?
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
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
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