Skip to content

Commit

Permalink
limit to stampy addressed messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik committed Nov 1, 2023
1 parent 170e261 commit 3626f40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def is_at_me(self, message: ServiceMessage) -> Union[str, Literal[False]]:
r",? @?[sS](tampy)?(?P<punctuation>[.!?]*)$", r"\g<punctuation>", text
)
at_me = True
elif re.search(r'^[sS]tamp[ys]?\?', text):
at_me = True

if message.is_dm:
# DMs are always at you
Expand Down
19 changes: 17 additions & 2 deletions modules/stampy_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,26 @@ def _add_message(self, message: ServiceMessage) -> deque[ServiceMessage]:
self._messages[message.channel].append(message)
return self._messages[message.channel]

def make_query(self, messages):
if not messages:
return '', messages

current = messages[-1]
query, history = '', list(messages)
while message := (history and history.pop()):
if message.author != current.author:
break
query = message.content + ' ' + query
current = message
return query, history

def process_message(self, message: ServiceMessage) -> Response:
history = self._add_message(message)
history.append(message)

query = message.content
if not self.is_at_me(message):
return Response()

query, history = self.make_query(history)
nlp = top_nlp_search(query)
if nlp.get('score', 0) > STAMPY_ANSWER_MIN_SCORE and nlp.get('status') == 'Live on site':
return Response(confidence=5, text=f'Check out {nlp.get("url")} ({nlp.get("title")})')
Expand Down
1 change: 1 addition & 0 deletions utilities/flaskutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ def from_dict(data):
id=str(time.time()),
)
msg.modules = modules
msg.clean_content = msg.content
return msg

0 comments on commit 3626f40

Please sign in to comment.