Open Shom770 opened 3 years ago
I would guess a flag would be the best way to do this? Maybe -t \
I would guess a flag would be the best way to do this? Maybe -t
Then a user would do .so -t
That's true. I can update it to take a flag instead.
This is my first shot at it, definitely could clean up the string combination as well as having an embedded error message for more than 3 tags.
async def stackoverflow(self, ctx: commands.Context, *, search_query: str, ) -> None:
"""Sends the top 5 results of a search query from stackoverflow."""
def tag_parse(query: str) -> str:
list_query = query.split()
if "-t" in list_query:
stop_index = list_query.index("-t")
if len(list_query) - stop_index < 3:
query = " ".join(term for term in list_query[:stop_index])
tags = " ".join(term for term in list_query[stop_index+1:])
else:
raise ValueError(f"Too many tags were passed to the command: {query}")
else:
query = query
tags = None
return query, tags
search_query, tags = tag_parse(search_query)
search_query += f"tagged={tags}"
I had an idea in the original PR, maybe you could allow people to search using the stackoverflow search syntax: and use a regular experession to get and pass in the tags, authors, etc. This would not only make it neater, but also provide support for other filters like authors and whether or not the question is answered.
I had an idea in the original PR, maybe you could allow people to search using the stackoverflow search syntax: and use a regular experession to get and pass in the tags, authors, etc. This would not only make it neater, but also provide support for other filters like authors and whether or not the question is answered.
That would be pretty cool to be honest, I can work on adding other features too, I presume the Stack Exchange API allows all of these parameters in one API request?
I had an idea in the original PR, maybe you could allow people to search using the stackoverflow search syntax: and use a regular experession to get and pass in the tags, authors, etc. This would not only make it neater, but also provide support for other filters like authors and whether or not the question is answered.
That would be pretty cool to be honest, I can work on adding other features too, I presume the Stack Exchange API allows all of these parameters in one API request?
Yup, here are the parameters allowed:
q
- a free form text parameter, will match all question properties based on an undocumented algorithm.
accepted
- true to return only questions with accepted answers, false to return only those without. Omit to elide constraint.
answers
- the minimum number of answers returned questions must have.
body
- text which must appear in returned questions' bodies.
closed
- true to return only closed questions, false to return only open ones. Omit to elide constraint.
migrated
- true to return only questions migrated away from a site, false to return only those not. Omit to elide constraint.
notice
- true to return only questions with post notices, false to return only those without. Omit to elide constraint.
nottagged
- a semicolon delimited list of tags, none of which will be present on returned questions.
tagged
- a semicolon delimited list of tags, of which at least one will be present on all returned questions.
title
- text which must appear in returned questions' titles.
user
- the id of the user who must own the questions returned.
url
- a url which must be contained in a post, may include a wildcard.
views
- the minimum number of views returned questions must have.
wiki
- true to return only community wiki questions, false to return only non-community wiki ones. Omit to elide constraint.
Ah alright, thanks!
Hey are you still planning on working on this? Someone sent me this link for Discord Flags: https://pypi.org/project/discord-flags/might be helpful to use these for all of the parameters? Could default most of them to None.
Hey are you still planning on working on this? Someone sent me this link for Discord Flags: https://pypi.org/project/discord-flags/might be helpful to use these for all of the parameters? Could default most of them to None.
Hey @brad90four, I was thinking that there is no need for using flagged arguments, as I have mentioned here. This would even add functionalityfor more filters.
Hey are you still planning on working on this? Someone sent me this link for Discord Flags: https://pypi.org/project/discord-flags/might be helpful to use these for all of the parameters? Could default most of them to None.
Hey @brad90four, I was thinking that there is no need for using flagged arguments, as I have mentioned here. This would even add functionalityfor more filters.
So I presume we would be using Regex?
We're thinking of slimming down the stackoverflow command because it looks like a dumpster fire on mobile, so I'm going to mark this as stalled until we fix that up.
Planning can continue, if possible.
We're thinking of slimming down the stackoverflow command because it looks like a dumpster fire on mobile, so I'm going to mark this as stalled until we fix that up.
Is there an issue for that? I think it would make sense to move the hyperlink for each question to the title of each answer rather than the stats of the answer. Not sure if you meant that as I think that would make it render better on mobile, or if you meant actually reducing the size
@wookie184 There is no current issue for it, I was thinking we should reduce the size of the embed for the benefit of all platforms, including mobile.
Description
The proposal is that we allow tags to be specified as another argument for the stackoverflow command. Stack Exchange API allows filtering by tags with the query, so if the user would like to specify the tags for a certain query, i,e.
.so JSON [tags]
, the stackoverflow command would add the additionaltagged
parameter with the Stack Exchange API with the query 'JSON'.Reasoning
The current stackoverflow command will search for the top 5 results, but it can't filter by tag. If someone wanted a specific query specific to a certain topic, they can filter by tags with this feature to get the tags for their query relating to said specific topic.
Proposed Implementation
Using the parameter
tagged={}
when using the StackExchange API, you can filter by tags. Below are some screenshots of filtering by tag in usage:This shows an example of filtering by one tag, with 'JSON' being the query and 'python' being the tag to filter by.
This shows an example of filtering by multiple tags, with 'JSON' being the query and 'python' and 'mongodb' being the two tags (separated by the delimiter ',') that must be in the answer along with other tags for it to show.
Do note that the tags only go up to the first 3 tags, so while sometimes the tag you filtered by may not show, the tag is in the overall count of tags, just not the first three tags.
Would you like to implement this yourself?