Skip to content

Commit

Permalink
Merge pull request #257 from QuartzAl/converter
Browse files Browse the repository at this point in the history
changes to follow python conventions in converter.py
  • Loading branch information
Dhruvacube authored Oct 24, 2021
2 parents 16501f3 + dc95348 commit 07ee35e
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions minato_namikaze/bot_files/lib/classes/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@ def can_execute_action(ctx, user, target):
class MemberID(commands.Converter):
async def convert(self, ctx, argument):
try:
m = await commands.MemberConverter().convert(ctx, argument)
member = await commands.MemberConverter().convert(ctx, argument)
except commands.BadArgument:
try:
member_id = int(argument, base=10)
argument = int(argument, base=10)
except ValueError:
raise commands.BadArgument(
f"{argument} is not a valid member or member ID."
) from None
else:
m = await ctx.bot.get_or_fetch_member(ctx.guild, member_id)
if m is None:
member = await ctx.bot.get_or_fetch_member(ctx.guild, argument)
if member is None:
# hackban case
return type(
"_Hackban",
(),
{"id": member_id, "__str__": lambda s: f"Member ID {s.id}"},
{"id": argument, "__str__": lambda s: f"Member ID {s.id}"},
)()

if not can_execute_action(ctx, ctx.author, m):
raise commands.BadArgument(
"You cannot do this action on this user due to role hierarchy."
)
return m
if not can_execute_action(ctx, ctx.author, member):
raise commands.BadArgument("You cannot do this action on this user due to role hierarchy.")
return member


class BannedMember(commands.Converter):
Expand All @@ -74,17 +72,13 @@ async def convert(self, ctx, argument):
try:
return await ctx.guild.fetch_ban(discord.Object(id=member_id))
except discord.NotFound:
raise commands.BadArgument(
"This member has not been banned before."
) from None
raise commands.BadArgument("This member has not been banned before.") from None

ban_list = await ctx.guild.bans()
entity = discord.utils.find(
lambda u: str(u.user) == argument, ban_list)
entity = discord.utils.find(lambda u: str(u.user) == argument, ban_list)

if entity is None:
raise commands.BadArgument(
"This member has not been banned before.")
raise commands.BadArgument("This member has not been banned before.")
return entity


Expand All @@ -94,9 +88,7 @@ async def convert(self, ctx, argument):

if len(ret) > 512:
reason_max = 512 - len(ret) + len(argument)
raise commands.BadArgument(
f"Reason is too long ({len(argument)}/{reason_max})"
)
raise commands.BadArgument(f"Reason is too long ({len(argument)}/{reason_max})")
return ret


Expand Down

0 comments on commit 07ee35e

Please sign in to comment.