Code: Select all
# Jokes.tcl - Copyright C.Leonhardt Nov.25.2006 - rosc2112 at yahoo com http://members.dandy.net/~fbn/jokes.tcl.txt
# Pulls a random joke from a file and spits it out in channel. If you format jokes with a semi-colon seperator,
# it'll add a small delay to the subsequent parts of a joke (for like, Have you heard about? type jokes)
# Lines can have more than 1 seperator.
# Example: What do you call two butches bonding?;Hockey night in Canada.
# The second part ("Hockey night in Canada") will be shown after the delay.
# If there is no semi-colon seperator, then the entire joke on one line will be shown. Joke length per line
# is limited by your IRCD's line length (generally 400 chars long.)
# You will need to rehash if you edit your jokes file, since it's only read once, when this script is (re)loaded.
# Usage: .joke - Typed in channel
# Todo: Create function to add/delete jokes from the joke file (me being lazy today..)
#----------------------------------------------------------------------------------------------------------------------
# Config #
#--------#
# Channels where we allow public use:
set jokechans "#ComedyCentral #Staff"
# Out of the above channels, these ones will send responses only to PRIVMSG:
set jokequietchans "#Staff"
# Joke file (Remember to have only 1 joke per line, with semi-colon seperators if it's a multi-part joke)
set jokefile "/home/eggdrop/ComedyBot/jokes.txt"
# How many seconds delay between parts of a joke do you want to wait before showing the next part?
set jokedelay 5
#----------------------------------------------------------------------------------------------------------------------
# Code below #
#------------#
catch {unbind pub - .joke proc:joke}
if {[file exists $jokefile]} {
set jdata ""
set jokesin [open $jokefile r]
set jokesdata [split [read $jokesin] \n]
catch {close $jokesin}
foreach line $jokesdata {
set line [string trim $line]
if {$line != ""} {
lappend jdata $line
}
}
if {$jdata != ""} {
set jokesdata $jdata
bind pub - .joke proc:joke
putlog "Jokes.tcl 0.1a by rosc - Loaded jokefile.."
} else {
putlog "Jokes.tcl: \002Joke data was empty! Not binding command..\002"
}
} else {
putlog "Jokes.tcl: \002No joke file found. Not binding command..\002"
}
proc proc:joke {nick host hand chan text} {
global jokesdata jokedelay
if {([lsearch -exact $::jokechans $chan] == -1)} {return}
if {([lsearch -exact $::jokequietchans $chan] != -1)} {set chan $nick}
set joke [lindex $jokesdata [rand [llength $jokesdata]]]
set jokeparts [split $joke \;]
set jokellen [llength $jokeparts]
for {set j 0} {$j < $jokellen} {incr j} {
if {$j == 0} {
puthelp "PRIVMSG $chan :[lindex $jokeparts $j]"
} else {
utimer [expr $jokedelay * $j] [list jokespew $chan [lindex $jokeparts $j]]
}
}
}
proc jokespew {chan text} {
puthelp "PRIVMSG $chan :$text"
}