| View previous topic :: View next topic |
| Author |
Message |
m4s Halfop

Joined: 30 Jan 2017 Posts: 97
|
Posted: Wed May 16, 2018 2:21 pm Post subject: [Solved]Old ban remover |
|
|
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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu May 17, 2018 3:30 am Post subject: |
|
|
| Code: |
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. _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Wed May 23, 2018 1:11 am; edited 3 times in total |
|
| Back to top |
|
 |
m4s Halfop

Joined: 30 Jan 2017 Posts: 97
|
Posted: Thu May 17, 2018 12:30 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu May 17, 2018 12:58 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
m4s Halfop

Joined: 30 Jan 2017 Posts: 97
|
Posted: Thu May 17, 2018 1:01 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu May 17, 2018 6:24 pm Post subject: |
|
|
| 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: |
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 ! |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri May 18, 2018 12:43 am Post subject: |
|
|
willyw is right.
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.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri May 18, 2018 1:49 pm Post subject: |
|
|
| 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
| Quote: | Thanks willyw.  |
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 ! |
|
| Back to top |
|
 |
m4s Halfop

Joined: 30 Jan 2017 Posts: 97
|
Posted: Tue May 22, 2018 11:44 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Tue May 22, 2018 6:16 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed May 23, 2018 1:10 am Post subject: |
|
|
/facepalm
| Code: |
if {![info exists $data]} return
|
should be:
| Code: |
if {![info exists data]} return
|
notice the missing $
First is with clearbans(max) set to 5, then set it to 2 to see what happens.
| Quote: |
[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:
| Quote: |
[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. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed May 23, 2018 2:24 am Post subject: |
|
|
excellent it works well
thnx caesar. |
|
| Back to top |
|
 |
m4s Halfop

Joined: 30 Jan 2017 Posts: 97
|
Posted: Wed May 23, 2018 1:47 pm Post subject: Super |
|
|
The script works, thank you caesar!
And thanks for willyw as well!
May I upload it to the tclarchive.org? |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu May 24, 2018 12:43 am Post subject: |
|
|
Your welcome. Sure, no problem. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|