This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Match nicks from a file.

Old posts that have not been replied to for several years.
Locked
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Match nicks from a file.

Post by Sir_Fz »

I wrote a script that's supposed to ban users matching certain nicks in a file
the nicks are in this form in the file:
nick1
nick2
nick3
nick4
...
I used

Code: Select all

set spamnicks [split [read -nonewline [open $spnfile]] "\n"]
close [open $spnfile]
foreach spamnick $spamnicks {
 if {[string match -nocase $spamnick $nick]} {
## action
 }
}
to see if the joined nick matches any of the nicks in the file, but it gave an error, my guess is that the spamnicks are not in a list like { "nick1" "nick2" "..." }, so can anyone give me a better method ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

try something like:

Code: Select all

set f [open "search.txt" r] 
while {[gets $f spamnick]>-1} { 
if {[string match -nocase $nick $spamnick]} { 
# we have a match here
}
}
close $f
# search complete.. nothing found
Once the game is over, the king and the pawn go back in the same box.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

thanx :)

what if I want to add nicks into the file using a dcc command.

would the code be like this ?

Code: Select all

set af [open "$spnfile" a]
while {[gets $af spnick]>-1} {
  if {![string match -nocase $spnick $arg]} {
# $arg will be added into file
 }
}
close $af
Sorry, but its my first time working with files :p
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Your welcome.. something like that, yes. Give it a try.
Once the game is over, the king and the pawn go back in the same box.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Re: Match nicks from a file.

Post by strikelight »

Sir_Fz wrote:I wrote a script that's supposed to ban users matching certain nicks in a file
the nicks are in this form in the file:
nick1
nick2
nick3
nick4
...
I used

Code: Select all

set spamnicks [split [read -nonewline [open $spnfile]] "\n"]
close [open $spnfile]
foreach spamnick $spamnicks {
 if {[string match -nocase $spamnick $nick]} {
## action
 }
}
to see if the joined nick matches any of the nicks in the file, but it gave an error, my guess is that the spamnicks are not in a list like { "nick1" "nick2" "..." }, so can anyone give me a better method ?
The main problem I see with this, is that you are not closing the file you opened when you read in the data from file.... What you did is open another instance of the file just to be closed.

Code: Select all

set spamnicks [split [string tolower [read [set inf [open $spnfile]]]] "\n"][close $inf]
if {[set spamnick [lindex $spamnicks [lsearch $spamnicks [string tolower $nick]]]] != ""} {
  ## action
}
As for your writing to file.. you cannot read from a filehandle that has been opened in write mode...
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

yeah, I realized that :) anyway caesar's way worked and looks better.
as for adding nicks into the file by a dcc command, I did open file r to read and open file a to write into it, isn't there a way to add both a and r into the same var like set f [open $file ar] (but this didn't work)

may I also ask for, how can I remove the nick from a file ? what's the command for removing the specified arg from the file if it exists ?
Last edited by Sir_Fz on Thu Nov 06, 2003 5:16 pm, edited 1 time in total.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Consult the open manual :P

As for your second question, just read and save all the stuff in an variable then by using the lsearch and lreplace just remove them from there and then save the contenst of the variable in to the file.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

can you give an example please ?

also

Code: Select all

proc add:spamnick {hand idx arg} {
global spnfile
set af [open "$spnfile" a+]
while {[gets $af spnick]>-1} {
  if {![string match -nocase $spnick $arg]} {
   puts $af [split $arg]
   putlog "Added [split $arg] into $spnfile"
   return 0
  }
 }
close $af
putlog "\002[split $arg]\002 already exists in SPNICKS-list"
}
this adds the nick several times in the script, and when I remove the nicks from the script and try to add them again using the dcc coomand, it tells me that the nick already exists.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

strange, when I do set af [open $spnfile a+] the bot always says that the nick already exists... but when I put 2 sets (a and r) on separate lines it works with the adding.

But I'm not able to remove using a command... anyone ?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Your code with comments added...

Post by user »

Code: Select all

proc add:spamnick {hand idx arg} { 
	global spnfile
	# opening with a+ will set the initial access position to the end of the file...
	set af [open "$spnfile" a+]
	# ...meaning the body of this while loop will never get executed
	# but if you'd add "seek $af 0" before the loop things would be different :)
	while {[gets $af spnick]>-1} {
		# now 'spnick' contains one line read from the file...
		# Are you sure 'string match' is what you want? Does your file contain masks?
		if {![string match -nocase $spnick $arg]} {
			# when you reach this point you have no idea about the rest of the file
			# ...just the last line read from it...then you proceed to overwrite the
			# existing data at the next line (if any) because you forget to move the
			# access position to the end...
			puts $af [split $arg]
			putlog "Added [split $arg] into $spnfile" 
			# you sure did :P
			return 0 
			# oops..forgot to close the file :)
		}
	}
	close $af
	putlog "\002[split $arg]\002 already exists in SPNICKS-list" 
}
Have you ever read "The Manual"?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Thanx :) ; I figured it out thanx to some scripts out there.

and Thank you strikelight for your code, its pure.
C
Careto
Voice
Posts: 11
Joined: Tue Mar 02, 2004 1:33 pm

Post by Careto »

and if in the file is nicks with [ ] or { }?
for example (file):
[diesel ]
[^__^]
AtesT
MuSa
^^TeO^^
{ gurru }
How it would be the code?

:cry: :cry: :cry: :cry: :roll:
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

use string map

Code: Select all

string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\}.....} $arg
XplaiN but think of me as stupid
User avatar
hikaro
Halfop
Posts: 68
Joined: Wed Mar 10, 2004 4:29 am

Post by hikaro »

set f [open "search.txt" r]
while {[gets $f spamnick]>-1} {
if {[string match -nocase $nick $spamnick]} {
# we have a match here
}
}
close $f
# search complete.. nothing found
how if i want in search.txt i put the host ex *!*@*.net
Locked