Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Removing Chat Signatures

Removing Chat Signatures

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Traz   (31 posts)  Bio
Date Wed 21 Feb 2018 01:47 AM (UTC)
Message
Ok, so there are some people in the mud I play that like to use signatures in their messages.
Example:
(SNET 1) Traz: -I'm Amazing- Hey guys, whats up? -So Amazing-

I'm trying to find a way to gag the message and then replace it in a chat redirector that I already have without the signature.

I'm just trying to find a way to make my chat more readable without this nonsense in it. Any help would be greatly appreciated.
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 21 Feb 2018 03:21 AM (UTC)
Message
In the chat redirector you already have there would be triggers that pick up the chat messages. Just make one that matches this annoying guy (how old is he? eight?) and remove the signature part before forwarding it to the chat window.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Traz   (31 posts)  Bio
Date Reply #2 on Wed 21 Feb 2018 03:51 AM (UTC)

Amended on Wed 21 Feb 2018 04:43 AM (UTC) by Traz

Message
In the gag part of the script I'm seeing that I can gag the message but I don't see how to replace it. Not too familiar with plugins.

I could share the plugin but how should I do so? It's 731 lines.
Top

Posted by Areadien   USA  (47 posts)  Bio
Date Reply #3 on Wed 21 Feb 2018 04:56 AM (UTC)

Amended on Wed 21 Feb 2018 04:59 AM (UTC) by Areadien

Message
The only way I know of doing this would be to gag the line and then display it again. The first section here is as though it would be in a plugin; the second is as though it's in your world file.

In this example, to show how to preserve the colours, I'm going to assume that (SNET 1) is cyan, "Traz:" is yellow, and, "Hey guys, what's up?" is white.


<triggers>
	<trigger enabled="y" ignore_case="y" keep_evaluating="y" match="^\(SNET 1\) (.*)\: (.*)$" omit_from_output="y" regexp="y" send_to="12" sequence="100">
		<send>remSig("%1", "%2")</send>
	</trigger>
</triggers>

function remSig(char, message)
	if char == "Traz" then
		message = string.gsub(message, "\-I'm Amazing\- (.*) \-So Amazing\-", "%1", "")
	end
	ColourTell("cyan", "black", "(SNET 1) ")
	ColourTell("yellow", "black", char .. ":")
	ColourNote("white", "black", message) --you could also do ColourTell here, followed by Note() on the next line
end


You could also copy and paste this into Ctrl+Shift+8


<triggers>
	<trigger enabled="y" ignore_case="y" keep_evaluating="y" match="^\(SNET 1\) (.*)\: (.*)$" omit_from_output="y" regexp="y" send_to="12" sequence="100">
		<send>local message = "%2"
if "%1" == "Traz" then
	message = string.gsub(message, "\-I'm Amazing\- (.*) \-So Amazing\-", "%1", "")
end
ColourTell("cyan", "black", "(SNET 1) ")
ColourTell("yellow", "black", "%1" .. ":")
ColourNote("white", "black", message) --you could also do ColourTell here, followed by Note() on the next line</send>
	</trigger>
</triggers>
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 21 Feb 2018 05:00 AM (UTC)
Message
Traz said:

I could share the plugin but how should I do so? It's 731 lines.


Put it into Pastebin or something. I just want to have an idea of what you are currently doing.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Traz   (31 posts)  Bio
Date Reply #5 on Wed 21 Feb 2018 07:02 AM (UTC)
Message
Here's the plugin: https://pastebin.com/W9f6BHRN

It's late here so I'll read your last post later, I just wanted to get the plugin posted in case it helps.

Thanks again.
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 21 Feb 2018 10:34 PM (UTC)
Message
OK, so most of the triggers go to redirect or redirect2 functions.

It would be a case of sending to some other function, stripping out the signature, and then forwarding it on.

If the signature is in its own style run, that would require one method, if not, do a different one.

Let's assume for a moment that the signature is in one style.

Make the trigger's script routine be "redirect_nosig" (you don't need to send to script, just make sure that this is the function that gets called, like in the other triggers). Then:



function redirect_nosig (name, line, wildcards, styles)

  for i, v in ipairs (styles) do
     -- remove: -I'm Amazing-
     v.text = string.gsub (v.text, "%-I'm Amazing%-", "")
     -- remove: -So Amazing-
     v.text = string.gsub (v.text, "%-So Amazing%-", "")
     styles [i].text = v.text    -- put text back
     styles [i].length = #v.text -- recompute length
  end -- for each style

  -- pass it on
  redirect (name, line, wildcards, styles)

end -- redirect_nosig


That goes through each style run (assuming therefore that "-I'm Amazing-" is in a single style), and if found, removes it. Ditto for "-So Amazing-".

Now you might find that this gets rid of too much (for example, if you are talking about how annoying "-I'm Amazing-" is to someone else).

You could narrow if down if necessary, for example if "-I'm Amazing-" is always in style 2 then add that as a check:


     -- remove: -I'm Amazing-
     if i == 2 then  -- only check in style #2
       v.text = string.gsub (v.text, "%-I'm Amazing%-", "")
     end -- if style #2


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Traz   (31 posts)  Bio
Date Reply #7 on Thu 22 Feb 2018 08:15 PM (UTC)

Amended on Thu 22 Feb 2018 08:27 PM (UTC) by Traz

Message
So if I wanted to block another signature, I would just need to add another 'for' statement?
Would I also have to use different variables instead of i and v?

Also, what are the % for in the string.gsub? I couldn't find them in the regular expression metacharacters table.
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #8 on Thu 22 Feb 2018 08:49 PM (UTC)

Amended on Thu 22 Feb 2018 08:50 PM (UTC) by Nick Gammon

Message
Traz said:

So if I wanted to block another signature, I would just need to add another 'for' statement?


No, you could test for other signatures in the same loop.

Traz said:

Would I also have to use different variables instead of i and v?


No, loop control variables are local to inside that loop.

Traz said:

Also, what are the % for in the string.gsub? I couldn't find them in the regular expression metacharacters table.


Functions like string.find and string.gsub use Lua patterns, not PCRE ones. They are different in a few ways, in particular Lua uses "%" to escape things like hyphens, unlike PCRE which uses "\". The PCRE regular expressions are used inside triggers, but in Lua you use Lua patterns.

http://www.gammon.com.au/scripts/doc.php?lua=string.find

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #9 on Thu 22 Feb 2018 08:58 PM (UTC)
Message
You could make a table of everything you want to omit, to save having a lengthy lot of string.gsub. For example:


signatures = {

  "-I'm Amazing-",
  "-So Amazing-",
  "-CYA later!",
  "-Bye for now!",
  
  -- put others here

} -- end of signatures

-- -----------------------------------------------------------------
-- for converting things like ^ $ * etc. into "escaped" sequences
-- -----------------------------------------------------------------
function fix_regexp_magic_characters (r)
    return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
end -- fix_regexp_magic_characters

-- Once only, fix up the signatures to "escape" things like hyphens
for k, v in ipairs (signatures) do
  signatures [k] = fix_regexp_magic_characters (v)
end -- for

function redirect_nosig (name, line, wildcards, styles)

  -- for each style run
  for i, v in ipairs (styles) do

     -- remove anything in the signatures table  
     for _, sig in ipairs (signatures) do
       v.text = string.gsub (v.text, sig, "")     
     end -- for
     
     styles [i].text = v.text    -- put text back
     styles [i].length = #v.text -- recompute length
  end -- for each style

  -- pass it on
  redirect (name, line, wildcards, styles)

end -- redirect_nosig


Now we have an inner loop (using different loop variables because this is a loop inside another loop) which goes through the table of signatures you want to omit, and tries each one. The function fix_regexp_magic_characters saves you the trouble of putting "%" in front of hyphens, etc.




Your only problem here is that if someone uses a signature which is in common use (eg. "bye") then it will be omitted from every chat, wherever it appears. However maybe this isn't a big issue for you. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Traz   (31 posts)  Bio
Date Reply #10 on Sat 24 Feb 2018 08:54 PM (UTC)

Amended on Sat 24 Feb 2018 08:56 PM (UTC) by Traz

Message
Ok, so it seems to work fine when the signature has no color codes which I tested, but with color codes something seems to break. I can't for the life of me figure out how to fix this.

Here is an example of one of the simple signatures I'm trying to fix, with color codes:
&16(&07C&15as&16u&15a&07l&16)&07 *message* &16(&05G&13e&05n&16o&13c&05i&16d&05e&16)&07

Without color codes:
(Casual) *message* (Genocide)

Are the color codes breaking the script?

The script still works for redirecting but it's just not removing the colored signatures.
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #11 on Sat 24 Feb 2018 09:22 PM (UTC)

Amended on Sun 25 Feb 2018 02:33 AM (UTC) by Nick Gammon

Message
Traz said:

Are the color codes breaking the script?



Yes they are, because the technique suggested above tries to keep the original colours. You can make it somewhat more complex by trying to detect the word over multiple style runs, or what is simpler is to de-colour it.

In other words, ignore the style runs and do the find and replace on line which is the entire line, without colour information. That will, of course, discard the colours.

If you don't care about highly-coloured chats you can just choose a colour you like and make up your own style run. This would only need to apply for those chats involving these turkeys.

Something like this, for the redirect_nosig function (the rest would be the same):


function redirect_nosig (name, line, wildcards, styles)

  local fixedLine = line
  
   -- remove anything in the signatures table  
   for _, sig in ipairs (signatures) do
     fixedLine  = string.gsub (fixedLine,  sig, "")     
   end -- for
   
   if fixedLine == line then
     -- pass it on unchanged
     redirect (name, line, wildcards, styles)
     return
   end -- if no change to line
   
   styles = { }  -- remove styles
   -- add a single style run which is all the text that is left
   table.insert (styles, {
      text = fixedLine,
      length = #fixedLine,
      textcolour = ColourNameToRGB "gray",   -- choose some colour
      backcolour = ColourNameToRGB "black",  -- whatever the background usually is
      style = 0,  -- not bold, underlined, etc.
      } )
      
    -- pass it on
   redirect (name, fixedLine, wildcards, styles)

end -- redirect_nosig


This - for a message with a signature in it - would throw away all the colour information and replace it with gray on black. For lines with no signature they are passed on unchanged. You can, of course, choose your own colour.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


35,418 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.