Multiple Chat Capture Miniwindow

Posted by Xinefus on Thu 23 Apr 2020 07:39 PM — 10 posts, 37,488 views.

#0
Hello everyone, I am a long time snooper and first time joining the conversation.

I have been using MUSHclient for a number of years, playing SMAUG based MUDs.

I recently decided to try and spice up my visual experience and try my hand at some plugins to parse different elements of my MUD to miniwindows. I really enjoy the concept but my limited knowledge in lua hinders my progress.

I have been able to successfully implement a Chat Capture Miniwindow such as outlined in Post #5 of:

http://www.gammon.com.au/forum/bbshowpost.php?id=10728&page=1

I would however like to have multiple of these same style miniwindows, each for different chatter that happens in the MUD, such as one for tells and one for ooc?

I have so far been able to put them all in one miniwindow, but I don't know how to create a new window so that I can send different items to it.

Your help with this would be greatly appreciated.

Thanks a bunch.
Amended on Thu 23 Apr 2020 07:56 PM by Xinefus
Australia Forum Administrator #1
The mapper window name is based on the plugin ID, so what you could do is make multiple plugins (all with a different ID) near the start:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
    <plugin
    name="Chat_Capture_Miniwindow"
    author="Fiendish"
    id="565dae21eb816a2fdb8d50f9"    <---------- PLUGIN ID
    language="Lua"
...


Use MUSHclient's Edit menu -> Generate Unique ID to make yourself new plugin IDs.

Now replace the triggers with ones that match the particular text you want to be in the chat window.

To save duplicating all the code, pull out the code part (between <script> and </script>) and put into a separate file (in the same folder as the plugins). Then include it like this:


<!--  Script  -->

<script>
    dofile (GetPluginInfo (GetPluginID (), 20) .. "My_Chat_Window.lua")
</script>


You can add extra lines at the start as required (for example, the chat window name), eg.


<!--  Script  -->

<script>

    CHAT_WINDOW_NAME = "Tells"

    dofile (GetPluginInfo (GetPluginID (), 20) .. "My_Chat_Window.lua")
</script>


Now further down in the code (in the file you just made) find the lines:


    -- Title text
    WindowText(Win, "titlefont"..Win, "COMMUNICATION", ...


And change the fixed word "COMMUNICATION" to be the variable above, eg.


    -- Title text
    WindowText(Win, "titlefont"..Win, CHAT_WINDOW_NAME, ...


Notice the absence of quotes as this is a variable, not a literal.

Now each window will have a different title.

Then install each of the plugins you made.
#2
Oh my! What a speedy and thorough response!

This worked fantastically!

Thank you so much for the help and push in the right direction.

I'll be working on other little tidbits as I go, maybe you will see me on here again.


Cheers!
#3
I've been able to make this work and I really love it.

Is there a way to have 1 plugin do multiple chat miniwindows?

lets say I want a few of the triggers to go in one window and other triggers to go in another?

Right now, each plugin sends the triggers to the 'chats' script. How would I go about changing this so within the same plugin there could be 2 or 3 diff windows.. Is this something that is possible?

Refs: A. https://github.com/DBNU-Braska/DBNU/blob/master/Chat_Capture_Miniwindow.xml
B. https://github.com/DBNU-Braska/DBNU/blob/master/My_Chat_Window.lua
Amended on Thu 14 May 2020 07:57 PM by Xinefus
Australia Forum Administrator #4
Almost anything is possible. This will probably be a bit more work for you. :)

In most plugins which show one window there is a global variable for the window name (usually win or Win but it could be anything). For example from that plugin:


    WindowShow( Win, false )


Now if you want to have multiple windows you would need to assign different names for the different windows, for example instead of:


Win = GetPluginID()


You might have:


Group_Win  = GetPluginID() .. "_group"
Newbie_Win = GetPluginID() .. "_newbie"
Clan_Win   = GetPluginID() .. "_clan"


Now the stuff that creates windows etc. would have to be done for each one. The easy thing would be to keep using Win in most of the code, and in the trigger for each chat type switch the contents of that variable, like this:


-- inside the trigger

Win = Group_Win  -- this stuff goes into the Group window

-- do usual stuff here


You would also have to switch around the buffer which holds the lines. Again, this could be done by making various tables (rawlines in the plugin I am looking at) and then switch the table appropriately. In Lua tables are stored by reference, so this would be fast.

So yes, it could be done.
#5
Alright, so before I jump into this (which you do say it is possible!), here is what I understand, and a bit that I don't.

Let's go with your example of Group, Newbie, Clan all in one plugin.

For this to work, I assign additional window names just as you mention; this is in my "My_Chat_Window.lua". From the trigger portion within my plugin, Do I just add the new line within the trigger:

	<trigger
   enabled="y"
   match="<(OOC|IMM)> {(.+)} \((.+)\) ([a-zA-Z]+) \'(.*?)\'$"
   omit_from_output="y"
   regexp="y"
   script="chats"
   Win = Group_Win  -- this stuff goes into the Group window
   sequence="100"
  >
  </trigger>


Or does that line go in the script portion? Do I have to create functions (group_chats, newbie_chats, clan_chats) within scripts that send the info to "My_Chat_Window.lua" while defining the Win along with the window name?

Right now I am using "My_Chat_Window.lua" to create multiple miniwindows with separate plugins. These use the same tables? I'm a bit confused how I can be using the same .lua but they are different tables.
Australia Forum Administrator #6
Not exactly. You can't put script stuff inside the XML part of the trigger.

Instead of:


script="chats"


You could have what you suggest, eg.


script="group_chats"


OK, so now you need a group_chats function. So that could look like this:


function group_chats (name, line, wildcards, styles)
  Win = Group_Win  -- switch to the Group window name
  chats (name, line, wildcards, styles) -- call the usual function
end -- group_chats


You are basically redirecting the trigger to a function that does one more thing before calling the usual one.

You also need new tables for the lines, so instead of:


-- where to store the chat line
lines = {}  -- table of recent chat lines
rawlines = {}



You could have:


-- where to store the chat line
Group_lines = {}  -- table of recent group chat lines
Group_rawlines = {}
Clan_lines = {}  -- table of recent clan chat lines
Clan_rawlines = {}
Newbie_lines = {}  -- table of recent newbie chat lines
Newbie_rawlines = {}


So now the function above also "switches" to those tables:


function group_chats (name, line, wildcards, styles)
  Win = Group_Win  -- switch to the Group window name
  lines = Group_lines  -- and the group lines
  rawlines = Group_rawlines  -- and the group rawlines
  chats (name, line, wildcards, styles) -- call the usual function
end -- group_chats


There may be other variables around that need switching around but that is the basic idea.
#7
Thanks for the boost. I am not comfortable enough to be doing such a complicated thing in lua. I don't understand enough of how the relationships work within the miniwindow.

I tried to understand the

GetPluginID() .. "_group"

But I can't figure out what Win parts I should and should not have to change within the plugin.

In function init(firstTime), would I have to duplicate each of the statements one for each Group_Win and Clan_Win? or is the 'switch' doing that already for me?

For the tables:

if (firstTime == true) then
        Group_lines = {}
        Clan_lines = {}
        for _,styles in ipairs(Group_rawlines, Clan_rawlines) do 
            fillBuffer(styles)
        end  -- for each line


Is the tables part right?
Australia Forum Administrator #8

No, sorry.

I tried to do it myself, and realize now that the plugin was designed with one window in mind, and lots of it (like the table of lines, the resizing, all sorts of things) follow from that design decision.

To rework it would take a long time (especially as Fiendish modified my original code, so I’m not totally familiar with it).

I don’t think the effort involved justifies the time, considering that the multiple plugins idea works fine for you.

To be clear, it could be done — almost anything is possible, but the effort involved would be considerable, and if you are not familiar with Lua you would need to spend quite a bit of time learning that first.

#9
Not a problem! I will keep it as is then and create a couple of plugins to do just what I am looking to do.