lunarflu HF staff commited on
Commit
e4e85e6
1 Parent(s): e3fa325

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -95,19 +95,17 @@ async def on_message(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
 
95
 
96
 
97
  def extract_adjacent_words(content, trigger):
98
+ words = content.split()
99
+ pattern = r'\b' + r'\b\s*\b'.join(map(re.escape, trigger)) + r'\b'
100
+ regex = re.compile(pattern, re.IGNORECASE)
101
 
102
+ for match in regex.finditer(content):
103
  start, end = match.span()
104
+ before = content[:start].split()[-5:]
105
+ after = content[end:].split()[:5]
106
+ print('...' + ' '.join(before + [match.group()] + after) + '...')
107
+ return '...' + ' '.join(before + [match.group()] + after) + '...'
108
+ return content
 
 
 
109
 
110
 
111
  @bot.event