DiscordPYComponents 0.2.11__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.
- discordpycomponents-0.2.11/DiscordPYComponents.egg-info/PKG-INFO +6 -0
- discordpycomponents-0.2.11/DiscordPYComponents.egg-info/SOURCES.txt +13 -0
- discordpycomponents-0.2.11/DiscordPYComponents.egg-info/dependency_links.txt +1 -0
- discordpycomponents-0.2.11/DiscordPYComponents.egg-info/requires.txt +1 -0
- discordpycomponents-0.2.11/DiscordPYComponents.egg-info/top_level.txt +1 -0
- discordpycomponents-0.2.11/PKG-INFO +6 -0
- discordpycomponents-0.2.11/py_components/__init__.py +4 -0
- discordpycomponents-0.2.11/py_components/components.py +26 -0
- discordpycomponents-0.2.11/py_components/enums.py +5 -0
- discordpycomponents-0.2.11/py_components/http.py +15 -0
- discordpycomponents-0.2.11/py_components/registry.py +10 -0
- discordpycomponents-0.2.11/py_components/ui.py +28 -0
- discordpycomponents-0.2.11/py_components/view.py +33 -0
- discordpycomponents-0.2.11/pyproject.toml +10 -0
- discordpycomponents-0.2.11/setup.cfg +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
DiscordPYComponents.egg-info/PKG-INFO
|
|
3
|
+
DiscordPYComponents.egg-info/SOURCES.txt
|
|
4
|
+
DiscordPYComponents.egg-info/dependency_links.txt
|
|
5
|
+
DiscordPYComponents.egg-info/requires.txt
|
|
6
|
+
DiscordPYComponents.egg-info/top_level.txt
|
|
7
|
+
py_components/__init__.py
|
|
8
|
+
py_components/components.py
|
|
9
|
+
py_components/enums.py
|
|
10
|
+
py_components/http.py
|
|
11
|
+
py_components/registry.py
|
|
12
|
+
py_components/ui.py
|
|
13
|
+
py_components/view.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiohttp
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
py_components
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .enums import ButtonStyle
|
|
2
|
+
|
|
3
|
+
class Text:
|
|
4
|
+
def __init__(self, content):
|
|
5
|
+
self.content = content
|
|
6
|
+
|
|
7
|
+
def to_dict(self):
|
|
8
|
+
return {
|
|
9
|
+
"type": 10,
|
|
10
|
+
"content": self.content
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Button:
|
|
15
|
+
def __init__(self, label, custom_id, style=ButtonStyle.primary):
|
|
16
|
+
self.label = label
|
|
17
|
+
self.custom_id = custom_id
|
|
18
|
+
self.style = style
|
|
19
|
+
|
|
20
|
+
def to_dict(self):
|
|
21
|
+
return {
|
|
22
|
+
"type": 2,
|
|
23
|
+
"label": self.label,
|
|
24
|
+
"custom_id": self.custom_id,
|
|
25
|
+
"style": self.style
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
|
|
3
|
+
API = "https://discord.com/api/v10"
|
|
4
|
+
|
|
5
|
+
async def send_message(channel_id, token, payload):
|
|
6
|
+
url = f"{API}/channels/{channel_id}/messages"
|
|
7
|
+
|
|
8
|
+
headers = {
|
|
9
|
+
"Authorization": f"Bot {token}",
|
|
10
|
+
"Content-Type": "application/json"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async with aiohttp.ClientSession() as session:
|
|
14
|
+
async with session.post(url, json=payload, headers=headers) as resp:
|
|
15
|
+
return await resp.text()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from .http import send_message
|
|
2
|
+
|
|
3
|
+
class UI:
|
|
4
|
+
def __init__(self, *components):
|
|
5
|
+
self.components = list(components)
|
|
6
|
+
|
|
7
|
+
def add(self, component):
|
|
8
|
+
self.components.append(component)
|
|
9
|
+
|
|
10
|
+
def to_payload(self):
|
|
11
|
+
return {
|
|
12
|
+
"flags": 1 << 15,
|
|
13
|
+
"components": [
|
|
14
|
+
{
|
|
15
|
+
"type": 17,
|
|
16
|
+
"components": [c.to_dict() for c in self.components]
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async def send(self, ctx):
|
|
22
|
+
token = ctx.bot.http.token
|
|
23
|
+
return await send_message(ctx.channel.id, token, self.to_payload())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async def send_ui(ctx, ui):
|
|
27
|
+
token = ctx.bot.http.token
|
|
28
|
+
return await send_message(ctx.channel.id, token, ui.to_payload())
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .components import Button
|
|
2
|
+
|
|
3
|
+
def button(label):
|
|
4
|
+
def wrapper(func):
|
|
5
|
+
func._button_label = label
|
|
6
|
+
return func
|
|
7
|
+
return wrapper
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class View:
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self.components = []
|
|
13
|
+
self.registry = {}
|
|
14
|
+
|
|
15
|
+
def add_button(self, label, custom_id, callback=None):
|
|
16
|
+
btn = Button(label, custom_id)
|
|
17
|
+
self.components.append(btn)
|
|
18
|
+
|
|
19
|
+
if callback:
|
|
20
|
+
self.registry[custom_id] = callback
|
|
21
|
+
|
|
22
|
+
return btn
|
|
23
|
+
|
|
24
|
+
def to_payload(self):
|
|
25
|
+
return {
|
|
26
|
+
"flags": 1 << 15,
|
|
27
|
+
"components": [
|
|
28
|
+
{
|
|
29
|
+
"type": 17,
|
|
30
|
+
"components": [c.to_dict() for c in self.components]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "DiscordPYComponents"
|
|
3
|
+
version = "0.2.11"
|
|
4
|
+
description = "Discord Components V2 for discord.py"
|
|
5
|
+
authors = [{name="2gm49"}]
|
|
6
|
+
dependencies = ["aiohttp"]
|
|
7
|
+
|
|
8
|
+
[build-system]
|
|
9
|
+
requires = ["setuptools"]
|
|
10
|
+
build-backend = "setuptools.build_meta"
|