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.

publicnotes1.0.1 - help please?

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
salyn
Voice
Posts: 6
Joined: Sat Jun 17, 2006 7:27 pm

publicnotes1.0.1 - help please?

Post by salyn »

Script works great........except it won't erase the notes. ideas?

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
}


so when i do the !erasenotes i get this error in the bot:
[17:28] Tcl error [erase_notes]: couldn't execute "rm": no such file or directory
Last edited by salyn on Thu Jun 29, 2006 11:06 pm, edited 1 time in total.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Code: Select all

eval "exec rm ./publicnotes/public$lowercasenick.txt" 
It would appear the above folder, publicnotes, is not being created or the file is not being created within it (if it does indeed exist).
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
salyn
Voice
Posts: 6
Joined: Sat Jun 17, 2006 7:27 pm

Post by salyn »

It would appear the above folder, publicnotes, is not being created or the file is not being created within it (if it does indeed exist).
yea the folder is there, and the file is created. i'm getting the notes

next idea?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Presumably this is on a windows box, which doesn't have an 'rm' command, it has 'del'

BTW, that script is exploitable, since it does not handle tcl-special chars, and especially since you're using 'exec'

I rewrote that script to be safe. If you want to look it over for ideas, it's at:
http://members.dandy.net/~fbn/publicnot ... 12.tcl.txt
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

and if you use "file delete" from TCL it will run even on both :D.

Edit: has it been tried to be used with the full functional TCL like 8.4.9 was? Meaning no need for that stdin/ou thing.
Last edited by De Kus on Thu Jun 29, 2006 5:20 am, edited 1 time in total.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

According to another post, 'file delete' doesn't work either in windows. See:
http://forum.egghelp.org/viewtopic.php?p=62509
User avatar
salyn
Voice
Posts: 6
Joined: Sat Jun 17, 2006 7:27 pm

Post by salyn »

Hmm, tried your script, and maybe i'm just not awake enough to think this through, but when i tested it, i got
06:18 <decadent`pleasure> You must have a *.users.undernet.org hostmask to use notes, sorry!
i'm not using this on undernet
User avatar
salyn
Voice
Posts: 6
Joined: Sat Jun 17, 2006 7:27 pm

Post by salyn »

and if you use "file delete" from TCL it will run even on both Very Happy.

De Kus
Ok, little more awake.......forget about using that other script, one small little change worked.

thanks so much
Post Reply