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}")