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
➜ Lua
➜ Trigger on matches based on a table
Trigger on matches based on a table
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Rene
(46 posts) Bio
|
Date
| Wed 06 Dec 2017 06:21 AM (UTC) |
Message
| Is there a way to make a plugin that matches based on a table within the plugin?
I know I can do it by using '*' to match everything and then have the script check if it matches, the problem is if it does I want to omit it from output, and it doesn't seem right to have the script catching everything then putting it back in with a ColourNote if it did not match.
I know I can also do a regex that includes all of them, but I want to be able to simply add to the table later and have it start matching that as well.
Thanks.
(Meaning it should match a table
matchtable = { "There is a chair here", "You have a pot", Why are there no flowers?" } | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #1 on Wed 06 Dec 2017 06:53 PM (UTC) |
Message
| I don't think so.
Quote: it doesn't seem right to have the script catching everything then putting it back in with a ColourNote if it did not match.
This is pretty much what I do. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Rene
(46 posts) Bio
|
Date
| Reply #2 on Wed 06 Dec 2017 07:24 PM (UTC) |
Message
| Hmm, two things then, will it lose other changes to the colour from other colour triggers if the plugin is replacing the text?
Also, my reason for this is I want to check for aggressive lines by specific char names, so I want to be able to easily add more types of aggro lines or edit the table of char names I am worried about, so if the plugin can save these as a table and then check from there it will be simple to add or remove.
I was thinking now of having it build triggers using AddTrigger from a table that might allow me to not have to write individual triggers for each one and build the triggers from a table, any thoughts? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Wed 06 Dec 2017 10:53 PM (UTC) Amended on Wed 06 Dec 2017 11:42 PM (UTC) by Nick Gammon
|
Message
| One approach is to make a variable on-the-fly from your table. For example, with this trigger:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="@!my_trigger_list"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
ColourNote ("orange", "", [[Omitted line: %0]])</send>
</trigger>
</triggers>
 |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
Then run this script in a function when you want to alter the items to be matched on:
matchtable = { "There is a chair here", "You have a pot", "Why are there no flowers?" }
local whatToMatch = { }
for k, v in ipairs (matchtable) do
-- "escape" magic characters
local fixed = string.gsub (v, "[%^%$%(%)%.%[%]%*%+%-%?{}\\]", "\\%1")
table.insert (whatToMatch, fixed)
end -- for
SetVariable ("my_trigger_list", "^(" .. table.concat (whatToMatch, "|") .. ")$")
That changes the variable "my_trigger_list" used in the trigger. Basically it concatenates all the strings you want to match, allowing for "magic" regexp characters appearing in the string and escaping them. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Wed 06 Dec 2017 10:55 PM (UTC) |
Message
| An alternative approach would be to use AddTrigger to generate the triggers from your table. Put them into a group so you can easily delete the old ones (go through the group and delete each one) and then add in the new ones based on what is in the table. |
- 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.
16,482 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top