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 typing import Dict |
27
|
|
|
|
28
|
|
|
from ..objects.application_command import AppCommandInteractionDataOption |
29
|
|
|
from ..objects.channel import Channel |
30
|
|
|
from ..objects.guild_member import GuildMember |
31
|
|
|
from ..objects.interaction_base import InteractionType |
32
|
|
|
from ..objects.message import Message |
33
|
|
|
from ..objects.role import Role |
34
|
|
|
from ..objects.select_menu import SelectOption |
35
|
|
|
from ..objects.user import User |
36
|
|
|
from ..utils import APIObject, APINullable, MISSING, Snowflake, convert |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
@dataclass |
40
|
|
|
class ResolvedData(APIObject): |
41
|
|
|
""" |
42
|
|
|
Represents a Discord Resolved Data structure |
43
|
|
|
|
44
|
|
|
:param users: |
45
|
|
|
Map of Snowflakes to user objects |
46
|
|
|
|
47
|
|
|
:param members: |
48
|
|
|
Map of Snowflakes to partial member objects |
49
|
|
|
|
50
|
|
|
:param roles: |
51
|
|
|
Map of Snowflakes to role objects |
52
|
|
|
|
53
|
|
|
:param channels: |
54
|
|
|
Map of Snowflakes to partial channel objects |
55
|
|
|
|
56
|
|
|
:param messages: |
57
|
|
|
Map of Snowflakes to partial message objects |
58
|
|
|
""" |
59
|
|
|
users: APINullable[Dict[Snowflake, User]] = MISSING |
60
|
|
|
members: APINullable[Dict[Snowflake, GuildMember]] = MISSING |
61
|
|
|
roles: APINullable[Dict[Snowflake, Role]] = MISSING |
62
|
|
|
channels: APINullable[Dict[Snowflake, Channel]] = MISSING |
63
|
|
|
messages: APINullable[Dict[Snowflake, Message]] = MISSING |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
@dataclass |
|
|
|
|
67
|
|
|
class InteractionData(APIObject): |
68
|
|
|
""" |
69
|
|
|
Represents a Discord Interaction Data structure |
70
|
|
|
|
71
|
|
|
:param id: |
72
|
|
|
the `ID` of the invoked command |
73
|
|
|
|
74
|
|
|
:param name: |
75
|
|
|
the `name` of the invoked command |
76
|
|
|
|
77
|
|
|
:param type: |
78
|
|
|
the `type` of the invoked command |
79
|
|
|
|
80
|
|
|
:param resolved: |
81
|
|
|
converted users + roles + channels |
82
|
|
|
|
83
|
|
|
:param options: |
84
|
|
|
the params + values from the user |
85
|
|
|
|
86
|
|
|
:param custom_id: |
87
|
|
|
the `custom_id` of the component |
88
|
|
|
|
89
|
|
|
:param component_type: |
90
|
|
|
the type of the component |
91
|
|
|
|
92
|
|
|
:param values: |
93
|
|
|
the values the user selected |
94
|
|
|
|
95
|
|
|
:param target_id: |
96
|
|
|
id of the user or message targeted by a user or message command |
97
|
|
|
""" |
98
|
|
|
id: Snowflake |
99
|
|
|
name: str |
100
|
|
|
type: int |
101
|
|
|
|
102
|
|
|
resolved: APINullable[ResolvedData] = MISSING |
103
|
|
|
options: APINullable[AppCommandInteractionDataOption] = MISSING |
104
|
|
|
custom_id: APINullable[str] = MISSING |
105
|
|
|
component_type: APINullable[int] = MISSING |
106
|
|
|
values: APINullable[SelectOption] = MISSING |
107
|
|
|
target_id: APINullable[Snowflake] = MISSING |
108
|
|
|
|
109
|
|
|
def __post_init__(self): |
110
|
|
|
self.id = convert(self.id, Snowflake.from_string) |
111
|
|
|
self.resolved = convert( |
112
|
|
|
self.resolved, |
113
|
|
|
ResolvedData.from_dict, |
114
|
|
|
ResolvedData |
115
|
|
|
) |
116
|
|
|
self.options = convert( |
117
|
|
|
self.options, |
118
|
|
|
AppCommandInteractionDataOption.from_dict, |
119
|
|
|
AppCommandInteractionDataOption |
120
|
|
|
) |
121
|
|
|
self.values = convert(self.values, SelectOption.from_dict, SelectOption) |
122
|
|
|
self.target_id = convert(self.target_id, Snowflake.from_string) |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
@dataclass |
|
|
|
|
126
|
|
|
class Interaction(APIObject): |
127
|
|
|
""" |
128
|
|
|
Represents a Discord Interaction object |
129
|
|
|
|
130
|
|
|
:param id: |
131
|
|
|
id of the interaction |
132
|
|
|
|
133
|
|
|
:param application_id: |
134
|
|
|
id of the application this interaction is for |
135
|
|
|
|
136
|
|
|
:param type: |
137
|
|
|
the type of interaction |
138
|
|
|
|
139
|
|
|
:param data: |
140
|
|
|
the command data payload |
141
|
|
|
|
142
|
|
|
:param guild_id: |
143
|
|
|
the guild it was sent from |
144
|
|
|
|
145
|
|
|
:param channel_id: |
146
|
|
|
the channel it was sent from |
147
|
|
|
|
148
|
|
|
:param member: |
149
|
|
|
guild member data for the invoking user, including permissions |
150
|
|
|
|
151
|
|
|
:param user: |
152
|
|
|
user object for the invoking user, if invoked in a DM |
153
|
|
|
|
154
|
|
|
:param token: |
155
|
|
|
a continuation token for responding to the interaction |
156
|
|
|
|
157
|
|
|
:param version: |
158
|
|
|
read-only property, always `1` |
159
|
|
|
|
160
|
|
|
:param message: |
161
|
|
|
for components, the message they were attached to |
162
|
|
|
""" |
163
|
|
|
id: Snowflake |
164
|
|
|
application_id: Snowflake |
165
|
|
|
type: InteractionType |
166
|
|
|
token: str |
167
|
|
|
|
168
|
|
|
version: int = 1 |
169
|
|
|
data: APINullable[InteractionData] = MISSING |
170
|
|
|
guild_id: APINullable[Snowflake] = MISSING |
171
|
|
|
channel_id: APINullable[Snowflake] = MISSING |
172
|
|
|
member: APINullable[GuildMember] = MISSING |
173
|
|
|
user: APINullable[User] = MISSING |
174
|
|
|
message: APINullable[Message] = MISSING |
175
|
|
|
|
176
|
|
|
def __post_init__(self): |
177
|
|
|
self.id = convert(self.id, Snowflake.from_string) |
178
|
|
|
self.application_id = convert(self.application_id, |
179
|
|
|
Snowflake.from_string) |
180
|
|
|
self.type = convert(self.type, InteractionType) |
181
|
|
|
self.data = convert( |
182
|
|
|
self.data, |
183
|
|
|
InteractionData.from_dict, |
184
|
|
|
InteractionData |
185
|
|
|
) |
186
|
|
|
self.guild_id = convert(self.guild_id, Snowflake.from_string) |
187
|
|
|
self.channel_id = convert(self.channel_id, Snowflake.from_string) |
188
|
|
|
self.member = convert(self.member, GuildMember.from_dict, GuildMember) |
189
|
|
|
self.user = convert(self.user, User.from_dict, User) |
190
|
|
|
self.message = convert(self.message, Message.from_dict, Message) |
191
|
|
|
|