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.

Topic TCL

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
KhashayaR
Voice
Posts: 22
Joined: Thu Jul 19, 2007 9:34 pm
Location: World
Contact:

Topic TCL

Post by KhashayaR »

hello I wonder if someone can help me with this TCL here is what I would like to happen

-currently, the TCL read the topic content from inside the TCL as you can see, is there any way TCL read the topic content from a separate text file?

please see below

Code: Select all

#######################################################################
# Set the Topic format here. See below for a list of format settings. #
# ------------------------------------------------------------------- #
# $chan - Name of channel                                             #
####################################################################### 

set TopicToUse {
{ Random quotes can be most effecatious }

}

#############################################################################
#############################################################################
############################### STOP EDITING ################################
#############################################################################
#############################################################################

bind time - "00 * * * *" Displaytimenow
bind time - "360 * * * *" Displaytimenow

## Proc to Randomly Select an Info Item!
proc get_TopicRandomItem { } {
 global TopicToUse
 set output [lindex $TopicToUse [rand [llength $TopicToUse]]]
 return $output
}

proc Displaytimenow {n h handle ch te} { 
 global botnick showtimechans
 foreach channel [channels] {
 set topichan [get_TopicRandomItem]
 regsub {\$chan} $topichan $channel topichan
 putquick "TOPIC $channel :$topichan"
 }
}

## -----------------------------------------------------------------------
putlog "Random Topic loaded Successfuly..."
===
IRC Network: DALnet
Nick: KhashayaR
===
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

proc getRandomTopic

Post by SpiKe^^ »

This process should return a random line from a file.

Code: Select all

set TopicFile "scripts/TopicFile.txt"

proc getRandomTopic {} {
  global TopicFile

  if {![file exists $TopicFile]} { return "$TopicFile does not exist" }

  set openfile [open $TopicFile]
  set topics [split [read -nonewline $openfile] \n]
  close $openfile

  set output [lindex $topics [rand [llength $topics]]]
  return $output
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
KhashayaR
Voice
Posts: 22
Joined: Thu Jul 19, 2007 9:34 pm
Location: World
Contact:

Post by KhashayaR »

Thanks SpiKe^^
===
IRC Network: DALnet
Nick: KhashayaR
===
User avatar
KhashayaR
Voice
Posts: 22
Joined: Thu Jul 19, 2007 9:34 pm
Location: World
Contact:

Post by KhashayaR »

I'm not sure what is wrong in here :( but it's not working

my aim is TCL read the topic content from a separate text file located on script/

Code: Select all

bind time - "00 * * * *" Displaytimenow
bind time - "05 * * * *" Displaytimenow

set TopicFile "scripts/TopicFile.txt"

proc getRandomTopic {} {
  global TopicFile

  if {![file exists $TopicFile]} { return "$TopicFile does not exist" }

  set openfile [open $TopicFile]
  set topics [split [read -nonewline $openfile] \n]
  close $openfile

  set output [lindex $topics [rand [llength $topics]]]
  return $output
}

proc Displaytimenow {n h handle ch te} {
 global botnick showtimechans
 foreach channel [channels] {
 set topichan [get_TopicRandomItem]
 regsub {\$chan} $topichan $channel topichan
 putquick "TOPIC $channel :$topichan"
 }
}
===
IRC Network: DALnet
Nick: KhashayaR
===
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

You would need to call your new getRandomTopic process when needed...

Try replace [get_TopicRandomItem] with [getRandomTopic]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply