This is not the scripting help forum. Making this script is not as easy as it sounds and could be dangerous if done by a newbie (directory traversal bugs)Tosser^^ wrote:Take a look at http://forum.egghelp.org/viewtopic.php?t=6885 for basic file operations, then modify one of the scripts you have found to your requirements. Learn the file commands to grab the contents of a dir and display the list of subdirs, and the contents of the file(s) you want to display along with foreach loop for your line-to-line output.
Code: Select all
namespace eval ::txthing {
bind pub - !display ::txthing::pubcmd
variable basedir "~/"
variable fileext ".txt"
proc pubcmd {nick uhost hand chan arg} {
# scan takes care of two things; stripping whitespace and counting the words
switch -- [scan $arg %s%s%s 0 1 2] {
-1 - 0 {
# 0 args - list dirs
if {![llength [set dirs [list_dirs]]]} {
puthelp "PRIVMSG $chan :$nick: Configuration error: basedir does not exist or is empty."
} {
puthelp "PRIVMSG $chan :$nick: [join $dirs ", "]"
}
}
1 {
# 1 arg - list files in a dir
if {[catch {list_files $0} files]} {
puthelp "PRIVMSG $chan :$nick: Error: $files"
} {
puthelp "PRIVMSG $chan :$nick: [join $files ", "]"
}
}
2 {
# 2 args - fetch file contents
if {[catch {get_file "$0 $1"} lines]} {
puthelp "PRIVMSG $chan :$nick: Error: $lines"
} {
foreach line $lines {
# puthelp will give you about 4 seconds delay between lines
puthelp "PRIVMSG $nick :$line"
}
}
}
default {
# 3 or more args
puthelp "PRIVMSG $chan :$nick: usage: $::lastbind ?category? ?subcategory?"
}
}
}
proc list_dirs {} {
variable basedir
set list {}
foreach dir [glob -nocomplain -type d -dir $basedir *] {
lappend list [file tail $dir]
}
set list
}
proc list_files dir {
variable basedir
variable fileext
# no . or / allowed in names (quick hack to prevent directory traversal)
if {![regexp {^[^\./]+$} $dir]} {
error "invalid category"
}
set dir [file join $basedir $dir]
if {![file isdir $dir]} {
error "invalid category"
}
set list {}
foreach file [glob -nocomplain -type f -dir $dir *$fileext] {
lappend list [file root [file tail $file]]
}
set list
}
proc get_file arg {
variable basedir
variable fileext
# no . or / allowed in names (quick hack to prevent directory traversal)
if {![regexp {^([^\./ ]+)\s+([^\./ ]+)$} $arg arg dir file]} {
error "invalid category or subcategory"
}
set dir [file join $basedir $dir]
if {![file isdir $dir]} {
error "invalid category"
}
set file [file join $dir $file$fileext]
if {![file isfile $file]} {
error "invalid subcategory"
}
split [read -nonewline [set file [open $file]]][close $file] \n
}
}
You need to use "!display sports cricket" to display the contents. The bot can't read your mind thus it won't know what you want unless you tell it what you want.Faraibi wrote:thanks user and tosser.
user i tried your tcl.
it works fine for listing directory. But it is not dumping the text file.
<TuN>!display
<Shugal> TuN: sports, games
<TuN>!display sports
<Shugal>TuN: cricket, playingminds
<TuN>!display cricket
<Shugal> TuN: Error: invalid category
I made cricket.txt inside sports directory. it displays the name
but when i do this !display cricket
or !display cricket.txt the result is:
<Shugal> TuN: Error: invalid category
(Shugal is my botnick)
I also did "!display sports cricket" and "!display sports cricket.txt" but it dint work, the same error "<Shugal> TuN: Error: invalid category". So, any idea what is the problem ?
That's what i was asking, it is not displaying the file contents (dumping the file in the channel)You need to use "!display sports cricket" to display the contents. The bot can't read your mind thus it won't know what you want unless you tell it what you want.
Code: Select all
puthelp "PRIVMSG $nick :$line"
Code: Select all
puthelp "PRIVMSG $chan :$line"
Code: Select all
foreach line $lines {
# puthelp will give you about 4 seconds delay between lines
puthelp "PRIVMSG $chan :$line"
}
Code: Select all
foreach line $lines {
# puthelp will give you about 4 seconds delay between lines
utimer 30 [ putserv "PRIVMSG $chan :$line" ]
}
Code: Select all
set time 0
if {[catch {get_file "$0 $1"} lines]} {
puthelp "PRIVMSG $chan :$nick: Error: $lines"
} {
foreach line $lines {
# puthelp will give you about 4 seconds delay between lines
utimer [incr time 30] [list putserv "PRIVMSG $chan :$line"]
}
}