render-lab-tasks-discord 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.
- render_lab_tasks_discord/__init__.py +1 -0
- render_lab_tasks_discord/_app.py +3 -0
- render_lab_tasks_discord/add_reaction.py +18 -0
- render_lab_tasks_discord/await_button.py +26 -0
- render_lab_tasks_discord/await_reaction.py +18 -0
- render_lab_tasks_discord/client.py +139 -0
- render_lab_tasks_discord/create_thread.py +18 -0
- render_lab_tasks_discord/create_webhook_message.py +20 -0
- render_lab_tasks_discord/edit_message.py +18 -0
- render_lab_tasks_discord/list_messages.py +18 -0
- render_lab_tasks_discord/post_message.py +18 -0
- render_lab_tasks_discord/py.typed +0 -0
- render_lab_tasks_discord/retry.py +5 -0
- render_lab_tasks_discord/tasks.py +29 -0
- render_lab_tasks_discord/types.py +94 -0
- render_lab_tasks_discord-0.1.0.dist-info/METADATA +67 -0
- render_lab_tasks_discord-0.1.0.dist-info/RECORD +19 -0
- render_lab_tasks_discord-0.1.0.dist-info/WHEEL +4 -0
- render_lab_tasks_discord-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Import .tasks explicitly to register durable tasks."""
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import DISCORD_RETRY
|
|
6
|
+
from .types import AddReactionInput, AddReactionResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def add_reaction_impl(
|
|
10
|
+
ctx: TaskContext, input: AddReactionInput, *, deps: Deps | None = None
|
|
11
|
+
) -> AddReactionResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.add_reaction(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.addReaction", retry=DISCORD_RETRY)
|
|
17
|
+
async def add_reaction(ctx: TaskContext, input: AddReactionInput) -> AddReactionResult:
|
|
18
|
+
return await add_reaction_impl(ctx, input)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps
|
|
5
|
+
from .retry import AWAIT_BUTTON_RETRY
|
|
6
|
+
from .types import AwaitButtonInput, AwaitButtonResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def await_button_impl(
|
|
10
|
+
ctx: TaskContext, input: AwaitButtonInput, *, deps: Deps | None = None
|
|
11
|
+
) -> AwaitButtonResult:
|
|
12
|
+
if deps is None or deps.interactions is None:
|
|
13
|
+
raise ValueError(
|
|
14
|
+
"awaitButton: no interaction source configured. Inject deps.interactions "
|
|
15
|
+
"with an InteractionPort; Discord REST cannot recover button clicks."
|
|
16
|
+
)
|
|
17
|
+
hit = await deps.interactions.find_click(input["messageId"], input.get("customId"))
|
|
18
|
+
if hit is None:
|
|
19
|
+
suffix = f" for {input['customId']}" if input.get("customId") else ""
|
|
20
|
+
raise RuntimeError(f"awaitButton: no click yet on {input['messageId']}{suffix}")
|
|
21
|
+
return {"clicked": True, "userId": hit["userId"], "customId": hit["customId"]}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@app.task(name="discord.awaitButton", retry=AWAIT_BUTTON_RETRY)
|
|
25
|
+
async def await_button(ctx: TaskContext, input: AwaitButtonInput) -> AwaitButtonResult:
|
|
26
|
+
return await await_button_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import AWAIT_REACTION_RETRY
|
|
6
|
+
from .types import AwaitReactionInput, AwaitReactionResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def await_reaction_impl(
|
|
10
|
+
ctx: TaskContext, input: AwaitReactionInput, *, deps: Deps | None = None
|
|
11
|
+
) -> AwaitReactionResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.await_reaction(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.awaitReaction", retry=AWAIT_REACTION_RETRY)
|
|
17
|
+
async def await_reaction(ctx: TaskContext, input: AwaitReactionInput) -> AwaitReactionResult:
|
|
18
|
+
return await await_reaction_impl(ctx, input)
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Injected vendor interface and one-attempt async HTTP adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import AsyncIterator, Mapping
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any, Protocol
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
from render_lab_tasks_core.http import HttpClient, enc, js_string, nullish, pick, required
|
|
13
|
+
|
|
14
|
+
from . import types as t
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class InteractionPort(Protocol):
|
|
18
|
+
async def find_click(
|
|
19
|
+
self, message_id: str, custom_id: str | None = None
|
|
20
|
+
) -> dict[str, str] | None: ...
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Port(Protocol):
|
|
24
|
+
async def add_reaction(self, input: t.AddReactionInput) -> t.AddReactionResult: ...
|
|
25
|
+
async def await_reaction(self, input: t.AwaitReactionInput) -> t.AwaitReactionResult: ...
|
|
26
|
+
async def create_thread(self, input: t.CreateThreadInput) -> t.ThreadRef: ...
|
|
27
|
+
async def create_webhook_message(
|
|
28
|
+
self, input: t.CreateWebhookMessageInput
|
|
29
|
+
) -> t.CreateWebhookMessageResult: ...
|
|
30
|
+
async def edit_message(self, input: t.EditMessageInput) -> t.EditMessageResult: ...
|
|
31
|
+
async def list_messages(self, input: t.ListMessagesInput) -> list[t.DiscordMessage]: ...
|
|
32
|
+
async def post_message(self, input: t.PostMessageInput) -> t.MessageRef: ...
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class Deps:
|
|
37
|
+
discord: Port
|
|
38
|
+
interactions: InteractionPort | None = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Client:
|
|
42
|
+
def __init__(self, http: httpx.AsyncClient, env: Mapping[str, str] | None = None) -> None:
|
|
43
|
+
self.env = os.environ if env is None else env
|
|
44
|
+
self.http = HttpClient(
|
|
45
|
+
http,
|
|
46
|
+
"https://discord.com/api/v10",
|
|
47
|
+
auth=lambda: {"authorization": "Bot " + required(self.env, "DISCORD_BOT_TOKEN")},
|
|
48
|
+
label="Discord API",
|
|
49
|
+
)
|
|
50
|
+
self.webhook = HttpClient(http, "", label="Discord webhook")
|
|
51
|
+
|
|
52
|
+
async def post_message(self, input: t.PostMessageInput) -> Any:
|
|
53
|
+
body = pick(input, "content")
|
|
54
|
+
if input.get("components") is not None:
|
|
55
|
+
body["components"] = input["components"]
|
|
56
|
+
data = await self.http.call(
|
|
57
|
+
f"/channels/{input['channelId']}/messages", method="POST", body=body
|
|
58
|
+
)
|
|
59
|
+
return {"messageId": data["id"], "channelId": input["channelId"]}
|
|
60
|
+
|
|
61
|
+
async def edit_message(self, input: t.EditMessageInput) -> Any:
|
|
62
|
+
body = pick(input, "content")
|
|
63
|
+
if input.get("components") is not None:
|
|
64
|
+
body["components"] = input["components"]
|
|
65
|
+
data = await self.http.call(
|
|
66
|
+
f"/channels/{input['channelId']}/messages/{input['messageId']}",
|
|
67
|
+
method="PATCH",
|
|
68
|
+
body=body,
|
|
69
|
+
)
|
|
70
|
+
return {"id": data["id"]}
|
|
71
|
+
|
|
72
|
+
async def create_thread(self, input: t.CreateThreadInput) -> Any:
|
|
73
|
+
path = f"/channels/{input['channelId']}"
|
|
74
|
+
body: dict[str, Any] = {"name": input["name"]}
|
|
75
|
+
if input.get("messageId"):
|
|
76
|
+
path += f"/messages/{input['messageId']}"
|
|
77
|
+
else:
|
|
78
|
+
body["type"] = 11
|
|
79
|
+
data = await self.http.call(path + "/threads", method="POST", body=body)
|
|
80
|
+
return {"threadId": data["id"]}
|
|
81
|
+
|
|
82
|
+
async def add_reaction(self, input: t.AddReactionInput) -> Any:
|
|
83
|
+
await self.http.call(
|
|
84
|
+
f"/channels/{input['channelId']}/messages/{input['messageId']}/reactions/{enc(input['emoji'])}/@me",
|
|
85
|
+
method="PUT",
|
|
86
|
+
response_type="text",
|
|
87
|
+
)
|
|
88
|
+
return {"ok": True}
|
|
89
|
+
|
|
90
|
+
async def await_reaction(self, input: t.AwaitReactionInput) -> Any:
|
|
91
|
+
users = await self.http.call(
|
|
92
|
+
f"/channels/{input['channelId']}/messages/{input['messageId']}/reactions/{enc(input['emoji'])}"
|
|
93
|
+
)
|
|
94
|
+
match = next(
|
|
95
|
+
(u for u in users if not input.get("userId") or u["id"] == input["userId"]), None
|
|
96
|
+
)
|
|
97
|
+
if match is None:
|
|
98
|
+
suffix = f" from {input['userId']}" if input.get("userId") else ""
|
|
99
|
+
raise RuntimeError(
|
|
100
|
+
f"awaitReaction: no {input['emoji']} reaction yet on "
|
|
101
|
+
f"{input['channelId']}/{input['messageId']}{suffix}"
|
|
102
|
+
)
|
|
103
|
+
return {"reacted": True, "userId": match["id"]}
|
|
104
|
+
|
|
105
|
+
async def create_webhook_message(self, input: t.CreateWebhookMessageInput) -> Any:
|
|
106
|
+
body = pick(input, "content")
|
|
107
|
+
if input.get("username"):
|
|
108
|
+
body["username"] = input["username"]
|
|
109
|
+
await self.webhook.call(input["webhookUrl"], method="POST", body=body, response_type="text")
|
|
110
|
+
return {"ok": True}
|
|
111
|
+
|
|
112
|
+
async def list_messages(self, input: t.ListMessagesInput) -> Any:
|
|
113
|
+
limit = js_string(nullish(input.get("limit"), 50))
|
|
114
|
+
data = await self.http.call(f"/channels/{input['channelId']}/messages?limit={limit}")
|
|
115
|
+
return [
|
|
116
|
+
{
|
|
117
|
+
"id": m["id"],
|
|
118
|
+
"authorId": m["author"]["id"],
|
|
119
|
+
"content": m["content"],
|
|
120
|
+
"timestamp": m["timestamp"],
|
|
121
|
+
}
|
|
122
|
+
for m in data
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@asynccontextmanager
|
|
127
|
+
async def dependencies(deps: Deps | None) -> AsyncIterator[Deps]:
|
|
128
|
+
if deps is not None:
|
|
129
|
+
yield deps
|
|
130
|
+
else:
|
|
131
|
+
async with httpx.AsyncClient(
|
|
132
|
+
timeout=30, transport=httpx.AsyncHTTPTransport(retries=0)
|
|
133
|
+
) as http:
|
|
134
|
+
yield Deps(discord=Client(http))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
DiscordPort = Port
|
|
138
|
+
DiscordClient = Client
|
|
139
|
+
DiscordDeps = Deps
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import DISCORD_RETRY
|
|
6
|
+
from .types import CreateThreadInput, ThreadRef
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_thread_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateThreadInput, *, deps: Deps | None = None
|
|
11
|
+
) -> ThreadRef:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.create_thread(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.createThread", retry=DISCORD_RETRY)
|
|
17
|
+
async def create_thread(ctx: TaskContext, input: CreateThreadInput) -> ThreadRef:
|
|
18
|
+
return await create_thread_impl(ctx, input)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import DISCORD_RETRY
|
|
6
|
+
from .types import CreateWebhookMessageInput, CreateWebhookMessageResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_webhook_message_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateWebhookMessageInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CreateWebhookMessageResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.create_webhook_message(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.createWebhookMessage", retry=DISCORD_RETRY)
|
|
17
|
+
async def create_webhook_message(
|
|
18
|
+
ctx: TaskContext, input: CreateWebhookMessageInput
|
|
19
|
+
) -> CreateWebhookMessageResult:
|
|
20
|
+
return await create_webhook_message_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import DISCORD_RETRY
|
|
6
|
+
from .types import EditMessageInput, EditMessageResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def edit_message_impl(
|
|
10
|
+
ctx: TaskContext, input: EditMessageInput, *, deps: Deps | None = None
|
|
11
|
+
) -> EditMessageResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.edit_message(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.editMessage", retry=DISCORD_RETRY)
|
|
17
|
+
async def edit_message(ctx: TaskContext, input: EditMessageInput) -> EditMessageResult:
|
|
18
|
+
return await edit_message_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import DISCORD_RETRY
|
|
6
|
+
from .types import DiscordMessage, ListMessagesInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def list_messages_impl(
|
|
10
|
+
ctx: TaskContext, input: ListMessagesInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[DiscordMessage]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.list_messages(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.listMessages", retry=DISCORD_RETRY)
|
|
17
|
+
async def list_messages(ctx: TaskContext, input: ListMessagesInput) -> list[DiscordMessage]:
|
|
18
|
+
return await list_messages_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import DISCORD_RETRY
|
|
6
|
+
from .types import MessageRef, PostMessageInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def post_message_impl(
|
|
10
|
+
ctx: TaskContext, input: PostMessageInput, *, deps: Deps | None = None
|
|
11
|
+
) -> MessageRef:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.discord.post_message(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="discord.postMessage", retry=DISCORD_RETRY)
|
|
17
|
+
async def post_message(ctx: TaskContext, input: PostMessageInput) -> MessageRef:
|
|
18
|
+
return await post_message_impl(ctx, input)
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from render import Retry
|
|
2
|
+
|
|
3
|
+
DISCORD_RETRY = Retry(max_retries=3, wait_duration_ms=1000, backoff_scaling=2)
|
|
4
|
+
AWAIT_BUTTON_RETRY = Retry(max_retries=360, wait_duration_ms=10000, backoff_scaling=1)
|
|
5
|
+
AWAIT_REACTION_RETRY = Retry(max_retries=360, wait_duration_ms=10000, backoff_scaling=1)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from ._app import app
|
|
2
|
+
from .add_reaction import add_reaction, add_reaction_impl
|
|
3
|
+
from .await_button import await_button, await_button_impl
|
|
4
|
+
from .await_reaction import await_reaction, await_reaction_impl
|
|
5
|
+
from .create_thread import create_thread, create_thread_impl
|
|
6
|
+
from .create_webhook_message import create_webhook_message, create_webhook_message_impl
|
|
7
|
+
from .edit_message import edit_message, edit_message_impl
|
|
8
|
+
from .list_messages import list_messages, list_messages_impl
|
|
9
|
+
from .post_message import post_message, post_message_impl
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"app",
|
|
13
|
+
"add_reaction",
|
|
14
|
+
"add_reaction_impl",
|
|
15
|
+
"await_button",
|
|
16
|
+
"await_button_impl",
|
|
17
|
+
"await_reaction",
|
|
18
|
+
"await_reaction_impl",
|
|
19
|
+
"create_thread",
|
|
20
|
+
"create_thread_impl",
|
|
21
|
+
"create_webhook_message",
|
|
22
|
+
"create_webhook_message_impl",
|
|
23
|
+
"edit_message",
|
|
24
|
+
"edit_message_impl",
|
|
25
|
+
"list_messages",
|
|
26
|
+
"list_messages_impl",
|
|
27
|
+
"post_message",
|
|
28
|
+
"post_message_impl",
|
|
29
|
+
]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""JSON contracts ported from the pinned TypeScript pack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal, NotRequired, TypedDict
|
|
6
|
+
|
|
7
|
+
type Json = str | float | bool | None | list[Json] | dict[str, Json]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PostMessageInput(TypedDict):
|
|
11
|
+
channelId: str
|
|
12
|
+
content: str
|
|
13
|
+
components: NotRequired[list[Json]]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MessageRef(TypedDict):
|
|
17
|
+
messageId: str
|
|
18
|
+
channelId: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CreateThreadInput(TypedDict):
|
|
22
|
+
channelId: str
|
|
23
|
+
name: str
|
|
24
|
+
messageId: NotRequired[str]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ThreadRef(TypedDict):
|
|
28
|
+
threadId: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AwaitButtonInput(TypedDict):
|
|
32
|
+
messageId: str
|
|
33
|
+
customId: NotRequired[str]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AwaitButtonResult(TypedDict):
|
|
37
|
+
clicked: Literal[True]
|
|
38
|
+
userId: str
|
|
39
|
+
customId: str
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class EditMessageInput(TypedDict):
|
|
43
|
+
channelId: str
|
|
44
|
+
messageId: str
|
|
45
|
+
content: str
|
|
46
|
+
components: NotRequired[list[Json]]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class EditMessageResult(TypedDict):
|
|
50
|
+
id: str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AddReactionInput(TypedDict):
|
|
54
|
+
channelId: str
|
|
55
|
+
messageId: str
|
|
56
|
+
emoji: str
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class AddReactionResult(TypedDict):
|
|
60
|
+
ok: Literal[True]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class AwaitReactionInput(TypedDict):
|
|
64
|
+
channelId: str
|
|
65
|
+
messageId: str
|
|
66
|
+
emoji: str
|
|
67
|
+
userId: NotRequired[str]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class AwaitReactionResult(TypedDict):
|
|
71
|
+
reacted: Literal[True]
|
|
72
|
+
userId: str
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class CreateWebhookMessageInput(TypedDict):
|
|
76
|
+
webhookUrl: str
|
|
77
|
+
content: str
|
|
78
|
+
username: NotRequired[str]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class CreateWebhookMessageResult(TypedDict):
|
|
82
|
+
ok: Literal[True]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class ListMessagesInput(TypedDict):
|
|
86
|
+
channelId: str
|
|
87
|
+
limit: NotRequired[float]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class DiscordMessage(TypedDict):
|
|
91
|
+
id: str
|
|
92
|
+
authorId: str
|
|
93
|
+
content: str
|
|
94
|
+
timestamp: str
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: render-lab-tasks-discord
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: discord tasks for Render Workflows
|
|
5
|
+
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: httpx<0.29,>=0.28
|
|
10
|
+
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.0
|
|
11
|
+
Requires-Dist: render==1.0.1
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# render-lab-tasks-discord
|
|
15
|
+
|
|
16
|
+
Python port of all 8 registered tasks in the pinned TypeScript pack at
|
|
17
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
18
|
+
|
|
19
|
+
From the repository, install this pack and its supporting core together:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install render-lab-tasks-discord==0.1.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import task definitions from `render_lab_tasks_discord.tasks`. Combine its `app` with
|
|
26
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
27
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
28
|
+
retain the TS spelling; Python functions use snake_case.
|
|
29
|
+
|
|
30
|
+
## Tasks
|
|
31
|
+
|
|
32
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `discord.addReaction` | `add_reaction` |
|
|
35
|
+
| `discord.awaitButton` | `await_button` |
|
|
36
|
+
| `discord.awaitReaction` | `await_reaction` |
|
|
37
|
+
| `discord.createThread` | `create_thread` |
|
|
38
|
+
| `discord.createWebhookMessage` | `create_webhook_message` |
|
|
39
|
+
| `discord.editMessage` | `edit_message` |
|
|
40
|
+
| `discord.listMessages` | `list_messages` |
|
|
41
|
+
| `discord.postMessage` | `post_message` |
|
|
42
|
+
|
|
43
|
+
## Dependencies and retries
|
|
44
|
+
|
|
45
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
46
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
47
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
48
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
49
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
50
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
51
|
+
|
|
52
|
+
## Environment
|
|
53
|
+
|
|
54
|
+
| Variable | Contract |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `DISCORD_BOT_TOKEN` | Required for bot REST tasks. Webhook URLs carry their own credentials; awaitButton uses an injected interaction store. |
|
|
57
|
+
|
|
58
|
+
## Verification and limitations
|
|
59
|
+
|
|
60
|
+
awaitButton requires Deps(interactions=...) with an async find_click(message_id, custom_id) implementation. Discord REST cannot recover past button interactions. The default wrapper fails clearly until re-registered with an interaction store. Button/reaction waits check once per durable attempt, every 10 seconds for 360 retries. Empty components clear components. Webhook calls never carry the bot token.
|
|
61
|
+
|
|
62
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
63
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
64
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
65
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
66
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
67
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
render_lab_tasks_discord/__init__.py,sha256=fGcyw3Sxjue9wB_1RdFbEFKm5DXSlw_6vD2ud03a6og,58
|
|
2
|
+
render_lab_tasks_discord/_app.py,sha256=nkWSD_6eq3xzdPJ_G7z6d5mv8tSB-Rq21yp07usJihA,48
|
|
3
|
+
render_lab_tasks_discord/add_reaction.py,sha256=5Dk5h2aJtJNzLdVygRJq1xVeTQKTVLKpEgKuwwmTQdU,612
|
|
4
|
+
render_lab_tasks_discord/await_button.py,sha256=pmjF2G8R5IqkBenxnZSw2nwzwe28-Aw19fjm_XUMqME,1116
|
|
5
|
+
render_lab_tasks_discord/await_reaction.py,sha256=kbFdpeJthsRdH7yJlHiftxi-rzUn4oseE-HloReVWi4,648
|
|
6
|
+
render_lab_tasks_discord/client.py,sha256=MG6h7j5o02Aje1r-HUdg2ssAAq5NMu2HpqX9k0xYFQs,5265
|
|
7
|
+
render_lab_tasks_discord/create_thread.py,sha256=MK3EtBy8aXMl0elfrzjugMmsUEO43bN54aVDwVVKs9M,596
|
|
8
|
+
render_lab_tasks_discord/create_webhook_message.py,sha256=A4I1-YOIRTGfO8rXgrfCBLM3btv_6mxNJwSdvRSE7KU,721
|
|
9
|
+
render_lab_tasks_discord/edit_message.py,sha256=mc9LvOTNwO8BgeK0RYOQ378TuaXIqfxeQxzk_54qez8,612
|
|
10
|
+
render_lab_tasks_discord/list_messages.py,sha256=voONKHOh19hMJXM5C4LBKbUgmn1jifIYxxiJrmjykX4,623
|
|
11
|
+
render_lab_tasks_discord/post_message.py,sha256=6Kwh8FCw2OK-FIQfpYI1APM169_l_epw5tplBJJsEFE,591
|
|
12
|
+
render_lab_tasks_discord/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
render_lab_tasks_discord/retry.py,sha256=k8T5YWPgLnBDDt0zCggSzZlaJxYemkLWDl3Rcxw0CvQ,281
|
|
14
|
+
render_lab_tasks_discord/tasks.py,sha256=4MNgIPG1rM-gngeJVfcGMArMKyKPExWnYktvQrf3aOg,942
|
|
15
|
+
render_lab_tasks_discord/types.py,sha256=5HJebxmMUvPthLWf2GtghYqI-YBk4eAI27uIUCV5uaI,1645
|
|
16
|
+
render_lab_tasks_discord-0.1.0.dist-info/METADATA,sha256=NoL_RriBXzt9pm8aJwgt1FsSRgHw1HQ89MhguBTaeyw,3045
|
|
17
|
+
render_lab_tasks_discord-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
18
|
+
render_lab_tasks_discord-0.1.0.dist-info/licenses/LICENSE,sha256=LvmsuKGkhvlSISJRqvBIPUQ_BqVDFRe0RghPSmDebzU,1067
|
|
19
|
+
render_lab_tasks_discord-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Render Lab
|
|
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.
|