Code: Select all
bind join - * onjoin_notes
bind msg - !erasenotes erase_notes
bind msg - !leavenote leave_notes
bind msg - !getnotes get_notes
bind msg - !noteshelp help_notes
bind msg - !delnotes erase_notes
bind msg - !sendnote leave_notes
bind msg - !notehelp help_notes
bind msg - !checknotes get_notes
bind msg - !notes help_notes
#This is the per user limit on notes received at one time (not sent! :).
set limitnotes 20
proc help_notes { nick uhost hand text } {
global botnick
puthelp "PRIVMSG $nick :Use /msg $botnick !leavenote <nick> <text> to send a note to any of the DJ's."
puthelp "PRIVMSG $nick :DJ's? Use /msg $botnick !getnotes to read your notes or /msg $botnick !erasenotes to delete them."
puthelp "PRIVMSG $nick :The script will let you know if you have notes when you join the channel. Please delete your notes after reading them. Otherwise you wont be able to get more (limit is 20)."
return 1
}
proc onjoin_notes { nick uhost hand chan } {
global botnick
set n [dosearchnote $nick]
if ($n>0) {
putserv "PRIVMSG $nick :You have $n notes waiting to be read. Use /msg $botnick !getnotes to read them."
return 1
}
return 0
}
proc erase_notes { nick uhost hand text } {
set lowercasenick [string tolower $nick]
set a [dosearchnote $nick]
if ($a>0) {
putserv "PRIVMSG $nick :All your notes have been deleted"
eval "exec rm ./publicnotes/public$lowercasenick.txt"
return 1
} else {
putserv "PRIVMSG $nick :You didnt have any notes :P"
return 0
}
}
proc dosearchnote {getnick} {
set lowercasenick [string tolower $getnick]
set notesf [file exists "./publicnotes/public$lowercasenick.txt"]
if ($notesf==0) {
return 0
}
set notesfile [open "./publicnotes/public$lowercasenick.txt" "r+"]
set numbernotes 0
while {[eof $notesfile] == 0} {
set line [gets $notesfile]
set nickline [lindex $line 0]
if {[string compare [string tolower $nickline] [string tolower $getnick]] == 0} {
set numbernotes [incr numbernotes]
}
}
close $notesfile
return $numbernotes
}
proc leave_notes { nick uhost hand text } {
global limitnotes
set getnick [lindex $text 0]
set msg [lrange $text 1 end]
set numbernotes [dosearchnote $getnick]
set cmp [expr $numbernotes >= $limitnotes]
if ($cmp>0) {
putserv "PRIVMSG $nick :The user already has $limitnotes notes. No more notes can be added to prevent spam."
} else {
set lowercasenick [string tolower $getnick]
set thereis [file exists "./publicnotes/public$lowercasenick.txt"]
set cmp [expr $thereis == 1]
if ($cmp) {
set notesfile [open "./publicnotes/public$lowercasenick.txt" "a"]
} else {
set notesfile [open "./publicnotes/public$lowercasenick.txt" "w+"]
}
puts $notesfile "$getnick $nick $msg"
putserv "PRIVMSG $nick :Note to $getnick has been stored."
close $notesfile
}
return 1
}
proc get_notes { nick uhost hand text } {
set lowercasenick [string tolower $nick]
set thereis [file exists "./publicnotes/public$lowercasenick.txt"]
if ($thereis==0) {
putserv "PRIVMSG $nick :You didnt have any notes."
return 1
}
set notesfile [open "./publicnotes/public$lowercasenick.txt" "r+"]
if {[eof $notesfile]} {
putserv "PRIVMSG $nick :You dont have any notes."
close $notesfile
} else {
set yes 0
set b [dosearchnote $nick]
set cmp [expr $b > 0]
if ($cmp<=0) {
putserv "PRIVMSG $nick :You dont have any notes."
close $notesfile
return 1
}
while {[eof $notesfile] == 0} {
set line [gets $notesfile]
set thisnick [lindex $line 0]
set cmpstr [string compare [string tolower $thisnick] [string tolower $nick]]
if ($cmpstr==0) {
set sendnick [lindex $line 1]
set msg [lrange $line 2 end]
putserv "PRIVMSG $nick :You have a note from $sendnick -> $msg"
set yes 1
}
}
if { $yes==0 } {
putserv "PRIVMSG $nick :You dont have any notes. Stop bugging me."
}
close $notesfile
}
return 1
}
[17:28] Tcl error [erase_notes]: couldn't execute "rm": no such file or directory
Code: Select all