Skip to content

Commit 5189eaf

Browse files
clari7744Gorialis
authored andcommitted
result was moved inside an if statement in SlimChannelConverter, causing it to be unbound if ctx.guild is None
1 parent 664e009 commit 5189eaf

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

jishaku/features/invocation.py

+19-23
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
from jishaku.types import ContextA, ContextT
3030

3131
UserIDConverter = commands.IDConverter[typing.Union[discord.Member, discord.User]]
32-
ChannelIDConverter = commands.IDConverter[typing.Union[discord.abc.GuildChannel, discord.abc.PrivateChannel, discord.Thread]]
32+
ChannelIDConverter = commands.IDConverter[
33+
typing.Union[discord.abc.GuildChannel, discord.abc.PrivateChannel, discord.Thread]
34+
]
3335

3436

3537
class SlimUserConverter(UserIDConverter): # pylint: disable=too-few-public-methods
@@ -39,7 +41,7 @@ class SlimUserConverter(UserIDConverter): # pylint: disable=too-few-public-meth
3941

4042
async def convert(self, ctx: ContextA, argument: str) -> typing.Union[discord.Member, discord.User]:
4143
"""Converter method"""
42-
match = self._get_id_match(argument) or re.match(r'<@!?([0-9]{15,20})>$', argument) # type: ignore
44+
match = self._get_id_match(argument) or re.match(r"<@!?([0-9]{15,20})>$", argument) # type: ignore
4345

4446
if match is not None:
4547
user_id = int(match.group(1))
@@ -61,15 +63,18 @@ class SlimChannelConverter(ChannelIDConverter): # pylint: disable=too-few-publi
6163
does not perform plaintext name or guild checks.
6264
"""
6365

64-
async def convert(self, ctx: ContextA, argument: str) -> typing.Union[discord.abc.GuildChannel, discord.abc.PrivateChannel, discord.Thread]:
66+
async def convert(
67+
self, ctx: ContextA, argument: str
68+
) -> typing.Union[discord.abc.GuildChannel, discord.abc.PrivateChannel, discord.Thread]:
6569
"""Converter method"""
66-
match = self._get_id_match(argument) or re.match(r'<#([0-9]{15,20})>$', argument)
70+
match = self._get_id_match(argument) or re.match(r"<#([0-9]{15,20})>$", argument)
6771

6872
if match is not None:
6973
channel_id = int(match.group(1))
70-
if ctx.guild:
74+
result = None
75+
if ctx.guild is not None:
7176
result = ctx.guild.get_channel_or_thread(channel_id)
72-
if not result:
77+
if result is None:
7378
result = ctx.bot.get_channel(channel_id)
7479
if result is not None:
7580
return result
@@ -84,13 +89,7 @@ class InvocationFeature(Feature):
8489
OVERRIDE_SIGNATURE = typing.Union[SlimUserConverter, SlimChannelConverter]
8590

8691
@Feature.Command(parent="jsk", name="override", aliases=["execute", "exec", "override!", "execute!", "exec!"])
87-
async def jsk_override(
88-
self,
89-
ctx: ContextT,
90-
overrides: commands.Greedy[OVERRIDE_SIGNATURE],
91-
*,
92-
command_string: str
93-
):
92+
async def jsk_override(self, ctx: ContextT, overrides: commands.Greedy[OVERRIDE_SIGNATURE], *, command_string: str):
9493
"""
9594
Run a command with a different user, channel, or thread, optionally bypassing checks and cooldowns.
9695
@@ -100,7 +99,7 @@ async def jsk_override(
10099
kwargs: typing.Dict[str, typing.Any] = {}
101100

102101
if ctx.prefix:
103-
kwargs["content"] = ctx.prefix + command_string.lstrip('/')
102+
kwargs["content"] = ctx.prefix + command_string.lstrip("/")
104103
else:
105104
await ctx.send("Reparsing requires a prefix")
106105
return
@@ -128,12 +127,12 @@ async def jsk_override(
128127

129128
if alt_ctx.command is None:
130129
if alt_ctx.invoked_with is None:
131-
await ctx.send('This bot has been hard-configured to ignore this user.')
130+
await ctx.send("This bot has been hard-configured to ignore this user.")
132131
return
133132
await ctx.send(f'Command "{alt_ctx.invoked_with}" is not found')
134133
return
135134

136-
if ctx.invoked_with and ctx.invoked_with.endswith('!'):
135+
if ctx.invoked_with and ctx.invoked_with.endswith("!"):
137136
await alt_ctx.command.reinvoke(alt_ctx)
138137
return
139138

@@ -209,17 +208,14 @@ async def jsk_source(self, ctx: ContextA, *, command_name: str):
209208
pass
210209

211210
# getsourcelines for some reason returns WITH line endings
212-
source_text = ''.join(source_lines)
211+
source_text = "".join(source_lines)
213212

214213
if use_file_check(ctx, len(source_text)): # File "full content" preview limit
215-
await ctx.send(file=discord.File(
216-
filename=filename,
217-
fp=io.BytesIO(source_text.encode('utf-8'))
218-
))
214+
await ctx.send(file=discord.File(filename=filename, fp=io.BytesIO(source_text.encode("utf-8"))))
219215
else:
220-
paginator = WrappedPaginator(prefix='```py', suffix='```', max_size=1980)
216+
paginator = WrappedPaginator(prefix="```py", suffix="```", max_size=1980)
221217

222-
paginator.add_line(source_text.replace('```', '``\N{zero width space}`'))
218+
paginator.add_line(source_text.replace("```", "``\N{zero width space}`"))
223219

224220
interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
225221
await interface.send_to(ctx)

0 commit comments

Comments
 (0)