| View previous topic :: View next topic |
| Author |
Message |
KhashayaR Voice

Joined: 19 Jul 2007 Posts: 22 Location: World
|
Posted: Fri Jun 05, 2020 3:13 am Post subject: Topic TCL |
|
|
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: |
#######################################################################
# 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
=== |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Fri Jun 05, 2020 2:17 pm Post subject: proc getRandomTopic |
|
|
This process should return a random line from a file.
| Code: |
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
. |
|
| Back to top |
|
 |
KhashayaR Voice

Joined: 19 Jul 2007 Posts: 22 Location: World
|
Posted: Mon Jun 08, 2020 8:37 am Post subject: |
|
|
Thanks SpiKe^^ _________________ ===
IRC Network: DALnet
Nick: KhashayaR
=== |
|
| Back to top |
|
 |
KhashayaR Voice

Joined: 19 Jul 2007 Posts: 22 Location: World
|
Posted: Sun Jun 28, 2020 3:52 am Post subject: |
|
|
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: |
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
=== |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sun Jun 28, 2020 8:48 am Post subject: |
|
|
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
. |
|
| Back to top |
|
 |
|