|
29 | 29 | from jishaku.types import ContextA, ContextT
|
30 | 30 |
|
31 | 31 | UserIDConverter = commands.IDConverter[typing.Union[discord.Member, discord.User]]
|
32 |
| -ChannelIDConverter = commands.IDConverter[discord.TextChannel] |
33 |
| -ThreadIDConverter = commands.IDConverter[discord.Thread] |
| 32 | +ChannelIDConverter = commands.IDConverter[typing.Union[discord.abc.GuildChannel, discord.abc.PrivateChannel, discord.Thread]] |
34 | 33 |
|
35 | 34 |
|
36 | 35 | class SlimUserConverter(UserIDConverter): # pylint: disable=too-few-public-methods
|
@@ -58,44 +57,31 @@ async def convert(self, ctx: ContextA, argument: str) -> typing.Union[discord.Me
|
58 | 57 |
|
59 | 58 | class SlimChannelConverter(ChannelIDConverter): # pylint: disable=too-few-public-methods
|
60 | 59 | """
|
61 |
| - Identical to the stock TextChannelConverter, but does not perform plaintext name checks. |
| 60 | + Similar to Union[GuildChannelConverter, ThreadConverter], but can return PrivateChannels and |
| 61 | + does not perform plaintext name or guild checks. |
62 | 62 | """
|
63 | 63 |
|
64 |
| - async def convert(self, ctx: ContextA, argument: str) -> discord.TextChannel: |
| 64 | + async def convert(self, ctx: ContextA, argument: str) -> typing.Union[discord.abc.GuildChannel, discord.abc.PrivateChannel, discord.Thread]: |
65 | 65 | """Converter method"""
|
66 |
| - match = self._get_id_match(argument) or re.match(r'<@!?([0-9]{15,20})>$', argument) |
| 66 | + match = self._get_id_match(argument) or re.match(r'<#([0-9]{15,20})>$', argument) |
67 | 67 |
|
68 | 68 | if match is not None:
|
69 | 69 | channel_id = int(match.group(1))
|
70 |
| - result = ctx.bot.get_channel(channel_id) or discord.utils.get(ctx.message.channel_mentions, id=channel_id) |
| 70 | + if ctx.guild: |
| 71 | + result = ctx.guild.get_channel_or_thread(channel_id) |
| 72 | + if not result: |
| 73 | + result = ctx.bot.get_channel(channel_id) |
71 | 74 | if result is not None:
|
72 | 75 | return result
|
73 | 76 | raise commands.ChannelNotFound(argument)
|
74 | 77 |
|
75 | 78 |
|
76 |
| -class SlimThreadConverter(ThreadIDConverter): # pylint: disable=too-few-public-methods |
77 |
| - """ |
78 |
| - Identical to the stock ThreadConverter, but does not perform plaintext name checks. |
79 |
| - """ |
80 |
| - |
81 |
| - async def convert(self, ctx: ContextA, argument: str) -> discord.Thread: |
82 |
| - """Converter method""" |
83 |
| - match = self._get_id_match(argument) or re.match(r'<@!?([0-9]{15,20})>$', argument) |
84 |
| - |
85 |
| - if match is not None: |
86 |
| - thread_id = int(match.group(1)) |
87 |
| - result = ctx.guild.get_thread(thread_id) |
88 |
| - if result is not None: |
89 |
| - return result |
90 |
| - raise commands.ThreadNotFound(argument) |
91 |
| - |
92 |
| - |
93 | 79 | class InvocationFeature(Feature):
|
94 | 80 | """
|
95 | 81 | Feature containing the command invocation related commands
|
96 | 82 | """
|
97 | 83 |
|
98 |
| - OVERRIDE_SIGNATURE = typing.Union[SlimUserConverter, SlimChannelConverter, SlimThreadConverter] |
| 84 | + OVERRIDE_SIGNATURE = typing.Union[SlimUserConverter, SlimChannelConverter] |
99 | 85 |
|
100 | 86 | @Feature.Command(parent="jsk", name="override", aliases=["execute", "exec", "override!", "execute!", "exec!"])
|
101 | 87 | async def jsk_override(
|
|
0 commit comments