Trigger on matches based on a table

Posted by Rene on Wed 06 Dec 2017 06:21 AM — 5 posts, 22,648 views.

#0
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?" }
USA Global Moderator #1
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.
#2
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?
Australia Forum Administrator #3
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>



Template:pasting
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.
Amended on Wed 06 Dec 2017 11:42 PM by Nick Gammon
Australia Forum Administrator #4
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.