Skip to content

Commit

Permalink
Merge pull request #317 from StampyAI/hotfix-question-detection
Browse files Browse the repository at this point in the history
Hotfix question detection
  • Loading branch information
MatthewBaggins authored Jul 5, 2023
2 parents dbec3f7 + 918b9c2 commit f46b14b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
27 changes: 18 additions & 9 deletions modules/question_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,14 @@ async def cb_question_approval(
"""Obtain GDoc links to approved questions and change their status in coda
to `Live on site`.
"""
if not is_from_reviewer(message):
return Response(
confidence=10,
text=f"You're not a reviewer, <@{message.author}> -_-",
why="Only, reviewers can accept questions",
)
msg_from_reviewer = is_from_reviewer(message)

if isinstance(parsed, list): # is GDocLinks (list of strings)
gdoc_links = parsed
else: # is MsgRefId (string)
msg_ref_id = parsed
assert isinstance(message.channel, DiscordChannel)
if not isinstance(message.channel, DiscordChannel):
return Response()
await self.find_gdoc_links_in_msg(message.channel, msg_ref_id)
gdoc_links = self.msg_id2gdoc_links.get(msg_ref_id, [])

Expand All @@ -332,6 +328,15 @@ async def cb_question_approval(

questions = self.coda_api.get_questions_by_gdoc_links(gdoc_links)

if not msg_from_reviewer:
if not questions:
return Response()
return Response(
confidence=10,
text=f"You're not a reviewer, <@{message.author}> -_-",
why="Only reviewers can accept questions",
)

if not questions:
return Response(
confidence=10,
Expand Down Expand Up @@ -384,7 +389,9 @@ def parse_edit_tag(self, text: str, message: ServiceMessage) -> Optional[Respons
elif not (tag := parse_tag(text)):
return

query = parse_question_spec_query(text, return_last_by_default=True)
query = parse_question_spec_query(text)
if query is None:
query = "Last", "DEFAULT"
return Response(
confidence=10,
callback=self.cb_edit_tag_or_altphr,
Expand All @@ -408,7 +415,9 @@ def parse_edit_altphr(
elif not (alt_phr := parse_alt_phr(text)):
return

query = parse_question_spec_query(text, return_last_by_default=True)
query = parse_question_spec_query(text)
if query is None:
query = "Last", "DEFAULT"
return Response(
confidence=10,
callback=self.cb_edit_tag_or_altphr,
Expand Down
4 changes: 3 additions & 1 deletion modules/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ def parse_get_question_info(
# must match regex and contain query info
if not self.re_get_question_info.match(text):
return
spec_data = parse_question_spec_query(text, return_last_by_default=True)
spec_data = parse_question_spec_query(text)
if spec_data is None:
return

return Response(
confidence=9,
Expand Down
20 changes: 1 addition & 19 deletions utilities/question_query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,7 @@ def parse_alt_phr(text: str) -> Optional[str]:
return text[start:end]


@overload
def parse_question_spec_query(
text: str,
) -> Optional[QuestionSpecQuery]:
...


@overload
def parse_question_spec_query(
text: str, *, return_last_by_default: Literal[True]
) -> QuestionSpecQuery:
...


def parse_question_spec_query(
text: str, *, return_last_by_default: bool = False
) -> Optional[QuestionSpecQuery]: # TODO: raise or sth if no last
def parse_question_spec_query(text: str) -> Optional[QuestionSpecQuery]:
"""Parse data specifying concrete questions"""
# QuestionLast
if mention := parse_question_last(text):
Expand All @@ -147,8 +131,6 @@ def parse_question_spec_query(
# so in order to remove interference with title parsing, we mask whatever is between double quotes
if question_title := parse_question_title(mask_quoted_text(text)):
return "Title", question_title
if return_last_by_default:
return "Last", "DEFAULT"


def parse_question_query(text: str) -> QuestionQuery:
Expand Down

0 comments on commit f46b14b

Please sign in to comment.