This commit is contained in:
parent
6bc9c9e9e9
commit
86c4894cf2
@ -2,4 +2,4 @@ export * from "@/lib/tether";
|
||||
|
||||
// Types
|
||||
export * from "@/types/config";
|
||||
export * from "@/types/user";
|
||||
export * from "@/types/user";
|
||||
|
@ -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;
|
||||
export default TetherConfig;
|
||||
|
2
JS-SDK/src/types/snowflake.ts
Normal file
2
JS-SDK/src/types/snowflake.ts
Normal file
@ -0,0 +1,2 @@
|
||||
type Snowflake = `${bigint}`;
|
||||
export default Snowflake;
|
@ -4,4 +4,4 @@ type SocketPacket = {
|
||||
*/
|
||||
op: number;
|
||||
};
|
||||
export default SocketPacket;
|
||||
export default SocketPacket;
|
||||
|
@ -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.
|
||||
@ -145,4 +168,4 @@ type SpotifyActivity = {
|
||||
ends: number;
|
||||
};
|
||||
|
||||
export default DiscordUser;
|
||||
export default DiscordUser;
|
||||
|
Loading…
x
Reference in New Issue
Block a user