Author Topic: Get ip o nicks from texts  (Read 5756 times)

0 Members and 1 Guest are viewing this topic.

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
Get ip o nicks from texts
« on: 26 October, 2003, 18:50:35 »
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

Code: [Select]
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
--## nErBoS Spot ##--

PtokaX forum

Get ip o nicks from texts
« on: 26 October, 2003, 18:50:35 »

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #1 on: 28 October, 2003, 01:18:24 »
I still need help out here please !!
--## nErBoS Spot ##--

Offline tezlo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +1/-0
(No subject)
« Reply #2 on: 28 October, 2003, 01:25:30 »
you need to read the whole file and write it all again without the desired nick/ip

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #3 on: 28 October, 2003, 13:27:23 »
And how can i do that ???
--## nErBoS Spot ##--

Offline klownietklowniet

  • Forum Ace
  • *****
  • Posts: 77
  • Karma: +0/-0
(No subject)
« Reply #4 on: 28 October, 2003, 14:17:27 »
Maybe something like:

Code: [Select]
  -- 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()

   
[ > DC - UniteD < ]

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #5 on: 28 October, 2003, 16:48:56 »
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 : )
« Last Edit: 28 October, 2003, 16:49:51 by nErBoS »
--## nErBoS Spot ##--

Offline klownietklowniet

  • Forum Ace
  • *****
  • Posts: 77
  • Karma: +0/-0
(No subject)
« Reply #6 on: 28 October, 2003, 18:15:42 »
give me a format...
[ > DC - UniteD < ]

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #7 on: 28 October, 2003, 18:28:36 »
My ban, nickban and kickban have this on the end

Code: [Select]
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
--## nErBoS Spot ##--

Offline klownietklowniet

  • Forum Ace
  • *****
  • Posts: 77
  • Karma: +0/-0
(No subject)
« Reply #8 on: 29 October, 2003, 01:39:32 »
Haven't tryed it.. but try something like this:

Code: [Select]
 -- 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()
[ > DC - UniteD < ]

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #9 on: 29 October, 2003, 03:08:59 »
Yes is working for the ip : )

can it be made for nick too ??
« Last Edit: 29 October, 2003, 03:21:34 by nErBoS »
--## nErBoS Spot ##--

Offline tezlo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +1/-0
(No subject)
« Reply #10 on: 29 October, 2003, 03:36:40 »

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #11 on: 29 October, 2003, 14:08:33 »
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 ??
--## nErBoS Spot ##--

Offline klownietklowniet

  • Forum Ace
  • *****
  • Posts: 77
  • Karma: +0/-0
(No subject)
« Reply #12 on: 30 October, 2003, 04:04:03 »
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..?
[ > DC - UniteD < ]

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #13 on: 30 October, 2003, 13:37:30 »
Because i want only to remove the last ban !!
--## nErBoS Spot ##--

Offline klownietklowniet

  • Forum Ace
  • *****
  • Posts: 77
  • Karma: +0/-0
(No subject)
« Reply #14 on: 30 October, 2003, 19:33:32 »
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... :-(
[ > DC - UniteD < ]

Offline tezlo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +1/-0
(No subject)
« Reply #15 on: 30 October, 2003, 19:39:37 »
i think hes logging users who ban.. not users who get banned
but then whats the point in removing any of these ?!

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #16 on: 31 October, 2003, 00:51:34 »
Ok, thanks both for all the help !!

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

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #17 on: 02 November, 2003, 17:28:25 »
Hi again can you help me out here i am callig this function

Code: [Select]
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 ??
--## nErBoS Spot ##--

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #18 on: 04 November, 2003, 01:15:53 »
Need some help please !!
--## nErBoS Spot ##--

Offline Guibs

  • Double Ace
  • *
  • Posts: 142
  • Karma: +3/-0
(No subject)
« Reply #19 on: 04 November, 2003, 03:17:50 »
Hi there,,

Maybe that one,.... ( not tested, so.... )
------
Code: [Select]
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,, ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #20 on: 04 November, 2003, 04:17:10 »
Yes it is working but the reason only sends the first word of the reason :(
--## nErBoS Spot ##--

Offline Guibs

  • Double Ace
  • *
  • Posts: 142
  • Karma: +3/-0
(No subject)
« Reply #21 on: 06 November, 2003, 00:23:51 »
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,, ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #22 on: 06 November, 2003, 02:38:24 »
Yep working, Thanks Guibs.

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

PtokaX forum

(No subject)
« Reply #22 on: 06 November, 2003, 02:38:24 »