i am currently on a forums that has a private radio for members and we also have an irc server
i wanted to have a channel were users could connect say add song and it gets written to a file i can upload to the djs so they can build a playlist from the songs suggested
i ask members when requesting to say add Artist - song after testing and trying to edit it myself i have failed (not the best with tcl)
it writes to the file fine but when checking to see if the artist - song is already in the file it fails unless its one word example song-artists with no spaces
an example of what the script does now
User1: add Mariah Carey - Without You
Bot: Added Mariah Carey - Without You to file
User2: add Mariah Carey - Without You
Bot: Added Mariah Carey - Without You to file
User1: add Mariah.Carey-Without.You
Bot: Added Mariah.Carey-Without.You to file
User2: add Mariah.Carey-Without.You
Bot: Song already in the list please choose another
#################
an example of what i want it to do
User1: add Mariah Carey - Without You
Bot: Added Mariah Carey - Without You to file
User2: add Mariah Carey - Without You
Bot: Song already in the list please choose another
Code: Select all
set datafile "/usr/home/Felix2003/Eggdrop/scripts/data.txt"
bind pub - add procadd
bind pub - del procdel
proc procadd {nick uhost hand chan text} {
global datafile
set text [split $text]
set ahand [lindex $text 0]
# check for duplicate songs
if {[file exists $datafile]} {
set input [open $datafile r]
while {![eof $input]} {
set curline [gets $input];set curline [split $curline]
if {[lindex $curline 0] == $text} {
puthelp "PRIVMSG $chan :$text already exists.. Pick another song"
catch {close $input}
return
}
}
catch {close $input}
}
# no dupes found, so add the new line
set output [open $datafile a]
puts $output "$text"
flush $output
catch {close $output}
puthelp "PRIVMSG $chan :Wrote $text to file.."
}
proc procdel {nick uhost hand chan text} {
global datafile
set text [split $text]
# check for valid input
if {$text == ""} {
puthelp "PRIVMSG $chan :meh"
return
}
# check for data file
if {![file exists $datafile]} {
puthelp "PRIVMSG $chan :No data file, nothing to delete!"
return
}
# check for requested handle
set data ""
set input [open $datafile r]
while {![eof $input]} {
set curline [gets $input];set curline [split $curline]
if {$curline != ""} {
set data [linsert $data end $curline]
}
}
catch {close $input}
set mark -1;set match ""
foreach line $data {
incr mark
if {[lindex $line 0] == $text} {
set match $mark
break
}
}
if {$match == ""} {
puthelp "PRIVMSG $chan :No handle matching $text found.."
return
}
set newdata [lreplace $data $mark $mark]
set output [open $datafile w]
foreach newline $newdata {
if {$newline != ""} {
puts $output $newline
}
}
flush $output
catch {close $output}
puthelp "PRIVMSG $chan :Deleted $text"
return
}
global datafile
if {![file exists $datafile]} {
puthelp "PRIVMSG $nick :No data file.."
return
}
set input [open $datafile r]
set lines [split [read $input] \n]
catch {close $input}
set cnt 0
foreach line $lines {
if {$line != ""} {
puthelp "PRIVMSG $nick :$line"
incr cnt
}
}
if {$cnt == 0} {
puthelp "PRIVMSG $nick :No saved data";return
} else {
puthelp "PRIVMSG $nick :End of list.."
}
#####################################################################################################################################
putlog "add/del script loaded.. Orig file created by rosc2112"