egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

write and delete file on trigger

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
televi
Voice


Joined: 13 Aug 2010
Posts: 4

PostPosted: Fri Aug 13, 2010 2:13 pm    Post subject: write and delete file on trigger Reply with quote

Hi, I am looking for a script that would write in a file on a given trigger..and deletes it after an hour

something like:
user> !trigger hello
bot> nick, message written.
....bot writes nick:message in a file saved on the shell. Once the hour is donee the bot deletes that line in the file.


It sounds simple and I hope its simple Smile

Any help is much appreciated!
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Fri Aug 13, 2010 2:52 pm    Post subject: Reply with quote

Code:

bind pub - !trigger trigger
proc trigger {nick host hand chan text} {
 set mfile "messages.txt"
    set msg [join [lindex [split $text] 0 end]]
    if {![file exists $mfile]} {
        close [open $mfile w]
    }
    set fs [open $mfile]
    set msgs [read -nonewline $fs]
  close $fs
    if {![llength $msgs]} {
        set fs [open $mfile w]
    } else {
        set fs [open $mfile a]
    }
    puts $fs "$nick:$msg"
 close $fs
    putserv "PRIVMSG $chan :$nick, added message: $nick:$msg."
    utimer 60 [list delete_file $mfile $nick $msg]
}

proc delete_file {mfile nick msg} {
    set fs [open $mfile]
    set msgs [split [read -nonewline $fs] \n]
   close $fs
    set line [lsearch -exact $msgs "$nick:$msg"]
    set lines [lreplace $msgs $line $line]
    set fs [open $mfile w]
    puts $fs [join $lines "\n"]
 close $fs
   putserv "PRIVMSG $chan :Message $nick:$msg has been deleted."
}



Messages will be written to ~/eggdrop/messages.txt. This seems incomplete to me though... this will write the data, but nothing is really being done with it, other than deleting...


Last edited by Luminous on Fri Aug 13, 2010 3:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
televi
Voice


Joined: 13 Aug 2010
Posts: 4

PostPosted: Fri Aug 13, 2010 3:07 pm    Post subject: thanx Reply with quote

thanx for the quick reply!

However, the bot does create the file messages.txt but does not write anything it in. I also do not see any errors/problems in partyline
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Fri Aug 13, 2010 3:10 pm    Post subject: Reply with quote

Try again mate, I fixed a few things. You probably loaded it before I edited. :S
Back to top
View user's profile Send private message
televi
Voice


Joined: 13 Aug 2010
Posts: 4

PostPosted: Fri Aug 13, 2010 3:17 pm    Post subject: thaaannkkk you! Reply with quote

Oh that I did! Smile

Thanx a lot man!!! you the best!!
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Fri Aug 13, 2010 3:37 pm    Post subject: Reply with quote

Your welcome. Smile And okay... I don't have a lot of time to work on it atm, but I'll see what I can do about that.
Back to top
View user's profile Send private message
televi
Voice


Joined: 13 Aug 2010
Posts: 4

PostPosted: Fri Aug 13, 2010 5:24 pm    Post subject: no worries Reply with quote

dont worry this is all i needed! Smile everything works fine, thanx a lot
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Fri Aug 13, 2010 10:18 pm    Post subject: Reply with quote

Your very welcome. Smile I didn't mean to make it sound like a hassle, I always enjoy scripting. I went ahead and used a familiar method, using the comment field to store a keyword to check for when allowing or disallowing messages. I am sure there is a better way to do this though. Maybe another scripter can provide a different/better way. Smile
Code:

bind pub - !trigger trigger
proc trigger {nick host hand chan text} {
 set mfile "messages.txt"
 set comment [getuser $hand comment]
  if {$comment eq "msg"} {
    putserv "NOTICE $nick :Sorry, you are only allowed to create one message per hour."
 return
  }
   setuser $hand comment "msg"
    set msg [join [lindex [split $text] 0 end]]
    if {![file exists $mfile]} {
        close [open $mfile w]
    }
    set fs [open $mfile]
    set msgs [read -nonewline $fs]
  close $fs
    if {![llength $msgs]} {
        set fs [open $mfile w]
    } else {
        set fs [open $mfile a]
    }
    puts $fs "$nick:$msg"
 close $fs
    putserv "PRIVMSG $chan :$nick, added message: $nick:$msg."
    utimer 60 [list delete_msg $mfile $nick $hand $msg $chan]
}

proc delete_msg {mfile nick hand msg chan} {
    set fs [open $mfile]
    set msgs [split [read -nonewline $fs] \n]
   close $fs
    set line [lsearch -exact $msgs "$nick:$msg"]
    set lines [lreplace $msgs $line $line]
    set fs [open $mfile w]
    puts $fs [join $lines "\n"]
 close $fs
   setuser $hand comment ""
   putserv "PRIVMSG $chan :Message \"$nick:$msg\" has been deleted."
}


I also fixed the error that probably occured with this line before: putserv "PRIVMSG $chan :Message \"$nick:$msg\" has been deleted."

Forgot to pass the chan arg, whoops.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber