Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
Dependencies
deno.land/x
github.com
jsdeliver.net
lodash@4.17
std
Versions
- v1.0.0-RCLatest
- v1.0.0-pre-release-11
- v1.0.0-pre-release-10
- v1.0.0-pre-release-9
- v1.0.0-doc-test-1
- v1.0.0-pre-release-8
- 1.0.0-pre-release-7
- v1.0.0-pre-release-6
- v1.0.0-pre-release-5
- v1.0.0-pre-release-4
- v1.0.0-pre-release-3
- v1.0.0-pre-release-2
- v1.0.0-pre-release
- v0.1.1
- v0.1.0
- v0.0.1-alpha.14
- v0.0.1-alpha.13
- v0.0.1-alpha.12
- v0.0.1-alpha.11
- v0.0.1-alpha.9
- v0.0.1-alpha.8
- v0.0.1-alpha.7
- v0.0.1-alpha.6
- v0.0.1-alpha.5
- v0.0.1-alpha.4
- v0.0.1-alpha.4
- v0.0.1-alpha.3
- v0.0.1-alpha.2
Tpy
A strongly typed Pylon API client. https://pylon.bot/
Tpy is a small and simplistic Deno module that provides an easier way to interact with the Pylon API. It provides the following qualities:
- 🧬 Cross runtime support.
- 🔑 Fully typed APIs.
- 🗺 Developer-friendly error interface.
- 📄 Extensive documentation.
- 📞 Keep-alive WebSocket client.
Documentation
The API documentation can be viewed on the Deno website.
Installation
npm install tpy
yarn add tpy
pnpm add tpy
If you would like to use Tpy in the browser, considering vendoring dependencies to download the type dependencies locally.
Examples
Get the token’s matching user.
const client = new Tpy({ token: "PYLON_TOKEN" });
const { displayName, id } = await client.getUser();
console.log(`Logged in as ${displayName} (<@${id}>).`);
Listen to a deployment’s console output.
const client = new Tpy({ token: "PYLON_TOKEN" });
const ws = client.connectSocket(
await client.getDeploymentIDfromGuild("GUILD_ID")),
);
ws.on("open", (_) => console.log("WebSocket Opened"));
ws.on("error", (_) => _);
// The array matches the console log parameter types.
ws.on<[string, string, number]>(
"message",
({ data }) =>
console.log(`${data[0]} said "${data[1]}" and sent ${data[2]} attachment(s).`),
);
// Remember this!
await ws.connect();
With the following Pylon code:
discord.on("MESSAGE_CREATE", async (message) => {
console.log(
// string
message.author.username,
// string
message.content,
// number
message.attachments.length,
);
});
Get a guild’s statistics.
const client = new Tpy({ token: "PYLON_TOKEN" });
const guildStats = await client.getGuildStats("GUILD_ID");
const mostRecent = guildStats.find((e) =>
e.date === Math.min(...guildStats.map((e) => e.date))
)!;
const { date, events, executionMsAvg } = mostRecent;
const mostRecentDateFormatted = new Date(date * 1000).toDateString();
console.log(
`On ${mostRecentDateFormatted}, there was a total of ${events} events with an average execution time of ${executionMsAvg} (in ms).`,
);
Get a deployment’s listening events and cron tasks.
const client = new Tpy({
token: "PYLON_TOKEN",
deploymentID: "DEPLOYMENT_ID",
});
const { config } = await client.getDeployment();
const { cronTasks } = config.tasks;
const { events } = config;
const cronTasksFormatted = cronTasks.map(({ cronString, name }) =>
` ${name} (${cronString})`
);
console.log(
`Listening to ${events.length} discord event(s):
${events.join(", ")}\n`,
`Running ${cronTasks.length} cron job(s):\n${cronTasksFormatted.join("\n")}`,
);
Get the keys in a KV namespace.
const client = new Tpy({ token: "PYLON_TOKEN" });
const kvnamespace = "tags";
const kv = client.KV(
kvnamespace,
await client.getDeploymentIDfromGuild("GUILD_ID"),
);
const keys = await kv.list({ limit: 10 });
const amountOfKeys = await kv.count();
console.log(
`There are ${amountOfKeys} key(s) within the ${kvnamespace} KV namespace, these are the first 10 (or less).
${keys.join(", ")}`,
);
Get and modify values within a KV namespace.
const client = new Tpy({ token: "PYLON_TOKEN" });
const kvnamespace = "NAMESPACE";
const kv = client.KV(
kvnamespace,
await client.getDeploymentIDfromGuild("GUILD_ID"),
);
const key = "cool_lang";
console.log(`Value of key "${key}":`, await kv.get(key));
await kv.put(key, "rust");
console.log(`Value of key "${key}":`, await kv.get(key));
await kv.delete(key);
console.log(`Value of key "${key}":`, await kv.get(key));
Increment a key in a KV namespace.
// This is NOT an atomic mutation.
const client = new Tpy({ token: "PYLON_TOKEN" });
const kvnamespace = "NAMESPACE";
const kv = client.KV(
kvnamespace,
await client.getDeploymentIDfromGuild("GUILD_ID"),
);
const upto = 10;
for (let i = 0; i < upto; i++) {
await kv.transact("counter", (p) => {
p ||= 0;
p++;
return p;
});
}
Contributing
If you’d like to contribute, please read the contributing guide before you start working. You can start a pre-setup remote workspace immediately by opening the project in Gitpod.
Legal
Pylon is a copyright (c) of Uplol Inc., all rights reserved to Uplol.
Tpy is licensed under the MIT License.