Update app.py
Browse files
app.py
CHANGED
@@ -125,12 +125,16 @@ async def on_message(message):
|
|
125 |
|
126 |
|
127 |
def extract_adjacent_words(content, trigger, num_words=3):
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
134 |
return content
|
135 |
|
136 |
|
|
|
125 |
|
126 |
|
127 |
def extract_adjacent_words(content, trigger, num_words=3):
|
128 |
+
words = content.split()
|
129 |
+
pattern = r'\b' + r'\b\s*\b'.join(map(re.escape, trigger)) + r'\b'
|
130 |
+
regex = re.compile(pattern, re.IGNORECASE)
|
131 |
+
|
132 |
+
for match in regex.finditer(content):
|
133 |
+
start, end = match.span()
|
134 |
+
before = content[:start].split()[-num_words:]
|
135 |
+
after = content[end:].split()[:num_words]
|
136 |
+
print('...' + ' '.join(before + [match.group()] + after) + '...')
|
137 |
+
return '...' + ' '.join(before + [match.group()] + after) + '...'
|
138 |
return content
|
139 |
|
140 |
|