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.tcl can't erase notes.

Support & discussion of released scripts, and announcements of new releases.
Post Reply
D
DarkStar723
Voice
Posts: 11
Joined: Fri Sep 09, 2005 7:30 pm

publicnotes1.0.1.tcl can't erase notes.

Post by DarkStar723 »

I am trying to get this script working under windows, and can't figure out how to get a tcl script to delete a file, this is what i have so far for the erase_notes process.

Code: Select all

 proc erase_notes { nick uhost hand chan text } {
  set lowercasenick [string tolower $nick]
  set a [dosearchnote $nick]
  if ($a>0) {
  putserv "NOTICE $nick :All your notes have been deleted"
  eval "exec cmd.exe >&@stdout <@stdin /c del .\publicnotes\public$lowercasenick.txt"
  return 1
  } else {
    putserv "NOTICE $nick :You didnt have any notes :P"
    return 0
  }
} 
I know the problem is somewhere in this line (or i think it is):

Code: Select all

eval "exec cmd.exe >&@stdout <@stdin /c del .\publicnotes\public$lowercasenick.txt"
Im just not sure what to change to get it working. Any changes just get me one of these two errors:

[22:21] Tcl error [erase_notes]: couldn't create error file for command: no such file or directory
[22:17] Tcl error [erase_notes]: child process exited abnormally

Original Script: http://www.egghelp.org/cgi-bin/tcl_arch ... oad&id=273
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Re: publicnotes1.0.1.tcl can't erase notes.

Post by DragnLord »

DarkStar723 wrote: Original Script: http://www.egghelp.org/cgi-bin/tcl_arch ... oad&id=273
If you want help post the original script within code tags. People are not going to download a script to help when they could more easily read it on the forum.
D
DarkStar723
Voice
Posts: 11
Joined: Fri Sep 09, 2005 7:30 pm

Post by DarkStar723 »

umm, okay, i thought it would be easier to just post the problematic part in forum so as to not be all spammy, and leave the complete script as a link in case anyone wanted to look at it, but heres the whole thing:
Note: i have modified the erase_notes proc in an attempt to get it working under windows, see first post (it doesnt work in its form here, or there).

Code: Select all

#################################
# Public notes by Sergio100 1.01 #
#################################

#You should make a directory named publicnotes where the eggdrop lives :)
#It's messy, i know... But i wrote it without help and without knowing TCL :)
#TO DO: Check users by host, not by nick.
#1.01: I was using string wordend for nicks, but it doesnt work with some characters.
#      So i now use lindex and lrange. It's quite faster too :D

bind join - * onjoin_notes
bind msg - .erasenotes erase_notes
bind msg - .leavenote leave_notes
bind msg - .getnotes get_notes
bind msg - .noteshelp help_notes

#This is the per user limit on notes received at one time (not sent! :).
set limitnotes 2

proc help_notes { nick uhost hand text } {
  global botnick
  puthelp "PRIVMSG $nick :Use /msg $botnick .leavenote <nick> <text> to send a note. 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 2)."
  return 1
}

proc onjoin_notes { nick uhost hand chan } {
  global botnick
  set n [dosearchnote $nick]
    if ($n>0) { 
      putserv "NOTICE $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 "NOTICE $nick :All your notes have been deleted"
  eval "exec rm ./publicnotes/public$lowercasenick.txt"
  return 1
  } else {
    putserv "NOTICE $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 "NOTICE $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 "NOTICE $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 "NOTICE $nick :You didnt have any notes."
    return 1
  }
  set notesfile [open "./publicnotes/public$lowercasenick.txt" "r+"]
  if {[eof $notesfile]} {
    putserv "NOTICE $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 "NOTICE $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 "NOTICE $nick :You have a note from $sendnick -> $msg"
        set yes 1
      }
    }
    if { $yes==0 } {
      putserv "NOTICE $nick :You dont have any notes. Stop bugging me."
    }
    close $notesfile
  }
  return 1
}

##############################
# Show load statement        #
##############################
putlog "Public Notes 1.0 by Sergio100 (EFNet)"
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I massively re-wrote this script myself, because it was so very unsecure.

But my changes rely on undernet, and users using a *!*@name.users.undernet.org mask, and made it work only with known-users (known to the bot) ...

I also changed it to handle special chars properly, because as it was, it does not handle them. I figured my changes were too specific to my own needs, so I haven't published the script publically. If there is interest, I can post my version publically.

In my version, I use:

file delete -force /full/path/to/publicnotes/note.$uhostname.txt

I assume that should work with tcl under windows? I do not recommend using exec!!! :P

Peronally, if I had to use eggdrop under windows (not even if it was the last OS on earth ;p) I would install cygwin and use tcl/eggdrop under cygwin, which gives you a unix-like OS under windows, so you would not have these problems with pathname differences and such :)
D
DarkStar723
Voice
Posts: 11
Joined: Fri Sep 09, 2005 7:30 pm

Post by DarkStar723 »

Thanks for the reply rosc2112, unfortunately that didnt work either, think im cursed with this script (would help if i knew what i was doing). I'm not sure about anyone else, but i personally would like to see your script.

(and tcl/eggdrop under cygwin, oh god, dont get me started on that, it caused so incredibly many bugs that i just gave up, and still has about the same problems *cries*.)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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

Post by rosc2112 »

Did a bit of updating on the script, since that was one of my first script re-writes..Amazing how much ya revise once you're more experienced ;)

(edit)
Made the notes saved path a configurable variable today..

Same url as above.
Post Reply