lunarflu HF staff commited on
Commit
e3fa325
1 Parent(s): 0d44148
Files changed (1) hide show
  1. app.py +13 -9
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, 3)
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, num_words=5):
98
- pattern = r'\b' + r'\b\s*\b'.join(map(re.escape, trigger)) + r'\b'
99
- regex = re.compile(pattern, re.IGNORECASE)
100
 
101
- for match in regex.finditer(content):
102
  start, end = match.span()
103
- before_words = re.findall(r'\b\w+\b', content[:start])[-num_words:]
104
- after_words = re.findall(r'\b\w+\b', content[end:end + 100])[:num_words]
105
- return '...' + ' '.join(before_words + [match.group()] + after_words) + '...'
106
- return content
 
 
 
 
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