regex
Browse files
app.py
CHANGED
@@ -66,7 +66,7 @@ async def on_message(message):
|
|
66 |
|
67 |
for trigger, slack_mention in TRIGGERS.items():
|
68 |
if all(word in content for word in trigger):
|
69 |
-
adjacent_words = extract_adjacent_words(message.content, trigger
|
70 |
daily_pings.append({
|
71 |
'author': str(message.author),
|
72 |
'content': adjacent_words,
|
@@ -94,16 +94,20 @@ async def on_message(message):
|
|
94 |
await bot.process_commands(message)
|
95 |
|
96 |
|
97 |
-
def extract_adjacent_words(content, trigger
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
start, end = match.span()
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
|
108 |
|
109 |
@bot.event
|
|
|
66 |
|
67 |
for trigger, slack_mention in TRIGGERS.items():
|
68 |
if all(word in content for word in trigger):
|
69 |
+
adjacent_words = extract_adjacent_words(message.content, trigger)
|
70 |
daily_pings.append({
|
71 |
'author': str(message.author),
|
72 |
'content': adjacent_words,
|
|
|
94 |
await bot.process_commands(message)
|
95 |
|
96 |
|
97 |
+
def extract_adjacent_words(content, trigger):
|
98 |
+
trigger_regex = re.compile(r'\b' + re.escape(trigger) + r'\b', re.IGNORECASE)
|
99 |
+
matches = trigger_regex.finditer(content)
|
100 |
|
101 |
+
if match in matches:
|
102 |
start, end = match.span()
|
103 |
+
before = content[:start].strip().split()
|
104 |
+
after = content[end:].strip().split()
|
105 |
+
|
106 |
+
context_before = ' '.join(before[-5:])
|
107 |
+
context_after = ' '.join(after[:5])
|
108 |
+
|
109 |
+
output = f"...{context_before} + {match.group()} + {context_after}..."
|
110 |
+
return output
|
111 |
|
112 |
|
113 |
@bot.event
|