Been looking at tcl faq adding files to try and get a bit of help with this
Im trying to get this to work not having no success what im trying to is get the bot to write to a file when someone does /botnick makenote username text will then notice #ops Note left about $username to view type /msg trainingbot viewnote $username
next it will need need to read makenote.txt when someone does /botnick viewnote username matching the username given then notice nick the text/note that is left against username have tried some of the quote scripts but was enable to mod them seperately
bind msg SA|SA makenote cmd:makenote
bind msg SA|SA viewnote cmd:viewnote
set channel "#Test"
set fname "makenote.txt"
if {[file exists $fname] == 0} {
set file [open $fname w]
close $file
}
proc cmd:makenote {nick uhost hand text} {
global botnick channel fname
set username [lindex [split $text] 0]
set text [lrange [split $text] 1 end]
set file [open $fname a]
puts $file "$username $text"
close $file
putserv "PRIVMSG $username :$text"
puthelp "NOTICE $channel :Note left about $username to view type /msg $botnick viewnote $username"
}
proc cmd:viewnote {nick uhost hand text} {
global fname
set username [lindex [split $text] 0]
if {$username == ""} { puthelp "NOTICE $nick :Try viewnote <username>"
return 0
}
set file [open $fname "r"]
set database [read -nonewline $file]
close $file
set data [split $database "\n"]
if {$database == ""} { puthelp "PRIVMSG $nick :There are no notes available"
return 0
}
foreach line $data {
set user [lindex [split $line] 0]
if {[string match -nocase $user $username]} {
set note [lrange [split $line] 1 end]
set found 1
puthelp "PRIVMSG $nick :The note for $username is :"
puthelp "PRIVMSG $nick :$note"
}
if {![info exists found]} {
puthelp "PRIVMSG $nick :There are no notes for $username"
}
}
}
bind msg SA|SA makenote cmd:makenote
bind msg SA|SA viewnote cmd:viewnote
set channel "#Test"
set fname "makenote.txt"
if {[file exists $fname] == 0} {
set file [open $fname w]
close $file
}
proc cmd:makenote {nick uhost hand text} {
global botnick channel fname
set username [lindex [split $text] 0]
set lin 0
set text [lrange [split $text] 1 end]
set file [open $fname "r"]
set database [read -nonewline $file]
close $file
set data [split $database "\n"]
foreach line $data {
set lin [expr $lin +1]
set userline [lindex [split $line] 0]
if {[string match -nocase $userline $username]} {
if {$line != ""} {
set num [expr $lin - 1]
set delete [lreplace $data $num $num]
set files [open $fname "w"]
puts $files [join $delete "\n"]
close $files
}
}
}
set file [open $fname "a"]
puts $file "$username $text"
close $file
putserv "PRIVMSG $username :$text"
puthelp "NOTICE $channel :Note left about $username to view type /msg $botnick viewnote $username"
}
proc cmd:viewnote {nick uhost hand text} {
global fname
set username [lindex [split $text] 0]
if {$username == ""} { puthelp "NOTICE $nick :Try viewnote <username>"
return 0
}
set file [open $fname "r"]
set database [read -nonewline $file]
close $file
set data [split $database "\n"]
if {$database == ""} { puthelp "PRIVMSG $nick :There are no notes available"
return 0
}
foreach line $data {
set user [lindex $line 0]
if {[string match -nocase $user $username]} {
set note [lrange [split $line] 1 end]
set found 1
puthelp "PRIVMSG $nick :The note for $username is :"
puthelp "PRIVMSG $nick :$note"
}
if {![info exists found]} {
puthelp "PRIVMSG $nick :There are no notes for $username"
}
}
}
Now it overwrites the message if the username is already in the makenote.txt
try it