aahnik / tgcf

The ultimate tool to automate custom telegram message forwarding. Live-syncer, Auto-poster, backup-bot, cloner, chat-forwarder, duplicator, ... Call it whatever you like! tgcf can fulfill your custom needs.
https://github.com/aahnik/tgcf/wiki
MIT License
1.34k stars 797 forks source link

Error in filtering for certain words starting with @ #138

Closed aahnik closed 3 years ago

aahnik commented 3 years ago

i want to add something here: words start with characters like '@' or '#' can't be filtered.

is this a feature request ? or you mean this happens ?

Yes. when someone wants to omit "@someid" the program run in to error.

Originally posted by @ehs4nm in https://github.com/aahnik/tgcf/issues/93#issuecomment-835210840

aahnik commented 3 years ago

What is the problem? There is no problem. I tested with the latest version of tgcf, and it works perfectly fine.

You must write those words under quotes.

Suppose you want to blacklist messages that contain the specific words #tag and @word.

Then in your configuration

plugins:
  filter:
    text:
      blacklist:
      - "#tag"
      - "@word"

If you want to blacklist messages that contain any word starting with # or @ then you can use the power to regex.

The expression for that is \s+(@\w+)\s*, replace @ with # incase of #

plugins:
  filter:
    text:
      regex: true
      blacklist:
        - "\\s+(#\\w+)\\s*"  # matches any word starting with a hashtag symbol
        - "\\s+(@\\w+)\\s*"  # matches any word starting with the at-the-rate symbol

Note The double slashes are for escaping the first slash in yaml

The above regex pattern has a limitation. It Will does not apply if the first word starts with @ or #. If you try and think, you can come up with a better regex pattern.