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.

REQ: Small Modification of Bartender Script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
a
achilles1900
Voice
Posts: 30
Joined: Mon Apr 21, 2008 5:40 am

REQ: Small Modification of Bartender Script

Post by achilles1900 »

Hello Egghelp Community,

I have a bartender script that i would like to be slightly modified.

Basically, i would like only people who are currently opped or voiced to be able to use the trigger.

It would be fantastic if you could add some scripting where i can select either channels ops or channel voiced or everybody who can use the trigger
e.g. 'users able to access trigger 1. only ops
2. ops & voices
3. Everyone

Currently the script allows anyone to use it and people have been abusing it, spamming and such. Would be a great help to us if you TCL Gurus can come to our aid. Also any modifications you see fit would be welcome too.

I thank you all in advance and please find the script below (i included only the first part and a drink)
best regards,
Achilles

Code: Select all

# Trigger
#############################################################################

set cmdz "!"

#############################################################################

bind pub - ${cmdz}booze pub_booze

proc pub_booze {nick uhost hand channel arg} {
  global botnick cmdz
    putquick "PRIVMSG $nick :1,13Bars Open! Heres what we got for ya:"
    putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
    putquick "PRIVMSG $nick :13,1${cmdz}Corona, ${cmdz}vodka"
    putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
    return 0
}

##############Start of the drinks#################

proc pub_corona {nick uhost hand channel arg} { 
  global botnick 
  set theNick $nick
  if { [llength $arg] == 1 } {
    set theNick [lindex [split $arg] 0]
  }
    putserv "PRIVMSG $channel :\001ACTION snaps off the top of a long-necked, ice cold Corona, slips in a slice of lime and hands it to you....enjoy mate"
    return 0        
}
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

You only have to change
set temp(type) "1"
1 = only voices
2 = only ops
3 = everyone

Code: Select all

### temp(type) "1" (only voice users can use the command)
### temp(type) "2" (only op users can use the command)
### temp(type) "3" (everyone can use the command)

# Trigger
#############################################################################

set cmdz "!"

#############################################################################

bind pub - ${cmdz}booze pub_booze

set temp(type) "1"

proc pub_booze {nick uhost hand channel arg} {
	global botnick cmdz temp

	if {$temp(type) == "1"} {
		if {[isvoice $nick $channel]} {
			putquick "PRIVMSG $nick :1,13Bars Open! Heres what we got for ya:"
			putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
			putquick "PRIVMSG $nick :13,1${cmdz}Corona, ${cmdz}vodka"
			putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
			return 0
		}
	} elseif {$temp(type) == "2"} {
		if {[isop $nick $channel]} {
			putquick "PRIVMSG $nick :1,13Bars Open! Heres what we got for ya:"
			putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
			putquick "PRIVMSG $nick :13,1${cmdz}Corona, ${cmdz}vodka"
			putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
			return 0
		}
	} elseif {$temp(type) == "2"} {
		putquick "PRIVMSG $nick :1,13Bars Open! Heres what we got for ya:"
		putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
		putquick "PRIVMSG $nick :13,1${cmdz}Corona, ${cmdz}vodka"
		putquick "PRIVMSG $nick :------------------------------------------------------------------------------------------------"
		return 0
	}
}

##############Start of the drinks#################

proc pub_corona {nick uhost hand channel arg} {
	global botnick temp

	if {$temp(type) == "1"} {
		if {[isvoice $nick $channel]} {
			set theNick $nick
			if { [llength $arg] == 1 } {
				set theNick [lindex [split $arg] 0]
			}
			putserv "PRIVMSG $channel :\001ACTION snaps off the top of a long-necked, ice cold Corona, slips in a slice of lime and hands it to you....enjoy mate"
			return 0
		}
	} elseif {$temp(type) == "2"} {
		if {[isop $nick $channel]} {
			set theNick $nick
			if { [llength $arg] == 1 } {
				set theNick [lindex [split $arg] 0]
			}
			putserv "PRIVMSG $channel :\001ACTION snaps off the top of a long-necked, ice cold Corona, slips in a slice of lime and hands it to you....enjoy mate"
			return 0
		}
	} elseif {$temp(type) == "3"} {
		set theNick $nick
		if { [llength $arg] == 1 } {
			set theNick [lindex [split $arg] 0]
		}
		putserv "PRIVMSG $channel :\001ACTION snaps off the top of a long-necked, ice cold Corona, slips in a slice of lime and hands it to you....enjoy mate"
		return 0
	}
}
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Here's my attempt to do this:

Code: Select all

dict set drinks "beer" "snaps off the top of a long-necked, ice cold Corona, slips in a slice of lime and hands it to you....enjoy mate"
dict set drinks "vodka" "here you go, knock yourself out!"
dict set drinks "tea" "I'm out  of tea, sorry.."

# 0 - everyone, 1 - currently opped or voiced
setudef int serving

bind pubm * "% !*" drink:order
bind pub * !drinks drink:menu

proc drink:order {nick uhost hand chan text} {
	set drink [lindex [split $text !] 1]
	if {[channel get $chan serving]} {
		if {[isop $nick $chan] || [isvoice $nick $chan]} {
			drink:serve $nick $chan $drink
		}
	} else {
		drink:serve $nick $chan $drink
	}
}

proc drink:serve {nick chan drink} {
	global drinks
	if {[string length $drink]} {
		if {[lsearch -nocase [dict keys $drinks] $drink] != -1} {
			puthelp "PRIVMSG $chan :[dict get $drinks $drink]"
		}
	}
}

proc drink:menu {nick uhost hand chan text} {
	if {[channel get $chan serving]} {
		if {[isop $nick $chan] || [isvoice $nick $chan]} {
			drink:fetch $nick $chan
		}
	} else {
		drink:fetch $nick $chan
	}
}

proc drink:fetch {nick chan} {
	puthelp "PRIVMSG $chan :Drinks currently available: [join [dict keys $::drinks] ", "]"
}
Feel free to add \001ACTION or whatever you wish.

Edit: Fixed. Damn typo.. :)
Last edited by caesar on Fri Feb 01, 2013 3:29 pm, edited 3 times in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Heh :) ive modifyed its code if i was to create another one it was smaller of course :P
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

# Tcl 8.4 friendly version .. 8)
# credit: caesar
# enable: .chanset #chan +serving

# Amount of drinks each person may
# request in a certain amount of time
# 3:30 means 3 drinks in 30 seconds
# the 4th is throttled until 30 seconds has
# elapsed from their first drink.
#
set drinkThrottle 3:30

# about the array:
# %nick will become $nick (the nickname)
# %chan will become $chan (the channel)
# \n will make the output span onto a new line.
#
array set drinks {
 corona "\001ACTION snaps off the top of a long-necked, ice cold Corona, slips in a slice of lime and hands it to %nick\001\nEnjoy mate."
 coors "\001ACTION pisses in a mug then slides it down the bar to %nick.\001\nDrink up %nick!"
 bud "Um...%nick, we don't serve that in %chan...\nTry a gay bar.. haw!"
 vodka "here you go %nick, knock yourself out!\n\001ACTION slides a shot down the bar to %nick.\001"
 tea "I'm out of tea, sorry %nick..\nOh wait, I do have tea.\nWait, no I don't.. :P"
 tip "%nick better follow the rules in %chan.\nOr does %nick want a nice kickban instead?"
}

setudef flag serving

bind pubm - "% !*" drink:order
bind pub - !drinks drink:menu

proc drink:order {nick uhost hand chan text} {
   if {[channel get $chan serving]} {
  	foreach {drink type} [split $text] { break }
      if {[isop $nick $chan] || [isvoice $nick $chan]} {
         drink:serve $nick $uhost $chan [string range $drink 1 end] $type
      }
   }
}

proc drink:serve {nick uhost chan drink type} {
   global drinks
   if {[string length $drink]} {
      foreach name [array names drinks] { lappend lowerDrinks [string tolower $name] }
      if {[lsearch -exact $lowerDrinks $drink] != -1} {
         if {[set wait [throttle_ $uhost,$chan,drink [lindex $::drinkThrottle 1] [lindex $::drinkThrottle 0)]]] != 0} {
            putserv "privmsg $chan :$nick, please wait [lindex $wait 0] seconds for your next drink. You are above the drink request limit by [expr {[lindex $wait 1] - $::drinkAmount}] at the moment. Slow down..."
         } else {
            if {[string length $type] && [onchan $type $chan]} { set nick $type }
            foreach line [split $drinks($drink) \n] {
               puthelp "PRIVMSG $chan :[string map [list %chan $chan %nick $nick] $line]"
             }
         }
      }
   }
}

proc drink:menu {nick uhost hand chan text} {
   if {[channel get $chan serving]} {
      if {[isop $nick $chan] || [isvoice $nick $chan]} {
         drink:fetch $nick $chan
      }
   } else {
      drink:fetch $nick $chan
   }
}

proc drink:fetch {nick chan} {
   global drinks
   puthelp "PRIVMSG $chan :Drinks currently available: ![join [array names drinks] ", !"]"
} 


# Throttle Proc (slightly altered, super action missles) - Thanks to user
# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc throttle_ {id seconds amount} {
   if {[info exists ::throttled_($id)]&&[lindex $::throttled_($id) 0]>[clock seconds]} {
      set ::throttled_($id) [list [lindex $::throttled_($id) 0] [set value [expr {[lindex $::throttled_($id) 1] +1}]]]
      if {$value > $amount} { set id ::throttled_($id) } { set id 0 }
   } {
      set ::throttled_($id) [list [expr {[clock seconds]+$seconds}] 1]
      set id 0
   }
}
# delete expired entries every 10 minutes
bind time - ?0* throttleclean_ 
# sub - clean throttled users
proc throttleclean_ {args} {
   set now [clock seconds]
   foreach {id time} [array get ::throttled_] {
      if {[lindex $time 0]<=$now} {unset ::throttled_($id)}
   }
} 
#eof
Edit1:
Modified post above from original. Since the script was corrected, here is a tcl8.4 friendly version of the same script. Also added a throttle system that will keep users from abusing and at the same time amusing.

Edit2:
Improved and added proactive throttle control.

Edit3:
Added ability to match intent of OP's original script:
!corona - the nick issuing !corona gets one.. yay
!corona <nick> - the nickname typed gets a corona if they are in channel otherwise the person typing it will.
Last edited by speechles on Fri Feb 01, 2013 7:54 pm, edited 30 times in total.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

meh.. was working with string map on another script and accidentally slipped it in instead of a simple join. :roll:

no, according to dict manual example I don't need to add
  • . and no. i intended to make serving an int as 0 means everyone and 1 only currently oped or voiced, and somehow after some tests ended with str.
Once the game is over, the king and the pawn go back in the same box.
Post Reply