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.

slennox's autolimit with pub cmd

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

slennox's autolimit with pub cmd

Post by simo »

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: Select all

##############################
## ------------------------ ##
## 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 ", "])"
}
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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).
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

if posible to input grace , limit and timer by pub cmd
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Without the utimer part is fine as well
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

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

tnx in advance
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

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.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

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

also could the enable disable pub cmd be added
Error, syntax: !adjust <limit:grace> (integer values)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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

Code: Select all

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

Code: Select all

if {[scan [join [split $text :]] {%d%d} limit grace] != 2} return 
As for adding the public enable/disable, just add:

Code: Select all

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

Code: Select all

bind pub o|o !adjust [namespace current]::adjust
and before the proc start args { insert:

Code: Select all

	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.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

looks to be working so far

only when disabling it doesnt remove -l

i added pushmode $chan -l
that seemed to work

tnx caesar.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Yeah, I forgot about that..

You could also add after:

Code: Select all

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. :)
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

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
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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: Select all

% 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.. :)

Code: Select all

	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.
Last edited by caesar on Sat Apr 22, 2017 3:04 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1073
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

your entire code gives me this:
[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: Select all

	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
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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: Select all

check $chan
with:

Code: Select all

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.
Once the game is over, the king and the pawn go back in the same box.
Post Reply