Hi all,
How can i remove a ip or nick from a text file for example:
when ever i do this commands !kick, !ban or nick ban
i made this in the end of the comand function
appendto(Banlist)
write("\r\n"..userToBeKicked.sName.."\t"..userToBeKicked.sIP.."\t"..reason)
writeto()
Now i would like to know how to remove by the ip or nick
in the banlist file. The search for the nick or ip int the banlist file must be from the end to the start to remove only the last ban from the nick !!
Can anyone help me out here ??
Best regards, nErBoS
I still need help out here please !!
you need to read the whole file and write it all again without the desired nick/ip
And how can i do that ???
Maybe something like:
-- first read the whole file
local tmp = ""
readfrom(Banlist) -- or the banlist filename in quotes
while 1 do
local line = read()
if (line == nil) then
break
else
-- do some filtering!
if line == "ip number to remove" then
else
-- write to file if it's not the one we want to remove (we append to a list for now)
tmp = tmp .. line .. "\r\n"
end
end
end
readfrom()
appendto("script_data/newreggedusers.txt")
write(tmp)
writeto()
Yes that works if the line was only the ip or nick but in my case in one line i have ip, user name and reason !!
How can i solve that ??
PS: Great to have tezlo and klownietklowniet back : )
give me a format...
My ban, nickban and kickban have this on the end
appendto(Banlist)
write("\r\n"..userToBeKicked.sName.."\t"..userToBeKicked.sIP.."\t"..reason)
writeto()
In the text file it will be like this
nErBoS 127.0.0.1 reason
Haven't tryed it.. but try something like this:
-- first read the whole file
local tmp = ""
readfrom(Banlist) -- or the banlist filename in quotes
while 1 do
local line = read()
if (line == nil) then
break
else
-- do some filtering!
local s, e, ip = strfind(line, "%S*%s(%S*)%s")
if ip == "ip number to remove" then
else
-- write to file if it's not the one we want to remove (we append to a list for now)
tmp = tmp .. line .. "\r\n"
end
end
end
readfrom()
appendto("script_data/newreggedusers.txt")
write(tmp)
writeto()
Yes is working for the ip : )
can it be made for nick too ??
yep (http://www.lua.org/manual/4.0/manual.html#pm)
Done many thanks tezlo the manual its very useful : )
Just one more thing I would like only to delete the last ban made for the ip or nick, for example if the nick or ip gave more then one ban i would like to remove only the last ban for that i need..
how can I make this function read from the end to the top ??
how can i make the function that when found the ip or nick stop the search for that ip or nick and write the rest of the file ??
Why would you wanna do that?
You mean you want to have double instances in the ban file? So if an ip number is banned 4 timres, you gotta unban it 4 times aswell?... or..?
Because i want only to remove the last ban !!
Doesn't make sence to me. You eather unban a user's ip, as in removing ALL instances, or you remove none. Just the last doesn't make any difference... or sence to me. Besides, it's not worth it.
You could do it from the beggining of the file and remove just one, then write the rest of the file dirrectly... but from the end towards the beggining there is no easy way to read.
You would have to read it into a list... then do a for loop from the end towards the beggining of that list and check for first accurance of the ip, remove it from the list, then break ot of the loop and finally write the new Banlist. Takes some resources.... and as I said, I don't see the point... :-(
i think hes logging users who ban.. not users who get banned
but then whats the point in removing any of these ?!
Ok, thanks both for all the help !!
Best regards, nErBoS
Hi again can you help me out here i am callig this function
function SeeBans(user, data)
GetArgML(data)
local tmp = ""
readfrom(Banlist)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick, ip = strfind(line, "(%S*)%s(%S*)%s%S*")
if (nick == arg or ip == arg) then
tmp = tmp..""..line.."\r\n"
else
tmp = tmp..""
end
end
end
readfrom()
user:SendPM(Bot, tmp)
end
This sends me back if arg is banned the lines of bans which have nick, ip and reason .
How can i make that the line only sends back the reason ??
Need some help please !!
Hi there,,
Maybe that one,.... ( not tested, so.... )
------
function SeeBans(user, data)
GetArgML(data)
local tmp = ""
readfrom(Banlist)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick, ip, reason = strfind(line, "(%S*)%s(%S*)%s(%S*)")
if (nick == arg or ip == arg) then
tmp = tmp..""..arg.." banned for: "..reason.."\r\n"
else
tmp = tmp..""
end
end
end
readfrom()
user:SendPM(Bot, tmp)
end
------
Good luck,, :)
l8tr,, ;)
Yes it is working but the reason only sends the first word of the reason :(
Hi,,
yup,, just modifye the way to parse,,... remplace:
----
local s, e, nick, ip, reason = strfind(line, "(%S*)%s(%S*)%s(%S*)")
----
by:
----
local s, e, nick, ip, reason = strfind(line, "(%S*)%s(%S*)%s(.*)")
----
& you should have the entire reason,,
l8tr,, ;)
Yep working, Thanks Guibs.
Best regards, nErBoS