|
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 ..app.interaction_flags import InteractionFlags |
|
11
|
|
|
from ...utils.convert_message import MessageConvertable |
|
12
|
|
|
from .user_message import UserMessage |
|
13
|
|
|
from ..app import ClientCommandStructure, Interaction |
|
14
|
|
|
from ..guild.member import GuildMember |
|
15
|
|
|
from ..user import User |
|
16
|
|
|
from ...utils.snowflake import Snowflake |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
@dataclass |
|
20
|
|
|
class MessageContext: |
|
21
|
|
|
""" |
|
22
|
|
|
Represents the context of a message interaction. |
|
23
|
|
|
|
|
24
|
|
|
:param author: |
|
25
|
|
|
The user whom invoked the interaction. |
|
26
|
|
|
|
|
27
|
|
|
:param command: |
|
28
|
|
|
The local command object for the command to whom this context |
|
29
|
|
|
belongs. |
|
30
|
|
|
|
|
31
|
|
|
interaction :class:`~pincer.objects.app.interaction.Interaction` |
|
32
|
|
|
The interaction this command belongs to. |
|
33
|
|
|
|
|
34
|
|
|
:param guild_id: |
|
35
|
|
|
The ID of the guild the interaction was invoked in. |
|
36
|
|
|
Can be None if it wasn't invoked in a guild. |
|
37
|
|
|
|
|
38
|
|
|
:param channel_id: |
|
39
|
|
|
The ID of the channel the interaction was invoked in. |
|
40
|
|
|
Can be None if it wasn't invoked in a channel. |
|
41
|
|
|
""" |
|
42
|
|
|
author: Union[GuildMember, User] |
|
43
|
|
|
command: ClientCommandStructure |
|
44
|
|
|
interaction: Interaction |
|
45
|
|
|
|
|
46
|
|
|
guild_id: Optional[Snowflake] = None |
|
47
|
|
|
channel_id: Optional[Snowflake] = None |
|
48
|
|
|
|
|
49
|
|
|
async def ack(self, flags: InteractionFlags): |
|
50
|
|
|
"""|coro| |
|
51
|
|
|
|
|
52
|
|
|
Alias for :func:`~pincer.objects.app.interactions.Interaction.ack`. |
|
53
|
|
|
|
|
54
|
|
|
Parameters |
|
55
|
|
|
---------- |
|
56
|
|
|
flags :class:`~pincer.objects.app.interaction_flags.InteractionFlags` |
|
57
|
|
|
The flags which must be applied to the reply. |
|
58
|
|
|
""" |
|
59
|
|
|
await self.interaction.ack(flags) |
|
60
|
|
|
|
|
61
|
|
|
async def reply(self, message: MessageConvertable): |
|
62
|
|
|
"""|coro| |
|
63
|
|
|
|
|
64
|
|
|
Alias for :func:`~pincer.objects.app.interactions.Interaction.reply`. |
|
65
|
|
|
|
|
66
|
|
|
Parameters |
|
67
|
|
|
---------- |
|
68
|
|
|
message :class:`~pincer.utils.convert_message.MessageConvertable` |
|
69
|
|
|
The response message! |
|
70
|
|
|
""" |
|
71
|
|
|
await self.interaction.reply(message) |
|
72
|
|
|
|
|
73
|
|
|
async def followup(self, message: MessageConvertable) -> UserMessage: |
|
74
|
|
|
"""|coro| |
|
75
|
|
|
|
|
76
|
|
|
Alias for :func:`~pincer.objects.app.interactions.Interaction.followup`. |
|
77
|
|
|
|
|
78
|
|
|
Parameters |
|
79
|
|
|
---------- |
|
80
|
|
|
message :class:`~pincer.utils.convert_message.MessageConvertable` |
|
81
|
|
|
The message to sent. |
|
82
|
|
|
""" |
|
83
|
|
|
return await self.interaction.followup(message) |
|
84
|
|
|
|
|
85
|
|
|
async def send(self, message: MessageConvertable) -> UserMessage: |
|
86
|
|
|
"""|coro| |
|
87
|
|
|
|
|
88
|
|
|
Send a response for an interaction. |
|
89
|
|
|
This object returns the sent object and may be used several |
|
90
|
|
|
times after eachoter. (first one will always be the main |
|
91
|
|
|
interaction response) |
|
92
|
|
|
|
|
93
|
|
|
Uses |
|
94
|
|
|
---- |
|
95
|
|
|
:func:`~pincer.objects.message.context.MessageContext.reply` |
|
96
|
|
|
Method gets called for initial send. |
|
97
|
|
|
:func:`~pincer.objects.app.interactions.Interaction.response` |
|
98
|
|
|
Method gets called for initial send to get response. |
|
99
|
|
|
:func:`~pincer.objects.message.context.MessageContext.followup` |
|
100
|
|
|
Method gets called for second message and onwards. |
|
101
|
|
|
|
|
102
|
|
|
Returns |
|
103
|
|
|
------- |
|
104
|
|
|
:class:`~pincer.objects.message.user_message.UserMessage` |
|
105
|
|
|
The message that was sent. |
|
106
|
|
|
""" |
|
107
|
|
|
if self.interaction.has_replied: |
|
108
|
|
|
return await self.followup(message) |
|
109
|
|
|
|
|
110
|
|
|
await self.reply(message) |
|
111
|
|
|
return await self.interaction.response() |
|
112
|
|
|
|