@@ -124,19 +124,19 @@ def mention(self):
124124
125125 @classmethod
126126 def __subclasshook__ (cls , C ):
127- if cls is User :
128- if Snowflake .__subclasshook__ (C ) is NotImplemented :
129- return NotImplemented
127+ if cls is not User :
128+ return NotImplemented
129+ if Snowflake .__subclasshook__ (C ) is NotImplemented :
130+ return NotImplemented
130131
131- mro = C .__mro__
132- for attr in ('display_name' , 'mention' , 'name' , 'avatar' , 'discriminator' , 'bot' ):
133- for base in mro :
134- if attr in base .__dict__ :
135- break
136- else :
137- return NotImplemented
138- return True
139- return NotImplemented
132+ mro = C .__mro__
133+ for attr in ('display_name' , 'mention' , 'name' , 'avatar' , 'discriminator' , 'bot' ):
134+ for base in mro :
135+ if attr in base .__dict__ :
136+ break
137+ else :
138+ return NotImplemented
139+ return True
140140
141141class PrivateChannel (metaclass = abc .ABCMeta ):
142142 """An ABC that details the common operations on a private Discord channel.
@@ -162,10 +162,7 @@ def __subclasshook__(cls, C):
162162 return NotImplemented
163163
164164 mro = C .__mro__
165- for base in mro :
166- if 'me' in base .__dict__ :
167- return True
168- return NotImplemented
165+ return next ((True for base in mro if 'me' in base .__dict__ ), NotImplemented )
169166 return NotImplemented
170167
171168class _Overwrites :
@@ -298,14 +295,10 @@ async def _edit(self, options, reason):
298295 payload = {
299296 'allow' : allow .value ,
300297 'deny' : deny .value ,
301- 'id' : target .id
298+ 'id' : target .id ,
299+ 'type' : 'role' if isinstance (target , Role ) else 'member' ,
302300 }
303301
304- if isinstance (target , Role ):
305- payload ['type' ] = 'role'
306- else :
307- payload ['type' ] = 'member'
308-
309302 perms .append (payload )
310303 options ['permission_overwrites' ] = perms
311304
@@ -330,7 +323,9 @@ def _fill_overwrites(self, data):
330323 for index , overridden in enumerate (data .get ('permission_overwrites' , [])):
331324 overridden_type = try_enum (PermissionType , overridden .pop ('type' ))
332325 if not overridden_type :
333- raise AttributeError ('Type type should be 0 - member, or 1 - role not %s' % overridden_type )
326+ raise AttributeError (
327+ f'Type type should be 0 - member, or 1 - role not { overridden_type } '
328+ )
334329 overridden_id = int (overridden .pop ('id' ))
335330 self ._overwrites .append (_Overwrites (id = overridden_id , type = overridden_type .name , ** overridden ))
336331
@@ -345,9 +340,7 @@ def _fill_overwrites(self, data):
345340 # swap it to be the first one.
346341 everyone_index = index
347342
348- # do the swap
349- tmp = self ._overwrites
350- if tmp :
343+ if tmp := self ._overwrites :
351344 tmp [everyone_index ], tmp [0 ] = tmp [0 ], tmp [everyone_index ]
352345
353346 @property
@@ -369,7 +362,7 @@ def changed_roles(self):
369362 @property
370363 def mention (self ):
371364 """:class:`str`: The string that allows you to mention the channel."""
372- return '<#%s>' % self .id
365+ return f '<#{ self .id } >'
373366
374367 @property
375368 def created_at (self ):
@@ -654,15 +647,14 @@ async def set_permissions(self, target, *, overwrite=_undefined, reason=None, **
654647 raise InvalidArgument ('target parameter must be either Member or Role' )
655648
656649 if isinstance (overwrite , _Undefined ):
657- if len ( permissions ) == 0 :
650+ if not permissions :
658651 raise InvalidArgument ('No overwrite provided.' )
659652 try :
660653 overwrite = PermissionOverwrite (** permissions )
661654 except (ValueError , TypeError ):
662655 raise InvalidArgument ('Invalid permissions given to keyword arguments.' )
663- else :
664- if len (permissions ) > 0 :
665- raise InvalidArgument ('Cannot mix overwrite and keyword arguments.' )
656+ elif permissions :
657+ raise InvalidArgument ('Cannot mix overwrite and keyword arguments.' )
666658
667659 # TODO: wait for event
668660
@@ -1049,14 +1041,13 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
10491041 _components .extend (ActionRow (* [obj for obj in component if isinstance (obj , (Button , SelectMenu ))]).to_dict ())
10501042 components = _components
10511043
1052- if allowed_mentions is not None :
1053- if state .allowed_mentions is not None :
1054- allowed_mentions = state .allowed_mentions .merge (allowed_mentions ).to_dict ()
1055- else :
1056- allowed_mentions = allowed_mentions .to_dict ()
1057- else :
1044+ if allowed_mentions is None :
10581045 allowed_mentions = state .allowed_mentions and state .allowed_mentions .to_dict ()
10591046
1047+ elif state .allowed_mentions is not None :
1048+ allowed_mentions = state .allowed_mentions .merge (allowed_mentions ).to_dict ()
1049+ else :
1050+ allowed_mentions = allowed_mentions .to_dict ()
10601051 if mention_author is not None :
10611052 allowed_mentions = allowed_mentions or AllowedMentions ().to_dict ()
10621053 allowed_mentions ['replied_user' ] = bool (mention_author )
@@ -1085,22 +1076,37 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
10851076 raise InvalidArgument ('file parameter must be File' )
10861077
10871078 try :
1088- if hidden is not None :
1089- data = await state .http .send_interaction_response (use_webhook = use_webhook ,
1090- interaction_id = interaction_id ,
1091- token = interaction_token ,
1092- application_id = application_id ,
1093- deferred = deferred ,
1094- files = [file ], allowed_mentions = allowed_mentions ,
1095- content = content , tts = tts , embeds = embeds ,
1096- components = components ,
1097- nonce = nonce , message_reference = reference ,
1098- flags = 64 if hidden is True else None ,
1099- followup = followup )
1100- else :
1101- data = await state .http .send_files (channel .id , files = [file ], allowed_mentions = allowed_mentions ,
1102- content = content , tts = tts , embeds = embeds , components = components ,
1103- nonce = nonce , message_reference = reference )
1079+ data = (
1080+ await state .http .send_interaction_response (
1081+ use_webhook = use_webhook ,
1082+ interaction_id = interaction_id ,
1083+ token = interaction_token ,
1084+ application_id = application_id ,
1085+ deferred = deferred ,
1086+ files = [file ],
1087+ allowed_mentions = allowed_mentions ,
1088+ content = content ,
1089+ tts = tts ,
1090+ embeds = embeds ,
1091+ components = components ,
1092+ nonce = nonce ,
1093+ message_reference = reference ,
1094+ flags = 64 if hidden is True else None ,
1095+ followup = followup ,
1096+ )
1097+ if hidden is not None
1098+ else await state .http .send_files (
1099+ channel .id ,
1100+ files = [file ],
1101+ allowed_mentions = allowed_mentions ,
1102+ content = content ,
1103+ tts = tts ,
1104+ embeds = embeds ,
1105+ components = components ,
1106+ nonce = nonce ,
1107+ message_reference = reference ,
1108+ )
1109+ )
11041110 finally :
11051111 file .close ()
11061112
@@ -1130,28 +1136,27 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
11301136 finally :
11311137 for f in files :
11321138 f .close ()
1139+ elif hidden is not None :
1140+ data = await state .http .send_interaction_response (use_webhook = use_webhook ,
1141+ interaction_id = interaction_id ,
1142+ token = interaction_token ,
1143+ application_id = application_id ,
1144+ deferred = deferred , allowed_mentions = allowed_mentions ,
1145+ content = content , tts = tts , embeds = embeds ,
1146+ components = components ,
1147+ nonce = nonce , message_reference = reference ,
1148+ flags = 64 if hidden is True else None ,
1149+ followup = followup )
11331150 else :
1134- if hidden is not None :
1135- data = await state .http .send_interaction_response (use_webhook = use_webhook ,
1136- interaction_id = interaction_id ,
1137- token = interaction_token ,
1138- application_id = application_id ,
1139- deferred = deferred , allowed_mentions = allowed_mentions ,
1140- content = content , tts = tts , embeds = embeds ,
1141- components = components ,
1142- nonce = nonce , message_reference = reference ,
1143- flags = 64 if hidden is True else None ,
1144- followup = followup )
1145- else :
1146- data = await state .http .send_message (channel .id , content , tts = tts , embeds = embeds , components = components ,
1147- nonce = nonce , allowed_mentions = allowed_mentions ,
1148- message_reference = reference )
1149- if not hidden is True :
1150- if not isinstance (data , dict ) and not hidden is None :
1151+ data = await state .http .send_message (channel .id , content , tts = tts , embeds = embeds , components = components ,
1152+ nonce = nonce , allowed_mentions = allowed_mentions ,
1153+ message_reference = reference )
1154+ if hidden is not True :
1155+ if not isinstance (data , dict ) and hidden is not None :
11511156 """Thanks Discord that they dont return the message when we send the interaction callback"""
11521157 data = await state .http .get_original_interaction_response (application_id = application_id , interaction_token = interaction_token )
11531158 ret = state .create_message (channel = channel , data = data )
1154- if ( delete_after is not None ) and ( not hidden is True ) :
1159+ if delete_after is not None and hidden is not True :
11551160 await ret .delete (delay = delete_after )
11561161 return ret
11571162
0 commit comments