aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-02-08 11:44:18 +0300
committerGravatar GitHub <[email protected]>2021-02-08 11:44:18 +0300
commit4109c05e614c9d768c974c46df659e4dcf0eae74 (patch)
treed25e1b1ce1fde3eb210ac0bec57c8b49d54a3958
parentMerge pull request #572 from Shivansh-007/feature/cheat.sh (diff)
parentAdd comment explaining why we need to pass curl as user agent (diff)
Merge pull request #580 from Shivansh-007/fix/cht.sh
Add curl User Agent Headers
-rw-r--r--bot/exts/evergreen/cheatsheet.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/bot/exts/evergreen/cheatsheet.py b/bot/exts/evergreen/cheatsheet.py
index 97485365..a64ddd69 100644
--- a/bot/exts/evergreen/cheatsheet.py
+++ b/bot/exts/evergreen/cheatsheet.py
@@ -26,6 +26,8 @@ If the problem persists send a message in <#{Channels.dev_contrib}>
URL = 'https://cheat.sh/python/{search}'
ESCAPE_TT = str.maketrans({"`": "\\`"})
ANSI_RE = re.compile(r"\x1b\[.*?m")
+# We need to pass headers as curl otherwise it would default to aiohttp which would return raw html.
+HEADERS = {'User-Agent': 'curl/7.68.0'}
class CheatSheet(commands.Cog):
@@ -92,7 +94,7 @@ class CheatSheet(commands.Cog):
search_string = quote_plus(" ".join(search_terms))
async with self.bot.http_session.get(
- URL.format(search=search_string)
+ URL.format(search=search_string), headers=HEADERS
) as response:
result = ANSI_RE.sub("", await response.text()).translate(ESCAPE_TT)