decent-chat / decent

Open source messaging platform for the modern web
https://meta.decent.chat
GNU General Public License v3.0
21 stars 5 forks source link

Let servers modify messages according to admin-defined Regular Expressions #286

Open joker314 opened 6 years ago

joker314 commented 6 years ago

This issue is a feature request.

Every server would be able to define a list of find-and-replace regular expressions. These would be applied to incoming messages before sending them out to all other clients.

For example, let's say "apple" is a very very naughty word. Then, into the decent command line, you could type

decent> add filter /apple/i redacted

The first argument is a regular expression, and the second argument is what the replacement should be. Referencing matched groups can be done through $number. For example, if a server for developing Decent wanted to replace numeric issue numbers with links to their GitHub issue and PRs, they could do

decent> add filter /#([0-9]+)/ [#$1](https://github.com/decent-chat/decent/issues/$1/)

(Note: /issues/ will redirect to /pulls/ automatically if needed).

This is useful because it edits messages in a different way to how a bot would. Main advantages are

For more complicated actions, you can of course use a bot.

How should we deal with removing these filters? I propose

decent> ls filter

There are currently 2 filters in place for this server:

+------+-------------+---------------------------------------------------------+
|  ID  | Matches     | Replaced by                                             |
+------+-----------------------+-----------------------------------------------+
|  1   | /#[0-9]+/   | [#$1](https://github.com/decent-chat/decent/issues/$1/) |
+------+-----------------------+-----------------------------------------------+
|  2   | /apple/i    | REDACTED                                                |
+------+------------------+----------------------------------------------------+
decent> delete filter 1

The filter with ID 1 had been removed. It was

/#[0-9]+/ ----> [#$1](https://github.com/decent-chat/decent/issues/$1/)

(aah took me way too long to construct that table in a proportional font)

Or, this could be done on the actual (web)client because it's not too hard to do that and it's not that advanced of a feature.

joker314 commented 6 years ago

Hmm I'm not sure how decisions are made here, but let's have a poll!

If you want a Filters server page then react with 👍 If you want a Filters CLI command then react with 👎

joker314 commented 6 years ago

Okay, for those wanting to implement the actual filtering bit, I guess this is relevant bit which decides what to do with incoming messages. I suppose the filtering should happen before it even enters the database?

https://github.com/decent-chat/decent/blob/0c10790d8319ab6fa661e8cf5b052dc5247af147/packages/server/api.js#L418

This is separate to how we receive the filter rules though.