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.

searching the userlist

Old posts that have not been replied to for several years.
Locked
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

searching the userlist

Post by simonbell »

Hi

I am trying to make a script which will search through the userlist for a nick matching a mask which a user would input. Using the command:
/msg $botnick search mask
Im guessing id search through the userlist using the userlist command and foreach which is fine, im not really sure how i would match it to a mask. If someone put search bob, and bob was a handle then that would be fine, but is it possible to put in something like b?b and the bot would output matches, such as bob?

thanks
Simon
s
spyda
Halfop
Posts: 64
Joined: Mon Aug 12, 2002 2:22 am
Location: Australia

Basic Coding

Post by spyda »

Code: Select all


foreach asus_nick [userlist] {
  if {[getuser $asus_nick HOSTS] == [lindex [split $text] 0]} {
  #do what you want it to do if the host matchs
}
That will do a search for all the hosts and every nick in the user file, then match it to the value you set with /msg $botnick search text.

------------
ThePope
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

hm, i dont want it to match hosts. I just want it to return a list of handles which match a mask the user enters. So if a user puts in a* it will return all handles which begin with the letter a, etc.

Simon
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The code posted, while it would work, it does not do the job, of checking the users current host, or if it matched using the mask (remember the bad old days of "del *.*", this is the type of matching we are on about).

OK, first, the mask used in this script, can be comprised of characters used in the Tcl "string match" command, Available here

Second, you would use somthing like

Code: Select all

set b [list]
foreach a [userlist] {
  if {[string match [lindex [split $text] 0] $a]} {
    lappend b $a
  }
}
puthelp "PRIVMSG $nick :Users that match \"[lindex [split $text] 0]\" are \"[string trimright [join $b {, }] {, }]\""
This is based on the fact, you use $nick to reply to, and that $text contains the incoming command arguments.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

i wrote this script which appears to be working:
proc msg_search {nick host hand arg} {
set search [lindex $arg 0]
putnotc $nick "Listing matches to your search criteria \(max 10\)"
foreach searchuser [userlist] {
if { [string match -nocase $search $searchuser] == 1 } {
putnotc $nick "$searchuser"
}
}
putnotc $nick "End of search"
}
now, is it possible to detect when the number of handles that have been output reach 10, and then halt the process, so that people dont get an endless list of lots of people?

Simon
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The script I produced above, is perfect for limiting the amount retruned to a user.

It cycles through each handle, if it matches, it then adds there handle to a list.

At the end of the foreach loop, it will then output this list on on like like "hand, hand2, hand3, hand4"

Changing the

Code: Select all

[join $b {, }]
to
[/code]
[join [lrange $b 0 9] {, }]
[/code]
WOuld limit the amount of the list, fed to the output function.
Locked