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 

[Solved]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: 42

PostPosted: Wed May 16, 2018 2:21 pm    Post subject: [Solved]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!


Last edited by m4s on Wed May 23, 2018 1:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3511
Location: Top Secret

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


Last edited by caesar on Wed May 23, 2018 1:11 am; edited 3 times in total
Back to top
View user's profile Send private message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 42

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: 3511
Location: Top Secret

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: 42

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: 973

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: 3511
Location: Top Secret

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: 973

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
m4s
Halfop


Joined: 30 Jan 2017
Posts: 42

PostPosted: Tue May 22, 2018 11:44 am    Post subject: Reply with quote

Hello,

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

I tried the updated script but still no result. After "clearbans #channel" nothing happens.
Confused


Last edited by m4s on Wed May 23, 2018 1:44 pm; edited 1 time in total
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 255

PostPosted: Tue May 22, 2018 6:16 pm    Post subject: Reply with quote

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


Joined: 14 Oct 2001
Posts: 3511
Location: Top Secret

PostPosted: Wed May 23, 2018 1:10 am    Post subject: Reply with quote

/facepalm
Code:

if {![info exists $data]} return

should be:
Code:

if {![info exists data]} return

notice the missing $ Rolling Eyes

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. Smile
_________________
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
simo
Master


Joined: 22 Mar 2015
Posts: 255

PostPosted: Wed May 23, 2018 2:24 am    Post subject: Reply with quote

excellent it works well

thnx caesar.
Back to top
View user's profile Send private message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 42

PostPosted: Wed May 23, 2018 1:47 pm    Post subject: Super Reply with quote

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

May I upload it to the tclarchive.org?
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3511
Location: Top Secret

PostPosted: Thu May 24, 2018 12:43 am    Post subject: Reply with quote

Your welcome. Sure, no problem.
_________________
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
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