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.

enforce bans / kicks on all common channels

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

enforce bans / kicks on all common channels

Post by simo »

greetings i was wondering if this enforceban / enforce kick script be modified to set a ban or kick on all common channels the bot is sitting in and the kicked/banned user

Code: Select all

bind mode - "* +b" enforcebans

proc enforcebans {nick uhost hand chan mc ban} {
 foreach n [chanlist $chan] {
  if {[string match -nocase $ban $n![getchanhost $n $chan]]} {
    if {![botisop $chan]} { return 0 }
    if {[isop $n $chan]} { return 0 }
    if {[ishalfop $n $chan]} { return 0 }
    if {[matchattr [nick2hand $n] fnmo|fnmo $chan]} { return 0 }
    if {[isbotnick $n]} { return 0}
    putkick $chan $n "Ban $ban matches:  $n (You Are Banned ) " 
  }
 }
}




bind kick - "*" my:kick

 kick extractor
proc my:kick {n u h c p t} {
      set dbname [strftime %Y]
  if {$p == $::botnick} {
    putquick "CS INVITE $c" -next
    putquick "JOIN $c" -next
  putquick "PRIVMSG $c :$dbname [strftime "|%d.%m.%Y / %H:%M:%S|"] $p kicked from $c by ${n}: $t" -next  
}
  return
} 
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i found this small snippet on forum from speechless could this be integrated in the two snippets i posted

Code: Select all

proc check:common {nick uhost hand chan text} {
   if {![string length [set n [lindex [split $text] 0]]]} {
     puthelp "Usage: .common <nick> - please supply nickname ;P"
     return
   }
   foreach c [channels] {
      if {[onchan $n $c]} { lappend common $c }
   }
   if {[info exists common]} {
      puthelp "privmsg $chan :My common channels with $n are: [join $common ", "]."
   } else {
      puthelp "privmsg $chan :I share no common channels with $n."
   }
}
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

your question is that you remove the van
and kick in all channels you kicked,,,,
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

for the kick part i tried this but it gave me error

Tcl error [msg_on_kick]: wrong # args: should be "msg_on_kick nick uhost hand chan arg"

Code: Select all

bind kick - "* *" msg_on_kick
proc msg_on_kick {nick uhost hand chan arg} {
           foreach c [channels] {
      if {[onchan $n $c]} { lappend common $c }
   }
   if {[info exists common]} {
  putserv "privmsg $target :Hello 05 $target  you where kicked out from 02 $chan  by 3 ( $nick )  - with reason 06  ( $reason ) "
   } else {
      puthelp "privmsg $chan :I share no common channels with $n."
   }
}
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

simo wrote: ...

Tcl error [msg_on_kick]: wrong # args: should be "msg_on_kick nick uhost hand chan arg"
Go to:
http://www.eggheads.org/support/egghtml ... mands.html

and find:
bind kick
to see the correct parameters and number of them, for the proc.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

the default is like this only i dont know how to integrate it
and make bot kick user from all common channels

Code: Select all

bind kick - "* *" msg_on_kick

proc msg_on_kick {nick uhost handle chan target reason} {
        putserv "privmsg $target :Hello 05 $target  you where kicked out from 02 $chan  by 3 ( $nick )  - with reason 06  ( $reason )  - for more info please join 12 #help "
}
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

simo wrote:the default is like this only i dont know how to integrate it
and make bot kick user from all common channels

Code: Select all

bind kick - "* *" msg_on_kick

proc msg_on_kick {nick uhost handle chan target reason} {
        putserv "privmsg $target :Hello 05 $target  you where kicked out from 02 $chan  by 3 ( $nick )  - with reason 06  ( $reason )  - for more info please join 12 #help "
}
You could use something like this, from your enforceban procedure, to mimic your kick proc

Code: Select all

bind mode - "* +b" enforcebans

set accessFlags fnmo|fnmo

proc enforcebans {nick uhost hand chan mc ban} {
 global accessFlags
 foreach n [chanlist $chan] {
  foreach c [channels] {
   if {[string match -nocase $ban $n![getchanhost $n $c]]} {
    if {![botisop $c] || [isbotnick $n] || [isop $n $c] || [ishalfop $n $c] || [matchattr [nick2hand $n] $accessFlags $c]} {return}
    putquick "KICK $c $n :Ban $ban matches: $n (You Are Banned)"
   }
  }
 }
} 
Last edited by Get_A_Fix on Mon Jun 20, 2016 7:20 am, edited 1 time in total.
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Instead of {return} should be continue

What's the point to iterate all channels and kick the user matching the ban mask, when the ban was placed just on a single channel? You know the user can return on the channel he/she was kicked but not banned, right?

Also, you know about the enforcebans channel setting that is doing exactly what you wanted (kick people who match channel bans)?
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

would it possible to also have it set ban on all channels bot is sitting in as well Get_A_Fix ?

Code: Select all

bind mode - "* +b" enforcebans

set accessFlags fnmo|fnmo

proc enforcebans {nick uhost hand chan mc ban} {
 global accessFlags
 foreach n [chanlist $chan] {
  foreach c [channels] {
   if {[string match -nocase $ban $n![getchanhost $n $c]]} {
    if {![botisop $c] && [isbotnick $n] && [isop $n $c] && [ishalfop $n $c] && [matchattr [nick2hand $n] $accessFlags $c]} {return}
    putquick "KICK $c $n :Ban $ban matches: $n (You Are Banned)"
   }
  }
 }
}
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

Sure. I didn't know that's what you wanted. There are two ways to approach this, adding a server ban (so your @ and non-bot Ops can remove the ban), or an internal ban (which has to be manually removed from the bot).
For the internal ban, read the ~/eggdrop/doc/tcl-commands.doc form on newchanban or newban. For this example, I'll be using the server side ban.

Code: Select all

# In your code you can: set banmask [make:banmask $uhost $nick]
# and then use the ...: putquick "MODE $chan +b $banmask"

# BAN Types are given below;
# 1 - *!*@some.domain.com 
# 2 - *!*@*.domain.com
# 3 - *!*ident@some.domain.com
# 4 - *!*ident@*.domain.com
# 5 - *!*ident*@some.domain.com
# 6 - *nick*!*@*.domain.com
# 7 - *nick*!*@some.domain.com
# 8 - nick!ident@some.domain.com
# 9 - nick!ident@*.host.com
set bantype 1

# Set the access flags needed to be exempt
set accessFlags fnmo|fnmo

## Code Base ##
bind mode - "* +b" enforcebans

proc enforcebans {nick uhost hand chan mc ban} {
 global accessFlags
 foreach n [chanlist $chan] {
  foreach c [channels] {
   if {[string match -nocase $ban $n![getchanhost $n $c]]} {
    if {![botisop $c] || [isbotnick $n] || [isop $n $c] || [ishalfop $n $c] || [matchattr [nick2hand $n] $accessFlags $c]} {return}
    set banmask [make:banmask $uhost $nick]
    putquick "MODE $c +b $banmask"
    putquick "KICK $c $n :Ban $ban matches: $n (You Are Banned)"
   }
  }
 }
}

proc make:banmask {uhost nick} {
 global bantype
  switch -- $bantype {
   1 { set banmask "*!*@[lindex [split $uhost @] 1]" }
   2 { set banmask "*!*@[lindex [split [maskhost $uhost] "@"] 1]" }
   3 { set banmask "*!*$uhost" }
   4 { set banmask "*!*[lindex [split [maskhost $uhost] "!"] 1]" }
   5 { set banmask "*!*[lindex [split $uhost "@"] 0]*@[lindex [split $uhost "@"] 1]" }
   6 { set banmask "*$nick*!*@[lindex [split [maskhost $uhost] "@"] 1]" }
   7 { set banmask "*$nick*!*@[lindex [split $uhost "@"] 1]" }
   8 { set banmask "$nick![lindex [split $uhost "@"] 0]@[lindex [split $uhost @] 1]" }
   9 { set banmask "$nick![lindex [split $uhost "@"] 0]@[lindex [split [maskhost $uhost] "@"] 1]" }
   default { set banmask "*!*@[lindex [split $uhost @] 1]" }
   return $banmask
  }
}
Note: Code edited to reflect what caesar explained.
Last edited by Get_A_Fix on Mon Jun 20, 2016 7:24 am, edited 3 times in total.
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

caesar wrote:Instead of {return} should be continue

What's the point to iterate all channels and kick the user matching the ban mask, when the ban was placed just on a single channel? You know the user can return on the channel he/she was kicked but not banned, right?

Also, you know about the enforcebans channel setting that is doing exactly what you wanted (kick people who match channel bans)?
I always use return, just out of habit and the way I code.

As for enforcebans, which a lot of the core is ok, some is not, so for things like this I try to override the core calls. For example, using bind flud to process flood-chan and other specific events (like this script here). Easier to manage and modify as wanted.
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

% set elements [list 1 2 3 4 5]
1 2 3 4 5
% foreach ele $elements { if {$ele == 3} { return } else { puts $ele } }
1
2
% foreach ele $elements { if {$ele == 3} { continue } else { puts $ele } }
1
2
4
5
Notice the difference in using return and continue?

You are aware that the && in:

Code: Select all

if {![botisop $c] && [isbotnick $n] && [isop $n $c] && [ishalfop $n $c] && [matchattr [nick2hand $n] $accessFlags $c]} {return} 
means if bot is channel operator in channel AND bot is the nick AND nick is channel operator AND nick is halfop AND nick's user matches the global|channel flags you said THEN return. You should use || that means OR not && that means AND. For example:

Code: Select all

% foreach ele $elements { if {$ele == 3 && $ele == 5} { continue } else { puts $ele } }
1
2
3
4
5
% foreach ele $elements { if {$ele == 3 || $ele == 5} { continue } else { puts $ele } }
1
2
4
Notice the difference? he wants to exclude ANY of the matching cases, not the case that would match ALL of the tests.

Here's my take on this. Did some limited testing and works fine. I used putkick as it puts multiple names in the same line thus doesn't flood the server with multiple requests to kick a single member per line.

Code: Select all

namespace eval enforceBans {
	
	# How many members can be kicked in the same line
	set enforce(max) "6"
	
	# Define the reason. Notice the %ban that will be replaced with the actual mask.
	# You can use %nick as well and will also be replaced with the actual name of the user who set the ban.
	set enforce(reason) "Ban %ban set in %chan matches your host. You are banned!"

	bind mode - "% +b" [namespace current]::enforce

	proc enforce {nick uhost hand chan mc ban} {
		variable enforce
		foreach c [channels] {
			if {![botisop $c]} continue
			foreach n [lreplace [chanlist $c] 0 0] {
				if {![string match -nocase $ban $n![getchanhost $n $c]]} continue
				if {[isop $n $c] || [ishalfop $n $c] || [matchattr [nick2hand $n] "fnmo|fnmo" $c]} continue
				lappend kickList($c) $n
			}
		}
		foreach c [array names kickList] {
			set len [llength $kickList($c)]
			if {![string equal -nocase $c $chan]} {
				pushmode $c +b $ban
			}
			while {$len > 0} {
				if {$len > $enforce(max)} {
					set users [join [lrange $kickList($c) 0 [expr {$enforce(max) - 1}]] ,]
					set kickList($c) [lrange $kickList($c) $enforce(max) end]
					incr len - $enforce(max)
				} else {
					set users [join $kickList($c) ,]
					set len 0
				}
				set reason [string map [list "%chan" $chan "%ban" $ban "%nick" $nick] $enforce(reason)]
				putkick $c $users $reason
			}
		}
	}
}
When setting X bans on the same line the bot will trigger a bind mode - "% +b" proc X times for each ban mask, but will trigger a mode - "% -b" proc only once per 6 bans (or whatever is the max amount of bans per line the server you are connected allows) when removing bans. Honestly I fail to understand the logic behind this difference.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

I tried your version caesar it works fine if user is in common channels as eggbot. Is it possible to set ban anyway on all channels bot sits in even if banned nick isnt there to prevent him from joining and continuing the abuse
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

So now you want the bot to "copy" all bans on all the channels the bot is a channel operator, and top of that enforce the kicking of any members that would match the new banned mask?

If yes then try this and let me know how things work, cos I haven't tested anything this time.

Code: Select all

namespace eval enforceBans {

	# How many members can be kicked in the same line
	set enforce(max) "6"

	# Define the reason. Notice the %ban that will be replaced with the actual mask.
	# You can use %who as well and will also be replaced with the actual nick of the user who set the ban.
	set enforce(reason) "Ban %ban set in %from matches your host. You are banned!"

	bind mode - "% +b" [namespace current]::enforce

	proc enforce {nick uhost hand chan mc ban} {
		variable enforce
		set reason [string map [list "%from" $chan "%ban" $ban "%who" $nick] $enforce(reason)]
		foreach c [channels] {
			if {![botisop $c]} continue
			if {![string equal -nocase $c $chan]} {
				set match 0
				foreach b [chanbans $c] {
					if {![string match -nocase $b $ban]} continue
					incr match
					break
				}
				if {!$match} {
					pushmode $c +b $ban
				}
			}
			foreach n [lreplace [chanlist $c] 0 0] {
				if {![string match -nocase $ban $n![getchanhost $n $c]]} continue
				if {[isop $n $c] || [ishalfop $n $c] || [matchattr [nick2hand $n] "fnmo|fnmo" $c]} continue
				lappend kickList($c) $n
			}
			if {[info exists kickList($c)]} {
				set len [llength $kickList($c)]
				while {$len > 0} {
					if {$len > $enforce(max)} {
						set users [join [lrange $kickList($c) 0 [expr {$enforce(max) - 1}]] ,]
						set kickList($c) [lrange $kickList($c) $enforce(max) end]
						incr len -$enforce(max)
					} else {
						set users [join $kickList($c) ,]
						set len 0
					}
					putkick $c $users $reason
				}
			}
		}
	}
}
Just remember you had a little issue with banlist (discussion in here) and will adopt a similar solution to SpiKe's if will be the case.

While given the requested change we could use a faster queue than pushmode, I would honestly stick with it cos this function will be called for instance 6 times if 6 bans have been set in one line. This way the chances are it will also push all the 6 modes in a single line in other channels. Worth a test anyway. :)

Edit: 1st bug fix (link).
Last edited by caesar on Wed May 26, 2021 2:23 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

looks to be working good caesar
is it possible to have it also remove ban on all channels if a ban is removed
Post Reply