1
|
|
|
# Copyright Pincer 2021-Present |
|
|
|
|
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root. |
3
|
|
|
from __future__ import annotations |
4
|
|
|
|
5
|
|
|
from dataclasses import dataclass |
6
|
|
|
from typing import Optional, Union, TYPE_CHECKING |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
if TYPE_CHECKING: |
10
|
|
|
from ...utils.convert_message import MessageConvertable |
11
|
|
|
from .user_message import UserMessage |
12
|
|
|
from ..app import ClientCommandStructure, Interaction |
13
|
|
|
from ..guild.member import GuildMember |
14
|
|
|
from ..user import User |
15
|
|
|
from ...utils.snowflake import Snowflake |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
@dataclass |
19
|
|
|
class MessageContext: |
20
|
|
|
""" |
21
|
|
|
Represents the context of a message interaction. |
22
|
|
|
|
23
|
|
|
:param author: |
24
|
|
|
The user whom invoked the interaction. |
25
|
|
|
|
26
|
|
|
:param command: |
27
|
|
|
The local command object for the command to whom this context |
28
|
|
|
belongs. |
29
|
|
|
|
30
|
|
|
interaction :class:`~pincer.objects.app.interaction.Interaction` |
31
|
|
|
The interaction this command belongs to. |
32
|
|
|
|
33
|
|
|
:param guild_id: |
34
|
|
|
The ID of the guild the interaction was invoked in. |
35
|
|
|
Can be None if it wasn't invoked in a guild. |
36
|
|
|
|
37
|
|
|
:param channel_id: |
38
|
|
|
The ID of the channel the interaction was invoked in. |
39
|
|
|
Can be None if it wasn't invoked in a channel. |
40
|
|
|
""" |
41
|
|
|
author: Union[GuildMember, User] |
|
|
|
|
42
|
|
|
command: ClientCommandStructure |
|
|
|
|
43
|
|
|
interaction: Interaction |
|
|
|
|
44
|
|
|
|
45
|
|
|
guild_id: Optional[Snowflake] = None |
|
|
|
|
46
|
|
|
channel_id: Optional[Snowflake] = None |
47
|
|
|
|
48
|
|
|
async def send(self, message: MessageConvertable): |
|
|
|
|
49
|
|
|
if self.interaction.has_replied: |
50
|
|
|
await self.interaction.followup(message) |
51
|
|
|
else: |
52
|
|
|
await self.interaction.reply(message) |
53
|
|
|
|