Spartan,
This is the way I see that script request...
Script checks everyone joining the channel, see if they should be allowed to stay.
A trusted nick must meet at least one of these tests:
1) handle has any exempt flags
2) user matches an exempt hostmasks
- if still not a trusted nick, /whois nick...
3) is using a secure connection
4) is connecting via webirc
All other nicks are now judged as not trusted and could be ban/kicked?
Here's a script along those lines...
Code: Select all
#### whos.tcl ver 0.1 (17May2022) ####
namespace eval whos { variable whos
##### begin settings #####
# Channel(s) where bot to check on joins OR set to {*} for all channels
set whos(chans) {*}
# Exempt: hostmask(s) to not check on join
set whos(xmasks) {*!*@*.irccloud.com *!*@*.mibbit.com}
# Exempt: flag(s) to not check on join
set whos(xflags) "bfmno|bfmno"
# Bans: set channel ban(s) on the offenders?? (0 = no || 1 = yes)
set whos(dobans) 0
# Bans: set the type of banmask to use
# 0 = *!user@host
# 1 = *!*user@host
# 2 = *!*@host
# 3 = *!*user@*.host
# 4 = *!*@*.host
set whos(masktype) 2
# Bans: set ban time in minutes
# 0 = this script doesn't remove these bans
set whos(bantime) 5
# Kicks: kick offenders from the channels?? (0 = no || 1 = yes)
set whos(dokick) 0
# Kicks: set a custom reason to use when kicking offenders
set whos(reason) ""
# Modes: channel modes to set when an offender joins the channel??
set whos(domode) "+RN"
# Modes: remove the above channel modes after how many minutes?
# 0 = this script doesn't remove these modes
set whos(modetime) 2
###### end settings ######
setudef flag [set whos(udflag) [string trim [namespace current] ":"]]
set whos(chans) [split [string tolower [string trim $whos(chans)]]]
set whos(xmasks) [split [string trim $whos(xmasks)]]
set whos(xflags) [string trim $whos(xflags)]
if {$whos(bantime) > 0} { set whos(bantime) [expr {$whos(bantime) * 60}] }
set whos(reason) [string trim $whos(reason)]
set whos(domode) [string trim $whos(domode)]
if {$whos(domode) ne ""} {
if {![string match {[-+]?*} $whos(domode)]} { set whos(domode) +$whos(domode) }
if {$whos(modetime)>0} { set whos(unmode) [string map {+ - - +} $whos(domode)] }
}
if {$whos(modetime) > 0} { set whos(modetime) [expr {$whos(modetime) * 60}] }
############
bind join - * [namespace current]::onjoin
proc onjoin {nk uh hn ch} {
if {[isbotnick $nk]} { return 0 } ;# this Bot is Exempt from this script #
variable whos
putlog "proc onjoin : nk=($nk) uh=($uh) hn=($hn) ch=($ch)"
if {$hn ne "*" && $whos(xflags) ne ""} { ;# check if handle has any Exempt Flags #
if {[matchattr $hn $whos(xflags) $ch]} { return 0 }
}
set c [string tolower $ch] ; set validch 0 ;# check if is in a Valid Channel #
if {[channel get $ch $whos(udflag)]} { set validch 1 }
if {$whos(chans) eq "*" || $c in $whos(chans)} { set validch 1 }
if {$validch == 0} { return 0 }
foreach xmask $whos(xmasks) { ;# check if matches an Exempt Hostmask #
if {[matchaddr $xmask ${nk}!$uh]} { return 0 }
}
set n [string tolower $nk] ; set now [clock milliseconds]
set id "${c},$n"
set joininfo [dict create ms $now nik $nk uho $uh hnd $hn cha $ch]
if {![info exists whos(joinque)]} {
set whos(joinque) [dict create $id $joininfo]
putlog " sent1: WHOIS $nk ..." ;# <<== #################
putserv "WHOIS $nk" ; return 0
}
####
set jqlist [dict keys $whos(joinque) "*,$n"]
if {![llength $jqlist]} {
dict set whos(joinque) $id $joininfo
putlog " sent2: WHOIS $nk ..." ;# <<== #################
putserv "WHOIS $nk" ; return 0
}
if {$id in $jqlist} {
## Do something, maybe? #channel,nick :already in $whos(joinque) ##
return 0
}
dict set whos(joinque) $id $joininfo
####
return 0
} ;# end: proc onjoin
############
bind raw - 311 [namespace current]::onraw ;# "rname (realname)"
bind raw - 671 [namespace current]::onraw ;# "secure"
bind raw - 320 [namespace current]::onraw ;# "country & webirc"
bind raw - 318 [namespace current]::onraw ;# "done"
proc onraw {from num txt} {
putlog "=> proc onraw : from=($from) num=($num) txt=($txt)"
variable whos
if {![info exists whos(joinque)]} { return 0 }
set tx [join [lassign [split $txt] bot target]]
set tgt [string tolower $target]
set jqlist [dict keys $whos(joinque) "*,$tgt"]
if {![llength $jqlist]} { return 0 }
set key [lindex $jqlist 0]
if {$num == 311} { ;# "rname (realname)" #######
set rname [join [lassign [split $tx] user host astr]]
if {$astr eq "*" && [string index $rname 0] eq ":"} {
set rname [string range $rname 1 end]
dict set whos(joinque) $key rname $rname
#putlog " realname: $rname" ;# <<== #################
}
return 0
}
if {$num == 671} { ;# "secure" #######
if {[matchstr ":is using a Secure Connection*" $tx]} {
dict set whos(joinque) $key secure 1
}
return 0
}
if {$num == 320} { ;# "country & webirc" #######
if {[regexp {^:connected from (.+)$} $tx - country]} {
dict set whos(joinque) $key country $country
#putlog " country: $country" ;# <<== #################
}
if {[matchstr ":is connecting via WEBIRC" $tx]} {
dict set whos(joinque) $key webirc 1
}
return 0
}
if {$num == 318} { ;# "done" #######
if {[matchstr ":End of /WHOIS list." $tx]} {
set isSecure 0 ; set isWebirc 0 ; set isOk 0
if {[dict exists $whos(joinque) $key secure]} { set isSecure 1 }
if {[dict exists $whos(joinque) $key webirc]} { set isWebirc 1 }
if {$isSecure==1 || $isWebirc==1} { set isOk 1 }
foreach key $jqlist { set ch [dict get $whos(joinque) $key cha]
lappend cls $ch
}
if {$isOk==1} { ;# Is connected by secure and/or by webirc #
if {$isSecure==1 && $isWebirc==1} {
putlog " > IS connected Both Secure And Webirc! $target is allowed in: [join $cls]"
} elseif {$isSecure==1} {
putlog " > Is using a Secure Connection. $target is allowed in: [join $cls]"
} else { putlog " > Is connecting via WEBIRC. $target is allowed in: [join $cls]" }
} else { ;# Else is Not connected by secure or by webirc #
putlog " > NOT connected Secure or by Webirc! KickBan $target in: [join $cls]"
if {$whos(domode) ne ""} { ;# Set channel modes #######
foreach ch $cls { putquick "MODE $ch $whos(domode)"
if {$whos(modetime)>0} {
utimer $whos(modetime) [list putquick "MODE $ch $whos(unmode)"]
}
}
}
;# Set channel bans #######
if {$whos(dobans)==1} { set uho [dict get $whos(joinque) $key uho]
set bmask [maskhost "${target}!$uho" $whos(masktype)]
foreach ch $cls { pushmode $ch +b $bmask
if {$whos(bantime)>0} {
utimer $whos(bantime) [list pushmode $ch -b $bmask]
}
}
}
if {$whos(dokick)==1} { ;# Kick nicks from channel #######
foreach ch $cls {
if {$whos(reason) eq ""} { putkick $ch $target
} else { putkick $ch $target $whos(reason) }
}
}
} ;# END: Else is Not connected by secure or by webirc #
if {[llength $jqlist]>=[dict size $whos(joinque)]} { unset whos(joinque)
} else { set whos(joinque) [dict remove $whos(joinque) {*}$jqlist] }
}
} ;# end if 318 #
return 0
} ;# end: proc onraw
} ;## end of: namespace eval whos ##
putlog "whos.tcl ver 0.1 Loaded."
Check it out and let me know