disunity 0.1.8__tar.gz → 0.1.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {disunity-0.1.8 → disunity-0.1.9}/LICENSE +21 -21
  2. {disunity-0.1.8 → disunity-0.1.9}/PKG-INFO +1 -1
  3. {disunity-0.1.8 → disunity-0.1.9}/README.md +60 -60
  4. {disunity-0.1.8 → disunity-0.1.9}/pyproject.toml +29 -29
  5. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/__init__.py +6 -6
  6. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/cache.py +41 -41
  7. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/embed.py +131 -127
  8. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/errors.py +27 -27
  9. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/identifiers.py +178 -178
  10. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/__init__.py +15 -16
  11. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/components.py +237 -242
  12. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/context.py +127 -147
  13. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/interaction.py +63 -63
  14. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/member.py +22 -22
  15. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/message.py +128 -129
  16. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/models/user.py +24 -24
  17. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/package.py +205 -205
  18. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/server.py +280 -303
  19. {disunity-0.1.8 → disunity-0.1.9}/src/disunity/utils.py +42 -42
  20. {disunity-0.1.8 → disunity-0.1.9}/src/disunity.egg-info/PKG-INFO +1 -1
  21. {disunity-0.1.8 → disunity-0.1.9}/src/disunity.egg-info/SOURCES.txt +0 -1
  22. disunity-0.1.8/src/disunity/models/attachment.py +0 -36
  23. {disunity-0.1.8 → disunity-0.1.9}/setup.cfg +0 -0
  24. {disunity-0.1.8 → disunity-0.1.9}/src/disunity.egg-info/dependency_links.txt +0 -0
  25. {disunity-0.1.8 → disunity-0.1.9}/src/disunity.egg-info/top_level.txt +0 -0
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Duxle
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Duxle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: disunity
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Python framework for Discord interactions using a web server
5
5
  Author: Tadeo Murillo,
6
6
  Project-URL: Homepoge, https://github.com/murillotadeo/disunity
@@ -1,60 +1,60 @@
1
- # disunity
2
-
3
- Python framework for Discord interactions using a web server
4
-
5
- # Installation
6
- `pip install disunity`
7
-
8
- # Introduction to Disunity
9
- ```python
10
- import disunity
11
-
12
- server = disunity.DisunityServer()
13
-
14
- if __name__ == '__main__':
15
- server.run()
16
- ```
17
-
18
- Using packages
19
- ```python
20
- import disunity
21
- import pathlib
22
-
23
- server = disunity.DisunityServer()
24
-
25
- @server.before_serving
26
- def load_packages():
27
- for package in [f"{f.parent}.{f.stem}" for f in pathlib.Path("packages").glob("*.py")]:
28
- server.load_package(package)
29
-
30
- if __name__ == '__main__':
31
- server.run()
32
-
33
- ```
34
-
35
- # Setting up a package
36
-
37
- ```python
38
- from disunity import package, utils
39
-
40
- class FirstPackage(package.Package):
41
- def __init__(self, app):
42
- self.app = app
43
-
44
- @package.Package.command('ping')
45
- async def ping(self, ctx):
46
- return await ctx.callback("Pong!")
47
-
48
- def setup(app):
49
- app.register_package(FirstPackage(app))
50
-
51
- ```
52
-
53
- # Disclaimer
54
-
55
- This will require that you already have hosting service for the server to run on as well as a domain to host the server on. If you have neither of these, an alternative would be to host on Heroku using a web application with Gunicorn.
56
-
57
- # Side note
58
-
59
- The server will receive interactions to the `/interactions` endpoint of your server. It will look like this: `https://example.com/interactions`. Once you run the server, put the url with the added interactions endpoint into the `interactions` URL on your app located in the Discord developer portal.
60
-
1
+ # disunity
2
+
3
+ Python framework for Discord interactions using a web server
4
+
5
+ # Installation
6
+ `pip install disunity`
7
+
8
+ # Introduction to Disunity
9
+ ```python
10
+ import disunity
11
+
12
+ server = disunity.DisunityServer()
13
+
14
+ if __name__ == '__main__':
15
+ server.run()
16
+ ```
17
+
18
+ Using packages
19
+ ```python
20
+ import disunity
21
+ import pathlib
22
+
23
+ server = disunity.DisunityServer()
24
+
25
+ @server.before_serving
26
+ def load_packages():
27
+ for package in [f"{f.parent}.{f.stem}" for f in pathlib.Path("packages").glob("*.py")]:
28
+ server.load_package(package)
29
+
30
+ if __name__ == '__main__':
31
+ server.run()
32
+
33
+ ```
34
+
35
+ # Setting up a package
36
+
37
+ ```python
38
+ from disunity import package, utils
39
+
40
+ class FirstPackage(package.Package):
41
+ def __init__(self, app):
42
+ self.app = app
43
+
44
+ @package.Package.command('ping')
45
+ async def ping(self, ctx):
46
+ return await ctx.callback("Pong!")
47
+
48
+ def setup(app):
49
+ app.register_package(FirstPackage(app))
50
+
51
+ ```
52
+
53
+ # Disclaimer
54
+
55
+ This will require that you already have hosting service for the server to run on as well as a domain to host the server on. If you have neither of these, an alternative would be to host on Heroku using a web application with Gunicorn.
56
+
57
+ # Side note
58
+
59
+ The server will receive interactions to the `/interactions` endpoint of your server. It will look like this: `https://example.com/interactions`. Once you run the server, put the url with the added interactions endpoint into the `interactions` URL on your app located in the Discord developer portal.
60
+
@@ -1,29 +1,29 @@
1
- [build-system]
2
- requires = [
3
- "setuptools>=61.0",
4
- "aiohttp>=3.6.0,<3.8.0",
5
- "PyNaCl>=1.5.0",
6
- "requests>=2.26.0",
7
- "quart>=0.17.0"
8
- ]
9
- build-backend = "setuptools.build_meta"
10
-
11
- [project]
12
- name = "disunity"
13
- version = "0.1.8"
14
- authors = [
15
- {name="Tadeo Murillo"},
16
- {name=""}
17
- ]
18
- description = "Python framework for Discord interactions using a web server"
19
- readme = "README.md"
20
- requires-python = ">=3.10.0"
21
- classifiers = [
22
- "Programming Language :: Python :: 3",
23
- "License :: OSI Approved :: MIT License",
24
- "Operating System :: OS Independent"
25
- ]
26
-
27
- [project.urls]
28
- "Homepoge" = "https://github.com/murillotadeo/disunity"
29
- "Bug Tracker" = "https://github.com/murillotadeo/disunity/issues"
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=61.0",
4
+ "aiohttp>=3.6.0,<3.8.0",
5
+ "PyNaCl>=1.5.0",
6
+ "requests>=2.26.0",
7
+ "quart>=0.17.0"
8
+ ]
9
+ build-backend = "setuptools.build_meta"
10
+
11
+ [project]
12
+ name = "disunity"
13
+ version = "0.1.9"
14
+ authors = [
15
+ {name="Tadeo Murillo"},
16
+ {name=""}
17
+ ]
18
+ description = "Python framework for Discord interactions using a web server"
19
+ readme = "README.md"
20
+ requires-python = ">=3.10.0"
21
+ classifiers = [
22
+ "Programming Language :: Python :: 3",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Operating System :: OS Independent"
25
+ ]
26
+
27
+ [project.urls]
28
+ "Homepoge" = "https://github.com/murillotadeo/disunity"
29
+ "Bug Tracker" = "https://github.com/murillotadeo/disunity/issues"
@@ -1,6 +1,6 @@
1
- from . import utils
2
- from .embed import Embed
3
- from .identifiers import SubOption
4
- from .models import Message, Attachment
5
- from .package import Package
6
- from .server import DisunityServer
1
+ from . import utils
2
+ from .embed import Embed
3
+ from .identifiers import SubOption
4
+ from .models import Message
5
+ from .package import Package
6
+ from .server import DisunityServer
@@ -1,41 +1,41 @@
1
- from .identifiers import (
2
- Autocomplete,
3
- CacheableSubCommand,
4
- Command,
5
- Component,
6
- TopLevelSubCommand,
7
- )
8
-
9
-
10
- class ApplicationCache:
11
- def __init__(self):
12
- self.commands = dict()
13
- self.components = dict()
14
- self.autocompletes = dict()
15
-
16
- def add_item(
17
- self, incoming: TopLevelSubCommand | Command | Component | Autocomplete
18
- ):
19
- if isinstance(incoming, TopLevelSubCommand):
20
- if "2" not in self.commands:
21
- self.commands["2"] = {} # Sub commands will always by type 2
22
-
23
- if incoming.name in self.commands["2"]:
24
- self.commands["2"][str(incoming.name)].add(incoming)
25
- else:
26
- cacheable = CacheableSubCommand(str(incoming.name)).add(incoming)
27
- self.commands["2"][str(incoming.name)] = cacheable
28
-
29
- elif isinstance(incoming, Command):
30
- if str(incoming.command_type) not in self.commands:
31
- self.commands[str(incoming.command_type)] = {}
32
- self.commands[str(incoming.command_type)][incoming.name] = incoming
33
-
34
- elif isinstance(incoming, Component):
35
- self.components[str(incoming.name)] = incoming
36
-
37
- elif isinstance(incoming, Autocomplete):
38
- self.autocompletes[str(incoming.command_name)] = incoming
39
-
40
- else:
41
- raise TypeError
1
+ from .identifiers import (
2
+ Autocomplete,
3
+ CacheableSubCommand,
4
+ Command,
5
+ Component,
6
+ TopLevelSubCommand,
7
+ )
8
+
9
+
10
+ class ApplicationCache:
11
+ def __init__(self):
12
+ self.commands = dict()
13
+ self.components = dict()
14
+ self.autocompletes = dict()
15
+
16
+ def add_item(
17
+ self, incoming: TopLevelSubCommand | Command | Component | Autocomplete
18
+ ):
19
+ if isinstance(incoming, TopLevelSubCommand):
20
+ if "2" not in self.commands:
21
+ self.commands["2"] = {} # Sub commands will always by type 2
22
+
23
+ if incoming.name in self.commands["2"]:
24
+ self.commands["2"][str(incoming.name)].add(incoming)
25
+ else:
26
+ cacheable = CacheableSubCommand(str(incoming.name)).add(incoming)
27
+ self.commands["2"][str(incoming.name)] = cacheable
28
+
29
+ elif isinstance(incoming, Command):
30
+ if str(incoming.command_type) not in self.commands:
31
+ self.commands[str(incoming.command_type)] = {}
32
+ self.commands[str(incoming.command_type)][incoming.name] = incoming
33
+
34
+ elif isinstance(incoming, Component):
35
+ self.components[str(incoming.name)] = incoming
36
+
37
+ elif isinstance(incoming, Autocomplete):
38
+ self.autocompletes[str(incoming.command_name)] = incoming
39
+
40
+ else:
41
+ raise TypeError
@@ -1,127 +1,131 @@
1
- from __future__ import annotations
2
-
3
-
4
- class EmptyEmbedError(Exception):
5
- def __init__(self, message):
6
- super().__init__(message)
7
-
8
-
9
- class Embed:
10
- def __init__(
11
- self,
12
- title: None | str = None,
13
- description: None | str = None,
14
- color: None | int = None,
15
- ):
16
- self.__json: dict = {"type": "rich", "color": color}
17
-
18
- self._title: None | str = title
19
- self._description: None | str = description
20
- self._color: None | int = color
21
-
22
- self.title = title
23
- self.description = description
24
-
25
- @property
26
- def description(self) -> None | str:
27
- return self._description
28
-
29
- @description.setter
30
- def description(self, value: None | str) -> None:
31
- if value is not None:
32
- value = str(value)
33
- self._description = value
34
- self.__json["description"] = value
35
-
36
- @property
37
- def color(self) -> None | int:
38
- return self._color
39
-
40
- @color.setter
41
- def color(self, value: None | int) -> None:
42
- self._color = value
43
- self.__json["color"] = value
44
-
45
- @property
46
- def title(self) -> None | str:
47
- return self._title
48
-
49
- @title.setter
50
- def title(self, value: None | str) -> None:
51
- if value is not None:
52
- value = str(value)
53
- self._title = value
54
- self.__json["title"] = value
55
-
56
- @property
57
- def fields(self) -> None | list[dict]:
58
- return self.__json.get("fields", None)
59
-
60
- def add_field(self, name: str, value: str, inline: bool = False) -> Embed:
61
- if not bool(name) or not bool(value):
62
- raise EmptyEmbedError("Embed field cannot contain an empty value")
63
-
64
- if "fields" not in self.__json:
65
- self.__json["fields"] = []
66
-
67
- self.__json["fields"].append({"name": name, "value": value, "inline": inline})
68
- return self
69
-
70
- @property
71
- def footer(self) -> None | dict:
72
- return self.__json.get("footer", None)
73
-
74
- def set_footer(self, text: None | str = None, icon_url: None | str = None) -> Embed:
75
- if "footer" not in self.__json:
76
- self.__json["footer"] = {}
77
-
78
- if text is not None:
79
- self.__json["footer"]["text"] = str(text)
80
-
81
- if icon_url is not None:
82
- self.__json["footer"]["icon_url"] = str(icon_url)
83
-
84
- return self
85
-
86
- @property
87
- def image(self) -> None | dict:
88
- return self.__json.get("url", None)
89
-
90
- def set_image(self, image_url: str) -> Embed:
91
- if "image" not in self.__json:
92
- self.__json["image"] = {}
93
-
94
- self.__json["image"]["url"] = str(image_url)
95
- return self
96
-
97
- @property
98
- def thumbnail(self) -> None | dict:
99
- return self.__json.get("thumbnail", None)
100
-
101
- def set_thumbnail(self, thumbnail_url: str) -> Embed:
102
- if "thumbnail" not in self.__json:
103
- self.__json["thumbnail"] = {}
104
-
105
- self.__json["thumbnail"]["url"] = str(thumbnail_url)
106
- return self
107
-
108
- @property
109
- def author(self) -> None | dict:
110
- return self.__json.get("author", None)
111
-
112
- def set_author(
113
- self, name: str, url: None | str = None, icon_url: None | str = None
114
- ) -> Embed:
115
- if "author" not in self.__json:
116
- self.__json["author"] = {"name": str(name)}
117
-
118
- if url is not None:
119
- self.__json["author"]["url"] = str(url)
120
-
121
- if icon_url is not None:
122
- self.__json["author"]["icon_url"] = str(icon_url)
123
-
124
- return self
125
-
126
- def as_dict(self) -> dict:
127
- return self.__json
1
+ from __future__ import annotations
2
+
3
+
4
+ class EmptyEmbedError(Exception):
5
+ def __init__(self, message):
6
+ super().__init__(message)
7
+
8
+
9
+ class Embed:
10
+ def __init__(
11
+ self,
12
+ title: None | str = None,
13
+ description: None | str = None,
14
+ color: None | int = None,
15
+ ):
16
+ self.__json: dict = {"type": "rich", "color": color}
17
+
18
+ self._title: None | str = title
19
+ self._description: None | str = description
20
+ self._color: None | int = color
21
+
22
+ if self._title is not None:
23
+ self._title = str(self.title)
24
+ self.__json["title"] = self.title
25
+
26
+ if self._description is not None:
27
+ self.__json["description"] = str(self._description)
28
+
29
+ @property
30
+ def description(self) -> None | str:
31
+ return self._description
32
+
33
+ @description.setter
34
+ def description(self, value: None | str) -> None:
35
+ if value is not None:
36
+ value = str(value)
37
+ self._description = value
38
+ self.__json["description"] = value
39
+
40
+ @property
41
+ def color(self) -> None | int:
42
+ return self._color
43
+
44
+ @color.setter
45
+ def color(self, value: None | int) -> None:
46
+ self._color = value
47
+ self.__json["color"] = value
48
+
49
+ @property
50
+ def title(self) -> None | str:
51
+ return self._title
52
+
53
+ @title.setter
54
+ def title(self, value: None | str) -> None:
55
+ if value is not None:
56
+ value = str(value)
57
+ self._title = value
58
+ self.__json["title"] = value
59
+
60
+ @property
61
+ def fields(self) -> None | list[dict]:
62
+ return self.__json.get("fields", None)
63
+
64
+ def add_field(self, name: str, value: str, inline: bool = False) -> Embed:
65
+ if not bool(name) or not bool(value):
66
+ raise EmptyEmbedError("Embed field cannot contain an empty value")
67
+
68
+ if "fields" not in self.__json:
69
+ self.__json["fields"] = []
70
+
71
+ self.__json["fields"].append({"name": name, "value": value, "inline": inline})
72
+ return self
73
+
74
+ @property
75
+ def footer(self) -> None | dict:
76
+ return self.__json.get("footer", None)
77
+
78
+ def set_footer(self, text: None | str = None, icon_url: None | str = None) -> Embed:
79
+ if "footer" not in self.__json:
80
+ self.__json["footer"] = {}
81
+
82
+ if text is not None:
83
+ self.__json["footer"]["text"] = str(text)
84
+
85
+ if icon_url is not None:
86
+ self.__json["footer"]["icon_url"] = str(icon_url)
87
+
88
+ return self
89
+
90
+ @property
91
+ def image(self) -> None | dict:
92
+ return self.__json.get("url", None)
93
+
94
+ def set_image(self, image_url: str) -> Embed:
95
+ if "image" not in self.__json:
96
+ self.__json["image"] = {}
97
+
98
+ self.__json["image"]["url"] = str(image_url)
99
+ return self
100
+
101
+ @property
102
+ def thumbnail(self) -> None | dict:
103
+ return self.__json.get("thumbnail", None)
104
+
105
+ def set_thumbnail(self, thumbnail_url: str) -> Embed:
106
+ if "thumbnail" not in self.__json:
107
+ self.__json["thumbnail"] = {}
108
+
109
+ self.__json["thumbnail"]["url"] = str(thumbnail_url)
110
+ return self
111
+
112
+ @property
113
+ def author(self) -> None | dict:
114
+ return self.__json.get("author", None)
115
+
116
+ def set_author(
117
+ self, name: str, url: None | str = None, icon_url: None | str = None
118
+ ) -> Embed:
119
+ if "author" not in self.__json:
120
+ self.__json["author"] = {"name": str(name)}
121
+
122
+ if url is not None:
123
+ self.__json["author"]["url"] = str(url)
124
+
125
+ if icon_url is not None:
126
+ self.__json["author"]["icon_url"] = str(icon_url)
127
+
128
+ return self
129
+
130
+ def as_dict(self) -> dict:
131
+ return self.__json
@@ -1,27 +1,27 @@
1
- class InvalidMethodUse(Exception):
2
- def __init__(self, reason):
3
- super().__init__(reason)
4
-
5
-
6
- class CommandNotFound(Exception):
7
- def __init__(self, command):
8
- super().__init__(f"Command with name {command} could not be found")
9
-
10
-
11
- class ComponentNotFound(Exception):
12
- def __init__(self, component):
13
- super().__init__(f"No listener for components with name {component} exists")
14
-
15
-
16
- class AutocompleteNotFound(Exception):
17
- def __init__(self, command_name):
18
- super().__init__(
19
- f"No listener for autocomplete for command {command_name} exists"
20
- )
21
-
22
-
23
- class HTTPRequestError(Exception):
24
- def __init__(self, status_code, error_message):
25
- super().__init__(
26
- f"HTTP request returned with status {status_code}: {error_message}"
27
- )
1
+ class InvalidMethodUse(Exception):
2
+ def __init__(self, reason):
3
+ super().__init__(reason)
4
+
5
+
6
+ class CommandNotFound(Exception):
7
+ def __init__(self, command):
8
+ super().__init__(f"Command with name {command} could not be found")
9
+
10
+
11
+ class ComponentNotFound(Exception):
12
+ def __init__(self, component):
13
+ super().__init__(f"No listener for components with name {component} exists")
14
+
15
+
16
+ class AutocompleteNotFound(Exception):
17
+ def __init__(self, command_name):
18
+ super().__init__(
19
+ f"No listener for autocomplete for command {command_name} exists"
20
+ )
21
+
22
+
23
+ class HTTPRequestError(Exception):
24
+ def __init__(self, status_code, error_message):
25
+ super().__init__(
26
+ f"HTTP request returned with status {status_code}: {error_message}"
27
+ )