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.

[solved]how to read a text file top to bottom ??

Help for those learning Tcl or writing their own scripts.
Post Reply
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

[solved]how to read a text file top to bottom ??

Post by doggo »

my script reads from a txt file that looks like this

Code: Select all

Track list for - Vertex_-_Archipelago-(TESD001)-WEB-2010-HQEM
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
01-vertex-oceanos.mp3
02-vertex-archipelago.mp3
03-vertex-hungary_dance.mp3
04-float_and_vertex-oceansphere.mp3
heres the script...

Code: Select all

# Rls: track_list.v1.0.tcl
# Date: 19/06/10
# Coded by: SaNcTuM
# Contact: #a.b.inner-sanctum@EFNET
###################################

bind PUB - -tlist SaNcTuM_tracks

set track_list "/home/eggdrop/requests/track_lists"

proc SaNcTuM_tracks {nick uhost hand chan text} {
    set tracks [open $::track_list/[lindex $text 0].txt r]
    set data [split [read -nonewline $tracks] \n]
    close $tracks
    foreach music_info $data {
        utimer 3 [list putquick "NOTICE $nick :\00315$music_info"]
    }
    return 0
 } 

putlog "track_list.v1.0 LOADED"
but it reads the .txt file from the bottom up :/

Code: Select all

[18:51] <@mojo> -tlist 31810
[18:51] -moopig- 04-float_and_vertex-oceansphere.mp3
[18:51] -moopig- 03-vertex-hungary_dance.mp3
[18:51] -moopig- 02-vertex-archipelago.mp3
[18:51] -moopig- 01-vertex-oceanos.mp3
[18:51] -moopig- -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
[18:51] -moopig- Track list for - Vertex_-_Archipelago-(TESD001)-WEB-2010-HQEM
i would also like it to notice the user if there is no file to display :)

thanks guys.. :)
Last edited by doggo on Mon Jul 05, 2010 3:44 am, edited 1 time in total.
h
horgh
Voice
Posts: 10
Joined: Sat Feb 13, 2010 3:12 pm

Post by horgh »

Code: Select all

# Rls: track_list.v1.0.tcl
# Date: 19/06/10
# Coded by: SaNcTuM
# Contact: #a.b.inner-sanctum@EFNET
###################################

bind PUB - -tlist SaNcTuM_tracks

set track_list "/home/eggdrop/requests/track_lists"

proc SaNcTuM_tracks {nick uhost hand chan text} {
    set number [lindex [split $text] 0]
    set filename ${::track_list}/${number}.txt
    if {![file exists $filename]} {
        putquick "NOTICE $nick :Track list file not found."
        return
    }

    set tracks [open $filename]
    set data [split [read -nonewline $tracks] \n]
    close $tracks
    foreach music_info $data {
        putquick "NOTICE $nick :\00315$music_info"
    }
 }

putlog "track_list.v1.0 LOADED"
It's probably showing in reverse due to utimer. There's no need to use utimer here I think as putquick is already queued.

I made it extract argument more correctly and added the check for if file doesn't exist.

But I didn't test this so ;p
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

thanks dude, works perfectly now :)


if you get on EFNET #mp3.spam to see it working :D
Post Reply