1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
# MIT License |
3
|
|
|
# |
4
|
|
|
# Copyright (c) 2021 Pincer |
5
|
|
|
# |
6
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining |
7
|
|
|
# a copy of this software and associated documentation files |
8
|
|
|
# (the "Software"), to deal in the Software without restriction, |
9
|
|
|
# including without limitation the rights to use, copy, modify, merge, |
10
|
|
|
# publish, distribute, sublicense, and/or sell copies of the Software, |
11
|
|
|
# and to permit persons to whom the Software is furnished to do so, |
12
|
|
|
# subject to the following conditions: |
13
|
|
|
# |
14
|
|
|
# The above copyright notice and this permission notice shall be |
15
|
|
|
# included in all copies or substantial portions of the Software. |
16
|
|
|
# |
17
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
20
|
|
|
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
21
|
|
|
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
22
|
|
|
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
23
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24
|
|
|
|
25
|
|
|
from dataclasses import dataclass |
26
|
|
|
from enum import Enum |
27
|
|
|
from typing import Dict |
28
|
|
|
|
29
|
|
|
from pincer.objects.application_command import \ |
30
|
|
|
ApplicationCommandInteractionDataOption |
31
|
|
|
from pincer.objects.channel import Channel |
32
|
|
|
from pincer.objects.guild_member import GuildMember |
33
|
|
|
from pincer.objects.message import Message |
34
|
|
|
from pincer.objects.role import Role |
35
|
|
|
from pincer.objects.select_menu import SelectOption |
36
|
|
|
from pincer.objects.user import User |
37
|
|
|
from pincer.utils.api_object import APIObject |
38
|
|
|
from pincer.utils.constants import MISSING, APINullable |
39
|
|
|
from pincer.utils.snowflake import Snowflake |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class InteractionType(Enum): |
43
|
|
|
""" |
44
|
|
|
Represents the different types of interactions the client |
45
|
|
|
can have with a member. |
46
|
|
|
|
47
|
|
|
:param CHAT_INPUT: |
48
|
|
|
Slash commands; a text-based command that shows up when a user types / |
49
|
|
|
|
50
|
|
|
:param USER: |
51
|
|
|
A UI-based command that shows up when you right click or tap on a user |
52
|
|
|
|
53
|
|
|
:param MESSAGE: |
54
|
|
|
A UI-based command that shows up when you right click or tap on a message |
55
|
|
|
""" |
56
|
|
|
PING = 1 |
57
|
|
|
APPLICATION_COMMAND = 2 |
58
|
|
|
MESSAGE_COMPONENT = 2 |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
@dataclass |
62
|
|
|
class ResolvedData(APIObject): |
63
|
|
|
""" |
64
|
|
|
Represents a Discord Resolved Data structure |
65
|
|
|
|
66
|
|
|
:param users: |
67
|
|
|
Map of Snowflakes to user objects |
68
|
|
|
|
69
|
|
|
:param members: |
70
|
|
|
Map of Snowflakes to partial member objects |
71
|
|
|
|
72
|
|
|
:param roles: |
73
|
|
|
Map of Snowflakes to role objects |
74
|
|
|
|
75
|
|
|
:param channels: |
76
|
|
|
Map of Snowflakes to partial channel objects |
77
|
|
|
|
78
|
|
|
:param messages: |
79
|
|
|
Map of Snowflakes to partial message objects |
80
|
|
|
""" |
81
|
|
|
users: APINullable[Dict[Snowflake, User]] = MISSING |
82
|
|
|
members: APINullable[Dict[Snowflake, GuildMember]] = MISSING |
83
|
|
|
roles: APINullable[Dict[Snowflake, Role]] = MISSING |
84
|
|
|
channels: APINullable[Dict[Snowflake, Channel]] = MISSING |
85
|
|
|
messages: APINullable[Dict[Snowflake, Message]] = MISSING |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
@dataclass |
89
|
|
|
class InteractionData(APIObject): |
90
|
|
|
""" |
91
|
|
|
Represents a Discord Interaction Data structure |
92
|
|
|
|
93
|
|
|
:param id: |
94
|
|
|
the `ID` of the invoked command |
95
|
|
|
|
96
|
|
|
:param name: |
97
|
|
|
the `name` of the invoked command |
98
|
|
|
|
99
|
|
|
:param type: |
100
|
|
|
the `type` of the invoked command |
101
|
|
|
|
102
|
|
|
:param resolved: |
103
|
|
|
converted users + roles + channels |
104
|
|
|
|
105
|
|
|
:param options: |
106
|
|
|
the params + values from the user |
107
|
|
|
|
108
|
|
|
:param custom_id: |
109
|
|
|
the `custom_id` of the component |
110
|
|
|
|
111
|
|
|
:param component_type: |
112
|
|
|
the type of the component |
113
|
|
|
|
114
|
|
|
:param values: |
115
|
|
|
the values the user selected |
116
|
|
|
|
117
|
|
|
:param target_id: |
118
|
|
|
id of the user or message targeted by a user or message command |
119
|
|
|
""" |
120
|
|
|
id: Snowflake |
121
|
|
|
name: str |
122
|
|
|
type: int |
123
|
|
|
|
124
|
|
|
resolved: APINullable[ResolvedData] = MISSING |
125
|
|
|
options: APINullable[ApplicationCommandInteractionDataOption] = MISSING |
126
|
|
|
custom_id: APINullable[str] = MISSING |
127
|
|
|
component_type: APINullable[int] = MISSING |
128
|
|
|
values = APINullable[SelectOption] = MISSING |
129
|
|
|
target_id = APINullable[Snowflake] = MISSING |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
@dataclass |
133
|
|
|
class MessageInteraction(APIObject): |
134
|
|
|
""" |
135
|
|
|
Represents a Discord Message Interaction object |
136
|
|
|
|
137
|
|
|
This is sent on the message object when the message |
138
|
|
|
is a response to an Interaction without an existing message. |
139
|
|
|
|
140
|
|
|
:param id: id of the interaction |
141
|
|
|
:param type: the type of interaction |
142
|
|
|
:param name: the name of the application command |
143
|
|
|
:param user: the user who invoked the interaction |
144
|
|
|
""" |
145
|
|
|
id: Snowflake |
146
|
|
|
type: InteractionType |
147
|
|
|
name: str |
148
|
|
|
user: User |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
@dataclass |
152
|
|
|
class Interaction(APIObject): |
153
|
|
|
""" |
154
|
|
|
Represents a Discord Interaction object |
155
|
|
|
|
156
|
|
|
:param id: |
157
|
|
|
id of the interaction |
158
|
|
|
|
159
|
|
|
:param application_id: |
160
|
|
|
id of the application this interaction is for |
161
|
|
|
|
162
|
|
|
:param type: |
163
|
|
|
the type of interaction |
164
|
|
|
|
165
|
|
|
:param data: |
166
|
|
|
the command data payload |
167
|
|
|
|
168
|
|
|
:param guild_id: |
169
|
|
|
the guild it was sent from |
170
|
|
|
|
171
|
|
|
:param channel_id: |
172
|
|
|
the channel it was sent from |
173
|
|
|
|
174
|
|
|
:param member: |
175
|
|
|
guild member data for the invoking user, including permissions |
176
|
|
|
|
177
|
|
|
:param user: |
178
|
|
|
user object for the invoking user, if invoked in a DM |
179
|
|
|
|
180
|
|
|
:param token: |
181
|
|
|
a continuation token for responding to the interaction |
182
|
|
|
|
183
|
|
|
:param version: |
184
|
|
|
read-only property, always `1` |
185
|
|
|
|
186
|
|
|
:param message: |
187
|
|
|
for components, the message they were attached to |
188
|
|
|
""" |
189
|
|
|
id: Snowflake |
190
|
|
|
application_id: Snowflake |
191
|
|
|
type: InteractionType |
192
|
|
|
token: str |
193
|
|
|
|
194
|
|
|
version: int = 1 |
195
|
|
|
data: APINullable[InteractionData] = MISSING |
196
|
|
|
guild_id: APINullable[Snowflake] = MISSING |
197
|
|
|
channel_id: APINullable[Snowflake] = MISSING |
198
|
|
|
member: APINullable[GuildMember] = MISSING |
199
|
|
|
user: APINullable[User] = MISSING |
200
|
|
|
message: APINullable[Message] = MISSING |
201
|
|
|
|