Chat prefixes

Posted by Norbert on Fri 19 May 2006 03:31 PM — 2 posts, 13,456 views.

USA #0
I was wondering if a script function could be added to allow the Chat prefixes to be changed. I know the one in the world configuration is there, which I use that one. It's the one that is generated immediately after that one that I want to change. For example:

my chat prefix is [C] and I currently see

[C]You chat to Player, 'message'
[C]Player chats to you, 'message'
[C]You emote to Player: Me nods.

What I'd like to see is

[C]Me says: 'message'
[C]Player says: 'message'
[C]Me nods.
[C]Player nods.

Or if there is already a way to adjust these with current script functions please let me know.
Australia Forum Administrator #1
Yes, the chat system was designed to be fully scriptable. To do this you need to modify the chat plugin. I have modified the Lua chat plugin because I prefer Lua these days. The functionality is the same as the VBscript one. It is at:

http://www.gammon.com.au/mushclient/plugins/Lua_Chat.xml


Edit the plugin in an editor, and search for the function OnPluginChatDisplay. This is called when MUSHclient is about to display a chat message. What we do is detect the normal chat message types (4 to 9) and modify their appearance. We need to do this with regular expression matching because the actual message (Like "You chat to Player,") is hard-coded into MUSHclient.

I am using a table of regular expressions, with the "before" being the key, and the "after" being the replacement. The plugin keeps scanning through the table until it gets a match. To save mucking around with the imbedded colour codes it uses StripANSI to convert the message back to raw text. If you really want the colours in the resulting message you would need to use ANSI in the replacement text and call AnsiNote to display it.



-- OnPluginChatDisplay
-- ------------------
--
--  MUSHclient is about to display message: type, text
--  Return TRUE to use the default display, FALSE to not display
--
--  Note - the message type number, which groups types
--         of messages, as follows:
--

--   0 Connection attempt    
--   1 Session start, end          
--   2 Name Change        
--   3 Message           
--   4 Incoming Personal  
--   5 Incoming Everybody 
--   6 Incoming Group     
--   7 Outgoing Personal  
--   8 Outgoing Everybody 
--   9 Outgoing Group     
--  10 Peek List          
--  11 Connection List    
--  12 Ping              
--  13 Information       
--  14 File              
--  15 Snoop Data         
--  16 Command

-- table of conversions of chat messages

chat_conversions = {

  -- outgoing
     ["^You chat to (.+), "] = "Me says ",
     ["^You emote to (.+): (.+) "] = "Me ",
  
  -- incoming   
     ["^(.+) chats to (.+), "] = "%1 says ",
     ["^To you, (.+) "] = "%1 ",

}    -- end of chat_conversions table

function OnPluginChatDisplay (message, sText)
  local k, v, count
  
  if message >= 4 and message <= 9 then

-- adjust message text

     sText = StripANSI (sText)
     
     for k, v in pairs (chat_conversions) do
       sText, count = string.gsub (sText, k, v, 1) 
       if count > 0 then
          break
       end -- if
     end -- for
          
     ColourNote ("red", "black", sText)
                  
    return false
  end -- if 
  

  return true -- display it

end -- function