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.
k
kingkong
Voice
Posts: 10
Joined: Sun Apr 08, 2012 5:02 am

Post by kingkong »

speechles wrote:...

hi. on this last code, i have been experienced some issue on my needs. as first, i want to use outputs in one specific channel and/or make a udef channel flag to enable announces. i don't want script will announce in all channels. i want that will announce only in 1 channel or in some channels the bot is in. it should not repeat the output if it's working in one channel but user joins more than one common channels with the bot. and another fork is it doesn't trim the message lenghts on max char limits. for example, if max char as 250 per msg, it doesn't care this. continues till the end of line and ends up at there. it should trim and continue from the second line. it would be fine if there will be !forget nick function to delete a nick on the txt too. and only allowed persons would use this !forget function. i hope, it's not much :)

Plus that the post channel should be able to set different than the monitored channel. simply, it will monitor in all bot channels but announce will be for example in specified channel only (it will no repeat the output if user will join more than one bot channels in that case, it will give 1 output if so). or if we set the announces for more than one channel, it will work in this same way too. saves from all monitored channels but announce will be in flagged channel(s) only.
Last edited by kingkong on Sun Mar 03, 2013 3:36 am, edited 4 times in total.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Here's a channel specific version of the script, using 'setudef flag nicktrack'

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 

setudef flag nicktrack

# 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} { 
   if {![channel get $chan "nicktrack"]} {  return 0  }
   join_onjoin $newnick $uhost $hand $chan 
   return 0
} 

# check for joins 
proc join_onjoin {nick uhost hand chan} { 
   global filename dupes 
   if {![channel get $chan "nicktrack"]} {  return 0  }
   # 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 
   } 
   return 0
} 

putlog "Nickname/Uhost tracker enabled."

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
k
kingkong
Voice
Posts: 10
Joined: Sun Apr 08, 2012 5:02 am

Post by kingkong »

thanks SpiKe^^ you're very quick :) i have edited my post to mention somethings important too. i hope, announces will be able to set different than monitored channels. thanks for quick response and help :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I believe this is much closer to what you were looking for.
Will monitor all channels the bot is on, for joins and nick changes.
Will then report all other nicks that uhost has also been know as,
to all channels and/or nicks listed in the 'report_to' setting.

Script is completely untested, so let me know how it works out.

Code: Select all

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

# Revised version by SpiKe^^ (5 Mar 2013) #

# set your filename 
set filename "nicklist.txt" 

# set the channel(s) and/or nick(s) to report the nick info to
# space separated list
# example:  set report_to {#chanadmin}
# example:  set report_to {#admin #chan2 bart ted}
set report_to {#somechannel}

# set the number of seconds not to report on the same nick
set nk_recent "15"

# set the maximum number of lines to keep in the file
# the oldest last seen uhosts/nicks will be deleted from the file
set file_max "100"

# set the maximum number of chars to use for a line of text
set char_max "350"

# set the text to use for the beginning of each line sent
set txt_pre "%nick% is also known as :"

# set the text to use for the separator between the nicks
set txt_sep ", "

################### END OF SETTINGS ###################

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 
} 

set report_to [split $report_to]

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

# check for joins 
proc join_onjoin {nick uhost hand chan} { 
   global filename report_to nk_recent file_max char_max txt_pre txt_sep nktrack
   # see if this nick has been reported in last $nk_recent seconds
   set nklow [string tolower $nick]
   if {[llength [set recent [array names nktrack]]]>"0"} {
      set old [expr {[unixtime]-$nk_recent}]
      set fnd 0
      foreach ename $recent {
        if {$nktrack($ename)<$old} {  unset nktrack($ename)
        } elseif {$ename eq $nklow} {  set fnd 1  }
      }
      if {$fnd=="1"} {  return 0  }
   }
   set nktrack($nklow) [unixtime]
   # keep uhost lowercase for simplicity. 
   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 in the file 
      set nlist [list $nick]
   } else { 
      # the host exists, so set our list of nicks for that host 
      set nicks [lindex [split [lindex $text $found] "<"] 0]
      set nlslow [split [string tolower $nicks] ","]
      set nlist [split $nicks ","] 
      # remove the found line from the text
      set text [lreplace $text $found $found]
      # is the nick already known for that host? 
      if {[set pos [lsearch $nlslow $nklow]]>"-1"} { set nlist [lreplace $nlist $pos $pos] }
      # if nick is also known as someone else, say so
      if {[llength $nlist]>"0"} {
        set pre [string map [list %nick% $nick] $txt_pre]
        set tmp $pre[join $nlist $txt_sep]
        if {[string length $tmp]<=$char_max} {
          foreach tgt $report_to {  putserv "privmsg $tgt :$tmp"  }
        } else {  set tmp $pre[lindex $nlist 0]
          foreach nk [lrange $nlist 1 end] {
            set nx $tmp$txt_sep$nk
            if {[string length $nx]>$char_max} {
              foreach tgt $report_to {  putserv "privmsg $tgt :$tmp"  }
              set tmp $pre$nk
            } else {  set tmp $nx  }
          }
          foreach tgt $report_to {  putserv "privmsg $tgt :$tmp"  }
        }
      }
      lappend nlist $nick
   } 
   # write the new file, this uhost and nicks first
   set file [open $filename "w"]
   puts $file [join $nlist ","]<$uhost  ;  set cnt 1
   foreach line $text {
     if {[string length $line]} {  puts $file "$line"  ;  incr cnt  }
     if {$cnt==$file_max} {  break  }
   } 
   close $file 
   return 0
} 

putlog "Nickname/Uhost tracker enabled."

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
k
kingkong
Voice
Posts: 10
Joined: Sun Apr 08, 2012 5:02 am

Post by kingkong »

SpiKe^^ wrote:I believe this is much closer to what you were looking for.
Will monitor all channels the bot is on, for joins and nick changes.
Will then report all other nicks that uhost has also been know as,
to all channels and/or nicks listed in the 'report_to' setting.

Script is completely untested, so let me know how it works out.

Code: Select all

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

# Revised version by SpiKe^^ (5 Mar 2013) #

# set your filename 
set filename "nicklist.txt" 

# set the channel(s) and/or nick(s) to report the nick info to
# space separated list
# example:  set report_to {#chanadmin}
# example:  set report_to {#admin #chan2 bart ted}
set report_to {#somechannel}

# set the number of seconds not to report on the same nick
set nk_recent "15"

# set the maximum number of lines to keep in the file
# the oldest last seen uhosts/nicks will be deleted from the file
set file_max "100"

# set the maximum number of chars to use for a line of text
set char_max "350"

# set the text to use for the beginning of each line sent
set txt_pre "%nick% is also known as :"

# set the text to use for the separator between the nicks
set txt_sep ", "

################### END OF SETTINGS ###################

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 
} 

set report_to [split $report_to]

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

# check for joins 
proc join_onjoin {nick uhost hand chan} { 
   global filename report_to nk_recent file_max char_max txt_pre txt_sep nktrack
   # see if this nick has been reported in last $nk_recent seconds
   set nklow [string tolower $nick]
   if {[llength [set recent [array names nktrack]]]>"0"} {
      set old [expr {[unixtime]-$nk_recent}]
      set fnd 0
      foreach ename $recent {
        if {$nktrack($ename)<$old} {  unset nktrack($ename)
        } elseif {$ename eq $nklow} {  set fnd 1  }
      }
      if {$fnd=="1"} {  return 0  }
   }
   set nktrack($nklow) [unixtime]
   # keep uhost lowercase for simplicity. 
   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 in the file 
      set nlist [list $nick]
   } else { 
      # the host exists, so set our list of nicks for that host 
      set nicks [lindex [split [lindex $text $found] "<"] 0]
      set nlslow [split [string tolower $nicks] ","]
      set nlist [split $nicks ","] 
      # remove the found line from the text
      set text [lreplace $text $found $found]
      # is the nick already known for that host? 
      if {[set pos [lsearch $nlslow $nklow]]>"-1"} { set nlist [lreplace $nlist $pos $pos] }
      # if nick is also known as someone else, say so
      if {[llength $nlist]>"0"} {
        set pre [string map [list %nick% $nick] $txt_pre]
        set tmp $pre[join $nlist $txt_sep]
        if {[string length $tmp]<=$char_max} {
          foreach tgt $report_to {  putserv "privmsg $tgt :$tmp"  }
        } else {  set tmp $pre[lindex $nlist 0]
          foreach nk [lrange $nlist 1 end] {
            set nx $tmp$txt_sep$nk
            if {[string length $nx]>$char_max} {
              foreach tgt $report_to {  putserv "privmsg $tgt :$tmp"  }
              set tmp $pre$nk
            } else {  set tmp $nx  }
          }
          foreach tgt $report_to {  putserv "privmsg $tgt :$tmp"  }
        }
      }
      lappend nlist $nick
   } 
   # write the new file, this uhost and nicks first
   set file [open $filename "w"]
   puts $file [join $nlist ","]<$uhost  ;  set cnt 1
   foreach line $text {
     if {[string length $line]} {  puts $file "$line"  ;  incr cnt  }
     if {$cnt==$file_max} {  break  }
   } 
   close $file 
   return 0
} 

putlog "Nickname/Uhost tracker enabled."



Hello. Thanks a lot SpiKe^^ for this patch. it works nice and solves the ex problems indeed. i was testing it enough of time and saw some needs or minor issues which i will state here now.

-script should have an exempt flags setting... so it doesnt try to track the bots or known users. it would be nice if i will not need to add this user on bot's .user file but script may creates it's own exempt file for this purpose maybe. or the better option is to point the user on nicklist.text file on source without create another file. for my opinion, if i ran "!exempt ip" command in the channel, the script will add # sign at the beginning of line in nicklist.text for this nick's ip. so, it will not match or announce it on nick changes or joins. if you have better idea, it's ok too. (i am using only ip numbers to catch users. no idents included on my edited script, so, just cloaked ip's as *!*@ip.here on each nick is assigned on nicklist.text at my own patched script) if i will use !exempt nick then it may cause problem coz some users not registered their nicks and it will exempt to other users who used same nick too. i meant, so many different users can use the same nick. it may cause problem. that's why ip exempt better way. it shouldn't track exempted ip.

-!forget ip same as mentioned !exempt ip on above.

-if nick begins with [ sign then output being wrong. maybe it's having problem with ^ or ' and other signs, i'm not sure but sometimes outputs seems as weird and not alphanumeric. showing just random unrecognized signs. sometimes my nicklist.txt file being delete and lost. it begins from zero. i don't know why happens so, but i'm suspecting from those kinds of signs maybe creates problem while reading or writing?

-it would be nice if we can add some nicks to be exempted as Guest_997 Guest_998 Guest_999 etc. coz some users using only as Guest nicknames and they're having 200 old nicknames to be seen.

-use lreverse to show it the other direction. it would be better as like "NewNick < BeforeTheNewNick | blah2 | blah1" because now it's showing latest nick as in the end of list. oldest is on the beginning. On view it would be better if nicks will be shown from left to right. on left side, the latest nick will seem better.

-the commands would be able to run by bot ops. not by everyone.

- if {[isbotnick $nick]} { return 0 } so that bot should ignore his own joins. yeah and other bots joins etc? now bot announce repeats his own nick X times in a row on restarts or his own joins. bot should not announce hiw own and maybe owner|botops nicknames. :)

- i don't know why but nicklist.txt file starts from zero by itself on sometimes and i can't know when it happens. deletes the whole file and begins from zero. i need a backup system and automatic deletion to this backup files. ( i already wrote a script to make backups but need an automation to delete them. also, i can't know when the file returns to zero, that's the problem )

- there is biggest problem is that;

IP: 0E57D4.321A87.81A6DF.C1410C Realname: (BB1831196912) and IP: 0E57D4.321A87.81A6DF.A9F7A2 Realname: (BB1831196912)

those are two different ips and different users. but script shows them as same user. it's incorrect. if it's because of Realname part? can fix this please?

thanks a lot for all and script. :)
Last edited by kingkong on Sat Jun 01, 2013 8:53 am, edited 1 time in total.
h
hayuto
Voice
Posts: 14
Joined: Tue May 28, 2013 6:52 pm

Post by hayuto »

anyone know a script that could tell if someone uses a nick of a person from text file? i mean i would put known hosts and nock they uses to text file the script would alert the channel, not even kick, that this isnt really the peron we know?
Post Reply