aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2021-08-22 11:42:04 +0100
committerGravatar Chris Lovering <[email protected]>2021-08-22 11:42:43 +0100
commiteb5cedea9a432b6b98d5ef831a016f9e33d72cbb (patch)
treeb2dc5adda50ff640e6ef403e2e84492b2906394e
parentAdd alias for metabase export (diff)
Trigger typing, to avoid wrapping whole func in a context manager
-rw-r--r--bot/exts/moderation/metabase.py60
1 files changed, 30 insertions, 30 deletions
diff --git a/bot/exts/moderation/metabase.py b/bot/exts/moderation/metabase.py
index fa5f60ca6..d97b355a5 100644
--- a/bot/exts/moderation/metabase.py
+++ b/bot/exts/moderation/metabase.py
@@ -125,36 +125,36 @@ class Metabase(Cog):
Valid extensions are: csv and json.
"""
- async with ctx.typing():
-
- # Make sure we have a session token before running anything
- await self.init_task
-
- url = f"{MetabaseConfig.base_url}/api/card/{question_id}/query/{extension}"
-
- async with self.bot.http_session.post(url, headers=self.headers, raise_for_status=True) as resp:
- if extension == "csv":
- out = await resp.text(encoding="utf-8")
- # Save the output for use with int e
- self.exports[question_id] = list(csv.DictReader(StringIO(out)))
-
- elif extension == "json":
- out = await resp.json(encoding="utf-8")
- # Save the output for use with int e
- self.exports[question_id] = out
-
- # Format it nicely for human eyes
- out = json.dumps(out, indent=4, sort_keys=True)
-
- paste_link = await send_to_paste_service(out, extension=extension)
- if paste_link:
- message = f":+1: {ctx.author.mention} Here's your link: {paste_link}"
- else:
- message = f":x: {ctx.author.mention} Link service is unavailible."
- await ctx.send(
- f"{message}\nYou can also access this data within internal eval by doing: "
- f"`bot.get_cog('Metabase').exports[{question_id}]`"
- )
+ await ctx.trigger_typing()
+
+ # Make sure we have a session token before running anything
+ await self.init_task
+
+ url = f"{MetabaseConfig.base_url}/api/card/{question_id}/query/{extension}"
+
+ async with self.bot.http_session.post(url, headers=self.headers, raise_for_status=True) as resp:
+ if extension == "csv":
+ out = await resp.text(encoding="utf-8")
+ # Save the output for use with int e
+ self.exports[question_id] = list(csv.DictReader(StringIO(out)))
+
+ elif extension == "json":
+ out = await resp.json(encoding="utf-8")
+ # Save the output for use with int e
+ self.exports[question_id] = out
+
+ # Format it nicely for human eyes
+ out = json.dumps(out, indent=4, sort_keys=True)
+
+ paste_link = await send_to_paste_service(out, extension=extension)
+ if paste_link:
+ message = f":+1: {ctx.author.mention} Here's your link: {paste_link}"
+ else:
+ message = f":x: {ctx.author.mention} Link service is unavailible."
+ await ctx.send(
+ f"{message}\nYou can also access this data within internal eval by doing: "
+ f"`bot.get_cog('Metabase').exports[{question_id}]`"
+ )
# This cannot be static (must have a __func__ attribute).
async def cog_check(self, ctx: Context) -> bool: