cordless 0.1.0__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.
@@ -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"
File without changes
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+
6
+ [project]
7
+ name = "cordless"
8
+ version = "0.1.0"
9
+ description = "Serverless Discord interactions framework for AWS Lambda"
10
+ readme = "README.md"
11
+ requires-python = ">=3.10"
12
+ dependencies = []
13
+
14
+ authors = [
15
+ { name = "borhara" }
16
+ ]
17
+
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent"
22
+ ]
23
+
24
+
25
+ [project.urls]
26
+ Homepage = "https://github.com/borhara/cordless"
27
+
28
+
29
+ [project.optional-dependencies]
30
+ dev = [
31
+ "pytest>=8.0"
32
+ ]
33
+
34
+
35
+ [tool.setuptools]
36
+ package-dir = {"" = "src"}
37
+
38
+ [tool.setuptools.packages.find]
39
+ where = ["src"]
40
+
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -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))
@@ -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}}
@@ -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,13 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/cordless/__init__.py
4
+ src/cordless/app.py
5
+ src/cordless/context.py
6
+ src/cordless/router.py
7
+ src/cordless.egg-info/PKG-INFO
8
+ src/cordless.egg-info/SOURCES.txt
9
+ src/cordless.egg-info/dependency_links.txt
10
+ src/cordless.egg-info/requires.txt
11
+ src/cordless.egg-info/top_level.txt
12
+ src/cordless/response/responder.py
13
+ tests/test_router.py
@@ -0,0 +1,3 @@
1
+
2
+ [dev]
3
+ pytest>=8.0
@@ -0,0 +1 @@
1
+ cordless
@@ -0,0 +1,26 @@
1
+ import asyncio
2
+ from cordless.app import Cordless
3
+
4
+
5
+ def test_ping():
6
+ bot = Cordless()
7
+
8
+ @bot.command("ping")
9
+ async def ping(ctx):
10
+ return await ctx.send("pong")
11
+
12
+ event = {
13
+ "body": """
14
+ {
15
+ "type": 2,
16
+ "data": {
17
+ "name": "ping"
18
+ }
19
+ }
20
+ """
21
+ }
22
+
23
+ result = bot.handle(event)
24
+
25
+ assert result["statusCode"] == 200
26
+ assert result["body"]["data"]["content"] == "pong"