mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
feat(handlers): add getGatewayBot() & getApplicationInformation() (#428)
* feat(handlers): add getGatewayBot() * refactor(bot): use getGatewayBot() to get gateway data * feat(handlers): add getApplicationInformation * add(handlers): getApplicationInformation jsdoc * Add oauth required types * create separate file * delete misc * OAuthApplication * forgot to update import * idk why that was here
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { DiscordBotGatewayData } from "../../types/mod.ts";
|
||||||
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
|
/** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */
|
||||||
|
export function getGatewayBot() {
|
||||||
|
return RequestManager.get(
|
||||||
|
endpoints.GATEWAY_BOT,
|
||||||
|
) as Promise<DiscordBotGatewayData>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { OAuthApplication } from "../../types/oauth.ts";
|
||||||
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
|
/** Returns the bot's OAuth2 application object without `flags`. */
|
||||||
|
export function getApplicationInformation() {
|
||||||
|
return RequestManager.get(endpoints.OAUTH2_APPLICATION) as Promise<
|
||||||
|
OAuthApplication
|
||||||
|
>;
|
||||||
|
}
|
||||||
+4
-8
@@ -1,11 +1,11 @@
|
|||||||
import { RequestManager } from "./rest/request_manager.ts";
|
import { getGatewayBot } from "./api/handlers/gateway.ts";
|
||||||
import {
|
import {
|
||||||
BotConfig,
|
BotConfig,
|
||||||
DiscordBotGatewayData,
|
DiscordBotGatewayData,
|
||||||
EventHandlers,
|
EventHandlers,
|
||||||
Intents,
|
Intents,
|
||||||
} from "./types/mod.ts";
|
} from "./types/mod.ts";
|
||||||
import { baseEndpoints, endpoints, GATEWAY_VERSION } from "./util/constants.ts";
|
import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
|
||||||
import { spawnShards } from "./ws/shard_manager.ts";
|
import { spawnShards } from "./ws/shard_manager.ts";
|
||||||
|
|
||||||
export let authorization = "";
|
export let authorization = "";
|
||||||
@@ -45,9 +45,7 @@ export async function startBot(config: BotConfig) {
|
|||||||
authorization = `Bot ${config.token}`;
|
authorization = `Bot ${config.token}`;
|
||||||
|
|
||||||
// Initial API connection to get info about bots connection
|
// Initial API connection to get info about bots connection
|
||||||
botGatewayData = await RequestManager.get(
|
botGatewayData = await getGatewayBot();
|
||||||
endpoints.GATEWAY_BOT,
|
|
||||||
) as DiscordBotGatewayData;
|
|
||||||
|
|
||||||
// Explicitly append gateway version and encoding
|
// Explicitly append gateway version and encoding
|
||||||
botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`;
|
botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`;
|
||||||
@@ -102,9 +100,7 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Initial API connection to get info about bots connection
|
// Initial API connection to get info about bots connection
|
||||||
botGatewayData = await RequestManager.get(
|
botGatewayData = await getGatewayBot();
|
||||||
endpoints.GATEWAY_BOT,
|
|
||||||
) as DiscordBotGatewayData;
|
|
||||||
|
|
||||||
if (!data.wsURL) proxyWSURL = botGatewayData.url;
|
if (!data.wsURL) proxyWSURL = botGatewayData.url;
|
||||||
await spawnShards(
|
await spawnShards(
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { UserPayload } from "./guild.ts";
|
||||||
|
import { TeamPayload } from "./teams.ts";
|
||||||
|
|
||||||
|
export interface OAuthApplication {
|
||||||
|
/** id of the app */
|
||||||
|
id: string;
|
||||||
|
/** the name of the app */
|
||||||
|
name: string;
|
||||||
|
/** the icon hash of the app */
|
||||||
|
icon: string | null;
|
||||||
|
/** the description of the app */
|
||||||
|
description: string;
|
||||||
|
/** an array of rpc origin urls, if rpx is enabled */
|
||||||
|
rpc_origins?: string[];
|
||||||
|
/** when false only app owner can join the app's bot to guilds */
|
||||||
|
bot_public: boolean;
|
||||||
|
/** when true the app's bot will only join upon completion of the full oauth2 code grant flow */
|
||||||
|
bot_require_code_grand: boolean;
|
||||||
|
/** partial user object containing info on the owner of the application */
|
||||||
|
owner: Partial<UserPayload>;
|
||||||
|
/** if this application is a game sold on Disccord, this field will be the summary field for the store page of its primary sku */
|
||||||
|
summary: string;
|
||||||
|
/** the base64 enccoded key for the GameSDK'S GetTicket */
|
||||||
|
verify_key: string;
|
||||||
|
/** if the application belongs to a team, this will be a list of the members of that team */
|
||||||
|
team: TeamPayload | null;
|
||||||
|
/** if this application is a game sold on Discord, this field will be the guild to which it has been linked */
|
||||||
|
guild_id?: string;
|
||||||
|
/** if this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists */
|
||||||
|
primary_sku_id?: string;
|
||||||
|
/** if this application is a game sold on Discord, this field will be the URL slug that links to the store page */
|
||||||
|
slug?: string;
|
||||||
|
/** if this application is a game sold on Discord, this field wil be the hash of the image on store embeds */
|
||||||
|
cover_image?: string;
|
||||||
|
/** the application's public flags */
|
||||||
|
flags: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { UserPayload } from "./guild.ts";
|
||||||
|
|
||||||
|
/** https://discord.com/developers/docs/topics/teams#data-models-team-object */
|
||||||
|
export interface TeamPayload {
|
||||||
|
/** a hash of the image of the team's icon */
|
||||||
|
icon: string | null;
|
||||||
|
/** the unique id of the team */
|
||||||
|
id: string;
|
||||||
|
/** the members of the team */
|
||||||
|
members: TeamMembersPayload[];
|
||||||
|
/** the user id of the current team owner */
|
||||||
|
owner_user_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** https://discord.com/developers/docs/topics/teams#data-models-team-members-object */
|
||||||
|
export interface TeamMembersPayload {
|
||||||
|
/** the user's membership state on the team */
|
||||||
|
membership_state: MembershipState;
|
||||||
|
/** will always be ["*"] */
|
||||||
|
permissions: string[];
|
||||||
|
/** the id of the parent team of which they are a member */
|
||||||
|
team_id: string;
|
||||||
|
/** the avatar, discriminator, id, and username of the user */
|
||||||
|
user: Partial<UserPayload>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** https://discord.com/developers/docs/topics/teams#data-models-membership-state-enum */
|
||||||
|
export enum MembershipState {
|
||||||
|
INVITED = 1,
|
||||||
|
ACCEPTED,
|
||||||
|
}
|
||||||
@@ -164,4 +164,7 @@ export const endpoints = {
|
|||||||
USER_DM: `${baseEndpoints.BASE_URL}/users/@me/channels`,
|
USER_DM: `${baseEndpoints.BASE_URL}/users/@me/channels`,
|
||||||
USER_CONNECTIONS: `${baseEndpoints.BASE_URL}/users/@me/connections`,
|
USER_CONNECTIONS: `${baseEndpoints.BASE_URL}/users/@me/connections`,
|
||||||
USER_NICK: (guildID: string) => `${GUILDS_BASE(guildID)}/members/@me/nick`,
|
USER_NICK: (guildID: string) => `${GUILDS_BASE(guildID)}/members/@me/nick`,
|
||||||
|
|
||||||
|
// oAuth2
|
||||||
|
OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user