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.

CloneScanner Showing Too Many results

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

CloneScanner Showing Too Many results

Post by ComputerTech »

Hello all me and my friend made this script it's a simple clonescanner that has two options pm/notices the user of what clones there is or simply kickbans the clones so far it's been good, but there is a problem once the clones are kickbanned i remove the ban and make the clone return the bot kicks the clone right away without me typing !clonescan

Geo on freenode #eggdrop told me to put this line

Code: Select all

putlog $cloneslist
before the kick and it gave these results

http://paste.tclhelp.net/?id=6jd6

by the way my two test clones are kai and black

so here is the script


Code: Select all

set sect "1"

namespace eval ::CloneScan {

	bind pub o|o !clonescan ::CloneScan::clonescan

	proc areClones { user other chan } {
		if {$user == $other} {
			return 0
		}
		if {[getchanhost $user $chan] == [getchanhost $other $chan]} {
			return 1
		}
		return 0
	}
	proc listClones { user chan } {
		set clones {}
		foreach other [chanlist $chan] {
			if {[areClones $user $other $chan]} {
				lappend clones $other
			}
		}
		if {[llength $clones]} {
			lappend clones $user
		}
		return $clones ;
	}

	proc clonescan {nick host hand chan arg} {
		global sect
		set userlist [chanlist $chan]
		set cloneslist {}
		set banlist {}
		foreach user $userlist {
			# if user has been detected as clone before, no need to check again!
			if {[lsearch -exact $cloneslist $user] != -1} {
				continue
			}
			set clones [listClones $user $chan]
			foreach clone $clones {
				lappend cloneslist $clone
			}
			lappend banlist [lindex $clones 0]
		}
		if {$sect == "1"} {
			foreach nik $banlist {
				set uhost [getchanhost $nick $chan]
				set mask $host
				foreach nick $cloneslist {
					putlog $cloneslist
                               pushmode $chan +b $host; after 200 putkick $chan $nick <3
			
                           }
			}
		}
		if {$sect == "0"} {
			set realusers {}
			foreach user $userlist {
				if {[lsearch -exact $cloneslist $user] == -1} {
					lappend realusers $user
				}
			}
			set numreal [llength $realusers]
			set numclones [llength $cloneslist]
			putserv "PRIVMSG $chan :CloneScan: There are $numreal real users on $chan ($numclones clones found)."
			putserv "PRIVMSG $chan :CloneScan: The clones are: [join $cloneslist]"

		}
	}
} ;#end namspace CloneScan
cheers all who help me with this in advanced :)
ComputerTech
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

See if this taken from another topic (link) works:

Code: Select all

namespace eval clonescan {
   variable trigger "."
   
   bind pub m|o "${trigger}clone" [namespace current]::clonescan
   bind pub m|o "${trigger}clones" [namespace current]::clonescan
   
   proc checknick {nick} {
      set skip [list "S" "Q"]
      set test [expr {[lsearch -nocase $skip $nick] > -1 ? "1" : "0"}]
   }

   proc clonescan {nick uhost hand chan text} {
      puthelp "PRIVMSG $chan :Starting clonescan for $chan..."
      set start [clock clicks]
      foreach user [chanlist $chan] {
         if {[checknick $user] || [isbotnick $user]} continue
            set host [lindex [split [getchanhost $user $chan] @] 1]
            lappend clones($host) $user
      }
      set total 0
      set count 0
      foreach host [array names clones] {
         set len [llength $clones($host)]
         if {$len > 1} {
            set nickList [join [join $clones($host)] ", "]
            puthelp "PRIVMSG $chan :\($host\) Nick list: $nickList - Clones: [expr $len - 1]"
            incr count $len
         }
         incr total $len
      }
      set p(c) [expr {$total > 0 ? [format %.1f [expr ($count.0 * 100.0) / $total.0]] : "0.0"}] 
      set p(u) [expr (100.0 - $p(c))]
      set end [clock clicks]
      puthelp "PRIVMSG $chan :Clones: $count ($p(c)%) | Real users: [expr ($total - $count)] ($p(u)%) | Took: [expr ($end-$start)/1000.0]ms."
   }
}
and we can add the punishment later.
Once the game is over, the king and the pawn go back in the same box.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Alright so i tested the script you provided me and here is the results.

Code: Select all

<Techy> Starting clonescan for ##computertech123...
<Techy> (bitcoinshell.mooo.com) Nick list: Kai, BLACK - Clones: 1
<Techy> (unaffiliated/computertech) Nick list: CT123, ComputerTech - Clones: 1
<Techy> Clones: 4 (12.1%) | Real users: 29 (87.9%) | Took: 0.427ms.
seems to work pretty good


my not need the percentage info %

but it seems awesome :D

maybe this would need changed

Code: Select all

<Techy> (bitcoinshell.mooo.com) Nick list: Kai, BLACK - Clones: 1

Code: Select all

since there was Two clones the results would need to be Clones: 2
prehaps we could change that to my liking hehe ;)
and add a punishment as you mentioned above

also cheers caesar in advanced appreciate your help :D
ComputerTech
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

In the original topic first was considered "human" and the second one was the clone, hence the numbers says 1 clone.

Anyway, so, basically you want on-command to scan and punish clones if are more than specified amount? I've linked to this old code cos I found the percentage interesting. :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

yeah i do like the percentage thing thats cool
so i'll keep it

what i want is for me to be able to set two options

to scan for clones and if over set amount privmsg me

and for the other option


to simply kickban all clones if over set amount :D

and also dont want this script to scan for clones when they join, i want this script to simply only activate on command :)
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

now i tried to edit the clonescanner you gave me and here's as far as i got so far

Code: Select all


       set trigger "!"
       
       set ghz "1"     
  
       bind pub -|- "${trigger}clones" [namespace current]::clonescan
       
    
       proc clonescan {nick uhost hand chan text} {
          global ghz
          puthelp "NOTICE $nick :Starting clonescan for $chan..."
          set start [clock clicks]
          foreach user [chanlist $chan] {
             if {[checknick $user] || [isbotnick $user]} continue
                set host [lindex [split [getchanhost $user $chan] @] 1]
                lappend clones($host) $user
          }
          set total 0
          set count 0
          if {$ghz == "0"} {
           foreach host [array names clones] {
             set len [llength $clones($host)]
             if {$len > 1} {
                set nickList [join [join $clones($host)] ", "]
                puthelp "NOTICE $nick :\($host\) Nick list: $nickList - Clones: [expr $len - 1]"
           	   }
             if {$ghz == "1"} {
            foreach cloneXz $nickList {putnow "kick $chan $cloneXz"}
          }

                incr count $len
             }
             incr total $len

  }
}
not sure if you see what i'm trying to do, but i hope you can help me out what i'm doing wrong

if i set

Code: Select all

set ghz "1"
it privmsg's me of the clones which is good but when i set it to 0 it just stays at

-Techy- Starting clonescan for ###789...

so not sure what i'm doing wrong hehe cheers :D

and after i get this going i will tidy the script up hehe
ComputerTech
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Untested code:

Code: Select all

namespace eval clonescan {

	set trigger "!"
	set ghz "1"     
	set skip { "S" "Q" }

	bind pub -|- "${trigger}clones" [namespace current]::clonescan

	proc checknick {nick} {
		variable skip
		set test [expr {[lsearch -nocase $skip $nick] > -1 ? "1" : "0"}]
	}
   
	proc clonescan {nick uhost hand chan text} {
		global ghz
		puthelp "NOTICE $nick :Starting clonescan for $chan..."
		foreach user [chanlist $chan] {
			if {[checknick $user] || [isbotnick $user]} continue
			set host [lindex [split [getchanhost $user $chan] @] 1]
			lappend clones($host) $user
		}
		switch -- $ghz {
			0 {
				foreach host [array names clones] {
					set len [llength $clones($host)]
					if {$len > 1} {
						set nickList [join [join $clones($host)] ", "]
						puthelp "NOTICE $nick :\($host\) Nick list: $nickList - Clones: [expr $len - 1]"
						incr count $len
					}
				}
			}
			1 {
				set kickList {}
				set banList {}
				foreach host [array names clones] {
					set len [llength $clones($host)]
					if {$len > 1} {
						lappend kickList [join $clones($host)]
						lappend banList "*!*@$host"
					}
				}
				stackBans $chan $banList
				stackKicks $chan $kicklist "We don't like clones."
			}
			default { return }
		}
	}
	
	proc stackBans {chan banlist} {
		set max 25
		set count [llength $banlist]
		while {$count > 0} {
			if {$count> $max} {
				set mode [string repeat "b" $max]
				set masks [join [lrange $banlist 0 [expr {$max - 1}]]]
				set banlist [lrange $banlist $max end]
				incr count -$max
				incr total $max
			 } else {
				set mode [string repeat "b" $count]
				set masks [join $banlist]
				incr total $count
				set count 0
			}
			puthelp "MODE $chan +$mode $masks"
		}
   }
   
   proc stackKicks {chan kicklist reason} {
		set max 25
		set count [llength $kicklist]
		while {$count > 0} {
			if {$count > $max} {
				set users [join [lrange $kicklist 0 [expr {$max - 1}]] ","]
				set kicklist [lrange $kicklist $max end]
				incr count -$max
			} else {
				set users [join $kicklist ","]
				set count 0
			}
			puthelp "KICK $chan $users :$reason"
		}
	}
}
Typo fixed.
Last edited by caesar on Tue May 26, 2020 10:49 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

getting this error

Code: Select all

Tcl error [::clonescan::clonescan]: can't read "skip": no such variable
also not sure if this helps but..

http://paste.tclhelp.net/?id=6jeu

would that error cause a problem?
ComputerTech
Online
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Simple typo.
Look for where the variable is set.
See the difference in: kicklist and kickList .
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Oh, forgot about this post heh, i'll try the fixed version and report back

Cheers in advanced caesar :)
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

That worked great caesar, cheers :D
ComputerTech
Post Reply