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.

Makenote viewnotes makenote.txt help[Solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Makenote viewnotes makenote.txt help[Solved]

Post by blake »

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: Select all

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
  }
}
Last edited by blake on Thu Dec 24, 2009 11:43 am, edited 1 time in total.
User avatar
BLaCkShaDoW
Op
Posts: 121
Joined: Sun Jan 11, 2009 4:50 am
Location: Romania
Contact:

Post by BLaCkShaDoW »

Code: Select all

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
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

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
User avatar
BLaCkShaDoW
Op
Posts: 121
Joined: Sun Jan 11, 2009 4:50 am
Location: Romania
Contact:

Post by BLaCkShaDoW »

Code: Select all

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
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

:D @ BLaCkShaDoW
Post Reply