|
15 | 15 | GuestRoleDoesNotExistError, |
16 | 16 | GuildDoesNotExistError, |
17 | 17 | MemberRoleDoesNotExistError, |
18 | | - RolesChannelDoesNotExistError, |
19 | | - RulesChannelDoesNotExistError, |
20 | 18 | ) |
21 | 19 | from utils import ( |
22 | 20 | CommandChecks, |
@@ -77,59 +75,60 @@ async def on_member_update(self, before: discord.Member, after: discord.Member) |
77 | 75 | await IntroductionReminderOptOutMember.objects.aget(discord_id=before.id) |
78 | 76 | ).adelete() |
79 | 77 |
|
80 | | - async for message in after.history(): |
| 78 | + reminder_message: discord.Message |
| 79 | + async for reminder_message in after.history(): |
81 | 80 | MESSAGE_IS_INTRODUCTION_REMINDER: bool = bool( |
82 | | - ("joined the " in message.content) |
83 | | - and (" Discord guild but have not yet introduced" in message.content) |
84 | | - and message.author.bot |
| 81 | + ("joined the " in reminder_message.content) |
| 82 | + and (" Discord guild but have not yet introduced" in reminder_message.content) |
| 83 | + and reminder_message.author.bot |
85 | 84 | ) |
86 | 85 | if MESSAGE_IS_INTRODUCTION_REMINDER: |
87 | | - await message.delete( |
| 86 | + await reminder_message.delete( |
88 | 87 | reason="Delete introduction reminders after member is inducted.", |
89 | 88 | ) |
90 | 89 |
|
91 | | - # noinspection PyUnusedLocal |
92 | | - rules_channel_mention: str = "**`#welcome`**" |
93 | | - with contextlib.suppress(RulesChannelDoesNotExistError): |
94 | | - rules_channel_mention = (await self.bot.rules_channel).mention |
95 | | - |
96 | | - # noinspection PyUnusedLocal |
97 | | - roles_channel_mention: str = "**`#roles`**" |
98 | | - with contextlib.suppress(RolesChannelDoesNotExistError): |
99 | | - roles_channel_mention = (await self.bot.roles_channel).mention |
100 | | - |
101 | | - user_type: Literal["guest", "member"] = "guest" |
102 | | - with contextlib.suppress(MemberRoleDoesNotExistError): |
103 | | - if await self.bot.member_role in after.roles: |
104 | | - user_type = "member" |
105 | | - |
| 90 | + user_type: Literal["guest", "member"] |
106 | 91 | try: |
107 | | - await after.send( |
| 92 | + user_type = "member" if await self.bot.member_role in after.roles else "guest" |
| 93 | + except MemberRoleDoesNotExistError: |
| 94 | + user_type = "guest" |
| 95 | + |
| 96 | + messages_to_send: list[str] = [ |
| 97 | + ( |
108 | 98 | f"**Congrats on joining the {self.bot.group_short_name} Discord server " |
109 | 99 | f"as a {user_type}!** " |
110 | 100 | "You now have access to communicate in all the public channels.\n\n" |
111 | 101 | "Some things to do to get started:\n" |
112 | | - f"1. Check out our rules in {rules_channel_mention}\n" |
113 | | - f"2. Head to {roles_channel_mention} and click on the icons to get " |
114 | | - "optional roles like pronouns and year groups\n" |
| 102 | + f"1. Check out our rules in { |
| 103 | + await self.bot.get_mention_string(self.bot.rules_channel) |
| 104 | + }\n" |
| 105 | + f"2. Head to { |
| 106 | + await self.bot.get_mention_string(self.bot.roles_channel) |
| 107 | + } and click on the icons to get optional roles like pronouns and year groups\n" |
115 | 108 | "3. Change your nickname to whatever you wish others to refer to you as " |
116 | 109 | "(You can do this by right-clicking your name in the members-list " |
117 | | - 'to the right & selecting "Edit Server Profile").', |
| 110 | + 'to the right & selecting "Edit Server Profile").' |
| 111 | + ), |
| 112 | + ] |
| 113 | + |
| 114 | + if user_type != "member": |
| 115 | + messages_to_send.append( |
| 116 | + f"You can also get yourself an annual membership " |
| 117 | + f"to {self.bot.group_full_name} for only £5! " |
| 118 | + f"Just head to {settings['PURCHASE_MEMBERSHIP_URL']}. " |
| 119 | + "You'll get awesome perks like a free T-shirt:shirt:, " |
| 120 | + "access to member only events:calendar_spiral: and a cool green name on " |
| 121 | + f"the {self.bot.group_short_name} Discord server:green_square:! " |
| 122 | + f"Checkout all the perks at {settings['MEMBERSHIP_PERKS_URL']}", |
118 | 123 | ) |
119 | | - if user_type != "member": |
120 | | - await after.send( |
121 | | - f"You can also get yourself an annual membership " |
122 | | - f"to {self.bot.group_full_name} for only £5! " |
123 | | - f"Just head to {settings['PURCHASE_MEMBERSHIP_URL']}. " |
124 | | - "You'll get awesome perks like a free T-shirt:shirt:, " |
125 | | - "access to member only events:calendar_spiral: and a cool green name on " |
126 | | - f"the {self.bot.group_short_name} Discord server:green_square:! " |
127 | | - f"Checkout all the perks at {settings['MEMBERSHIP_PERKS_URL']}", |
128 | | - ) |
| 124 | + |
| 125 | + try: |
| 126 | + message_to_send: str |
| 127 | + for message_to_send in messages_to_send: |
| 128 | + await after.send(message_to_send) |
129 | 129 | except discord.Forbidden: |
130 | 130 | logger.info( |
131 | | - "Failed to open DM channel to user %s so no welcome message was sent.", |
132 | | - after, |
| 131 | + "Failed to open DM channel to user %s so no welcome message was sent.", after |
133 | 132 | ) |
134 | 133 |
|
135 | 134 |
|
@@ -227,34 +226,28 @@ async def _perform_induction( |
227 | 226 | return |
228 | 227 |
|
229 | 228 | if not silent: |
230 | | - general_channel: discord.TextChannel = await self.bot.general_channel |
231 | | - |
232 | | - # noinspection PyUnusedLocal |
233 | | - roles_channel_mention: str = "**`#roles`**" |
234 | | - with contextlib.suppress(RolesChannelDoesNotExistError): |
235 | | - roles_channel_mention = (await self.bot.roles_channel).mention |
236 | | - |
237 | | - await general_channel.send( |
| 229 | + await (await self.bot.general_channel).send( |
238 | 230 | f"{await self.get_random_welcome_message(induction_member)} :tada:\n" |
239 | | - f"Remember to grab your roles in {roles_channel_mention} " |
240 | | - "and say hello to everyone here! :wave:", |
| 231 | + f"Remember to grab your roles in { |
| 232 | + await self.bot.get_mention_string(self.bot.roles_channel) |
| 233 | + } and say hello to everyone here! :wave:", |
241 | 234 | ) |
242 | 235 |
|
243 | 236 | await induction_member.add_roles( |
244 | 237 | guest_role, |
245 | 238 | reason=INDUCT_AUDIT_MESSAGE, |
246 | 239 | ) |
247 | 240 |
|
248 | | - # noinspection PyUnusedLocal |
249 | | - applicant_role: discord.Role | None = None |
250 | | - with contextlib.suppress(ApplicantRoleDoesNotExistError): |
251 | | - applicant_role = await ctx.bot.applicant_role |
252 | | - |
253 | | - if applicant_role and applicant_role in induction_member.roles: |
254 | | - await induction_member.remove_roles( |
255 | | - applicant_role, |
256 | | - reason=INDUCT_AUDIT_MESSAGE, |
257 | | - ) |
| 241 | + try: |
| 242 | + applicant_role: discord.Role = await ctx.bot.applicant_role |
| 243 | + except ApplicantRoleDoesNotExistError: |
| 244 | + pass |
| 245 | + else: |
| 246 | + if applicant_role in induction_member.roles: |
| 247 | + await induction_member.remove_roles( |
| 248 | + applicant_role, |
| 249 | + reason=INDUCT_AUDIT_MESSAGE, |
| 250 | + ) |
258 | 251 |
|
259 | 252 | tex_emoji: discord.Emoji | None = self.bot.get_emoji(743218410409820213) |
260 | 253 | if not tex_emoji: |
@@ -365,7 +358,7 @@ async def induct( # type: ignore[misc] |
365 | 358 |
|
366 | 359 |
|
367 | 360 | class InductContextCommandsCog(BaseInductCog): |
368 | | - """Cog class that defines the context-menu induction commands & their call-back methods.""" |
| 361 | + """Cog class to define the context-menu induction commands and their call-back methods.""" |
369 | 362 |
|
370 | 363 | @discord.user_command(name="Induct User") # type: ignore[no-untyped-call, misc] |
371 | 364 | @CommandChecks.check_interaction_user_has_committee_role |
@@ -434,7 +427,6 @@ async def non_silent_message_induct( # type: ignore[misc] |
434 | 427 | class EnsureMembersInductedCommandCog(TeXBotBaseCog): |
435 | 428 | """Cog class that defines the "/ensure-members-inducted" command and call-back method.""" |
436 | 429 |
|
437 | | - # noinspection SpellCheckingInspection |
438 | 430 | @discord.slash_command( # type: ignore[no-untyped-call, misc] |
439 | 431 | name="ensure-members-inducted", |
440 | 432 | description="Ensures all users with the @Member role also have the @Guest role.", |
|
0 commit comments