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 

slennox's autolimit with pub cmd
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Sat Apr 15, 2017 9:18 am    Post subject: slennox's autolimit with pub cmd Reply with quote

i tried editing slennox's autolimit tcl to work with pub cmd but it doesn't seem to do well after i did the changes other than that the tcl works fine without it i just wanted it to work for with pub cmd for chan admins to enable incase of floodings and what not and turn off if all cools down as autolimits are spammy in general to keep on non stop

I would appreciate help if from author himself would be even better since it is his code and it works fine thats why i wanted to stick to it and have pub cmd added to enable/disable and if possible add grace and threshold manually as well i seen some autolimit tcls do that but without on join bind (using timers) wich takes ages for it to set chan limit

tnx in advance.

Code:
##############################
## ------------------------ ##
## 10. Channel Limit Script ##
## ------------------------ ##
##############################


#Channels in which to activate limiting, this should be a list like
#"#elephants #wildlife #etc". Leave it set to "" if you wish to activate
#limiting on all channels the bot is on.
set cl_chans ""

#Limit to set (number of users on the channel + this setting)
set cl_limit "2"

#Limit grace (if the limit doesn't need to be changed by more than this,
#don't bother setting a new limit)
set cl_grace "1"

# Frequency of checking whether a new limit needs to be set (in seconds)
set cl_utimer "5"


########################################################
#- Don't edit below unless you know what you're doing -#
########################################################

proc isatleasthalfop3209 {nick chan} {  if {[matchattr [nick2hand $nick] nmo|nmo $chan]} { return 1 }; foreach type {op halfop admin owner} { if {[is$type $nick $chan]} { return 1 } }; return 0 }

bind pub -|- !chanlim autolimit_control
bind pub -|- !limit autolimit_control
bind pub -|- !autolimit autolimit_control

proc autolimit_control {nick host handle chan args} {
   global joinpart botnick
   if {![isatleasthalfop3209 $nick $chan]} { return 0 }
   if { ![channel get $chan autolimit] && [string compare $args "on"] == 0 } {
      channel set $chan +autolimit
      putserv "NOTICE $nick :autolimit: enabled on $chan"
   } elseif { [channel get $chan autolimit] && [string compare $args "off"] == 0 } {
      channel set $chan -autolimit
      putserv "NOTICE $nick :autolimit: disabled on $chan"

   }
}

setudef flag autolimit

bind join - "*" limit:chng:on:bot:join

proc limit:chng:on:bot:join {nick uhost hand chan} {
   if { ![channel get $chan autolimit] } {  return 0  }
   global cl_chans limit_delay
   if {[isbotnick $nick] && ([lsearch -exact [split [string tolower $cl_chans]] [string tolower $chan]] != -1)} {
      set limit_delay([string tolower $chan]) 1
      utimer 3 [list unset limit_delay([string tolower $chan])]
   }
}

proc cl_dolimit {} {
   global cl_chans cl_limit cl_grace cl_utimer limit_delay
   utimer $cl_utimer cl_dolimit
   foreach chan [string tolower [channels]] {
      if {$cl_chans != ""} {
         if { ![channel get $chan autolimit] } {  return 0  }
         if {([lsearch -exact [split [string tolower $cl_chans]] [string tolower $chan]] == -1)} { continue }
      }
      if {[info exists limit_delay($chan)]} { continue }
      if {![botisop $chan]} { continue }
      set numusers [llength [chanlist $chan]]
      set newlimit [expr $numusers + $cl_limit]
      if {[string match "*l*" [lindex [getchanmode $chan] 0]]} {
         set currlimit [string range [getchanmode $chan] [expr [string last " " [getchanmode $chan]] + 1] end]
      } else {
         set currlimit 0
      }
      if {$newlimit == $currlimit} { continue }
      if {$newlimit > $currlimit} {
         set difference [expr $newlimit - $currlimit]
      } elseif {$currlimit > $newlimit} {
         set difference [expr $currlimit - $newlimit]
      }
      if {$difference <= $cl_grace} { continue }
      putnow "MODE $chan +l $newlimit"
      #putquick "MODE $chan +l $newlimit" -next
   }
}

proc cl_startlimit {} {
   global cl_utimer
   if {[string match "*cl_dolimit*" [utimers]]} { return 0 }
   utimer $cl_utimer cl_dolimit
}

cl_startlimit

if {$cl_chans == ""} {
   putlog "Loaded chanlimit.tcl v1.5 by slennox (active on all channels)"
} else {
   putlog "Loaded chanlimit.tcl v1.5 by slennox (active on: [join $cl_chans ", "])"
}
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Sun Apr 16, 2017 2:57 am    Post subject: Reply with quote

Please don't revive old topics and post whatever info you want in your own and link to them.

What exactly you want to adjust on the fly? The limit to set (cl_limit)? Limit grace (cl_grace)? Want a adjustable timer (cl_timer) for each channel or one for all will do fine like is in the chanlimit.tcl by Slennox? I'm asking cos he used timer (minutes) and in your code i see you switched to utimer (seconds).
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Sun Apr 16, 2017 7:58 am    Post subject: Reply with quote

if posible to input grace , limit and timer by pub cmd
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Sun Apr 16, 2017 2:14 pm    Post subject: Reply with quote

Adjusting the grace and limit on the fly is easy to implement, but the utimer part will be a bit tricky as would have to kill previous utimer before making and calling a new one.

If nobody jumps on this will do something tomorrow.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Mon Apr 17, 2017 3:49 pm    Post subject: Reply with quote

Without the utimer part is fine as well
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Thu Apr 20, 2017 9:27 am    Post subject: Reply with quote

does anyone know how to modify the code to have it work with pub commands

tnx in advance
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Fri Apr 21, 2017 5:07 am    Post subject: Reply with quote

Code:

namespace eval autoLimit {

   setudef flag autolimit
   setudef str limitData

   bind join * * [namespace current]::joins
   bind pub o|o !adjust [namespace current]::adjust

   proc joins {nick uhost hand chan} {
      if {![channel get $chan autolimit]} return
      if {[isbotnick $nick] || ![botisop $chan]} return
      check $chan
   }

   proc adjust {nick uhost hand chan text} {
      if {![channel get $chan autolimit]} return
      if {[scan $text {%d%d} limit grace] != 2} {
         puthelp "NOTICE $nick :Error, syntax: !adjust <limit:grace> (integer values)"
         return
      }
      channel set $chan limitData "$limit:$grace"
      puthelp "NOTICE $nick :Success, channel limit has been set to $limit and grace set to $grace"
      check $chan
   }

   proc check {{chan ""}} {
      if {[llength $chan]} {
         set chan [string tolower $chan]
         if {![channel get $chan autolimit]} return
         if {[scan [join [split [channel get $chan limitData] :]] {%d%d} limit grace] != 2} return
         set count [llength [chanlist $chan]]
         set newlimit [expr $count + $limit]
         set cm [getchanmode $chan]
         if {[lsearch -exact [split $cm ""] "l"] != -1} {
            set currlimit [lindex [split $cm] 1]
         } else {
            set currlimit 0
         }
         if {$newlimit == $currlimit} return
         if {$newlimit > $currlimit} {
            set diff [expr $newlimit - $currlimit]
         } else {
            set diff [expr $currlimit - $newlimit]
         }
         if {$diff <= $grace} return
         pushmode $chan +l $newlimit
      } else {
         foreach chan [channels] {
            check $chan
         }
      }
   }

   proc start args {
      utimer 5 [namespace current]::check
   }

   start
}

Forgot to add the activation/deactivation from channel command so for now do .chanset #channel +autolimit from DCC Chat/telnet. Set the limit and grace with !adjust limit:grace (integer numbers), for example !adjust 3:5, or from DCC Chat/Telnet with .chanset #channel limitData limit:grace (integer numbers).

I could tie an utimer for each channel as well, if that is really needed.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Fri Apr 21, 2017 7:34 am    Post subject: Reply with quote

i tried it and no matter what value i use in !adjust i get get:

also could the enable disable pub cmd be added

Quote:
Error, syntax: !adjust <limit:grace> (integer values)
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Fri Apr 21, 2017 8:41 am    Post subject: Reply with quote

Initially the code had the limit and grace in two separate arguments and forgot to change this part as well. Embarassed
Replace:
Code:

if {[scan $text {%d%d} limit grace] != 2} {
with:
Code:

if {[scan [join [split $text :]] {%d%d} limit grace] != 2} return

As for adding the public enable/disable, just add:
Code:

bind pub o|o !limit [namespace current]::limit

behind:
Code:

bind pub o|o !adjust [namespace current]::adjust

and before the proc start args { insert:
Code:

   proc limit {nick uhost hand chan text} {
      if {[scan $text {%s} mode] != 1} {
         puthelp "NOTICE $nick :Error, syntax: !limit <on/off>"
         return
      }
      set status [channel get $chan autolimit]
      switch -- [string tolower $mode] {
         "on" {
            if {$status} {
               puthelp "NOTICE $nick :Error, can't continue because autolimit is already enabled."
            } else {
               channel set $chan +autolimit
               puthelp "NOTICE $nick :Success, autolimit has been enabled."
            }
         }
         "off" {
            if {!$status} {
               puthelp "NOTICE $nick :Error, can't continue because autolimit is already disabled."
            } else {
               channel set $chan -autolimit
               puthelp "NOTICE $nick :Success, autolimit has been disabled."
            }
         }
         default {
            puthelp "NOTICE $nick :Error, given syntax is unknown: !limit <on/off>"
         }
      }
   }

As always, haven't tested anything.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Fri Apr 21, 2017 9:30 am    Post subject: Reply with quote

looks to be working so far

only when disabling it doesnt remove -l

i added pushmode $chan -l
that seemed to work

tnx caesar.
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Fri Apr 21, 2017 9:54 am    Post subject: Reply with quote

Yeah, I forgot about that..

You could also add after:
Code:

channel set $chan +autolimit

a check $chan to make it start limiting right away when the limit has been enabled. Your welcome.

I guess we could also add a proc for kick, part and quit to adjust the limit right away when one of the events happens. Up to you. Smile
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Fri Apr 21, 2017 10:56 am    Post subject: Reply with quote

concerning the adding of part/kick/quit seems good idea as well

i was also thinking about to check if the set limit and actual users in channel difference it bigger than the grace to then set new limit


so lets say there are 50 users current +l is 55 while we have set it at 3

if u understand what i gettin at afaik the grace calculates if the difference with the set limit is not beyond set grace value
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Fri Apr 21, 2017 12:11 pm    Post subject: Reply with quote

Let's say for disscussion sake channel has 50 people, channel doesn't have any limits set and settings are: limit 5 and grace 3.

When you first activate it, if there's no limit set it will set the count + limit, meaning 50 + 5. If new people join and the grace limit (meaning count + grace, meaning 50 + 3) isn't reached it won't change the channel limit. As soon as the 4th person joins and the new limit (50+4) is over the grace (53) it will change the channel mode to 59.

Proof of concept.
Code:

% proc push {limit grace count {cm "+stn"}} {
        set newlimit [expr $count + $limit]
        if {[lsearch -exact [split $cm ""] "l"] != -1} {
                set currlimit [lindex [split $cm] 1]
        } else {
                set currlimit 0
        }
        if {$newlimit == $currlimit} return
        if {$newlimit > $currlimit} {
                set diff [expr $newlimit - $currlimit]
        } else {
                set diff [expr $currlimit - $newlimit]
        }
        if {$diff <= $grace} return
        puts "mode change: +l $newlimit"
}
% push 5 3 50
mode change: +l 55
% push 5 3 50 "+stnl 55"
% push 5 3 52 "+stnl 55"
% push 5 3 53 "+stnl 55"
% push 5 3 54 "+stnl 55"
mode change: +l 59

I set the "+stn" to mimic default channel modes and then I set them to mimic the changed modes.

So, is it working as you wanted or not?

As for adding the kick, part and quit part is as easy as 1.. 2.. 3.. Smile
Code:

   bind part - * [namespace current]::del
   bind sign - * [namespace current]::del
   bind kick - * [namespace current]::kick
   
   proc del {nick uhost hand chan {text ""}} {
      if {![channel get $chan autolimit]} return
      if {[isbotnick $nick]} return
      check $chan
   }
   
   proc kick {nick uhost hand chan vict reason} {
      if {![channel get $chan autolimit]} return
      if {[isbotnick $vict]} return
      check $chan
   }

Edit: removed code.
_________________
You may say anything about me, but don't misspell my name.


Last edited by caesar on Sat Apr 22, 2017 3:04 am; edited 1 time in total
Back to top
View user's profile Send private message
simo
Master


Joined: 22 Mar 2015
Posts: 204

PostPosted: Fri Apr 21, 2017 12:50 pm    Post subject: Reply with quote

your entire code gives me this:
Quote:

[18:47:41] can't read "chan": no such variable
while executing
"channel set $chan limitData "$limit:$grace""
(in namespace eval "::autoLimit" script line 20)
invoked from within
"namespace eval autoLimit {

setudef flag autolimit
setudef str limitData

bind pub o|o !adjust [namespace current]::adjust
bind pub o|o !l..."
(file "scripts2a/autolimit-caesar2a.tcl" line 1)
invoked from within
"source scripts2a/autolimit-caesar2a.tcl"

with what i got so far i dont get any error so far:
Code:
   namespace eval autoLimit {

   setudef flag autolimit
   setudef str limitData

   bind join * * [namespace current]::joins
   bind pub o|o !adjust [namespace current]::adjust
   bind pub o|o !autolimit [namespace current]::limit   
   bind pub o|o !limit [namespace current]::limit
   bind pub o|o !climit [namespace current]::limit
 
    bind part - * [namespace current]::del
   bind sign - * [namespace current]::del
   bind kick - * [namespace current]::kick
   
   proc del {nick uhost hand chan {text ""}} {
      if {![channel get $chan autolimit]} return
      if {[isbotnick $nick]} return
      check $chan
   }
   
   proc kick {nick uhost hand chan vict reason} {
      if {![channel get $chan autolimit]} return
      if {[isbotnick $vict]} return
      check $chan
   }
   proc joins {nick uhost hand chan} {
      if {![channel get $chan autolimit]} return
      if {[isbotnick $nick] || ![botisop $chan]} return
      check $chan
   }

   proc adjust {nick uhost hand chan text} {
      if {![channel get $chan autolimit]} return
      if {[scan [join [split $text :]] {%d%d} limit grace] != 2} { 
         puthelp "NOTICE $nick :Error, syntax: !adjust <limit:grace> (integer values)"
         return
      }
      channel set $chan limitData "$limit:$grace"
      puthelp "NOTICE $nick :Success, channel limit has been set to $limit and grace set to $grace"
      check $chan
   }

   proc check {{chan ""}} {
      if {[llength $chan]} {
         set chan [string tolower $chan]
         if {![channel get $chan autolimit]} return
         if {[scan [join [split [channel get $chan limitData] :]] {%d%d} limit grace] != 2} return
         set count [llength [chanlist $chan]]
         set newlimit [expr $count + $limit]
         set cm [getchanmode $chan]
         if {[lsearch -exact [split $cm ""] "l"] != -1} {
            set currlimit [lindex [split $cm] 1]
         } else {
            set currlimit 0
         }
         if {$newlimit == $currlimit} return
         if {$newlimit > $currlimit} {
            set diff [expr $newlimit - $currlimit]
         } else {
            set diff [expr $currlimit - $newlimit]
         }
         if {$diff <= $grace} return
         pushmode $chan +l $newlimit
      } else {
         foreach chan [channels] {
            check $chan
         }
      }
   }

proc limit {nick uhost hand chan text} {
      if {[scan $text {%s} mode] != 1} {
         puthelp "NOTICE $nick :Error, syntax: !limit <on/off>"
         return
      }
      set status [channel get $chan autolimit]
      switch -- [string tolower $mode] {
         "on" {
            if {$status} {
               puthelp "NOTICE $nick :Error, can't continue because autolimit is already enabled."
            } else {
               channel set $chan +autolimit
             check $chan
             puthelp "NOTICE $nick :Success, autolimit has been enabled."
            }
         }
         "off" {
            if {!$status} {
               puthelp "NOTICE $nick :Error, can't continue because autolimit is already disabled."
             pushmode $chan -l
            } else {
               channel set $chan -autolimit
               puthelp "NOTICE $nick :Success, autolimit has been disabled."
             pushmode $chan -l
            }
         }
         default {
            puthelp "NOTICE $nick :Error, given syntax is unknown: !limit <on/off>"
         }
      }
   }

   proc start args {
      utimer 5 [namespace current]::check
   }

   start
}

also it sets new limit to fast after joins making it ineffiecient incase of a join flood since it makes way after every join

also it sets new limit after each quit making it very spammy
Back to top
View user's profile Send private message
caesar
Ass Kicker


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

PostPosted: Sat Apr 22, 2017 3:06 am    Post subject: Reply with quote

Ah, I messed up something and thus removed the code I posted. And yeah, you are right, should have added a utimer in the first place. Replace:
Code:

check $chan

with:
Code:

utimer 5 [list [namespace current]::check $chan]

And if you still aren't happy with the results then remove the binds for part, sign and kick and leave it as it was.
_________________
You may say anything about me, but don't misspell my name.
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
Goto page 1, 2  Next
Page 1 of 2

 
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