Skip to content

Commit 2eaab34

Browse files
committed
fix: edit removing other parameters
1 parent 90865a7 commit 2eaab34

File tree

1 file changed

+49
-73
lines changed

1 file changed

+49
-73
lines changed

discord_components/dpy_overrides.py

Lines changed: 49 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,55 @@ def get_component(self, custom_id: str) -> Optional[Component]:
3939
if component.custom_id == custom_id:
4040
return component
4141

42-
async def _components_edit(self, **fields):
42+
async def edit(
43+
self,
44+
content: Optional[str] = None,
45+
embed: Optional[Embed] = None,
46+
embeds: List[Embed] = None,
47+
suppress: bool = None,
48+
attachments: List[Attachment] = None,
49+
delete_after: Optional[float] = None,
50+
allowed_mentions: Optional[AllowedMentions] = None,
51+
components: List[Union[ActionRow, Component, List[Component]]] = None,
52+
**fields,
53+
):
54+
if self.ephemeral:
55+
return
56+
4357
state = self._state
4458
data = {}
4559

46-
if fields.get("content") is not None:
47-
data["content"] = fields["content"]
60+
if content is not None:
61+
data["content"] = content
4862

49-
if fields.get("embed") is not None and fields.get("embeds") is not None:
63+
if embed is not None and embeds is not None:
5064
raise InvalidArgument("cannot pass both embed and embeds parameter to edit()")
5165

52-
if fields.get("embed") is not None:
53-
data["embeds"] = [fields["embed"].to_dict()]
66+
if embed is not None:
67+
data["embeds"] = [embed.to_dict()]
5468

55-
if fields.get("embeds") is not None:
56-
data["embeds"] = [e.to_dict() for e in fields["embeds"]]
69+
if embeds is not None:
70+
data["embeds"] = [e.to_dict() for e in embeds]
5771

58-
if fields.get("suppress") is not None:
72+
if suppress is not None:
5973
flags = MessageFlags._from_value(0)
6074
flags.suppress_embeds = True
6175
data["flags"] = flags.value
6276

63-
if fields.get("allowed_mentions") is None:
77+
if allowed_mentions is None:
6478
if state.allowed_mentions is not None and self.author.id == self._state.self_id:
6579
data["allowed_mentions"] = state.allowed_mentions.to_dict()
6680
else:
6781
if state.allowed_mentions is not None:
68-
data["allowed_mentions"] = state.allowed_mentions.merge(
69-
fields["allowed_mentions"]
70-
).to_dict()
82+
data["allowed_mentions"] = state.allowed_mentions.merge(allowed_mentions).to_dict()
7183
else:
72-
data["allowed_mentions"] = fields["allowed_mentions"].to_dict()
84+
data["allowed_mentions"] = allowed_mentions.to_dict()
7385

74-
if fields.get("attachments") is not None:
75-
data["attachments"] = [a.to_dict() for a in fields["attachments"]]
86+
if attachments is not None:
87+
data["attachments"] = [a.to_dict() for a in attachments]
7688

77-
if fields.get("components") is not None:
78-
data["components"] = _get_components_json(fields["components"])
89+
if components is not None:
90+
data["components"] = _get_components_json(components)
7991

8092
if data:
8193
await state.http.request(
@@ -88,44 +100,8 @@ async def _components_edit(self, **fields):
88100
json=data,
89101
)
90102

91-
if fields.get("delete_after") is not None:
92-
await self.delete(delay=fields["delete_after"])
93-
94-
async def edit(
95-
self,
96-
content: Optional[str] = None,
97-
embed: Optional[Embed] = None,
98-
embeds: List[Embed] = None,
99-
attachments: List[Attachment] = None,
100-
delete_after: Optional[float] = None,
101-
allowed_mentions: Optional[AllowedMentions] = None,
102-
components: List[Union[ActionRow, Component, List[Component]]] = None,
103-
**fields,
104-
):
105-
if self.ephemeral:
106-
return
107-
108-
if components is not None:
109-
await self._components_edit(
110-
content=content,
111-
embed=embed,
112-
embeds=embeds,
113-
attachments=attachments,
114-
delete_after=delete_after,
115-
allowed_mentions=allowed_mentions,
116-
components=components,
117-
)
118-
else:
119-
await super().edit(
120-
content=content,
121-
embed=embed,
122-
embeds=embeds,
123-
attachments=attachments,
124-
delete_after=delete_after,
125-
allowed_mentions=allowed_mentions,
126-
components=components,
127-
**fields,
128-
)
103+
if delete_after is not None:
104+
await self.delete(delay=delete_after)
129105

130106
async def delete(self, *args, **kwargs):
131107
if self.ephemeral:
@@ -160,21 +136,21 @@ def send_files(
160136
components=None,
161137
):
162138
data = {"tts": tts}
163-
if content:
139+
if content is not None:
164140
data["content"] = content
165-
if embed:
141+
if embed is not None:
166142
data["embeds"] = [embed]
167-
if embeds:
143+
if embeds is not None:
168144
data["embeds"] = embeds
169-
if nonce:
145+
if nonce is not None:
170146
data["nonce"] = nonce
171-
if allowed_mentions:
147+
if allowed_mentions is not None:
172148
data["allowed_mentions"] = allowed_mentions
173-
if message_reference:
149+
if message_reference is not None:
174150
data["message_reference"] = message_reference
175-
if stickers:
151+
if stickers is not None:
176152
data["sticker_ids"] = stickers
177-
if components:
153+
if components is not None:
178154
data["components"] = components
179155

180156
form = _form_files(data, files, use_form=False)
@@ -201,31 +177,31 @@ def send_message(
201177
):
202178
payload = {}
203179

204-
if content:
180+
if content is not None:
205181
payload["content"] = content
206182

207-
if tts:
183+
if tts is not None:
208184
payload["tts"] = True
209185

210-
if embed:
186+
if embed is not None:
211187
payload["embeds"] = [embed]
212188

213-
if embeds:
189+
if embeds is not None:
214190
payload["embeds"] = embeds
215191

216-
if nonce:
192+
if nonce is not None:
217193
payload["nonce"] = nonce
218194

219-
if allowed_mentions:
195+
if allowed_mentions is not None:
220196
payload["allowed_mentions"] = allowed_mentions
221197

222-
if message_reference:
198+
if message_reference is not None:
223199
payload["message_reference"] = message_reference
224200

225-
if stickers:
201+
if stickers is not None:
226202
payload["sticker_ids"] = stickers
227203

228-
if components:
204+
if components is not None:
229205
payload["components"] = components
230206

231207
return self.request(

0 commit comments

Comments
 (0)