| View previous topic :: View next topic |
| Author |
Message |
blake Master
Joined: 23 Feb 2009 Posts: 201
|
Posted: Tue Dec 22, 2009 3:49 pm Post subject: Makenote viewnotes makenote.txt help[Solved] |
|
|
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
| Code: | bind msg SA|SA makenote cmd:makenote
bind msg SA|SA viewnote cmd:viewnote
set fname "makenote.txt"
proc cmd:makenote {nick uhost hand text} {
set username [lindex [split $arg] 0]
set text [lrange [split $arg] 1 end]
putserv "PRIVMSG $username :$text"
puthelp "NOTICE #Test :Note left about $username to view type /msg trainingbot viewnote $username"
}
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set where_to_insert 0
set lines [linsert $lines $makenote.txt $text]
set fp [open $fp "w"]
puts $fp [join $lines "\n"]
close $fp
}
} |
_________________ Blake
UKEasyHosting UKStormWatch
Last edited by blake on Thu Dec 24, 2009 11:43 am; edited 1 time in total |
|
| Back to top |
|
 |
BLaCkShaDoW Op

Joined: 11 Jan 2009 Posts: 115 Location: Romania
|
Posted: Wed Dec 23, 2009 3:48 am Post subject: |
|
|
| Code: | 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"
}
}
} |
try it  _________________ BLaCkShaDoW Production @ WwW.TclScripts.Net |
|
| Back to top |
|
 |
blake Master
Joined: 23 Feb 2009 Posts: 201
|
Posted: Thu Dec 24, 2009 8:18 am Post subject: |
|
|
Brill thanks BLaCkShaDoW works nice 1 more thing how can i add delnote username to this or get it to overwrite the existing note for username _________________ Blake
UKEasyHosting UKStormWatch |
|
| Back to top |
|
 |
BLaCkShaDoW Op

Joined: 11 Jan 2009 Posts: 115 Location: Romania
|
Posted: Thu Dec 24, 2009 10:56 am Post subject: |
|
|
| Code: | 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 _________________ BLaCkShaDoW Production @ WwW.TclScripts.Net |
|
| Back to top |
|
 |
blake Master
Joined: 23 Feb 2009 Posts: 201
|
|
| Back to top |
|
 |
|