updated content match message with all possible matches and contextes
This commit is contained in:
parent
99d6675688
commit
451412973c
@ -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}")
|
||||
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
|
||||
except Exception as e:
|
||||
logging.error(f"Error in message handler: {e}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user