|
87 | 87 | sticker,
|
88 | 88 | )
|
89 | 89 | from .types.snowflake import Snowflake, SnowflakeList
|
| 90 | + from .types.message import Attachment |
90 | 91 |
|
91 | 92 | from types import TracebackType
|
92 | 93 |
|
@@ -548,6 +549,88 @@ def send_files(
|
548 | 549 | stickers=stickers,
|
549 | 550 | components=components,
|
550 | 551 | )
|
| 552 | + |
| 553 | + def edit_multipart_helper( |
| 554 | + self, |
| 555 | + route: Route, |
| 556 | + *, |
| 557 | + files: Sequence[File], |
| 558 | + attachments: List[Attachment] = None, |
| 559 | + suppress: bool = False, |
| 560 | + content: Optional[str] = None, |
| 561 | + embed: Optional[embed.Embed] = None, |
| 562 | + embeds: Optional[Iterable[Optional[embed.Embed]]] = None, |
| 563 | + allowed_mentions: Optional[message.AllowedMentions] = None, |
| 564 | + components: Optional[List[components.Component]] = None, |
| 565 | + ) -> Response[message.Message]: |
| 566 | + form = [] |
| 567 | + |
| 568 | + payload: Dict[str, Any] = {} |
| 569 | + if attachments: |
| 570 | + payload['attachments'] = attachments |
| 571 | + if suppress: |
| 572 | + payload['suppress'] = suppress |
| 573 | + if content: |
| 574 | + payload['content'] = content |
| 575 | + if embed: |
| 576 | + payload['embeds'] = [embed] |
| 577 | + if embeds: |
| 578 | + payload['embeds'] = embeds |
| 579 | + if allowed_mentions: |
| 580 | + payload['allowed_mentions'] = allowed_mentions |
| 581 | + if components: |
| 582 | + payload['components'] = components |
| 583 | + |
| 584 | + form.append({'name': 'payload_json', 'value': utils._to_json(payload)}) |
| 585 | + if len(files) == 1: |
| 586 | + file = files[0] |
| 587 | + form.append( |
| 588 | + { |
| 589 | + 'name': 'file', |
| 590 | + 'value': file.fp, |
| 591 | + 'filename': file.filename, |
| 592 | + 'content_type': 'application/octet-stream', |
| 593 | + } |
| 594 | + ) |
| 595 | + else: |
| 596 | + for index, file in enumerate(files): |
| 597 | + form.append( |
| 598 | + { |
| 599 | + 'name': f'file{index}', |
| 600 | + 'value': file.fp, |
| 601 | + 'filename': file.filename, |
| 602 | + 'content_type': 'application/octet-stream', |
| 603 | + } |
| 604 | + ) |
| 605 | + |
| 606 | + return self.request(route, form=form, files=files) |
| 607 | + |
| 608 | + def edit_files( |
| 609 | + self, |
| 610 | + channel_id: Snowflake, |
| 611 | + message_id: Snowflake, |
| 612 | + *, |
| 613 | + files: Sequence[File], |
| 614 | + attachments: List[Attachment] = None, |
| 615 | + suppress: bool = False, |
| 616 | + content: Optional[str] = None, |
| 617 | + embed: Optional[embed.Embed] = None, |
| 618 | + embeds: Optional[List[embed.Embed]] = None, |
| 619 | + allowed_mentions: Optional[message.AllowedMentions] = None, |
| 620 | + components: Optional[List[components.Component]] = None, |
| 621 | + ) -> Response[message.Message]: |
| 622 | + r = Route('PATCH', f'/channels/{channel_id}/messages/{message_id}', channel_id=channel_id, message_id=message_id) |
| 623 | + return self.edit_multipart_helper( |
| 624 | + r, |
| 625 | + files=files, |
| 626 | + attachments=attachments, |
| 627 | + suppress=suppress, |
| 628 | + content=content, |
| 629 | + embed=embed, |
| 630 | + embeds=embeds, |
| 631 | + allowed_mentions=allowed_mentions, |
| 632 | + components=components, |
| 633 | + ) |
551 | 634 |
|
552 | 635 | def delete_message(
|
553 | 636 | self, channel_id: Snowflake, message_id: Snowflake, *, reason: Optional[str] = None
|
|
0 commit comments