Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced channel filters #1748

Merged
merged 54 commits into from Oct 18, 2020
Merged

Advanced channel filters #1748

merged 54 commits into from Oct 18, 2020

Conversation

dnsge
Copy link
Contributor

@dnsge dnsge commented Jun 21, 2020

Description

Adds custom channel filters complete with their own mini-language. Filters can be created in settings, and applied by clicking the three dots to open the Split menu and selecting "Set filters".

I tried my hand at creating an icon for the filters tab in settings, but I'd like feedback on its design.

Example filters:

  • message.content contains "hello"
  • message.length <= 40 || author.subscribed
  • (message.length <= 10 || message.content contains "look at this") && !(message.content contains "LULW")

Valid but useless filters:

  • 2 + 3 == 5
  • 10 / 2 == 3
  • 20 % 3 == 2

Available per-message variables:

Variable Type Description
Author User who sent the message
author.badges List List of author's badges
author.color Color Color code of author, or none
author.name String Display name of author
author.subbed Bool Whether author is subscribed
author.sub_length Int How long author has been subscribed (or zero)
Channel The channel where the message was sent
channel.name String Channel name
channel.watching Bool Whether the channel is being watched (requires Chatterino extension)
Flags Message-specific flags
flags.highlighted Bool Whether the message is highlighted
flags.points_redeemed Bool Whether the message was redeemed through channel points
flags.sub_message Bool Whether the message is a sub/resub/gift message
flags.system_message Bool Whether the message is a system message
flags.whisper Bool Whether the message is a whisper
Message Actual message sent
message.content String Message content
message.length Int Message length

Available operators:

Operator Description
&& And
|| Or
== Equals
!= Not equals
% Modulus
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
! Not
contains String, List, or Map contains
startswith String or List starts with text or string, respectively
endswith String or List ends with text or string, respectively
+ Add
- Subtract
* Multiply
/ Divide (integer)

Literals:

Name Example
Int 123, 5
String "Hello there", "Escaped \" quote"

Notes about the order of operations:

  • Math operations are evaluated from left to right, not by MDAS. 2 + 3 * 4 yields 20, not 14.
  • a && b || c && d is evaluated as (a && b) || (c && d)
  • a || b && c || d is evaluated as a || (b && c) || d

Still working on:

  • Persist assigned filters after relaunching Chatterino
  • User feedback for parsing of filter
  • Verifying that all types work correctly
  • Fixing order of operations
  • Documentation
  • Properly filtering messages from splits
  • Fixing edge cases

Closes #1643
Closes #1632
Closes #518

This PR should probably be squashed into one commit

@dnsge dnsge marked this pull request as ready for review June 26, 2020 01:00
dnsge and others added 3 commits June 25, 2020 21:02
Some compilers evaluate parameters from right to left which would lead
to incorrect parsing. The parser now works correctly regardless of the
compiler.
@dnsge dnsge marked this pull request as ready for review July 7, 2020 16:32
@fourtf
Copy link
Member

fourtf commented Jul 11, 2020

Why does this introduce a language for defining filters and not a GUI? Is this accessible to users that are not coders?

dnsge added a commit to dnsge/chatterino-wiki that referenced this pull request Sep 28, 2020
@ALazyMeme
Copy link
Collaborator

ALazyMeme commented Sep 29, 2020

Quick question: Is it as simple as adding a filter with author.subbed and the author of the message would have to be subscribed? If so, it isn't working for me.

image

Secondly, using author.subscribed completely crashes chatterino for me.
Thirdly, please create a pr for the wiki to add the filters page: https://github.com/Chatterino/wiki

@dnsge
Copy link
Contributor Author

dnsge commented Sep 29, 2020

@ALazyMeme
author.subbed is valid and works for me:
Screen Shot 2020-09-29 at 2 14 17 PM
Filters are only applied to new messages, not messages that are already present in the channel. Perhaps that's what happened?

As for creating and applying a filter author.subscribed, my Chatterino doesn't crash. Maybe it's a platform-specific bug?

Nevermind, I found the issue (fixed in 1025894). I don't know why I wasn't able to replicate the crash earlier.

@zneix zneix mentioned this pull request Oct 5, 2020
1 task
@pajlada
Copy link
Member

pajlada commented Oct 18, 2020

Will be merging this in as is once #2081 has been merged into master. Thanks a lot for your contribution!

@gempir
Copy link
Contributor

gempir commented Oct 18, 2020

This is an amazing feature that makes Chatterino stand out from a lot of other chat clients. Thank you!

@pajlada pajlada merged commit 0d3e00a into Chatterino:master Oct 18, 2020
pajlada pushed a commit that referenced this pull request Oct 18, 2020
Adds custom channel filters complete with their own mini-language. Filters can be created in settings, and applied by clicking the three dots to open the Split menu and selecting "Set filters".
@dnsge dnsge deleted the filtered-channels branch August 8, 2022 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter Message by username color Add filters to channels. Filterable /mentions tab
10 participants