diff options
| author | 2021-08-09 16:45:04 +0200 | |
|---|---|---|
| committer | 2021-08-09 16:45:04 +0200 | |
| commit | 78f1cd52abb5d1d25cbdc2d578abc1e953518a3f (patch) | |
| tree | 8c4da29580d176964679a1b73e46ffc8b5e64215 /bot/exts/evergreen/stackoverflow.py | |
| parent | Modify code to comply with new linter error N818 (diff) | |
| parent | Merge #804 - circumvent URL injections in various cogs (diff) | |
Merge branch 'main' into remove-gpl-deps
Diffstat (limited to 'bot/exts/evergreen/stackoverflow.py')
| -rw-r--r-- | bot/exts/evergreen/stackoverflow.py | 13 | 
1 files changed, 9 insertions, 4 deletions
diff --git a/bot/exts/evergreen/stackoverflow.py b/bot/exts/evergreen/stackoverflow.py index a53cecf7..40f149c9 100644 --- a/bot/exts/evergreen/stackoverflow.py +++ b/bot/exts/evergreen/stackoverflow.py @@ -10,7 +10,12 @@ from bot.constants import Colours, Emojis  logger = logging.getLogger(__name__) -BASE_URL = "https://api.stackexchange.com/2.2/search/advanced?order=desc&sort=activity&site=stackoverflow&q={query}" +BASE_URL = "https://api.stackexchange.com/2.2/search/advanced" +SO_PARAMS = { +    "order": "desc", +    "sort": "activity", +    "site": "stackoverflow" +}  SEARCH_URL = "https://stackoverflow.com/search?q={query}"  ERR_EMBED = Embed(      title="Error in fetching results from Stackoverflow", @@ -32,9 +37,8 @@ class Stackoverflow(commands.Cog):      @commands.cooldown(1, 15, commands.cooldowns.BucketType.user)      async def stackoverflow(self, ctx: commands.Context, *, search_query: str) -> None:          """Sends the top 5 results of a search query from stackoverflow.""" -        encoded_search_query = quote_plus(search_query) - -        async with self.bot.http_session.get(BASE_URL.format(query=encoded_search_query)) as response: +        params = SO_PARAMS | {"q": search_query} +        async with self.bot.http_session.get(url=BASE_URL, params=params) as response:              if response.status == 200:                  data = await response.json()              else: @@ -50,6 +54,7 @@ class Stackoverflow(commands.Cog):              return          top5 = data["items"][:5] +        encoded_search_query = quote_plus(search_query)          embed = Embed(              title="Search results - Stackoverflow",              url=SEARCH_URL.format(query=encoded_search_query),  |