aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Manuel Ignacio Pérez Alcolea <[email protected]>2019-12-22 03:36:40 -0300
committerGravatar Manuel Ignacio Pérez Alcolea <[email protected]>2019-12-22 03:36:40 -0300
commit32a3fdff0adce1ae76ad6915f5cf6119dde04621 (patch)
tree8bc5523f8d8dfeb5ec03f0d041f1cb80d758ac23
parentMerge branch 'master' into fetched-user (diff)
Correct log messages levels, add log messages and ctx.send message
-rw-r--r--bot/cogs/moderation/utils.py10
-rw-r--r--bot/converters.py9
2 files changed, 12 insertions, 7 deletions
diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py
index 3b39b52ac..8328e4c85 100644
--- a/bot/cogs/moderation/utils.py
+++ b/bot/cogs/moderation/utils.py
@@ -36,10 +36,10 @@ async def post_user(ctx: Context, user: t.Union[discord.User, discord.Object]) -
Used when an infraction needs to be applied on a user absent in the guild.
"""
- log.trace("Attempting to add user to the database.")
+ log.trace(f"Attempting to add user {user.id} to the database.")
if not isinstance(user, discord.User):
- log.warn("The given user is not a discord.User object.")
+ log.warn("The user being added to the DB is not a Member or User object.")
payload = {
'avatar_hash': getattr(user, 'avatar', 0),
@@ -52,12 +52,12 @@ async def post_user(ctx: Context, user: t.Union[discord.User, discord.Object]) -
try:
response = await ctx.bot.api_client.post('bot/users', json=payload)
- log.trace(f"User {user.id} added to the DB.")
+ log.info(f"User {user.id} added to the DB.")
return response
except ResponseCodeError as e:
- log.warn("Couldn't post user.")
+ log.error(f"Failed to add user {user.id} to the DB. {e}")
await ctx.send(
- "The attempt to add the user to the DB failed: "
+ ":x: The attempt to add the user to the DB failed: "
f"{e.status}, {e.response_text if e.response_text else 'no message received'}."
)
diff --git a/bot/converters.py b/bot/converters.py
index 28bf58cf4..5b33f6818 100644
--- a/bot/converters.py
+++ b/bot/converters.py
@@ -291,7 +291,8 @@ def proxy_user(user_id: str) -> discord.Object:
try:
user_id = int(user_id)
except ValueError:
- raise BadArgument
+ log.debug(f"Failed to create proxy user {user_id}: could not convert to int.")
+ raise BadArgument(f"User ID `{user_id}` is invalid - could not convert to an integer.")
user = discord.Object(user_id)
user.mention = user.id
@@ -314,14 +315,18 @@ class FetchedUser(Converter):
"""Convert `user_id` to a `discord.User` object, after fetching from the Discord API."""
try:
user_id = int(user_id)
+ log.trace(f"Fetching user {user_id}...")
user = await ctx.bot.fetch_user(user_id)
except ValueError:
+ log.debug(f"Failed to fetch user {user_id}: could not convert to int.")
raise BadArgument(f"The provided argument can't be turned into integer: `{user_id}`")
except discord.HTTPException as e:
# If the Discord error isn't `Unknown user`, save it in the log and return a proxy instead
if e.code != 10013:
- log.warning("Failed to fetch user, returning a proxy instead.")
+ log.warning(f"Failed to fetch user, returning a proxy instead: status {e.status}")
return proxy_user(user_id)
+
+ log.debug(f"Failed to fetch user {user_id}: user does not exist.")
raise BadArgument
return user