Skip to content

Commit 4ef6f86

Browse files
Fix user commands type hints and refactor (#738)
1 parent 3d9dfb7 commit 4ef6f86

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

cogs/make_applicant.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,27 @@ class BaseMakeApplicantCog(TeXBotBaseCog):
3434
"""
3535

3636
async def _perform_make_applicant(
37-
self, ctx: "TeXBotApplicationContext", applicant_member: discord.Member
37+
self, ctx: "TeXBotApplicationContext", applicant_member_id: int
3838
) -> None:
3939
"""Perform the actual process of making the user into a group-applicant."""
4040
# NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent
4141
main_guild: discord.Guild = ctx.bot.main_guild
4242
applicant_role: discord.Role = await ctx.bot.applicant_role
4343
guest_role: discord.Role = await ctx.bot.guest_role
4444

45+
applicant_member: discord.Member | None = main_guild.get_member(applicant_member_id)
46+
47+
if not applicant_member:
48+
await ctx.respond(
49+
content=(
50+
":information_source: "
51+
"No changes made. User cannot be made into an applicant "
52+
"because they have left the server :information_source:"
53+
),
54+
ephemeral=True,
55+
)
56+
return
57+
4558
if applicant_role in applicant_member.roles:
4659
await ctx.respond("User is already an applicant! Command aborted.")
4760
return
@@ -196,7 +209,7 @@ async def make_applicant(
196209
await self.command_send_error(ctx, message=member_id_not_integer_error.args[0])
197210
return
198211

199-
await self._perform_make_applicant(ctx, applicant_member)
212+
await self._perform_make_applicant(ctx, applicant_member.id)
200213

201214

202215
class MakeApplicantContextCommandsCog(BaseMakeApplicantCog):
@@ -206,7 +219,7 @@ class MakeApplicantContextCommandsCog(BaseMakeApplicantCog):
206219
@CommandChecks.check_interaction_user_has_committee_role
207220
@CommandChecks.check_interaction_user_in_main_guild
208221
async def user_make_applicant(
209-
self, ctx: "TeXBotApplicationContext", member: discord.Member
222+
self, ctx: "TeXBotApplicationContext", member: discord.Member | discord.User
210223
) -> None:
211224
"""
212225
Definition and callback response of the "make_applicant" user-context-command.
@@ -215,7 +228,7 @@ async def user_make_applicant(
215228
the "make_applicant" slash-command and thus gives the specified user the
216229
"Applicant" role and removes the "Guest" role if they have it.
217230
"""
218-
await self._perform_make_applicant(ctx, member)
231+
await self._perform_make_applicant(ctx, member.id)
219232

220233
@discord.message_command(name="Make Message Author Applicant")
221234
@CommandChecks.check_interaction_user_has_committee_role
@@ -230,19 +243,4 @@ async def message_make_applicant(
230243
the "make_applicant" slash-command and thus gives the specified user the
231244
"Applicant" role and removes the "Guest" role if they have it.
232245
"""
233-
try:
234-
member: discord.Member = await self.bot.get_member_from_str_id(
235-
str(message.author.id)
236-
)
237-
except ValueError:
238-
await ctx.respond(
239-
content=(
240-
":information_source: "
241-
"No changes made. User cannot be made into an applicant "
242-
"because they have left the server :information_source:"
243-
),
244-
ephemeral=True,
245-
)
246-
return
247-
248-
await self._perform_make_applicant(ctx, member)
246+
await self._perform_make_applicant(ctx, message.author.id)

cogs/strike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ async def _confirm_increase_strike(
393393
)
394394

395395
async def _command_perform_strike(
396-
self, ctx: "TeXBotApplicationContext", strike_member: discord.Member
396+
self, ctx: "TeXBotApplicationContext", strike_member: discord.Member | discord.User
397397
) -> None:
398398
"""
399399
Perform the actual process of giving a member an additional strike.
@@ -1075,7 +1075,7 @@ async def _send_message_to_committee(
10751075
@CommandChecks.check_interaction_user_has_committee_role
10761076
@CommandChecks.check_interaction_user_in_main_guild
10771077
async def user_strike(
1078-
self, ctx: "TeXBotApplicationContext", member: discord.Member
1078+
self, ctx: "TeXBotApplicationContext", member: discord.Member | discord.User
10791079
) -> None:
10801080
"""Call the _strike command, providing the required command arguments."""
10811081
await self._command_perform_strike(ctx, strike_member=member)

0 commit comments

Comments
 (0)