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 

Topic TCL

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
KhashayaR
Voice


Joined: 19 Jul 2007
Posts: 22
Location: World

PostPosted: Fri Jun 05, 2020 3:13 am    Post subject: Topic TCL Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Jun 05, 2020 2:17 pm    Post subject: proc getRandomTopic Reply with quote

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
View user's profile Send private message Visit poster's website
KhashayaR
Voice


Joined: 19 Jul 2007
Posts: 22
Location: World

PostPosted: Mon Jun 08, 2020 8:37 am    Post subject: Reply with quote

Thanks SpiKe^^
_________________
===
IRC Network: DALnet
Nick: KhashayaR
===
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
KhashayaR
Voice


Joined: 19 Jul 2007
Posts: 22
Location: World

PostPosted: Sun Jun 28, 2020 3:52 am    Post subject: Reply with quote

I'm not sure what is wrong in here Sad 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
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sun Jun 28, 2020 8:48 am    Post subject: Reply with quote

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
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 -> Script Requests 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