#(hyper) replacing specific text in a player message

143 messages · Page 1 of 1 (latest)

vernal plank
#

is there a way to retrieve or replace a list within another list? not sure how else I could have worded it but what I'm trying to do is replace an incoming message from a player with stars only on the blocked words.

basically what I'm trying to achieve here is ⬇️

player types: potato tomato bottle

the filter picks up that a word from the words yaml list was inside of the message list, and replaces that word only with stars.

player's message appears as : ****** tomato bottle

summer hingeBOT
#

(hyper) replacing specific text in a player message

summer hingeBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

vernal plank
#

ive already tried using regex with replace_text and without regex, it hasn't exactly worked so ._.

#

ive been playing around with regex using a list of words and replace_text.with but have yet to get a viable solution

#

I know that the following replaces all words, excluding spaces, in a message with a *: - determine <context.message.replace_text[regex:\w].with[*]>

unique berry
#

Couldn't you just .replace_text[ <[word]> ] for each word?

vernal plank
#

Not every word in the words list is one word, misleading name lol but some have spaces in them

unique berry
#

And how would you like to handle these?

#

The space should be left, and only the actual characters replaced with *?

vernal plank
#

Yeah only what is caught should replaced with a *

unique berry
#

Yeah but like, if the player says Hello there you're mean and you're mean is in the list, what should the output be?

vernal plank
#

Hello there ****** **** or Hello there ***’** ****

#

oh god formatting

#

one sec

#

alright there we go

#

something like that

#

either of the two works, but as long as the word/phrase and not the entire message gets starred out

leaden stormBOT
#

Tag parse results for <element[hello world yay].replace_text[world].with[<element[*].repeat[<[world].length]>]>: https://paste.denizenscript.com/View/105101

<element[hello world yay].replace_text[world].with[<element[*].repeat[<[world].length]>]>
#

Tag parse results for <element[hello world yay].replace_text[world].with[<element[*].repeat[<[world].length]>]>]>: https://paste.denizenscript.com/View/105102

hello  yay
Had error: Invalid definition name 'world'.
Had error: Tag <[world].length]> is invalid!
Had error: Unfilled or unrecognized sub-tag(s) '[world].length]' for tag <[world].length]>!
Had error: '[world].length]' is not a valid integer!
molten zenith
#

oh me dummy

leaden stormBOT
molten zenith
#

!t element.repeat

valid raftBOT
# molten zenith !t element.repeat

Returns a copy of the element, repeated the specified number of times.
For example, "hello" .repeat[3] returns "hellohellohello"
An input value or zero or a negative number will result in an empty element.

Group

element manipulation

Returns

ElementTag

molten zenith
#

!t element.length

valid raftBOT
vernal plank
#

ah

#

just what I was looking for

#

I’ll look and see if it accepts the spaces too or not

#

actually I could probably do it here

leaden stormBOT
vernal plank
#

Wonderful

#

Thankfully it was a simple solution ._.

#

I had this exactly in mind, to get the length of the word trying to be blocked and replace each with a * yesterday, but didn’t think to look for a repeat function

leaden stormBOT
#

Tag parse results for <element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]>]>: https://paste.denizenscript.com/View/105108

]>
Had error: (Initial detection) Tag processing failed: The tag 'element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]' is invalid due to misplaced [square brackets]. Did you forget to close some brackets?
Had error: Tag processing failed: The tag 'element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]' is invalid due to misplaced [square brackets]. Did you forget to close some brackets?
#

Tag parse results for <element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]>: https://paste.denizenscript.com/View/105109

Tag processing failed: The tag 'element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]' is invalid due to misplaced [square brackets]. Did you forget to close some brackets?
Had error: (Initial detection) Tag processing failed: The tag 'element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]' is invalid due to misplaced [square brackets]. Did you forget to close some brackets?
Had error: Tag processing failed: The tag 'element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]' is invalid due to misplaced [square brackets]. Did you forget to close some brackets?
#

Tag parse results for <element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]: https://paste.denizenscript.com/View/105110

<element[hello world yay].replace_text[<list[hello|yay]>].with[<element[*].repeat[<list[hello|yay]>.length>]
molten zenith
#

#bot-spam

vernal plank
#

sorry

#

is someone able to delete those messages

molten zenith
#

Don't have to

vernal plank
#

ok

mental pathBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please type </resolved:1028673926114594866> to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@vernal plank

vernal plank
#

still have to test this, having pc issues but once it turns on I’ll test

vernal plank
#

okay alright

#

sorry for taking so long but le computer is back up

#

is there a way to retrieve what is caught and to be starred?

vernal plank
#

is what im looking to do

#

but the word that is being watched out for is in a yml list

#

so the following <element[hello world yay].replace_text[hello world].with[<element[*].repeat[<element[hello world].length>]>]> would have to be more something like <element[hello world yay].replace_text[<yaml[wordsyml].read[words]>].with[<element[*].repeat[<element[wordtoberemoved].length>]>]>

#

trying to figure out what wordtoberemoved would be

molten zenith
#

<yaml[wordsyml].read[words]> - if that returns a ListTag no

vernal plank
#

yeah it does return a list tag

#

so uh

#

is there any way to replace the text with stars if the words that it's looking out for is a listtag? 👀

molten zenith
#

Hmm what you could do is to loop through the list of words

#

!c foreach

valid raftBOT
# molten zenith !c foreach
Group

queue

Syntax

foreach [stop/next/<object>|...] (as:<name>) (key:<name>) [<commands>]

Short Description

Loops through a ListTag, running a set of commands for each item.

Description

Loops through a ListTag of any type. For each item in the ListTag, the specified commands will be ran for that list entry.

Alternately, specify a map tag to loop over the set of key/value pairs in the map, where the key will be <[key]> and the value will be <[value]>.
Specify "key:<name>" to set the key definition name (if unset, will be "key").

Specify "as:<name>" to set the value definition name (if unset, will be "value").
Use "as:__player" to change the queue's player link, or "as:__npc" t...

molten zenith
#

You could filter the list of words first, so you don't foreach a list of 1k+ words

vernal plank
#
- foreach <yaml[wordsyml].read[words].filter[<context.message.contains_any_text[<yaml[wordsyml].read[words]>]>]>:
  - narrate <context.message.replace_text[<[value]>].with[*].repeat[<[value].length>]>
vernal plank
#

for each word in the words list, it filters out messages that don't contains text that are in the yaml. words return true go into value. it then looks to replace all words that fit the value, getting the length of each value and setting it as * in the message

molten zenith
#

use eh, definitions

#

might also be worth to add a ListTag support for element.replace_text

vernal plank
#

to make it simpler to read or

vernal plank
vernal plank
#

imma take a break and mull it over, maybe a possible solution will pop into my head

vernal plank
#

yeah i've got nothing ._.

vernal plank
#

I feel like I might hold off on this until, as Ice said above, ListTag support is added for element.replace_text or until a workaround is found.

solemn perch
#
- define message <context.message>
- foreach <yaml[wordsyml].read[words]> as:word:
  - define censored <element[*].repeat[<[word].length>]>
  - define message <[message].replace_text[<[word]>].with[<[censored]>]>
- determine <[message]>

wait can't you just do something like this

vernal plank
#

i tried setting the foreach to <list[<yaml[wordsyml].read[words]>].filter[<context.message>] instead of <yaml[wordsyml].read[words]> so that it filters out only the words that return true in the iteration and takes less time, but it returned the list as empty

molten zenith
#

!t list.filter

valid raftBOT
# molten zenith !t list.filter

Returns a copy of the list with all its contents parsed through the given tag and only including ones that returned 'true'.
One should generally prefer !tag ListTag.filter_tag.

Returns

ListTag

Examples
# Narrates a list of '3|4|5'
- narrate "<list[1|2|3|4|5].filter[is_more_than[3]]>
molten zenith
#

There must be a comparison that returns true

vernal plank
#

oh

molten zenith
#

ie: context.message.filter[contains_text[<[word]>]]

unique berry
#

Also

#

!g constructor

unique berry
#

You already read a list form the yaml file, you don't need another list constructor

#

Another thing which might help with performance, use a data script

#

!t data_key

valid raftBOT
# unique berry !t data_key
Cannot Specify Searched Tag

Multiple possible tags: <ScriptTag.data_key[<key_name>]>, <NPCTag.citizens_data_keys>.

unique berry
#

!l data script

valid raftBOT
# unique berry !l data script

Data script containers are generic script containers for information that will be referenced by other scripts.

No part of a 'data' script container is ever run as commands.

There are no required keys.

Generally, data is read using the !tag ScriptTag.data_key tag.


data_script_name:

    type: data

    # Your data here
    some_key: some value
    some_list_key:
    - some list value
    some_map_key:
        some_subkey: some value


Group

Script Container System

unique berry
#

It's also a better practice for storing lists / configs that will only every be used by Denizen scripts

molten zenith
#

Isn't a data script slower

unique berry
#

I don't think so? data_key is a static tag

vernal plank
#

the list is going to be modified so I don't think a data script container would be the best choice here

molten zenith
#

I remember we had that convo already

unique berry
#

Might be wrong, but I'm not sure why would that be the case - unless you're referring to like, slower reload times?

hot gullBOT
unique berry
#

yay

warm karmaBOT
#

+> YAY!!!

vernal plank
#

yay

warm karmaBOT
#

+> YAY!!!

unique berry
molten zenith
#

Looking for it

unique berry
molten zenith
#

Oh do static and static tags work different?

unique berry
#

What I meant was that a data script might be faster then using yaml because it's tags are static, and it's a better practice either way

molten zenith
#

Ah

unique berry
vernal plank
vernal plank
#

looks like by turning off debug, the messages got through faster

#

lol

solemn perch
#

I had a scoreboard script that was taking my mspt from 1 to like 6

#

But when I realised it was debug, I turned it off and it was like 1.2

vernal plank
#

damn

solemn perch
#

I think the best way to have it dynamic is to have it be a server flag

vernal plank
vernal plank
unique berry
# vernal plank also, I’m might still wait for listtag support for this because I don’t really t...

A foreach loop should usually be fine, just A. don't pre-optimize, unless something is actually causing lag issues, no need to spend time and effort on optimizing something you think might be laggy
And B. can always mess around with possible implementations / optimizations to see what helps (adding a filter_tag with contains_text checks, adding contains_text checks inside the loop, using a data script to store the words list, etc.)

unique berry
#

Have you attempted these? if so, are you still having performance issues?

#

If you are, then please post your current script so that we can try and optimize it further, otherwise -

mental pathBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please type </resolved:1028673926114594866> to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@vernal plank

vernal plank
vernal plank
patent phoenix
#

computers are wildly quick

#

it's something us humans really struggle to understand sometimes

#

Operations like text manipulation are not going to impact perfomance if they're used in any realistic quantity

#

i'd reiterate aya's point:

#

don't pre-optimize, unless something is actually causing lag issues, no need to spend time and effort on optimizing something you think might be laggy

mental pathBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please type </resolved:1028673926114594866> to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@vernal plank