/
monetization.py
153 lines (108 loc) · 5.29 KB
/
monetization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: utf-8 -*-
# cython: language_level=3
# Copyright (c) 2020 Nekokatt
# Copyright (c) 2021-present davfsa
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Models for monetized apps & premium features."""
from __future__ import annotations
__all__: typing.Sequence[str] = ("SKUType", "SKUFlags", "EntitlementType", "EntitlementOwnerType", "SKU", "Entitlement")
import datetime
import typing
import attrs
from hikari import snowflakes
from hikari.internal import enums
@typing.final
class SKUType(int, enums.Enum):
"""Represents the type of an entitlement."""
SUBSCRIPTION = 5
"""Represents a recurring subscription"""
SUBSCRIPTION_GROUP = 6
"""System-generated group for each SUBSCRIPTION SKU created"""
@typing.final
class SKUFlags(enums.Flag):
"""Represents the flags of a SKU."""
NONE = 0
"""No flags set"""
AVAILABLE = 1 << 2
"""SKU is available for purchase"""
GUILD_SUBSCRIPTION = 1 << 7
""" Recurring SKU that can be purchased by a user and applied to a single server.
Grants access to every user in that server.
"""
USER_SUBSCRIPTION = 1 << 8
"""Recurring SKU purchased by a user for themselves.
Grants access to the purchasing user in every server.
"""
@typing.final
class EntitlementType(int, enums.Enum):
"""Represents the type of an entitlement."""
APPLICATION_SUBSCRIPTION = 8
"""Entitlement was purchased as an app subscription"""
@typing.final
class EntitlementOwnerType(int, enums.Enum):
"""Represents the type of an entitlement owner."""
GUILD = 1
"""Entitlement is owned by a guild"""
USER = 2
"""Entitlement is owned by a user"""
@attrs.define(kw_only=True, weakref_slot=False)
class SKU(snowflakes.Unique):
"""Represents an SKU (stock-keeping unit).
SKUs on Discord represent premium offerings that can be
made available to your application's users or guilds.
"""
id: snowflakes.Snowflake = attrs.field(hash=True, repr=True)
"""The ID of the SKU"""
type: typing.Union[SKUType, int] = attrs.field(eq=False, hash=False, repr=True)
"""The type of the SKU"""
application_id: snowflakes.Snowflake = attrs.field(eq=False, hash=False, repr=True)
"""The ID of the parent application"""
name: str = attrs.field(eq=False, hash=False, repr=True)
"""Customer-facing name of the SKU"""
slug: str = attrs.field(eq=False, hash=False, repr=True)
"""Discord-generated URL slug based on the SKU's name"""
flags: SKUFlags = attrs.field(eq=False, hash=False, repr=True)
"""The flags for the SKU"""
@attrs.define(kw_only=True, weakref_slot=False)
class Entitlement(snowflakes.Unique):
"""An entitlement represents that a user or guild has access to a premium offering in your application."""
id: snowflakes.Snowflake = attrs.field(hash=True, repr=True)
"""ID of the entitlement"""
sku_id: snowflakes.Snowflake = attrs.field(eq=False, hash=False, repr=True)
"""ID of the SKU"""
application_id: snowflakes.Snowflake = attrs.field(eq=False, hash=False, repr=True)
"""ID of the parent application"""
user_id: typing.Optional[snowflakes.Snowflake] = attrs.field(eq=False, hash=False, repr=True)
"""ID of the user that is granted access to the entitlement's SKU"""
type: typing.Union[EntitlementType, int] = attrs.field(eq=False, hash=False, repr=True)
"""Type of entitlement"""
is_deleted: bool = attrs.field(eq=False, hash=False, repr=False)
"""Whether the entitlement has been deleted"""
starts_at: typing.Optional[datetime.datetime] = attrs.field(eq=False, hash=False, repr=False)
"""Start date at which the entitlement is valid. Not present when using test entitlements."""
ends_at: typing.Optional[datetime.datetime] = attrs.field(eq=False, hash=False, repr=False)
"""Date at which the entitlement is no longer valid. Not present when using test entitlements."""
guild_id: typing.Optional[snowflakes.Snowflake] = attrs.field(eq=False, hash=False, repr=False)
"""ID of the guild that is granted access to the entitlement's SKU"""
# Only partially documented by Discord
subscription_id: typing.Optional[snowflakes.Snowflake] = attrs.field(eq=False, hash=False, repr=False)
"""The ID of the subscription that this entitlement is associated with.
Not present when using test entitlements.
"""