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 

modify of jokes.tcl

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
blake
Master


Joined: 23 Feb 2009
Posts: 201

PostPosted: Wed Jul 27, 2011 8:54 am    Post subject: modify of jokes.tcl Reply with quote

Hey im using the following script to add jokes to a channel but have to type .joke per every joke is what i would like for it to do is type .joke once and then it just outputs one line at a time by its self

Code:
# 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"
}

_________________
Blake
UKEasyHosting UKStormWatch
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
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