|
Aennor Apprentice
Joined: 06 Dec 2001 Posts: 131 Location: USA
|
Posted: Mon Jan 14, 2002 11:35 pm
Help needed with logging to a file |
I'm attempting to write a script (actually modify one that Charbal provided that I can't get to work for me). I want to be able to read my mail and automagically log it to a file. I want to strip out page prompts and I want it to close the file again whenever I'm done.
This seems so simple to me but for the life of me I can't get it to work.
Here's what I came up with so far:
#CLASS {MailLog}
#VAR filenum {1}
#VAR filename {maillog.txt}
#TRIGGER {There is something written upon it:$$ ~* ~* ~* ~* Wheel of Time Mail System ~* ~* ~* ~*} {#t+ {MailLog|Log};#file @filenum @filename}
#CLASS {MailLog|Log}
#TRIGGER {^(%*)$} {#if %1="~* Press ~<Return~> to continue, q to quit ~*~>" {#cr};#if %1="^[o|~*] * > $" {#t- {MailLog|Log};#close @filenum};#if %1="^~* Press ~<Return~> to continue, q to quit ~*~>$" {#cr;#gag -1;#gag};#write @filenum %1;} "" {"prompt"}
#CLASS 0
A mail message will look like this:
* * * * Wheel of Time Mail System * * * *
Date: Thu Dec 20 23:28:57 2001
To: Aennor
From: Lysette
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
* Press <Return> to continue, q to quit *>
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
And then the prompt (that I want to close the file) always begins with a "o" or a "*" and ends with a "> ". Example:
* I104 R:14399 S:Inside >
I'm also trying to strip out the paging prompt and the line before it in the log... I *know* this is possible... I'm just a bit frustrated.
I don't even have a consistent error to point at... it just doesn't work! *pout* :P
Can someone lend a hand?
TIA for any help.
--
Aennor the Paragon of Gratuitous Agony
Staff on WoTMUD
wotmud.org 2222 |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Jan 15, 2002 1:59 am |
Step 1 to fixing it put "'s around %1 in the trigger! You are using %* in your patter and without those quotes your script could fry your stuff. All someone would have to do is mail you with "HI;;#KILLALL;Bye have a nice day" and it wouldn't be a nice day.
Step 2 remove the ~'s from inside the text you have quotes around. The quotes overide parsing of special characters meaning it won't match until your mud starts sending ~'s.
Step 3 Pattern matching is for trigger patterns, not if statements. Remove the ^ and $ where appropriate.
Step 4 Rewrite the if statement that currently compares %1="^[o|~*] * > $". I will give you the solution to this one:
#IF ((%begins("%1","o")|%begins("%1","*"))&%ends("%1","> ")) {#T- {MailLog|Log};#CLOSE @FileNum} |
|
|
|
Aennor Apprentice
Joined: 06 Dec 2001 Posts: 131 Location: USA
|
Posted: Tue Jan 15, 2002 3:38 am |
Ah, I see.. thank you for the help.
Of course the mud crashed when I saw this (critical need detector :P) so I'll check in a little bit.
This is what I end up with based on your comments though:
#CLASS {MailLog}
#VAR filenum {1}
#VAR filename {maillog.txt}
#TRIGGER {There is something written upon it:$$ ~* ~* ~* ~* Wheel of Time Mail System ~* ~* ~* ~*} {#t+ {MailLog|Log};#file @filenum @filename}
#CLASS {MailLog|Log}
#TRIGGER {^(%*)$} {#IF "%1"="* Press Return to continue, q to quit *>" {#CR} {#IF ((%begins( "%1", "o")|%begins( "%1", "*"))&%ends( "%1", "> ")) {#T- {MailLog|Log};#CLOSE @FileNum}{#write @filenum "%1"}}} "" {"prompt"}
#CLASS 0
Did I understand you correctly?
--
Aennor the Paragon of Gratuitous Agony
Staff on WoTMUD
wotmud.org 2222 |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
|
|
|
|
|