Skip to content

Commit d8bfc5a

Browse files
committed
Merge remote-tracking branch 'origin/unstable' into unstable
2 parents 2dc1242 + 871a359 commit d8bfc5a

File tree

10 files changed

+219
-7
lines changed

10 files changed

+219
-7
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
# -- Project information -----------------------------------------------------
2121

22-
project = "discord-interactions"
23-
copyright = "2021, goverfl0w"
22+
project = "interactions.py"
23+
copyright = "2022, goverfl0w"
2424
author = "goverfl0w"
2525
release = __version__
2626
version = ".".join(__version__.split(".", 2)[:2])

docs/ext.base.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. currentmodule:: interactions
2+
3+
Core Model
4+
==========
5+
6+
.. automodule:: interactions.ext.base
7+
:members:
8+
:noindex:

docs/ext.converter.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. currentmodule:: interactions
2+
3+
Converter Model
4+
===============
5+
6+
.. automodule:: interactions.ext.converter
7+
:members:
8+
:noindex:

docs/ext.error.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. currentmodule:: interactions
2+
3+
Error Exceptions
4+
================
5+
6+
.. automodule:: interactions.ext.error
7+
:members:
8+
:noindex:

docs/ext.gettingstarted.rst

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Getting started.
2+
================
3+
4+
Developing a 3rd party.
5+
***********************
6+
7+
Getting started with making a 3rd party library is pretty hard. Most of the time,
8+
you'll find yourself often checking the source code and directly making changes
9+
to the library. We want to make a change to that, and additionally, make it easier
10+
for developers to find creativity in the simplicity of our overengineered product.
11+
12+
.. warning::
13+
14+
If you're not familiar with the source code of the library, you should
15+
probably read the documentation first.
16+
17+
Basing your 3rd party libraries off of our ``unstable`` branch is a bad
18+
practice as this is regarded as our development branch. Breaking changes
19+
may become common, and as a result pose a risk in affecting your 3rd party.
20+
For this reason, we recommend you use the latest PyPI release or ``stable``
21+
branch.
22+
23+
Installing
24+
**********
25+
26+
Installing the external framework is a rather trivial process. You do not need
27+
to run any special installation on the library, as this comes built into our
28+
main core. However, you will need to install the dependencies involved with
29+
the library.
30+
31+
If you do not already have this library installed, you can do with this line
32+
below:
33+
34+
.. code-block:: bash
35+
36+
pip install -U discord-py-interactions
37+
38+
Creating the base.
39+
******************
40+
41+
For every official 3rd party library of interactions.py, we have a "core" for it,
42+
otherwise known as the base. This base is what we use to allow developers to easily
43+
setup their project onto PyPI and build, as well as storing additional information
44+
that bot developers can read off of for their bots.
45+
46+
This code shows a basic example for creating the base of a 3rd party:
47+
48+
.. code-block:: python
49+
50+
from interactions.ext import Base, build, Version
51+
52+
data = {
53+
"name": "interactions.ext.name_here"
54+
"description": "We do cool things!"
55+
"version": Version(version="0.0.1")
56+
"link": "https://example.com"
57+
}
58+
class MyThirdParty(Base):
59+
def __init__(self):
60+
super().__init__(**data)
61+
62+
library = MyThirdParty()
63+
build(library)
64+
65+
This configures the base of the library in a rather simple manner: you give the name
66+
and description of the 3rd party, as well as its own official version and link for
67+
reference. This is all that is required to build the library. The rest of the field
68+
that can be filled in are optional. You can look at the :ref:`Base class <ext.base:Core Model>`
69+
for more information.
70+
71+
Defining a version.
72+
*******************
73+
74+
As you may have noticed in the ``Base`` class, we have a ``Version`` class that helps
75+
define the version of the 3rd party. This is required to be written in our class for numerous reasons:
76+
77+
- To help enforce consistency in the formatting of 3rd party versions.
78+
- To allow for easy version comparison.
79+
- Forced semantic versioning.
80+
81+
This class is our most advanced and complicated one due to the abundant nature in emphasising
82+
a proper versioning system. We have a few options for versioning, and we have a few rules to follow.
83+
84+
1. Major, minor and patch versions **must** be declared as either their respective key-word arguments, or under the ``version`` kwarg.
85+
2. The version should not be author-less. Every library has an author behind a version.
86+
3. The version should not be a pre-release. Pre-releases are not supported by the official PyPI. To release as alpha or beta, use the ``extend_version()`` method.
87+
4. A version cannot contain more than 1 main author. If you have multiple authors, you should label them as co-authors instead.
88+
5. An alphanumeric version can only contain one instance of its own.
89+
90+
With these rules out of the way, let's look at a simple implementation of the ``Version`` class
91+
alongside its brother, ``VersionAuthor`` for adding authors of a version:
92+
93+
.. code-block:: python
94+
95+
from interactions.ext import Version, VersionAuthor
96+
97+
version = Version(
98+
major=1,
99+
minor=2,
100+
patch=3,
101+
# author=VersionAuthor(name="BobDotCom"),
102+
authors=[
103+
VersionAuthor(name="BobDotCom"),
104+
VersionAuthor(name="fl0w", shared=True),
105+
],
106+
) # Version(version="1.2.3")
107+
version.extend_version(beta=1) # Version(version="1.2.3-beta.1")
108+
109+
print(version.author) # <VersionAuthor object at 0x0000000>
110+
print(version.author.name) # BobDotCom
111+
print([author.name for author in version.authors]) # ['BobDotCom', 'fl0w']
112+
print(version.is_alphanumeric) # True
113+
114+
This code example can also show you the ways of retreiving information from a version. As
115+
seen here, this is a highly versatile class. These following are the shown methods and
116+
their purposes:
117+
118+
- The ``version`` attribute is the version string.
119+
- The ``major`` attribute is the major version number, e.g. "x.0.0"
120+
- The ``minor`` attribute is the minor version number, e.g. "0.x.0"
121+
- The ``patch`` attribute is the patch version number, e.g. "0.0.x"
122+
- The ``authors`` property method is a list of authors, regardless of if one is a co-author or not.
123+
- The ``is_alphanumeric`` property method is a boolean that indicates if the version is alphanumeric.
124+
125+
Converting models from one to another.
126+
**************************************
127+
128+
The term "conversion" is a gross exaggeration of what we're actually doing here. The problem
129+
that we've found with bot developers cross-referencing from different libraries is that
130+
their data models are simply different in design and structure. In order to combat against this,
131+
we have decided to create a conversion tool that will allow us to convert between models. This
132+
tool also allows for better comparison that will save the average developer many lines of code
133+
from having to be written. This is a basic example of how we "convert" these models:
134+
135+
.. code-block:: python
136+
137+
from interactions.ext import Converter
138+
139+
ref: dict = {
140+
"hello": "world",
141+
"foo": "bar",
142+
"goodbye": "cruel world",
143+
}
144+
some_random_thing: dict = {
145+
"hi": "everyone",
146+
"foo": "bar",
147+
"spam": "eggs",
148+
}
149+
150+
converted = Converter(ref, some_random_thing)
151+
print(converted.difference) # {'hello': 'world', 'goodbye': 'cruel world'}
152+
print(converted.missing) # {'hi': 'everyone', 'spam': 'eggs'}
153+
print(converted) # <Converter object at 0x0000000>
154+
155+
What about errors?
156+
******************
157+
158+
Don't worry---we've got you covered there. Each of our tools will raise special error exceptions that
159+
you can listen to. Since this is a pretty self-explanitory subject, we recommend :ref:`reading the documentation <ext.error:Error Exceptions>`
160+
on this.

docs/ext.version.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. currentmodule:: interactions
2+
3+
Versioning Models
4+
=================
5+
6+
.. automodule:: interactions.ext.version
7+
:members:
8+
:noindex:

docs/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You will be redirected to a new page. On the left you will see this:
3030

3131
Click on ``Bot``. You again will be redirected to another page, looking like this:
3232

33-
.. image:: _static.build_a_bot.png
33+
.. image:: _static/build_a_bot.png
3434

3535
Click on ``Add Bot`` and then on ``Yes, do it!``.
3636

interactions/api/models/guild.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ async def get_all_channels(self) -> List[Channel]:
11871187
"""
11881188
if not self._client:
11891189
raise AttributeError("HTTPClient not found!")
1190-
res = self._client.get_all_channels(int(self.id))
1190+
res = await self._client.get_all_channels(int(self.id))
11911191
return [Channel(**channel, _client=self._client) for channel in res]
11921192

11931193
async def get_all_roles(self) -> List[Role]:
@@ -1199,7 +1199,7 @@ async def get_all_roles(self) -> List[Role]:
11991199
"""
12001200
if not self._client:
12011201
raise AttributeError("HTTPClient not found!")
1202-
res = self._client.get_all_roles(int(self.id))
1202+
res = await self._client.get_all_roles(int(self.id))
12031203
return [Role(**role, _client=self._client) for role in res]
12041204

12051205
async def get_role(

interactions/ext/converter.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class Converter:
55
"""
66
A class representing the "conversion" or consistent mapping between
77
two objects' attributes.
8+
9+
:ivar object _obj1: The first object to be converted.
10+
:ivar object _obj2: The second object to be converted.
811
"""
912

1013
__slots__ = ("_obj1", "_obj2")
@@ -67,11 +70,21 @@ def ref(self) -> object:
6770
return self._obj1
6871

6972
@property
70-
def diff(self) -> List[dict]:
73+
def difference(self) -> List[dict]:
7174
"""
7275
Gets a list of keys and values that the models don't share in common.
7376
7477
:return: A list of dictionaries
7578
:rtype: List[dict]
7679
"""
7780
return [{key: val} for key, val in self._obj2 if key not in self._obj1]
81+
82+
@property
83+
def missing(self) -> List[dict]:
84+
"""
85+
Gets a list of keys and values missing from the "referenced" or first model.
86+
87+
:return: A list of dictionaries
88+
:rtype: List[dict]
89+
"""
90+
return [{key: val} for key, val in self._obj1 if key not in self._obj2]

interactions/ext/error.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33

44
class ErrorType(str, Enum):
5-
"""An enumerable object representing the type of error responses raised."""
5+
"""
6+
An enumerable object representing the type of error responses raised.
7+
8+
:ivar str INCORRECT_ALPHANUMERIC_VERSION: You cannot have more than one alphanumeric identifier, or identifier with a missing value.
9+
:ivar str MISSING_NUMERIC_VERSION: You cannot have a missing numerical value.
10+
:ivar str TOO_MANY_AUTHORS: A version can only have one main author. The rest of the authors must be co-authors.
11+
:ivar str UNKNOWN_SERVICE: The service specified does not exist.
12+
"""
613

714
INCORRECT_ALPHANUMERIC_VERSION = (
815
"You cannot have more than one alphanumeric identifier, or identifier with a missing value."

0 commit comments

Comments
 (0)