aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-08-03 14:08:08 +0200
committerGravatar Leon Sandøy <[email protected]>2020-08-03 14:08:08 +0200
commit312d31d408e2580a08b5b36a6f885f6d1a5955b9 (patch)
treef109becab86660fa450a5764ea59afb0c1aba6e2
parentMove function params to 4-space indentation. (diff)
Add some feedback to the _sync_data helper.
Previously, this would not provide any feedback at all, which is really terrible UX. Sorry about that. This also adds error handling in case the API call fails.
Diffstat (limited to '')
-rw-r--r--bot/cogs/filter_lists.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/bot/cogs/filter_lists.py b/bot/cogs/filter_lists.py
index 6249774bb..c15adc461 100644
--- a/bot/cogs/filter_lists.py
+++ b/bot/cogs/filter_lists.py
@@ -168,10 +168,18 @@ class FilterLists(Cog):
await ctx.send(embed=embed)
await ctx.message.add_reaction("❌")
- async def _sync_data(self) -> None:
+ async def _sync_data(self, ctx: Context) -> None:
"""Syncs the filterlists with the API."""
- log.trace("Synchronizing FilterList cache with data from the API.")
- await self.bot.cache_filter_list_data()
+ try:
+ log.trace("Attempting to sync FilterList cache with data from the API.")
+ await self.bot.cache_filter_list_data()
+ await ctx.message.add_reaction("✅")
+ except ResponseCodeError as e:
+ log.debug(
+ f"{ctx.author} tried to sync FilterList cache data but "
+ f"the API raised an unexpected error: {e}"
+ )
+ await ctx.message.add_reaction("❌")
@staticmethod
async def _validate_guild_invite(ctx: Context, invite: str) -> dict:
@@ -246,14 +254,14 @@ class FilterLists(Cog):
await self._list_all_data(ctx, False, list_type)
@whitelist.command(name="sync", aliases=("s",))
- async def allow_sync(self, _: Context) -> None:
+ async def allow_sync(self, ctx: Context) -> None:
"""Syncs both allowlists and denylists with the API."""
- await self._sync_data()
+ await self._sync_data(ctx)
@blacklist.command(name="sync", aliases=("s",))
- async def deny_sync(self, _: Context) -> None:
+ async def deny_sync(self, ctx: Context) -> None:
"""Syncs both allowlists and denylists with the API."""
- await self._sync_data()
+ await self._sync_data(ctx)
def cog_check(self, ctx: Context) -> bool:
"""Only allow moderators to invoke the commands in this cog."""