Removing prompt from logs to put it simply.

Posted by Wuggly on Wed 27 Apr 2016 08:28 PM — 3 posts, 14,366 views.

USA #0
Hello,
I have been working on something that has been boggling my mind for a few days now.

Basically, what I have done, is I made a trigger that captures every line, which is used to log specific things in the MUD I play.

I am trying to make an option that will automatically remove their prompt from the log. (I know, rough territory I am going into).

I have made two different things for this trying to figure out how to do it. The first one gives the player 10 seconds to copy their prompt then an input box pops up and asks them to paste it in.

From there, it converts it to an expression. I have also made one that converts it into a regular expression, and both adds a space after it since I noticed there is always a space after your prompt in this MUD.

The problem is I am clueless as how to compare it with the trigger that logs everything since I can't seem to use a simple if line == prompt statement since it compares it with the escapes or with the regex one the %d's and such.

Another attempt, I tried making a second trigger that would match on their prompt, which would set a variable updating exactly what their current prompt is, however I cannot do this since the trigger cannot be a variable. ie: match=their_converted_prompt

The trigger that logs everything is simple, just a * then the function uses the line to append it to notepad after a bunch of if statements so it only logs specific things.

Any ideas on how I could go about this? I've looked into comparing it with like string.match so it could be compared to an expression, but became lost on that as well.


Anyways, I thought the converting part might be useful for others if needed to convert something like that in a script, so here's that code. It's not perfect, but could easily be fixed up if someone were to use it. I just never finished it as I found it to be pointless to make with what I was trying to accomplish.


For basic expression, with a space added after prompt.

function promptConvert ()
 prompt = utils.inputbox ("Paste your full prompt into the box below", "Prompt Converter BASIC", "", "Courier", 9)
 if prompt ~= nil then 
   promptResult = string.gsub (prompt, "[%%%]%^%-$().<>:[*+?]", "%\\%1")
   promptResults = string.gsub (promptResult, "%d+", "%*") .. " "
   print(promptResults)
 end -- prompt
end -- function promptConvert

Example:
Input  -- <500hp(500) 500ma(500) 500mv(500)(78453) 221900gp ft: none sp: [commn] >
Output -- \<*hp\(*\) *ma\(*\) *mv\(*\)\(*\) *gp ft\: none sp\: \[commn\] \> 


For regular expression, with a space added after prompt.

function promptConvert ()
 prompt = utils.inputbox ("Paste your full prompt into the box below", "Prompt Converter REGEX", "", "Courier", 9)
 if prompt ~= nil then 
   promptResult = string.gsub (prompt, "[%%%]%^%-$().[*+?]", "%%%1")
   promptResults = string.gsub (promptResult, "%d+", "%%d") .. " "
   print(promptResults)
 end -- prompt
end -- function promptConvert

Example:
Input  -- <500hp(500) 500ma(500) 500mv(500)(78453) 221900gp ft: none sp: [commn] >
Output -- <%dhp%(%d%) %dma%(%d%) %dmv%(%d%)%(%d%) %dgp ft: none sp: %[commn%] > 
Amended on Wed 27 Apr 2016 10:41 PM by Wuggly
USA #1
I just wanted to say I've figured it out. I feel very dumb now.

Turned out to be very simple once I saw string.find could be used in an if statement without having to compare to something.

Before I was doing things like if line == string.find and of course that didn't work.

For anyone interested. I simply detected if a line contained both a < and >.

if string.find(line, "<") and string.find(line, ">") then


Wish I could delete this thread.
Amended on Sat 30 Apr 2016 01:24 PM by Wuggly
Australia Forum Administrator #2
How about:


if string.find(line, "<.*>")  then