@@ -124,19 +124,19 @@ def mention(self):
124
124
125
125
@classmethod
126
126
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
130
131
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
140
140
141
141
class PrivateChannel (metaclass = abc .ABCMeta ):
142
142
"""An ABC that details the common operations on a private Discord channel.
@@ -162,10 +162,7 @@ def __subclasshook__(cls, C):
162
162
return NotImplemented
163
163
164
164
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 )
169
166
return NotImplemented
170
167
171
168
class _Overwrites :
@@ -298,14 +295,10 @@ async def _edit(self, options, reason):
298
295
payload = {
299
296
'allow' : allow .value ,
300
297
'deny' : deny .value ,
301
- 'id' : target .id
298
+ 'id' : target .id ,
299
+ 'type' : 'role' if isinstance (target , Role ) else 'member' ,
302
300
}
303
301
304
- if isinstance (target , Role ):
305
- payload ['type' ] = 'role'
306
- else :
307
- payload ['type' ] = 'member'
308
-
309
302
perms .append (payload )
310
303
options ['permission_overwrites' ] = perms
311
304
@@ -330,7 +323,9 @@ def _fill_overwrites(self, data):
330
323
for index , overridden in enumerate (data .get ('permission_overwrites' , [])):
331
324
overridden_type = try_enum (PermissionType , overridden .pop ('type' ))
332
325
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
+ )
334
329
overridden_id = int (overridden .pop ('id' ))
335
330
self ._overwrites .append (_Overwrites (id = overridden_id , type = overridden_type .name , ** overridden ))
336
331
@@ -345,9 +340,7 @@ def _fill_overwrites(self, data):
345
340
# swap it to be the first one.
346
341
everyone_index = index
347
342
348
- # do the swap
349
- tmp = self ._overwrites
350
- if tmp :
343
+ if tmp := self ._overwrites :
351
344
tmp [everyone_index ], tmp [0 ] = tmp [0 ], tmp [everyone_index ]
352
345
353
346
@property
@@ -369,7 +362,7 @@ def changed_roles(self):
369
362
@property
370
363
def mention (self ):
371
364
""":class:`str`: The string that allows you to mention the channel."""
372
- return '<#%s>' % self .id
365
+ return f '<#{ self .id } >'
373
366
374
367
@property
375
368
def created_at (self ):
@@ -654,15 +647,14 @@ async def set_permissions(self, target, *, overwrite=_undefined, reason=None, **
654
647
raise InvalidArgument ('target parameter must be either Member or Role' )
655
648
656
649
if isinstance (overwrite , _Undefined ):
657
- if len ( permissions ) == 0 :
650
+ if not permissions :
658
651
raise InvalidArgument ('No overwrite provided.' )
659
652
try :
660
653
overwrite = PermissionOverwrite (** permissions )
661
654
except (ValueError , TypeError ):
662
655
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.' )
666
658
667
659
# TODO: wait for event
668
660
@@ -1049,14 +1041,13 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
1049
1041
_components .extend (ActionRow (* [obj for obj in component if isinstance (obj , (Button , SelectMenu ))]).to_dict ())
1050
1042
components = _components
1051
1043
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 :
1058
1045
allowed_mentions = state .allowed_mentions and state .allowed_mentions .to_dict ()
1059
1046
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 ()
1060
1051
if mention_author is not None :
1061
1052
allowed_mentions = allowed_mentions or AllowedMentions ().to_dict ()
1062
1053
allowed_mentions ['replied_user' ] = bool (mention_author )
@@ -1085,22 +1076,37 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
1085
1076
raise InvalidArgument ('file parameter must be File' )
1086
1077
1087
1078
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
+ )
1104
1110
finally :
1105
1111
file .close ()
1106
1112
@@ -1130,28 +1136,27 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
1130
1136
finally :
1131
1137
for f in files :
1132
1138
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 )
1133
1150
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 :
1151
1156
"""Thanks Discord that they dont return the message when we send the interaction callback"""
1152
1157
data = await state .http .get_original_interaction_response (application_id = application_id , interaction_token = interaction_token )
1153
1158
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 :
1155
1160
await ret .delete (delay = delete_after )
1156
1161
return ret
1157
1162
0 commit comments