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.
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.
Your very welcome. 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.