Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ General
➜ How to interact with table and wildcards?
How to interact with table and wildcards?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Khannon
(32 posts) Bio
|
Date
| Fri 14 Jan 2022 04:51 PM (UTC) |
Message
|
<triggers>
<trigger
enabled="y"
match="^This is wildcard (.*?) and this is another wildcard (.*?)'$"
regexp="y"
send_to="10"
sequence="100"
group="tablegroup"
script="learn_table"
>
</trigger>
</triggers>
t = {
"Small wildcard",
"Bigger wildcard",
"Biggest wildcard",
}
What I would to do is check if wildcard[2] is in the table. If it is in the table then I'd like to send a message example:
Execute("gt I'm sending this message because I found <Biggest wildcard>")
I would also like to know if I don't find a wildcard in my table how to send output saying I didn't find it in my table.
I have read quite a lot of tables, but I can't quite seem to grasp how to do it. I've always tried to do something with tables and it failed miserably every time.
Thanks in advance! | Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 14 Jan 2022 08:48 PM (UTC) |
Message
| I changed your trigger slightly because you had what seemed like a stray quote at the end, and you were sending to "Execute" however with nothing in the Send box.
<triggers>
<trigger
enabled="y"
group="tablegroup"
match="^This is wildcard (.*?) and this is another wildcard (.*?)$"
regexp="y"
script="learn_table"
sequence="100"
>
</trigger>
</triggers>
And the code in the script file would be:
t = {
"Small wildcard",
"Bigger wildcard",
"Biggest wildcard",
}
function learn_table (name, line, wildcards, styles)
local foo = wildcards [2]
for k, v in ipairs (t) do
if v == foo then
Execute ("gt I'm sending this message because I found " .. foo)
end -- if
end -- for
end -- learn_table
Alternatively you can do the whole thing inside the trigger without a script file, in which case you omit the script name "learn_table" from the trigger:
<triggers>
<trigger
enabled="y"
group="tablegroup"
match="^This is wildcard (.*?) and this is another wildcard (.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
t = {
"Small wildcard",
"Bigger wildcard",
"Biggest wildcard",
}
local foo = "%2"
for k, v in ipairs (t) do
if v == foo then
Execute ("gt I'm sending this message because I found " .. foo)
end -- if
end -- for
</send>
</trigger>
</triggers>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
The code is slightly inefficient because it involves a linear scan of the table, a better way would be to use a keyed table, and then just do a lookup, eg.
<triggers>
<trigger
enabled="y"
group="tablegroup"
match="^This is wildcard (.*?) and this is another wildcard (.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
t = {
["Small wildcard"] = true,
["Bigger wildcard"] = true,
["Biggest wildcard"] = true,
}
if t [ "%2" ] then
Execute ("gt I'm sending this message because I found %2" )
end -- if
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Khannon
(32 posts) Bio
|
Date
| Reply #2 on Fri 14 Jan 2022 11:58 PM (UTC) |
Message
| Thanks for the reply, Nick!
This is all excellent. I was googling about tables for so long, all it took you was write this reply and I immediately understood what I was doing wrong! | Top |
|
Posted by
| Khannon
(32 posts) Bio
|
Date
| Reply #3 on Sat 15 Jan 2022 01:51 AM (UTC) Amended on Sat 15 Jan 2022 01:55 AM (UTC) by Khannon
|
Message
| The first reason why I wanted to use the table in the script was to blacklist words/messages(in form of wildcards sort of) actually, I never figured that out.
In the reply you sent, I was able to successfully make my table work the way I intended, but in another script, I'd like to do the opposite if wildcards are in the table, prevent script shooting message/execute/action. This is something I was looking around in these forums, however, what I found was not exactly what I was looking for and I couldn't really write it correctly. If you have simple few lines to spare for me, would be wonderful. | Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sat 15 Jan 2022 05:06 AM (UTC) |
Message
| Make a try and post what you come up with. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Khannon
(32 posts) Bio
|
Date
| Reply #5 on Wed 19 Jan 2022 06:25 PM (UTC) Amended on Wed 19 Jan 2022 06:27 PM (UTC) by Khannon
|
Message
| Trigger to let's say an open chat/channel in-game. Someone calls someone else with a blacklisted word/phrase and I want to block the message being sent to another channel
<triggers>
<trigger
enabled="y"
group="bList"
match="^Open Chat: (.*?) called (.*?) <blacklisted word/phrase> $"
regexp="y"
script="bList"
sequence="100"
>
</trigger>
</triggers>
Based on last time I would make a table with words/phrases that I would want to be blacklisted.
t = {
"bad word",
"very bad word",
"bad phrase"
}
I would like to utilize I think string.find in my table in the script, but I don't quite know how to write it
function bList (name, line, wildcards)
-- the parts I don't know how to write
-- if msg doesn't include blacklisted words/phrases
-- send the Open Chat message to Global msg, if it does then -- don't forward the message to Global msg.
I have tried to utilize string.find in table, I guess I don't really know how to work with string.find and k and v.
But it also doesn't have to be string.find, it's just something I tried to mess with, but it was going nowhere at all, heh.
if I'm just trying to use string.find to match the variable, that much I've learned, I think.
str = wildcards[1]
if string.find(str, "Found string") then
print("Found string " ..str)
| Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 23 Jan 2022 06:57 AM (UTC) |
Message
| Is the blacklisted phrase in a wildcard?
If so, can you not at least find and print that (potentially) blacklisted phrase?
If you can print it, then you have something you know you want to look up in a table. Once you get to that point it is like my last answer. |
- 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.
12,377 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top