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.

limiting command user per users/user

Old posts that have not been replied to for several years.
Locked
d
difoo
Voice
Posts: 33
Joined: Sat Jul 03, 2004 9:56 am

limiting command user per users/user

Post by difoo »

hi,

i'm looking for a script that limits the usage for a specific proc per users & user.
i don't want 300 news added a week and would like to limit it to max 20 for all users in the userfile and max 10 for specific users. i can't think of a way how to do it myself. the limit should still work when the bot rehashes/restarts/dies..so i guess it has to be saved in a file how often each user has issued the command?

i want to limit the usage of !news <news here> to 20 a week, and the same command for <user-specific> to 10 a week. any help would be greatly appreciated.

greets difoo
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Code: Select all

set yourfloodflag "o|o"
set yourfloodfile "news.txt"
if { [file exists $yourfloodfile] } {
	set fd [open $yourfloodfile r]
		gets $fd yourflood
	close $fd
} else {
	close [open $yourfloodfile w]
}

bind evnt - save yourfloodsave
bind time - "00 00 *" yourfloodday
bind mkch - "*" yourfloodnkch

proc yourproc { ... } {
...
	if { $hand == "*" && ![matchattr $hand $::yourfloodflag $chan] } {
		if { [set line [lsearch -glob $::yourflood "all *"]] == -1 } {
			lappend ::yourflood [list all 1 0 0 0 0 0 0]
		} elseif { [expr [lindex [set entry [lindex $::yourflood $line]] 1] + [lindex $entry 2] + [lindex $entry 3] + [lindex $entry 4] + [lindex $entry 5] + [lindex $entry 6] + [lindex $entry 7]] >= 21 } {
			puthelp "NOTICE $nick :Your weekly limit has been reached!"
			return 0
		} else {
			set ::yourflood [lreplace $::yourflood $line $line [lreplace $entry 1 1 [expr [lindex $entry 1] + 1]]
		}
	} else {
		if { [set line [lsearch -glob $::yourflood "$hand *"]] == -1 } {
			lappend ::yourflood [list $hand 1 0 0 0 0 0 0]
		} elseif { [expr [lindex [set entry [lindex $::yourflood $line]] 1] + [lindex $entry 2] + [lindex $entry 3] + [lindex $entry 4] + [lindex $entry 5] + [lindex $entry 6] + [lindex $entry 7]] >= 11 } {
			puthelp "NOTICE $nick :Your weekly limit has been reached!"
			return 0
		} else {
			set ::yourflood [lreplace $::yourflood $line $line [lreplace $entry 1 1 [expr [lindex $entry 1] + 1]]
		}
	}
...
}

proc yourfloodday {min h d m y} {
	global yourflood
	set i 0
	foreach line $yourflood {
		set linsert $line 1 "0"
		set line [lreplace $line e e]
		set yourflood [lreplace $yourflood $i $i $line]
		incr i
	}
}

proc yourfloodnkch {old new} {
	if { [set line [lsearch -glob $::yourflood "$old *"]] != -1 } {
		set ::yourflood [lreplace $::yourflood $line $line [lreplace [lindex $::yourflood $line] 0 0 [split $new]]]
	}
	return 0
}

proc yourfloodsave {type} {
	set fd [open $::yourfloodfile w]
		puts -nonewline $::yourflood
	close $fd
	return 0
}
just wrote the idea down, haven't had the time to debug it yet.
you maybe replace any varnames or proc names, but replace them ALL then :P.
the part between ... should be inserted just before the news are actually created. If you add "yourflood" to the global var list, remove the leading :: from it. The flood should be saved for each day in a week and reset daily. The save to file is done when a save is initiated from the bot (so just before it rehashes, restarts, quits) and load it after it again.

NOTE: the script within ... assumes the nickname is stored in "nick" and the handle is stored in "hand", change it if your script uses diffrent var names! You should not have a user called "all" with the flag (case should matter).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

you could save the info to the XTRA field in the userlist, that way you get away with alot less code. (assuming only known users can execute commands.)
d
difoo
Voice
Posts: 33
Joined: Sat Jul 03, 2004 9:56 am

Post by difoo »

hi,

thanks for the reply, much appreciated

i'll try this when i get home from work in a few, thanks!
gb wrote:you could save the info to the XTRA field in the userlist, that way you get away with alot less code. (assuming only known users can execute commands.)
but how would it check for dates..? as in num/week. can't imagine this is possible.

greets difoo
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

I was mostly making suggestions to De Kus' script

But I suppose something like this will work if you want to reset something once a week

Code: Select all

bind time - "00 00 *" whatdayisit
proc whatdayisit {mi hr da mo yr} {
 if {[strftime %a]=="Mon"} {
  foreach u [userlist -b] {
   setuser $u XTRA count 0
  }
 }
}
Edit: fixed the typo mentioned by De Kus.
Last edited by greenbear on Fri Apr 22, 2005 6:46 pm, edited 1 time in total.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

the problem of resetting resetting it once week, you would have to wait up to a full week before you can post a news again, once you hit the max, on the other side, you can post 10 news on sunday and 10 on monday, maybe thats a bit much, too :D. So checking once a day and holding 7 values is more accurate.
But you are right, you could have saved it in an XTRA info line instead of a list, but wouldnt have saved much code (only the lsearch and the bind for nkch).

PS: your time bind triggers on each 1st of a month which is a monday, so will have only a few hits in a year :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

ya, i like the idea of a daily max limit better too.

another benefit with using xtra fields is that you can show the info on whois/.match real easy.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

yeah, but im too lazy to rewrite it. if the above code works without bugs it would be a miracle anyway, had no time to debug yet, but if the user doesnt complain so far... maybe it really is one :D.

in my list version, it would be fasted to open the file in a texteditor and search for the handle ^-^.

[quote="difoo"but how would it check for dates..? as in num/week. can't imagine this is possible.[/quote]
the solution would be the same: saving a 7 elemented, space sperated list with values ^^. its no mattter if it is within an XTRA field or an element of an higher list levell.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked