From 451412973c6a74fffcc3ca0b4eb02b71b987bc9e Mon Sep 17 00:00:00 2001 From: afolivieri Date: Fri, 11 Oct 2024 12:08:13 +0300 Subject: [PATCH 1/2] updated content match message with all possible matches and contextes --- streaming_overseer.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/streaming_overseer.py b/streaming_overseer.py index 29c9c9f..7144662 100644 --- a/streaming_overseer.py +++ b/streaming_overseer.py @@ -123,17 +123,20 @@ async def main(): async def handler(event): try: message_content = event.message.message if event.message else "" + words = [] + contexts = [] for word, pattern in word_patterns.items(): for match in pattern.finditer(message_content): start_pos = max(match.start() - 20, 0) end_pos = min(match.end() + 20, len(message_content)) context = message_content[start_pos:end_pos] - await client.send_message(channel_id, f"Keyword Match: {word}\nContext: {context}") - await asyncio.sleep(0.1) - await event.message.forward_to(channel_id) - await asyncio.sleep(0.5) - print(f'Forwarded Message: {message_content}') - break + words.append(word) + contexts.append(context) + await client.send_message(channel_id, f"Keyword Match: {', '.join(words)}\nContext: {', '.join(contexts)}") + await asyncio.sleep(0.1) + await event.message.forward_to(channel_id) + await asyncio.sleep(0.5) + print(f'Forwarded Message: {message_content}') except Exception as e: logging.error(f"Error in message handler: {e}") From 20c0e8b8d590b2caf12f3c97d31527297222943e Mon Sep 17 00:00:00 2001 From: afolivieri Date: Fri, 11 Oct 2024 12:14:05 +0300 Subject: [PATCH 2/2] updated content match message with all possible matches and contextes --- streaming_overseer.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/streaming_overseer.py b/streaming_overseer.py index 7144662..c1af354 100644 --- a/streaming_overseer.py +++ b/streaming_overseer.py @@ -132,11 +132,13 @@ async def main(): context = message_content[start_pos:end_pos] words.append(word) contexts.append(context) - await client.send_message(channel_id, f"Keyword Match: {', '.join(words)}\nContext: {', '.join(contexts)}") - await asyncio.sleep(0.1) - await event.message.forward_to(channel_id) - await asyncio.sleep(0.5) - print(f'Forwarded Message: {message_content}') + break + if words: + await client.send_message(channel_id, f"Keyword Match: {', '.join(words)}\nContext: {', '.join(contexts)}") + await asyncio.sleep(0.1) + await event.message.forward_to(channel_id) + await asyncio.sleep(0.5) + print(f'Forwarded Message: {message_content}') except Exception as e: logging.error(f"Error in message handler: {e}")