| View previous topic :: View next topic |
| Author |
Message |
televi Voice
Joined: 13 Aug 2010 Posts: 4
|
Posted: Fri Aug 13, 2010 2:13 pm Post subject: write and delete file on trigger |
|
|
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
Any help is much appreciated! |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Fri Aug 13, 2010 2:52 pm Post subject: |
|
|
| 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 |
|
 |
televi Voice
Joined: 13 Aug 2010 Posts: 4
|
Posted: Fri Aug 13, 2010 3:07 pm Post subject: thanx |
|
|
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 |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Fri Aug 13, 2010 3:10 pm Post subject: |
|
|
| Try again mate, I fixed a few things. You probably loaded it before I edited. :S |
|
| Back to top |
|
 |
televi Voice
Joined: 13 Aug 2010 Posts: 4
|
Posted: Fri Aug 13, 2010 3:17 pm Post subject: thaaannkkk you! |
|
|
Oh that I did!
Thanx a lot man!!! you the best!! |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Fri Aug 13, 2010 3:37 pm Post subject: |
|
|
Your welcome. 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 |
|
 |
televi Voice
Joined: 13 Aug 2010 Posts: 4
|
Posted: Fri Aug 13, 2010 5:24 pm Post subject: no worries |
|
|
dont worry this is all i needed! everything works fine, thanx a lot |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Fri Aug 13, 2010 10:18 pm Post subject: |
|
|
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.
| 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 |
|
 |
|