Skip to content

Commit 8d31037

Browse files
Fix mypy errors
1 parent 9f18b0d commit 8d31037

6 files changed

Lines changed: 51 additions & 20 deletions

File tree

‎cogs/induct.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async def _perform_induction(
252252
applicant_role, reason=INDUCT_AUDIT_MESSAGE
253253
)
254254

255-
tex_emoji: discord.Emoji | None = self.bot.get_emoji(743218410409820213)
255+
tex_emoji: discord.GuildEmoji | discord.AppEmoji | None = self.bot.get_emoji(743218410409820213)
256256
if not tex_emoji:
257257
tex_emoji = discord.utils.get(main_guild.emojis, name="TeX")
258258

‎cogs/make_applicant.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def _perform_make_applicant(
7676
await applicant_member.add_roles(applicant_role, reason=AUDIT_MESSAGE)
7777
logger.debug("Applicant role given to user %s", applicant_member)
7878

79-
tex_emoji: discord.Emoji | None = self.bot.get_emoji(743218410409820213)
79+
tex_emoji: discord.GuildEmoji | discord.AppEmoji | None = self.bot.get_emoji(743218410409820213)
8080
if not tex_emoji:
8181
tex_emoji = discord.utils.get(main_guild.emojis, name="TeX")
8282

‎cogs/remind_me.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ async def remind_me(
213213
parsed_time: tuple[time.struct_time, int] = parsedatetime.Calendar().parseDT(
214214
delay, tzinfo=timezone.get_current_timezone()
215215
)
216+
if not ctx.channel:
217+
await self.command_send_error(
218+
ctx, message="This command can only be used in channels."
219+
)
220+
return
216221

217222
if parsed_time[1] == 0:
218223
await self.command_send_error(
@@ -305,8 +310,9 @@ async def clear_reminders_backlog(self) -> None:
305310
discord.utils.utcnow() - reminder.send_datetime
306311
)
307312
if time_since_reminder_needed_to_be_sent > datetime.timedelta(minutes=15):
308-
user: discord.User | None = await self.bot.get_or_fetch_user(
309-
int(reminder.discord_member.discord_id)
313+
user: discord.User | None = await self.bot.get_or_fetch(
314+
object_type=discord.User,
315+
object_id=int(reminder.discord_member.discord_id)
310316
)
311317

312318
if not user:

‎cogs/stats/__init__.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ async def channel_stats(
8686
# 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
8787
main_guild: discord.Guild = self.bot.main_guild
8888

89-
channel_id: int = ctx.channel_id
89+
if isinstance(ctx.channel, (None | discord.CategoryChannel | discord.ForumChannel)):
90+
await self.command_send_error(
91+
ctx, message="This command can only be used in text channels."
92+
)
93+
return
94+
95+
channel_id: int | None = ctx.channel_id
9096

9197
if str_channel_id:
9298
if not re.fullmatch(r"\A\d{17,20}\Z", str_channel_id):
@@ -157,6 +163,12 @@ async def server_stats(self, ctx: "TeXBotApplicationContext") -> None:
157163
main_guild: discord.Guild = self.bot.main_guild
158164
guest_role: discord.Role = await self.bot.guest_role
159165

166+
if isinstance(ctx.channel, (None | discord.CategoryChannel | discord.ForumChannel)):
167+
await self.command_send_error(
168+
ctx, message="This command can only be used in text channels."
169+
)
170+
return
171+
160172
await ctx.defer(ephemeral=True)
161173

162174
message_counts: Mapping[str, Mapping[str, int]] = await get_server_message_counts(
@@ -237,6 +249,12 @@ async def user_stats(self, ctx: "TeXBotApplicationContext") -> None:
237249
interaction_member: discord.Member = await self.bot.get_main_guild_member(ctx.user)
238250
guest_role: discord.Role = await self.bot.guest_role
239251

252+
if isinstance(ctx.channel, (None | discord.CategoryChannel | discord.ForumChannel)):
253+
await self.command_send_error(
254+
ctx, message="This command can only be used in text channels."
255+
)
256+
return
257+
240258
if guest_role not in interaction_member.roles:
241259
await self.command_send_error(
242260
ctx,
@@ -314,6 +332,12 @@ async def left_member_stats(self, ctx: "TeXBotApplicationContext") -> None:
314332
# 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
315333
main_guild: discord.Guild = self.bot.main_guild
316334

335+
if isinstance(ctx.channel, (None | discord.CategoryChannel | discord.ForumChannel)):
336+
await self.command_send_error(
337+
ctx, message="This command can only be used in text channels."
338+
)
339+
return
340+
317341
await ctx.defer(ephemeral=True)
318342

319343
left_member_counts: dict[str, int] = {

‎cogs/strike.py‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ConfirmStrikeMemberView(View):
9494
@discord.ui.button(
9595
label="Yes", style=discord.ButtonStyle.red, custom_id="yes_strike_member"
9696
)
97-
async def yes_strike_member_button_callback( # type: ignore[misc]
97+
async def yes_strike_member_button_callback(
9898
self, _: discord.Button, interaction: discord.Interaction
9999
) -> None:
100100
"""
@@ -113,7 +113,7 @@ async def yes_strike_member_button_callback( # type: ignore[misc]
113113
@discord.ui.button(
114114
label="No", style=discord.ButtonStyle.grey, custom_id="no_strike_member"
115115
)
116-
async def no_strike_member_button_callback( # type: ignore[misc]
116+
async def no_strike_member_button_callback(
117117
self, _: discord.Button, interaction: discord.Interaction
118118
) -> None:
119119
"""
@@ -136,7 +136,7 @@ class ConfirmManualModerationView(View):
136136
@discord.ui.button(
137137
label="Yes", style=discord.ButtonStyle.red, custom_id="yes_manual_moderation_action"
138138
)
139-
async def yes_manual_moderation_action_button_callback( # type: ignore[misc]
139+
async def yes_manual_moderation_action_button_callback(
140140
self, _: discord.Button, interaction: discord.Interaction
141141
) -> None:
142142
"""
@@ -156,7 +156,7 @@ async def yes_manual_moderation_action_button_callback( # type: ignore[misc]
156156
@discord.ui.button(
157157
label="No", style=discord.ButtonStyle.grey, custom_id="no_manual_moderation_action"
158158
)
159-
async def no_manual_moderation_action_button_callback( # type: ignore[misc]
159+
async def no_manual_moderation_action_button_callback(
160160
self, _: discord.Button, interaction: discord.Interaction
161161
) -> None:
162162
"""
@@ -180,7 +180,7 @@ class ConfirmStrikesOutOfSyncWithBanView(View):
180180
@discord.ui.button(
181181
label="Yes", style=discord.ButtonStyle.red, custom_id="yes_out_of_sync_ban_member"
182182
)
183-
async def yes_out_of_sync_ban_member_button_callback( # type: ignore[misc]
183+
async def yes_out_of_sync_ban_member_button_callback(
184184
self, _: discord.Button, interaction: discord.Interaction
185185
) -> None:
186186
"""
@@ -200,7 +200,7 @@ async def yes_out_of_sync_ban_member_button_callback( # type: ignore[misc]
200200
@discord.ui.button(
201201
label="No", style=discord.ButtonStyle.grey, custom_id="no_out_of_sync_ban_member"
202202
)
203-
async def no_out_of_sync_ban_member_button_callback( # type: ignore[misc]
203+
async def no_out_of_sync_ban_member_button_callback(
204204
self, _: discord.Button, interaction: discord.Interaction
205205
) -> None:
206206
"""
@@ -264,7 +264,7 @@ async def _send_strike_user_message(
264264
async def _confirm_perform_moderation_action(
265265
self,
266266
message_sender_component: "MessageSavingSenderComponent",
267-
interaction_user: discord.User,
267+
interaction_user: discord.User | discord.Member,
268268
strike_user: discord.Member,
269269
confirm_strike_message: str,
270270
actual_strike_amount: int,
@@ -315,7 +315,7 @@ async def _confirm_perform_moderation_action(
315315
async def _confirm_increase_strike(
316316
self,
317317
message_sender_component: "MessageSavingSenderComponent",
318-
interaction_user: discord.User,
318+
interaction_user: discord.User | discord.Member,
319319
strike_user: discord.User | discord.Member,
320320
member_strikes: DiscordMemberStrikes,
321321
button_callback_channel: discord.TextChannel | discord.DMChannel,
@@ -401,6 +401,12 @@ async def _command_perform_strike(
401401
Also calls the process of performing the appropriate moderation action,
402402
given the new number of strikes that the member has.
403403
"""
404+
if not isinstance(ctx.channel, (discord.TextChannel, discord.DMChannel)):
405+
await self.command_send_error(
406+
ctx, message="This command can only be used in text channels or DMs."
407+
)
408+
return
409+
404410
if strike_member.bot:
405411
await self.command_send_error(
406412
ctx,
@@ -504,8 +510,7 @@ async def _confirm_manual_add_strike( # noqa: PLR0915
504510
async for _audit_log_entry in main_guild.audit_logs(
505511
after=discord.utils.utcnow() - datetime.timedelta(minutes=1), action=action
506512
)
507-
if _audit_log_entry.target.id
508-
== strike_user.id # NOTE: IDs are checked here rather than the objects themselves as the audit log provides an unusual object type in some cases.
513+
if _audit_log_entry.target and _audit_log_entry.target.id == strike_user.id # NOTE: IDs are checked here rather than the objects themselves as the audit log provides an unusual object type in some cases.
509514
)
510515
except (StopIteration, StopAsyncIteration):
511516
logger.debug("Printing 5 most recent audit logs:")
@@ -750,10 +755,7 @@ async def on_member_update(self, before: discord.Member, after: discord.Member)
750755

751756
audit_log_entry: discord.AuditLogEntry
752757
async for audit_log_entry in main_guild.audit_logs(limit=5):
753-
FOUND_CORRECT_AUDIT_LOG_ENTRY: bool = audit_log_entry.target.id == after.id and (
754-
audit_log_entry.action
755-
== discord.AuditLogAction.auto_moderation_user_communication_disabled
756-
)
758+
FOUND_CORRECT_AUDIT_LOG_ENTRY: bool = ((audit_log_entry.target is not None) and (audit_log_entry.target.id == after.id) and (audit_log_entry.action == discord.AuditLogAction.auto_moderation_user_communication_disabled))
757759
if FOUND_CORRECT_AUDIT_LOG_ENTRY:
758760
await self._confirm_manual_add_strike(
759761
strike_user=after, action=audit_log_entry.action

‎stubs/discord/__init__.pyi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ from .team import *
6262
from .template import *
6363
from .threads import *
6464
from .user import *
65-
from .voice_client import *
6665
from .webhook import *
6766
from .welcome_screen import *
6867
from .widget import *

0 commit comments

Comments
 (0)