js sdk changes
All checks were successful
Publish JS SDK / docker (push) Successful in 10s

This commit is contained in:
Braydon 2024-09-09 19:43:55 -04:00
parent 6bc9c9e9e9
commit 86c4894cf2
6 changed files with 48 additions and 25 deletions

@ -1,14 +1,15 @@
import TetherConfig from "@/types/config";
import DiscordUser from "@/types/user";
import {useEffect, useState} from "react";
import { useEffect, useState } from "react";
import Snowflake from "@/types/snowflake";
export const useTether = (
snowflake: bigint | string,
{endpoint, secure, realtime}: TetherConfig = {
export const useTetherWS = (
snowflake: Snowflake,
{ endpoint, secure }: TetherConfig = {
endpoint: "usetether.rest",
secure: true,
realtime: false
}): DiscordUser | undefined => {
}
): DiscordUser | undefined => {
const [user] = useState<DiscordUser | undefined>();
useEffect(() => {
@ -17,15 +18,17 @@ export const useTether = (
/**
* Establish a connection with the API.
*/
const connect = () => {
function connect() {
socket = new WebSocket(`ws${secure && "s"}://${endpoint}/gateway`); // Connect to the gateway
socket.addEventListener("open", () => console.log("[Tether] WebSocket connection established!"));
socket.addEventListener("open", () =>
console.log("[Tether] WebSocket connection established!")
);
socket.addEventListener("close", connect);
socket.addEventListener("message", event => {
socket.addEventListener("message", (event) => {
console.log("data:", event.data);
});
};
}
connect();
// Cleanup
@ -36,4 +39,4 @@ export const useTether = (
}, [endpoint, secure]);
return user;
}
};

@ -2,16 +2,11 @@ type TetherConfig = {
/**
* The API endpoint to connect to.
*/
endpoint?: string,
endpoint?: string;
/**
* Whether the connection should be secure.
*/
secure?: boolean,
/**
* Whether the data should be fetched in real-time.
*/
realtime?: boolean,
secure?: boolean;
};
export default TetherConfig;

@ -0,0 +1,2 @@
type Snowflake = `${bigint}`;
export default Snowflake;

@ -37,7 +37,13 @@ type DiscordUser = {
/**
* The online status of this user, if known.
*/
onlineStatus: "ONLINE" | "IDLE" | "DO_NOT_DISTURB" | "OFFLINE" | "UNKNOWN" | undefined;
onlineStatus:
| "ONLINE"
| "IDLE"
| "DO_NOT_DISTURB"
| "OFFLINE"
| "UNKNOWN"
| undefined;
/**
* The clients this user is active on, if known.
@ -67,13 +73,30 @@ type UserFlags = {
/**
* The list of flags the user has.
*/
list: ("STAFF" | "PARTNER" | "HYPESQUAD" | "BUG_HUNTER_LEVEL_1" | "HYPESQUAD_BRAVERY" | "HYPESQUAD_BRILLIANCE" | "HYPESQUAD_BALANCE" | "EARLY_SUPPORTER" | "TEAM_USER" | "BUGHUNTER_LEVEL_2" | "VERIFIED_BOT" | "VERIFIED_DEVELOPER" | "CERTIFIED_MODERATOR" | "BOT_HTTP_INTERACTIONS" | "ACTIVE_DEVELOPER" | "UNKNOWN")[];
list: (
| "STAFF"
| "PARTNER"
| "HYPESQUAD"
| "BUG_HUNTER_LEVEL_1"
| "HYPESQUAD_BRAVERY"
| "HYPESQUAD_BRILLIANCE"
| "HYPESQUAD_BALANCE"
| "EARLY_SUPPORTER"
| "TEAM_USER"
| "BUGHUNTER_LEVEL_2"
| "VERIFIED_BOT"
| "VERIFIED_DEVELOPER"
| "CERTIFIED_MODERATOR"
| "BOT_HTTP_INTERACTIONS"
| "ACTIVE_DEVELOPER"
| "UNKNOWN"
)[];
/**
* The raw flags the user has.
*/
raw: number;
}
};
/**
* A user's avatar.