Hootrix / keyword_alert_bot

telegram keyword alert bot ⏰
https://t.me/keyword_alert_bot
GNU General Public License v3.0
237 stars 59 forks source link

Keyword with spaces #12

Open jiegen78 opened 2 years ago

jiegen78 commented 2 years ago

is it possible to keyword a whole sentence? or, is it possible to make a filter "word 1 but not word 2" i.e. send notification if there is only word 1 but not word 2

thanks

Hootrix commented 2 years ago
  1. the entire sentence can be used as a keyword. try?
  2. Use regular expressions for exclusion

Advanced features require a little knowledge of regex basics. The keyword exclusion function can be arranged at leisure 😁

jiegen78 commented 2 years ago

i am not a regex expert but i digged the internet for a few hours for a regex "with js syntax" and found nothing working. can you kindly make me an example of the syntax? if I put /this is a sentence/ig does not work. thanks a lot

Hootrix commented 2 years ago

i am not a regex expert but i digged the internet for a few hours for a regex "with js syntax" and found nothing working. can you kindly make me an example of the syntax? if I put /this is a sentence/ig does not work. thanks a lot

try it. /^\s*this is a sentence\s*$/ig

jiegen78 commented 2 years ago

thanks for the example, it works on a regex test site, but if I put in the bot the command /subscribe /\ssentence with spaces\s/ig the command is not accepted (also with ^ and $ ) it looks like the bot uses space as a separator and does not read correctly the command after the first space, resulting into an incomplete command.

Hootrix commented 2 years ago

thanks for the example, it works on a regex test site,

but if I put in the bot the command /subscribe /\ssentence with spaces\s/ig the command is not accepted (also with ^ and $ )

it looks like the bot uses space as a separator and does not read correctly the command after the first space, resulting into an incomplete command.

yep. Spaces are indeed separators. I need to see the full command you entered. It may need to be fixed

jiegen78 commented 2 years ago

you can consider "/subscribe /\ssentence with spaces\s/i testchannel" as a non-specific copy of my command, I have not used ^ and $ because the sentence with spaces is part of the whole message I have to filter.

thanks a lot.

Hootrix commented 2 years ago

Sorry, the use of spaces does have a bug.

You can temporarily replace spaces with \s

example:

/subscribe /\bsentencs\s+with\s+spaces\b/i test-channel

jiegen78 commented 2 years ago

this works, thanks a lot

fabianski7 commented 2 months ago

an alternative I'm using is to allow the "+" to be used as a separator, it's simpler than using regular expressions. so:

/subscribe sentence+with+space test-channel

diff --git a/main.py b/main.py
index b53a257..4a23218 100644
--- a/main.py
+++ b/main.py
@@ -288,6 +288,7 @@ where ({' OR '.join(condition_strs)}) and l.status = 0  order by l.create_time
               else:
                 logger.debug(f'regex_match empty. regex:{keywords} ,message: t.me/{event_chat_username}/{event.message.id}')
             else:# Normal mode
+              keywords = keywords.replace('+', ' ')
               if keywords in text:
                 # # {chat_title} \n\n
                 channel_title = f"\n\nCHANNEL: {chat_title}" if not event_chat_username else ""