"""The MIT License (MIT)Copyright (c) 2021-present Pycord DevelopmentPermission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationthe rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHERDEALINGS IN THE SOFTWARE."""fromdatetimeimportdatetimefromtypingimportTYPE_CHECKING,Anyfromtyping_extensionsimportSelf,overridefromdiscordimportutilsfromdiscord.app.event_emitterimportEventfromdiscord.app.stateimportConnectionStatefromdiscord.channelimportDMChannel,GroupChannel,TextChannelfromdiscord.memberimportMemberfromdiscord.raw_modelsimportRawTypingEventfromdiscord.channel.threadimportThreadfromdiscord.userimportUserifTYPE_CHECKING:fromdiscord.messageimportMessageableChannel
[docs]classTypingStart(Event):"""Called when someone begins typing a message. The :attr:`channel` can be a :class:`abc.Messageable` instance, which could be :class:`TextChannel`, :class:`GroupChannel`, or :class:`DMChannel`. If the :attr:`channel` is a :class:`TextChannel` then the :attr:`user` is a :class:`Member`, otherwise it is a :class:`User`. This requires :attr:`Intents.typing` to be enabled. Attributes ---------- raw: :class:`RawTypingEvent` The raw event payload data. channel: :class:`abc.Messageable` The location where the typing originated from. user: :class:`User` | :class:`Member` The user that started typing. when: :class:`datetime.datetime` When the typing started as an aware datetime in UTC. """__event_name__:str="TYPING_START"raw:RawTypingEventchannel:"MessageableChannel"user:User|Memberwhen:datetime@classmethod@overrideasyncdef__load__(cls,data:Any,state:ConnectionState)->Self|None:raw=RawTypingEvent(data)member_data=data.get("member")ifmember_data:guild=awaitstate._get_guild(raw.guild_id)ifguildisnotNone:raw.member=Member(data=member_data,guild=guild,state=state)else:raw.member=Noneelse:raw.member=Nonechannel,guild=awaitstate._get_guild_channel(data)ifchannelisNone:returnuser=raw.memberorawait_get_typing_user(state,channel,raw.user_id)ifuserisNone:returnself=cls()self.raw=rawself.channel=channel# type: ignoreself.user=userself.when=raw.whenreturnself
asyncdef_get_typing_user(state:ConnectionState,channel:"MessageableChannel | None",user_id:int)->User|Member|None:"""Helper function to get the user who is typing."""ifisinstance(channel,DMChannel):returnchannel.recipientorawaitstate.get_user(user_id)elifisinstance(channel,(Thread,TextChannel))andchannel.guildisnotNone:returnawaitchannel.guild.get_member(user_id)# type: ignoreelifisinstance(channel,GroupChannel):returnutils.find(lambdax:x.id==user_id,channel.recipients)returnawaitstate.get_user(user_id)