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.

[SOLVED] Nickname/Uhost tracker script

Help for those learning Tcl or writing their own scripts.
i
ipone
Voice
Posts: 13
Joined: Mon Mar 20, 2006 7:00 am

[SOLVED] Nickname/Uhost tracker script

Post by ipone »

Hey eveyone. I need a script that do this.

*Log hosts and the nick to that host in a txt file.

like this.

* eggie (eggdrop@12.13.53.63) has joined #fubar
* eggie (eggdrop@12.13.53.63) has left #fubar
* whatever (eggdrop@12.13.53.63) has joined #fubar
* whatever (eggdrop@12.13.53.63) has left #fubar

that the script log this in a txt file or something.

example:
eggie, whatever - eggdrop@12.13.53.63

The script that i have now logs every join. but if i join/part like 10times there will be 10 lines with the same nick/host.

Code: Select all

set data "nicklist.txt"
bind join - * join_onjoin

proc join_onjoin {nick uhost hand chan} {
 global data
  set filename $data
  set txt [open $filename "a"]
  puts $txt "$nick $uhost"
  close $txt
}

set nicklist [list]
foreach entry $data {
 lappend nicklist [lindex [split $entry :] 0]
}

set uhostlist [list]
foreach entry $data {
 lappend uhostlist [lindex [split $entry :] 1]
}


foreach user $nicklist {
 if {[string match -nocase "*$user*" $nick]} {
  set nickfound 1; break
  }
}
if {![info exists nickfound]} {
 return 0

} else {
 set findnick [lsearch -glob [split [string tolower $nicklist]] *$nick*]
 set finduhost [lsearch -glob [split [string tolower $uhostlist]] *uhost*]
}

if {$findnick == $finduhost} {
}

}
So if someone joins and if there host is already in the txtfile it should add the nick of that person. And if its a nick thats already in txt file it should do nothing.

The use of this script is that you can check the host of some user and see what nick that user have been using from that host.
Last edited by ipone on Sat Jan 10, 2009 11:25 am, edited 1 time in total.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

There is a mIRC Addon that dose this. And is used a lot. The code may provide some help/insight.

:arrow: Although this addon dose do some good. I've often found this *type* of thing is very unethical, as have a lot of people.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: on join, store nicks and host script ;)

Post by speechles »

ipone wrote:The use of this script is that you can check the host of some user and see what nick that user have been using from that host.
Why not just use bseen or gseen and let either of them do this for you? After all this is why seen scripts were made, to handle just this very task...
!seen nickname - will give the most recent host associated with the nickname and the last time that person was online.
!seen *!*@some.host.here.com - will give the most recent nicknames associated with that host and the last time that person was online.

Code: Select all

 set findnick [lsearch -glob [split [string tolower $nicklist]] *$nick*]
 set finduhost [lsearch -glob [split [string tolower $uhostlist]] *uhost*] 
Also, this part of your code is flawed. You use [string tolower] on a list, then you split the list into a list?? Perhaps you meant to do it the way I have below?

Code: Select all

 set findnick [lsearch -exact [split [string tolower [join $nicklist]]] [string tolower $nick]]
 set finduhost [lsearch -exact [split [string tolower [join $uhostlist]]] [string tolower $uhost]]
Notice I've used a join to turn the list into a string, which allows us to use the string command string tolower. Then we split the newly created string back into a list so lsearch can process it. This is how you should do it. Realize as well that you may need to test for -1 on both findnick and finduhost as that is the result of a negative lsearch (result not found). Also changed your glob wildcard search into an exact search because of the flaw explained below occuring here as well.

Also, while we are on the subject of flaws, you might want to change this approach.

Code: Select all

foreach user $nicklist {
 if {[string match -nocase "*$user*" $nick]} {
  set nickfound 1; break
  }
} 
You are string matching using wildcards which is bad. This means if someone has the nickname GGD they will match for the nickname EGGDROP as well. This is likely not what you had in mind. Perhaps the code below is better.

Code: Select all

foreach user $nicklist {
 if {[string equal -nocase $user $nick]} {
  set nickfound 1; break
  }
} 
And finally, how exactly is this supposed to work?

Code: Select all

set nicklist [list]
foreach entry $data {
 lappend nicklist [lindex [split $entry :] 0]
}

set uhostlist [list]
foreach entry $data {
 lappend uhostlist [lindex [split $entry :] 1]
} 
You realize you haven't opened the file for reading right? You haven't stored the file into a variable you can process. Literally what happens when eggdrop executes this, is that foreach will run only once because there is only one entry in $data that being "nicklist.txt". Entry will become "nicklist.txt". Then you attempt to split entry and lindex position 0 for nicklist, and position 1 for uhostlist using a colon as a delineator. Suffice it to say nicklist will always be literally "nicklist.txt" and uhostlist will be an empty null. The problem there is explained below, space vs colon. But for now what you need to do is open and read the file into a variable as I have done below.

Code: Select all

set file [open $data r]
set text [split [read $file] \n]
close $file
You would then use $text to build your nick and uhost lists exactly as your doing which will now be based on contents of the file, not on the contents of the filename.. :)

Now, just for sake of being complete here comes that issue of spaces vs colons:

Code: Select all

  puts $txt "$nick $uhost" 
The problem is your splitting on colon (:) not on space ( ). If you want the split to work you will need to change that to this:

Code: Select all

  puts $txt "$nick:$uhost" 
Or you can simply remove those colons from the split as I have below:

Code: Select all

 set nicklist [list]
foreach entry $data {
 lappend nicklist [lindex [split $entry] 0]
}

set uhostlist [list]
foreach entry $data {
 lappend uhostlist [lindex [split $entry] 1]
}
I realize this is alot for you to take in and possibly confusing as hell to anyone new to tcl. But afterall, this was posted in the scripting help section and hopefully some of what I've written helps.. :lol:

One tiny little little detail I completely overlooked so here it is at the bottom. go figure..haha

Code: Select all

proc join_onjoin {nick uhost hand chan} {
 global data
  set filename $data
  set txt [open $filename "a"]
  puts $txt "$nick $uhost"
  close $txt
} 
You've ended the procedure prematurely and left the rest of the code hanging in global space which runs once invoked at script load or rehash/restart. That part of the code won't be invoked by a bind to your join_onjoin procedure. You also have one too many bracings. The one happening after "close $txt" should be removed. Your also appending the file before you have tested to see if the nick is already contained within it. You will definitely need to relocate that part a little bit further down in the code. 8)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Here is something much more simpler and concise. It should do exactly as you want.

Code: Select all

# Nickname/Uhost tracker script
# Egghelp version, donations to slennox are welcomed. :P

# should duplicate nicknames be allowed?
# 0 = no, 1 and above = yes
set dupes 0

#your filename
set filename "nicklist.txt"

bind nick - * nick_nickchange
bind join - * join_onjoin

# make sure the file exists before we go to read it
# this initializes the file if it doesn't already exist
# and makes it blank to start with.
if {![file exists $filename]} {
   set file [open $filename "w"]
   close $file
}

# check for nick changes
proc nick_nickchange {nick uhost hand chan newnick} {
   join_onjoin $newnick $uhost $hand $chan
}

# check for joins
proc join_onjoin {nick uhost hand chan} {
   global filename dupes
   # keep everything lowercase for simplicity.
   set nick [string tolower $nick]
   set uhost [string tolower $uhost]
   # read the file
   set file [open $filename "r"]
   set text [split [read $file] \n]
   close $file
   # locate a duplicate host
   set found [lsearch -glob $text "*<$uhost"]
   if {$found < 0} {
      # host isn't found so let's append the nick and host to our file
      set file [open $filename "a"]
      puts $file "$nick<$uhost"
      close $file
   } else {
      # the host exists, so set our list of nicks for that host
      set nicks [lindex [split [lindex $text $found] "<"] 0]
      # is the nick already known for that host?
      set known [lsearch -exact [split $nicks ","] $nick]
      if {[expr {($known > 0) && ($dupes > 0)}]} {
         # if the nick is known return
         return
      } else {
         # otherwise add the nick to the nicks for that host
         set text [lreplace $text $found $found "$nicks,$nick<$uhost"]
      }
      # now lets write the new list to the file
      set file [open $filename "w"]
      foreach line $text {
         puts $file "$line"
      }
      close $file
   }
}

putlog "Nickname/Uhost tracker enabled."
This should create a file containing a list like below. The less-than sign was chosen to delineate because it should never appear in nicknames or uhosts. This also allows several people to use the same nickname at different times and will not confuse the script. Tracking is first done by uhost and only secondarily does it scan for duplicate nickname for that uhost. I've also added your overlooked nickchange, so if people change nick the script will track that as well.
It would be rather easy to add a pub bind to search this list for display onto irc so typing say !find nick, !find ident@*, !find *@host.com returns relevant information to irc. I will leave this part up to you as the part which creates the list gives away alot of tips on how to accomplish it.

EDIT: Corrected problem mentioned below regarding too many newlines (blank lines) in the file.
Last edited by speechles on Fri Jan 09, 2009 6:38 pm, edited 5 times in total.
i
ipone
Voice
Posts: 13
Joined: Mon Mar 20, 2006 7:00 am

Post by ipone »

that was so awesome, it works just like i want it. just some small fixes, i think.

When a person /hop the channel to rejoin it. And if he has the same nick that is already in the txt file it adds the same nick. for example.
you,yew,yoo,yoo,yoo,yoo,yoo<mike@154.153.149.70.cfl.res.rr.com
and also theres alot of blank lines in the txt file. like.

sam,sam|away,sam|food,sam|bed<~sam@c-24-9-173-138.hsd1.co.comcast.net

and then 10-15 blank lines then the next nick and host.

And you should know i really appreciate that you take your time and helped me with that script so far. And it was really confusing to try to understand what you posted in those last posts. But im really enjoying that you cut the script into pices. For me and everyone else i think its mutch easier to understand. :D

Cheers!
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Yep, I forgot puts will add the newline unless you specify -nonewline. Removed those excess newlines and also added a configuration variable to allow duplicate nicknames or not. Amended the code above for you, this should be exactly what your looking for now.. Have fun. :lol:
i
ipone
Voice
Posts: 13
Joined: Mon Mar 20, 2006 7:00 am

Post by ipone »

now i feel like a pain in the ass, :D but it still dosent work, updated with the script you edited. and det txt still looks like this.


Heres a part of the txt file, just so you know how it looks for me. Note for example the user 'nibbb' has the same nick three times on the same line. That user join/parted the channel.
mrlolrofl,nizzleeee<~user@77.21.226.112
nibbb,nibbb,nibbb<~danielsen@84.53.42.196

psykos-<~fack71@c83-252-252-215.bredband.comhem.se
winc123,winc,winc123,winc<~fcdwsv@cpc2-pete1-0-0-cust845.pete.cable.ntl.com

dmitri<~for@hst-155-42.telelanas.lt



mlvs,mlvs,mlvs<~lsybrandt@084202108242.customer.alfanett.no
haydenn<shader__@cable-vlk-fef6f900-119.dhcp.inet.fi

dartik<dart@taisya.adsl.kis.ru
man1339<~bjorkman_@h178n1c1o1038.bredband.skanova.com
fischaaaa<~suosdouf@81-233-122-169-no79.tbcn.telia.com
cajan^pea<~next17@cpc2-pete1-0-0-cust845.pete.cable.ntl.com
gp|extreme<~seekandde@d54c69a80.access.telenet.be

asknakd<~kakd@78-69-59-136-no153.tbcn.telia.com

digydigy1d,cocoricco,ayouhou<nila@86.123.210.234




replaayy<replaayy@c-40bce255.09-295-6c756c10.cust.bredbandsbolaget.se
medved<~medvedjke@79-126-51-134.dynamic.mts-nn.ru
dare<~krille_al@90-230-131-62-no130.tbcn.telia.com
[old]spenan<spenan@pc193.net114.koping.net
fafa<~bollon252@90-231-213-39-no124.tbcn.telia.com
himkhjell[cb]<1839messo@cpc1-flit2-0-0-cust146.lutn.cable.ntl.com
zlaktarn^<~zlaktarn^@c-808be155.329-1-64736c12.cust.bredbandsbolaget.se
sniper87<sniper@sniper87.users.quakenet.org
vessia|jozzika<~niko_holl@ccbb9bf51.dhcp.bluecom.no
fixnix^<~christerc@ti0011a380-dhcp1050.bb.online.no
outrage<~outrage3@77.125.161.39

henken,henken<jonte_____@c-44-178-255-94.3.cust.bredband2.com
ailton<tapav@184-18-124-91.pool.ukrtel.net
gamerteam<~mandrut_j@79.118.146.195




Ive tryed to set dupes to 0 but it still will duplicate nicks :S
im really confused at this moment.

I dont know if this have anything to do with the problem, but the channel that the bot is in, have alot of traffic. its like on 5min there are like 15 new users in the channel, then 5mins after that theres 15-20 new users

And how the script is, that is exactly what i have been looking for, exept that the database works. ;)

Cheers!
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

# Nickname/Uhost tracker script
# Egghelp version, donations to slennox are welcomed. :P

# should duplicate nicknames be allowed?
# 0 = no, 1 and above = yes
set dupes 0

#your filename
set filename "nicklist.txt"

bind nick - * nick_nickchange
bind join - * join_onjoin

# make sure the file exists before we go to read it
# this initializes the file if it doesn't already exist
# and makes it blank to start with.
if {![file exists $filename]} {
   set file [open $filename "w"]
   close $file
}

# check for nick changes
proc nick_nickchange {nick uhost hand chan newnick} {
   join_onjoin $newnick $uhost $hand $chan
}

# check for joins
proc join_onjoin {nick uhost hand chan} {
   global filename dupes
   # keep everything lowercase for simplicity.
   set nick [string tolower $nick]
   set uhost [string tolower $uhost]
   # read the file
   set file [open $filename "r"]
   set text [split [read $file] \n]
   close $file
   # locate a duplicate host
   set found [lsearch -glob $text "*<$uhost"]
   if {$found < 0} {
      # host isn't found so let's append the nick and host to our file
      set file [open $filename "a"]
      puts $file "$nick<$uhost"
      close $file
   } else {
      # the host exists, so set our list of nicks for that host
      set nicks [lindex [split [lindex $text $found] "<"] 0]
      # is the nick already known for that host?
      set known [lsearch -exact [split $nicks ","] $nick]
      if {[expr {($known != -1) && ($dupes < 1)}]} {
         # if the nick is known return
         return
      } else {
         # otherwise add the nick to the nicks for that host
         set text [lreplace $text $found $found "$nicks,$nick<$uhost"]
      }
      # now lets write the new list to the file
      set file [open $filename "w"]
      foreach line $text {
         if {[string length $line]} { puts $file "$line" }
      }
      close $file
   }
}

putlog "Nickname/Uhost tracker enabled."
For dupes I had it backwards my bad. It will now work correctly. Also added detection for blank lines when rewriting the file. This should strip blank lines out when rewriting. Try the script above let me know how that works. :)

Edit: Corrected duplicate nick issue, hopefully.
Last edited by speechles on Sat Jan 10, 2009 11:15 am, edited 1 time in total.
i
ipone
Voice
Posts: 13
Joined: Mon Mar 20, 2006 7:00 am

Post by ipone »

Really loves your fast answers. :D

But sadly its still duplicating the nicks, But there are not any blank lines, that one works now. So just one problem left and thats the duplicate.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

ipone wrote:But sadly its still duplicating the nicks, But there are not any blank lines, that one works now. So just one problem left and thats the duplicate.
Try the edited script above. Had a slight bug with lindex positions.
i
ipone
Voice
Posts: 13
Joined: Mon Mar 20, 2006 7:00 am

Post by ipone »

Well now it works! and i really love it! cannot thank you enough!

Can mark it as [SOLVED] :D

edit: and i renamed it.
m
manipulativeJack
Voice
Posts: 13
Joined: Tue Feb 17, 2009 9:52 pm

Post by manipulativeJack »

Been trying for hours now and I am unable to determine a way to use this to display nicks in channel (or pm, or dcc) ...I would like something like this:

!nicks joe

<bot> joe has also been joe1, joe2 and sam32

or maybe something on the partyline when someone joins a channel?

joe has joined #channel
<bot partyline> joe has joined #channel - joe has also been joe1,joe2

...anyone willing to help?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

manipulativeJack wrote:Been trying for hours now and I am unable to determine a way to use this to display nicks in channel (or pm, or dcc) ...I would like something like this:

!nicks joe

<bot> joe has also been joe1, joe2 and sam32

or maybe something on the partyline when someone joins a channel?

joe has joined #channel
<bot partyline> joe has joined #channel - joe has also been joe1,joe2

...anyone willing to help?

Code: Select all

# is the nick already known for that host?
set known [lsearch -exact [split $nicks ","] $nick]
Change that part above to look like it is.. below

Code: Select all

# is the nick already known for that host?
set nlist [split $nicks ","]
if {[set pos [lsearch $nlist $nick]] != -1} { set nlist [lreplace $nlist $pos $pos] }
putserv "privmsg $chan :$nick is also known as :[join $nlist ", "]."
set known [lsearch -exact [split $nicks ","] $nick]
That should announce in channel. To do it thru partyline would require an idx channel, or you can putlog it if your console is +d for debug. Change the putserv to putlog and remove the privmsg $chan : part.

I enjoy retouching scripts I made long ago giving them new breath of life.. haw
m
manipulativeJack
Voice
Posts: 13
Joined: Tue Feb 17, 2009 9:52 pm

Post by manipulativeJack »

Let me first say how much I really appreciate the work that you do here for all of us. I can not speak for others but looking at the hundreds of comments I know others really appreciate your work as well. I myself use one or another of your scripts nearly every day.

That said... ;)


[04:06:24] Tcl error [nick_nickchange]: wrong # args: should be "set varName ?newValue?"
[04:06:30] Tcl error [nick_nickchange]: wrong # args: should be "lreplace list first last ?element element ...?"

has been popping up upon nick changes and nothing at all happens on join

edit: This happens on join in the bot logs (still nothing in channel):
[04:19:57] Tcl error [join_onjoin]: wrong # args: should be "lreplace list first last ?element element ...?"

The script also seems to only be showing one of the many possible nicks someone has used ... starting to wonder if I pasted/edited something wrong, though I have checked multiple times!

I by no means expect you to just jump up and fix this but I do wonder what is going on. I have been poking at it myself but am just making it worse. I have been looking over some tcl learning sources as I would really love to be able to give back to the community in the way you have.

That said again, any ideas? :)

(I also noticed that the nick case is not saved or relayed, is that a major change or just a little tweak?)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

# Nickname/Uhost tracker script
# Egghelp version, donations to slennox are welcomed. :P

# should duplicate nicknames be allowed?
# 0 = no, 1 and above = yes
set dupes 0

#your filename
set filename "nicklist.txt"

bind nick - * nick_nickchange
bind join - * join_onjoin

# make sure the file exists before we go to read it
# this initializes the file if it doesn't already exist
# and makes it blank to start with.
if {![file exists $filename]} {
   set file [open $filename "w"]
   close $file
}

# check for nick changes
proc nick_nickchange {nick uhost hand chan newnick} {
   join_onjoin $newnick $uhost $hand $chan
}

# check for joins
proc join_onjoin {nick uhost hand chan} {
   global filename dupes
   # keep everything lowercase for simplicity.
   set nick [string tolower $nick]
   set uhost [string tolower $uhost]
   # read the file
   set file [open $filename "r"]
   set text [split [read $file] \n]
   close $file
   # locate a duplicate host
   set found [lsearch -glob $text "*<$uhost"]
   if {$found < 0} {
      # host isn't found so let's append the nick and host to our file
      set file [open $filename "a"]
      puts $file "$nick<$uhost"
      close $file
   } else {
      # the host exists, so set our list of nicks for that host
      set nicks [lindex [split [lindex $text $found] "<"] 0]
      # is the nick already known for that host?
      set nlist [split $nicks ","]
      if {[set pos [lsearch $nlist $nick]] != -1} { set nlist [lreplace $nlist $pos $pos] }

      # MAKE SURE TO READ THE COMMENTS BELOW

      # To make it output to channel remove the # the begins the line below.
      #if {[string length [join $nlist]]} { putserv "privmsg $chan :$nick is also known as :[join $nlist ", "]." }

      # To make it output to partyline remove the # the begins the line below.
      #if {[string length [join $nlist]]} { putloglev d * "*** $nick on $chan is also known as :[join $nlist ", "]." }

      set known [lsearch -exact [split $nicks ","] $nick]
      if {($known != -1) && ($dupes < 1)} {
         # if the nick is known return
         return
      } else {
         # otherwise add the nick to the nicks for that host
         set text [lreplace $text $found $found "$nicks,$nick<$uhost"]
      }
      # now lets write the new list to the file
      set file [open $filename "w"]
      foreach line $text {
         if {[string length $line]} { puts $file "$line" }
      }
      close $file
   }
}

putlog "Nickname/Uhost tracker enabled."
Thanks for the compliments... :)
Try the script above. It should announce the alternate nicknames used, on join and nick changes. I haven't tested it but I see no reason why it wouldn't work.
Post Reply