egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Old ban remover

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 40

PostPosted: Wed May 16, 2018 2:21 pm    Post subject: Old ban remover Reply with quote

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!
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3455
Location: Area 51

PostPosted: Thu May 17, 2018 3:30 am    Post subject: Reply with quote

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 variable.
_________________
You may say anything about me, but at least don't misspell my name. xD


Last edited by caesar on Fri May 18, 2018 12:43 am; edited 2 times in total
Back to top
View user's profile Send private message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 40

PostPosted: Thu May 17, 2018 12:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3455
Location: Area 51

PostPosted: Thu May 17, 2018 12:58 pm    Post subject: Reply with quote

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?
_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 40

PostPosted: Thu May 17, 2018 1:01 pm    Post subject: Reply with quote

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! Smile

I forgot to mention a haven't got any error msgs aftet clearbans #channel.
Just nothing happened.
Back to top
View user's profile Send private message
willyw
Owner


Joined: 15 Jan 2009
Posts: 959

PostPosted: Thu May 17, 2018 6:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3455
Location: Area 51

PostPosted: Fri May 18, 2018 12:43 am    Post subject: Reply with quote

willyw is right. Embarassed

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
_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
willyw
Owner


Joined: 15 Jan 2009
Posts: 959

PostPosted: Fri May 18, 2018 1:49 pm    Post subject: Reply with quote

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. 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 !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber