3535
3636from hikari import channels
3737from hikari import intents
38+ from hikari import users
39+ from hikari .api import special_endpoints
3840from hikari .events import base_events
3941from hikari .events import shard_events
4042from hikari .utilities import attr_extensions
4547 from hikari import guilds
4648 from hikari import snowflakes
4749 from hikari import traits
48- from hikari import users
4950 from hikari .api import shard as gateway_shard
5051
5152
@@ -97,6 +98,18 @@ def channel(self) -> typing.Optional[channels.TextChannel]:
9798 The channel, if known.
9899 """
99100
101+ @property
102+ @abc .abstractmethod
103+ def user (self ) -> typing .Optional [users .User ]:
104+ """Get the cached user that is typing, if known.
105+
106+ Returns
107+ -------
108+ typing.Optional[hikari.users.User]
109+ The user, if known.
110+ """
111+
112+ @abc .abstractmethod
100113 async def fetch_channel (self ) -> channels .TextChannel :
101114 """Perform an API call to fetch an up-to-date image of this channel.
102115
@@ -105,10 +118,8 @@ async def fetch_channel(self) -> channels.TextChannel:
105118 hikari.channels.TextChannel
106119 The channel.
107120 """
108- channel = await self .app .rest .fetch_channel (self .channel_id )
109- assert isinstance (channel , channels .TextChannel )
110- return channel
111121
122+ @abc .abstractmethod
112123 async def fetch_user (self ) -> users .User :
113124 """Perform an API call to fetch an up-to-date image of this user.
114125
@@ -117,7 +128,17 @@ async def fetch_user(self) -> users.User:
117128 hikari.users.User
118129 The user.
119130 """
120- return await self .app .rest .fetch_user (self .user_id )
131+
132+ def trigger_typing (self ) -> special_endpoints .TypingIndicator :
133+ """Return a typing indicator for this channel that can be awaited.
134+
135+ Returns
136+ -------
137+ hikari.api.special_endpoints.TypingIndicator
138+ A typing indicator context manager and awaitable to trigger typing
139+ in a channel with.
140+ """
141+ return self .app .rest .trigger_typing (self .channel_id )
121142
122143
123144@base_events .requires_intents (intents .Intents .GUILD_MESSAGE_TYPING )
@@ -135,9 +156,6 @@ class GuildTypingEvent(TypingEvent):
135156 channel_id : snowflakes .Snowflake = attr .ib ()
136157 # <<inherited docstring from TypingEvent>>.
137158
138- user_id : snowflakes .Snowflake = attr .ib (repr = True )
139- # <<inherited docstring from TypingEvent>>.
140-
141159 timestamp : datetime .datetime = attr .ib (repr = False )
142160 # <<inherited docstring from TypingEvent>>.
143161
@@ -150,19 +168,32 @@ class GuildTypingEvent(TypingEvent):
150168 The ID of the guild that relates to this event.
151169 """
152170
153- member : guilds .Member = attr .ib (repr = False )
171+ user : guilds .Member = attr .ib (repr = False )
154172 """Member object of the user who triggered this typing event.
155173
174+ Unlike on `PrivateTypingEvent` instances, Discord will always send
175+ this field in any payload.
176+
156177 Returns
157178 -------
158179 hikari.guilds.Member
159180 Member of the user who triggered this typing event.
160181 """
161182
162183 @property
163- def channel (self ) -> typing .Optional [channels .GuildTextChannel ]:
164- # <<inherited docstring from TypingEvent>>.
165- return typing .cast ("channels.GuildTextChannel" , self .app .cache .get_guild_channel (self .channel_id ))
184+ def channel (self ) -> typing .Union [channels .GuildTextChannel , channels .GuildNewsChannel ]:
185+ """Get the cached channel object this typing event occurred in.
186+
187+ Returns
188+ -------
189+ typing.Union[hikari.channels.GuildTextChannel, hikari.channels.GuildNewsChannel]
190+ The channel.
191+ """
192+ channel = self .app .cache .get_guild_channel (self .channel_id )
193+ assert isinstance (
194+ channel , (channels .GuildTextChannel , channels .GuildNewsChannel )
195+ ), f"expected GuildTextChannel or GuildNewsChannel from cache, got { channel } "
196+ return channel
166197
167198 @property
168199 def guild (self ) -> typing .Optional [guilds .GatewayGuild ]:
@@ -177,10 +208,24 @@ def guild(self) -> typing.Optional[guilds.GatewayGuild]:
177208 """
178209 return self .app .cache .get_available_guild (self .guild_id ) or self .app .cache .get_unavailable_guild (self .guild_id )
179210
180- if typing .TYPE_CHECKING :
211+ @property
212+ def user_id (self ) -> snowflakes .Snowflake :
213+ # <<inherited docstring from TypingEvent>>.
214+ return self .user .id
181215
182- async def fetch_channel (self ) -> channels .GuildTextChannel :
183- ...
216+ async def fetch_channel (self ) -> typing .Union [channels .GuildTextChannel , channels .GuildNewsChannel ]:
217+ """Perform an API call to fetch an up-to-date image of this channel.
218+
219+ Returns
220+ -------
221+ typing.Union[hikari.channels.GuildTextChannel, hikari.channels.GuildNewsChannel]
222+ The channel.
223+ """
224+ channel = await self .app .rest .fetch_channel (self .channel_id )
225+ assert isinstance (
226+ channel , (channels .GuildTextChannel , channels .GuildNewsChannel )
227+ ), f"expected GuildTextChannel or GuildNewsChannel from API, got { channel } "
228+ return channel
184229
185230 async def fetch_guild (self ) -> guilds .Guild :
186231 """Perform an API call to fetch an up-to-date image of this guild.
@@ -202,7 +247,7 @@ async def fetch_guild_preview(self) -> guilds.GuildPreview:
202247 """
203248 return await self .app .rest .fetch_guild_preview (self .guild_id )
204249
205- async def fetch_member (self ) -> guilds .Member :
250+ async def fetch_user (self ) -> guilds .Member :
206251 """Perform an API call to fetch an up-to-date image of this member.
207252
208253 Returns
@@ -232,7 +277,6 @@ class PrivateTypingEvent(TypingEvent):
232277 # <<inherited docstring from TypingEvent>>.
233278
234279 timestamp : datetime .datetime = attr .ib (repr = False )
235-
236280 # <<inherited docstring from TypingEvent>>.
237281
238282 @property
@@ -246,7 +290,29 @@ def channel(self) -> typing.Optional[channels.DMChannel]:
246290 """
247291 return self .app .cache .get_dm (self .user_id )
248292
249- if typing .TYPE_CHECKING :
293+ @property
294+ def user (self ) -> typing .Optional [users .User ]:
295+ # <<inherited docstring from TypingEvent>>.
296+ return self .app .cache .get_user (self .user_id )
250297
251- async def fetch_channel (self ) -> channels .DMChannel :
252- ...
298+ async def fetch_channel (self ) -> channels .DMChannel :
299+ """Perform an API call to fetch an up-to-date image of this channel.
300+
301+ Returns
302+ -------
303+ hikari.channels.DMChannel
304+ The channel.
305+ """
306+ channel = await self .app .rest .fetch_channel (self .channel_id )
307+ assert isinstance (channel , channels .DMChannel ), f"expected DMChannel from API, got { channel } "
308+ return channel
309+
310+ async def fetch_user (self ) -> users .User :
311+ """Perform an API call to fetch an up-to-date image of the user.
312+
313+ Returns
314+ -------
315+ hikari.users.User
316+ The user.
317+ """
318+ return await self .app .rest .fetch_user (self .user_id )
0 commit comments