I have 40 poems, ALL in 1 file. They have between 5-20 lines each.
I do not know what index pointer would be best or how to locate it.
I have posted a "test" file at the bottom.
The channel commands will be like !p1 or !p25 or !p37
Thanks for any help given.
Code: Select all
# ### Poem Player ####
set poem_file "/home/eggdrop/poems/poemfile"
set poem_chan "#Poem_player_Testing"
set master_poem_mode "1"
set poem_mode "0"
set poem_chan [string tolower $poem_chan]
bind pubm -|- "!p" que:poem
proc que:poem {nick uhost handle channel text} {
global botnick master_poem_mode poem_chan poem_mode poem_file
# checks to see if an OP has turned off the player
if {$master_poem_mode == 0} {return 0}
# checks to see if the player is already playing
if {$poem_mode == 1} {return 0}
# checks to see if the channel is poem channel
set chan [string tolower $channel]
if {!($chan == $poem_chan)} {return 0}
if {![botisop $poem_chan]} {return 0}
set poem_to_play [lindex [split $text] 0]
if {[file exists $poem_file]} {
# set poem_mode 1
set opened_poem_file [open $poem_file r]
# ****** I do NOT know what to do here ******
# need to look for our index marker to retrive the correct Poem
# Remember: ALL 40 poems are in the same file with index markers
# I do not know what kind of index marker would be best,
# i am open for suggestions
set poem_timer 1
while {![eof $opened_poem_file]} {
set poem_line [gets $opened_poem_file]
# I am using proc and timer, so the poem can be stopped mid-poem
utimer $poem_timer [list play:poem $poem_line]
incr poem_timer 5
}
close $poem_file - or is it - close $opened_poem_file
# reset the poem mode so a new poem can be played
utimer [expr $poem_timer + 5] {set poem_mode 0}
return 0
}
set poem_mode 0
return 0
}
# Play Poem #
proc play:poem {poem_line} {
global master_poem_mode poem_chan
# I am using this proc and timer, so the poem can be stopped mid-poem
if {$master_poem_mode == 0} {return 0}
puthelp "PRIVMSG $poem_chan :$poem_line"
return 0
}
# Master shut-off Switch #
# Master shut-off switch, available to ANY OP in Channel
bind pub -|- "!pon" enable:poems
bind pub -|- "!poff" disable:poems
proc enable:poems {nick uhost handle channel} {
global poem_chan master_poem_mode poem_mode
if {[isop $nick $poem_chan]} {
set master_poem_mode "1"
set poem_mode "0"
puthelp "PRIVMSG $poem_chan :Type: !p<poem number> to play a Poem"
}
return 0
}
proc disable:poems {nick uhost handle channel text} {
global poem_chan master_poem_mode poem_mode
if {[isop $nick $poem_chan]} {
set master_poem_mode "0"
puthelp "PRIVMSG $poem_chan :Poem Player has been locked in OFF mode."
}
return 0
}
may need to be changed.
poemfile
Code: Select all
[1]
1. This line 1 from poem 1
2. This line 2 from poem 1
3. This line 3 from poem 1
4. This line 4 from poem 1
5. This line 5 from poem 1
6. This line 6 from poem 1
7. This line 7 from poem 1, the last line of poem 1
[2]
1. This line 1 from poem 2
2. This line 2 from poem 2
3. This line 3 from poem 2, the last line of poem 2
[3]
1. This line 1 from poem 3
2. This line 2 from poem 3
3. This line 3 from poem 3
4. This line 4 from poem 3
5. This line 5 from poem 3
6. This line 6 from poem 3, the last line of poem 3