This commit is contained in:
parent
6bc9c9e9e9
commit
86c4894cf2
@ -1,14 +1,15 @@
|
|||||||
import TetherConfig from "@/types/config";
|
import TetherConfig from "@/types/config";
|
||||||
import DiscordUser from "@/types/user";
|
import DiscordUser from "@/types/user";
|
||||||
import {useEffect, useState} from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import Snowflake from "@/types/snowflake";
|
||||||
|
|
||||||
export const useTether = (
|
export const useTetherWS = (
|
||||||
snowflake: bigint | string,
|
snowflake: Snowflake,
|
||||||
{endpoint, secure, realtime}: TetherConfig = {
|
{ endpoint, secure }: TetherConfig = {
|
||||||
endpoint: "usetether.rest",
|
endpoint: "usetether.rest",
|
||||||
secure: true,
|
secure: true,
|
||||||
realtime: false
|
}
|
||||||
}): DiscordUser | undefined => {
|
): DiscordUser | undefined => {
|
||||||
const [user] = useState<DiscordUser | undefined>();
|
const [user] = useState<DiscordUser | undefined>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -17,15 +18,17 @@ export const useTether = (
|
|||||||
/**
|
/**
|
||||||
* Establish a connection with the API.
|
* Establish a connection with the API.
|
||||||
*/
|
*/
|
||||||
const connect = () => {
|
function connect() {
|
||||||
socket = new WebSocket(`ws${secure && "s"}://${endpoint}/gateway`); // Connect to the gateway
|
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("close", connect);
|
||||||
|
|
||||||
socket.addEventListener("message", event => {
|
socket.addEventListener("message", (event) => {
|
||||||
console.log("data:", event.data);
|
console.log("data:", event.data);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
connect();
|
connect();
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
@ -36,4 +39,4 @@ export const useTether = (
|
|||||||
}, [endpoint, secure]);
|
}, [endpoint, secure]);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
};
|
||||||
|
@ -2,16 +2,11 @@ type TetherConfig = {
|
|||||||
/**
|
/**
|
||||||
* The API endpoint to connect to.
|
* The API endpoint to connect to.
|
||||||
*/
|
*/
|
||||||
endpoint?: string,
|
endpoint?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the connection should be secure.
|
* Whether the connection should be secure.
|
||||||
*/
|
*/
|
||||||
secure?: boolean,
|
secure?: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the data should be fetched in real-time.
|
|
||||||
*/
|
|
||||||
realtime?: 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;
|
@ -37,7 +37,13 @@ type DiscordUser = {
|
|||||||
/**
|
/**
|
||||||
* The online status of this user, if known.
|
* 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.
|
* The clients this user is active on, if known.
|
||||||
@ -67,13 +73,30 @@ type UserFlags = {
|
|||||||
/**
|
/**
|
||||||
* The list of flags the user has.
|
* 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.
|
* The raw flags the user has.
|
||||||
*/
|
*/
|
||||||
raw: number;
|
raw: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A user's avatar.
|
* A user's avatar.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user