aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar TizzySaurus <[email protected]>2021-08-11 16:41:45 +0100
committerGravatar Izan <[email protected]>2021-08-22 19:34:42 +0100
commit73bc01123efb8dbc1e3efb64545b028d21c044d2 (patch)
treeeaf19df6657a10aa7f9f5e09d4c661b10ab18822
parentMerge pull request #1738 from python-discord/dynamic-dormant-message (diff)
Remove converters made redundant by dpy V1.6's UserConverter update
-rw-r--r--bot/converters.py71
-rw-r--r--bot/exts/moderation/infraction/_utils.py2
2 files changed, 1 insertions, 72 deletions
diff --git a/bot/converters.py b/bot/converters.py
index 595809517..3df613379 100644
--- a/bot/converters.py
+++ b/bot/converters.py
@@ -439,29 +439,6 @@ class HushDurationConverter(Converter):
return duration
-def proxy_user(user_id: str) -> discord.Object:
- """
- Create a proxy user object from the given id.
-
- Used when a Member or User object cannot be resolved.
- """
- log.trace(f"Attempting to create a proxy user for the user id {user_id}.")
-
- try:
- user_id = int(user_id)
- except ValueError:
- 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
- user.display_name = f"<@{user.id}>"
- user.avatar_url_as = lambda static_format: None
- user.bot = False
-
- return user
-
-
class UserMentionOrID(UserConverter):
"""
Converts to a `discord.User`, but only if a mention or userID is provided.
@@ -480,51 +457,6 @@ class UserMentionOrID(UserConverter):
raise BadArgument(f"`{argument}` is not a User mention or a User ID.")
-class FetchedUser(UserConverter):
- """
- Converts to a `discord.User` or, if it fails, a `discord.Object`.
-
- Unlike the default `UserConverter`, which only does lookups via the global user cache, this
- converter attempts to fetch the user via an API call to Discord when the using the cache is
- unsuccessful.
-
- If the fetch also fails and the error doesn't imply the user doesn't exist, then a
- `discord.Object` is returned via the `user_proxy` converter.
-
- The lookup strategy is as follows (in order):
-
- 1. Lookup by ID.
- 2. Lookup by mention.
- 3. Lookup by name#discrim
- 4. Lookup by name
- 5. Lookup via API
- 6. Create a proxy user with discord.Object
- """
-
- async def convert(self, ctx: Context, arg: str) -> t.Union[discord.User, discord.Object]:
- """Convert the `arg` to a `discord.User` or `discord.Object`."""
- try:
- return await super().convert(ctx, arg)
- except BadArgument:
- pass
-
- try:
- user_id = int(arg)
- log.trace(f"Fetching user {user_id}...")
- return await ctx.bot.fetch_user(user_id)
- except ValueError:
- log.debug(f"Failed to fetch user {arg}: could not convert to int.")
- raise BadArgument(f"The provided argument can't be turned into integer: `{arg}`")
- except discord.HTTPException as e:
- # If the Discord error isn't `Unknown user`, return a proxy instead
- if e.code != 10013:
- log.info(f"Failed to fetch user, returning a proxy instead: status {e.status}")
- return proxy_user(arg)
-
- log.debug(f"Failed to fetch user {arg}: user does not exist.")
- raise BadArgument(f"User `{arg}` does not exist")
-
-
def _snowflake_from_regex(pattern: t.Pattern, arg: str) -> int:
"""
Extract the snowflake from `arg` using a regex `pattern` and return it as an int.
@@ -568,5 +500,4 @@ class Infraction(Converter):
Expiry = t.Union[Duration, ISODateTime]
-FetchedMember = t.Union[discord.Member, FetchedUser]
-UserMention = partial(_snowflake_from_regex, RE_USER_MENTION)
+FetchedMember = t.Union[discord.Member, discord.User]
diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py
index a4059a6e9..e3fcda730 100644
--- a/bot/exts/moderation/infraction/_utils.py
+++ b/bot/exts/moderation/infraction/_utils.py
@@ -24,8 +24,6 @@ INFRACTION_ICONS = {
RULES_URL = "https://pythondiscord.com/pages/rules"
# Type aliases
-UserObject = t.Union[discord.Member, discord.User]
-UserSnowflake = t.Union[UserObject, discord.Object]
Infraction = t.Dict[str, t.Union[str, int, bool]]
APPEAL_EMAIL = "[email protected]"