cordless 0.1.0__py3-none-any.whl
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.
- cordless/__init__.py +0 -0
- cordless/app.py +26 -0
- cordless/context.py +13 -0
- cordless/response/responder.py +9 -0
- cordless/router.py +35 -0
- cordless-0.1.0.dist-info/METADATA +13 -0
- cordless-0.1.0.dist-info/RECORD +9 -0
- cordless-0.1.0.dist-info/WHEEL +5 -0
- cordless-0.1.0.dist-info/top_level.txt +1 -0
cordless/__init__.py
ADDED
|
File without changes
|
cordless/app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
4
|
+
from .router import Router
|
|
5
|
+
from .context import Context
|
|
6
|
+
from .response.responder import Responder
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Cordless:
|
|
10
|
+
def __init__(self):
|
|
11
|
+
self.router = Router()
|
|
12
|
+
|
|
13
|
+
def command(self, name):
|
|
14
|
+
def decorator(func):
|
|
15
|
+
self.router.register_command(name, func)
|
|
16
|
+
return func
|
|
17
|
+
|
|
18
|
+
return decorator
|
|
19
|
+
|
|
20
|
+
def handle(self, event):
|
|
21
|
+
interaction = json.loads(event["body"])
|
|
22
|
+
|
|
23
|
+
responder = Responder()
|
|
24
|
+
ctx = Context(interaction, responder)
|
|
25
|
+
|
|
26
|
+
return asyncio.run(self.router.dispatch(interaction, ctx))
|
cordless/context.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Context:
|
|
2
|
+
def __init__(self, interaction, responder):
|
|
3
|
+
self.interaction = interaction
|
|
4
|
+
self.responder = responder
|
|
5
|
+
|
|
6
|
+
async def send(self, msg):
|
|
7
|
+
return self.responder.send(msg)
|
|
8
|
+
|
|
9
|
+
async def edit(self, msg):
|
|
10
|
+
return self.responder.edit(msg)
|
|
11
|
+
|
|
12
|
+
async def defer(self):
|
|
13
|
+
return self.responder.defer()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class Responder:
|
|
2
|
+
def send(self, msg):
|
|
3
|
+
return {"statusCode": 200, "body": {"type": 4, "data": {"content": msg}}}
|
|
4
|
+
|
|
5
|
+
def edit(self, msg):
|
|
6
|
+
return {"statusCode": 200, "body": {"type": 7, "data": {"content": msg}}}
|
|
7
|
+
|
|
8
|
+
def defer(self):
|
|
9
|
+
return {"statusCode": 200, "body": {"type": 5}}
|
cordless/router.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class Router:
|
|
2
|
+
def __init__(self):
|
|
3
|
+
self.commands = {}
|
|
4
|
+
self.buttons = {}
|
|
5
|
+
|
|
6
|
+
def register_command(self, name, handler):
|
|
7
|
+
self.commands[name] = handler
|
|
8
|
+
|
|
9
|
+
def register_button(self, custom_id, handler):
|
|
10
|
+
self.buttons[custom_id] = handler
|
|
11
|
+
|
|
12
|
+
async def dispatch(self, interaction, ctx):
|
|
13
|
+
itype = interaction["type"]
|
|
14
|
+
|
|
15
|
+
# Slash command
|
|
16
|
+
if itype == 2:
|
|
17
|
+
name = interaction["data"]["name"]
|
|
18
|
+
handler = self.commands.get(name)
|
|
19
|
+
|
|
20
|
+
if not handler:
|
|
21
|
+
raise Exception(f"Unknown command: {name}")
|
|
22
|
+
|
|
23
|
+
return await handler(ctx)
|
|
24
|
+
|
|
25
|
+
# Button
|
|
26
|
+
if itype == 3:
|
|
27
|
+
cid = interaction["data"]["custom_id"]
|
|
28
|
+
handler = self.buttons.get(cid)
|
|
29
|
+
|
|
30
|
+
if not handler:
|
|
31
|
+
raise Exception(f"Unknown button: {cid}")
|
|
32
|
+
|
|
33
|
+
return await handler(ctx)
|
|
34
|
+
|
|
35
|
+
raise Exception(f"Unsupported interaction type: {itype}")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cordless
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Serverless Discord interactions framework for AWS Lambda
|
|
5
|
+
Author: borhara
|
|
6
|
+
Project-URL: Homepage, https://github.com/borhara/cordless
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
cordless/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
cordless/app.py,sha256=gR0lvNjB6EVlEvhiP4Nyo_wAj8VX4Fbfdf920G0rj2c,586
|
|
3
|
+
cordless/context.py,sha256=3NzFBM81cU17jTPqkEPntItlHc6RdQt6-H92SaN4bew,347
|
|
4
|
+
cordless/router.py,sha256=UuU-R_eVNLuBfcPDf1PKBsujLZ-ui-35JFeb7chqjBM,954
|
|
5
|
+
cordless/response/responder.py,sha256=X3qDZU5pYDbxT5_Fyd-6j3abedsSq7V4Hpi5EU71qoQ,310
|
|
6
|
+
cordless-0.1.0.dist-info/METADATA,sha256=3u4n-irllOw9_NqwWcudziw1PvfEUl3GjFg3y3FJhAg,466
|
|
7
|
+
cordless-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
cordless-0.1.0.dist-info/top_level.txt,sha256=8nDZ-APw5YtGY9PRRH__m7y29dbiZRnSrufaRmuOKQw,9
|
|
9
|
+
cordless-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cordless
|