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]Old ban remover

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

[Solved]Old ban remover

Post by m4s »

Hello to everyone!

May I ask Your help to create a script for me?

My channel banlist often fills up and I thought my bot should remove the 5 oldest ban if a halfop gives a private command to the bot.

The bans are only channel bans and the format is *!*@host.
Nickbans should not be removed.

The private command and the nr. of bans should be configured in the script.

Thanks for your replies!
Last edited by m4s on Wed May 23, 2018 1:48 pm, edited 1 time in total.
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 clearbans(max) 5

bind msg o|o clearbans clear:bans

proc clear:bans {nick uhost hand text} {
	if {[scan $text {%s} chan] != 1} {
		puthelp "PRIVMSG $nick :Usage: clearbans #channel"
		return
	}
	if {[string first # $chan] == -1 || ![validchan $chan]} {
		puthelp "PRIVMSG $nick :Error: $chan is not a valid input."
		return
	}
	if {![botonchan $chan]} {
		puthelp "PRIVMSG $nick :Error: I'm not on $chan channel."
		return
	}
	if {![botisop $chan]} {
		puthelp "PRIVMSG $nick :Error: I'm not a channel operator on $chan channel."
		return
	}
	global clearbans
	foreach {ban bywho age} [join [chanbans $chan]] {
		scan $ban {%[^!]!%[^@]@%s} n u h
		# format is *!*@host
		if {$n != "*" || $u != "*"} continue
		lappend data [list $age $ban]
	}
	if {![info exists data]} return
	set data [lsort -decreasing -integer -index 0 $data]
	set no 0
	foreach {age ban} [join $data] {
		incr no
		if {$no > $clearbans(max)} break
		lappend banlist $ban
	}
	set len [llength $banlist]
	while {$len > 0} {
		if {$len > $clearbans(max)} {
			set mode [string repeat "b" $clearbans(max)]
			set masks [join [lrange $banlist 0 [expr {$clearbans(max) - 1}]]]
			set banlist [lrange $banlist $clearbans(max) end]
			incr len -$clearbans(max)
		} else {
			set mode [string repeat "b" $len]
			set masks [join $banlist]
			set len 0
		}
		puthelp "MODE $chan -$mode $masks"
	}
}
Haven't tested this so let me know if you get any errors.

Edit: Fixed variables.
Last edited by caesar on Wed May 23, 2018 1:11 am, edited 3 times in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Post by m4s »

Hi caesar!

Thank you for your help again.
I tested it but no action after clearbans #channel private command.

If I use clearbans I got: Usage: clearbans #channel
and clearbans channel (without #) I got: Error: help is not a valid input.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The #channel is a valid channel, bot is on it and has channel operator? Are there any channel bans set in the format you said you want?
Once the game is over, the king and the pawn go back in the same box.
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Post by m4s »

caesar wrote:The #channel is a valid channel, bot is on it and has channel operator? Are there any channel bans set in the format you said you want?
Yes of course! :)

I forgot to mention a haven't got any error msgs aftet clearbans #channel.
Just nothing happened.
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote: ...
Haven't tested this so let me know if you get any errors.
Me either ... I haven't loaded it.
But I found it interesting.

Have a look at this line:

Code: Select all

  if {$len > $max)} {
I don't see what sets $max prior to that line.
Maybe you meant to use the array var there?
That possibility might account for the unmatched ) too.

I hope this saves you some time.
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
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

willyw is right. :oops:

Initially had that piece of code inside another function, but then decided to drop it and forgot to replace the $max variable with $clearbans(max) to suit the names in this code.

Anyway, updated the code above and should be good now. Thanks willyw. :wink:
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote: Initially had that piece of code inside another function, but then decided to drop it and forgot to ....."
Do I ever know THAT feeling .... heheehehe
Thanks willyw. :wink:
You're welcome.
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
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Post by m4s »

Hello,

Sorry for the late answer, I was far from the "modern" world. :)

I tried the updated script but still no result. After "clearbans #channel" nothing happens.
:?
Last edited by m4s on Wed May 23, 2018 1:44 pm, edited 1 time in total.
s
simo
Revered One
Posts: 1070
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i tried it as well and nottin happens i made sure banlist is full and executed the script but it didnt do anything and no errors in PL
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

/facepalm

Code: Select all

if {![info exists $data]} return
should be:

Code: Select all

if {![info exists data]} return
notice the missing $ :roll:

First is with clearbans(max) set to 5, then set it to 2 to see what happens.
[08:02] * cez sets mode: +bbbbb *!*@host.com *!*@something.net *!bla@* john!*@* *!*@host.net
[08:02] * bot sets mode: -bbb *!*@host.net *!*@something.net *!*@host.com

[08:02] * cez sets mode: +bbb *!*@host.com *!*@something.net *!*@host.net
[08:02] * bot sets mode: -bb *!*@host.net *!*@host.com
Set it to 3 and removes 3 oldest bans as should:
[08:03] * cez sets mode: +bbb *!*@host.com *!*@something.net *!*@host.net
[08:05] * cez sets mode: +b *!*@host.org
[08:05] * bot sets mode: -bbb *!*@host.net *!*@something.net *!*@host.com
And it works as expected. :)
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 »

excellent it works well

thnx caesar.
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Super

Post by m4s »

The script works, thank you caesar! :)
And thanks for willyw as well!

May I upload it to the tclarchive.org?
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Your welcome. Sure, no problem.
Once the game is over, the king and the pawn go back in the same box.
Post Reply