mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
more handlers
This commit is contained in:
+37
-5
@@ -121,6 +121,9 @@ import {
|
|||||||
} from "./handlers/mod.ts";
|
} from "./handlers/mod.ts";
|
||||||
import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts";
|
import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts";
|
||||||
import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts";
|
import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts";
|
||||||
|
import { transformApplication } from "./transformers/application.ts";
|
||||||
|
import { transformTeam } from "./transformers/team.ts";
|
||||||
|
import { DiscordenoInvite, transformInvite } from "./transformers/invite.ts";
|
||||||
|
|
||||||
export async function createBot(options: CreateBotOptions) {
|
export async function createBot(options: CreateBotOptions) {
|
||||||
return {
|
return {
|
||||||
@@ -135,10 +138,17 @@ export async function createBot(options: CreateBotOptions) {
|
|||||||
constants: createBotConstants(),
|
constants: createBotConstants(),
|
||||||
handlers: createBotGatewayHandlers({}),
|
handlers: createBotGatewayHandlers({}),
|
||||||
cache: {
|
cache: {
|
||||||
forEach: function (
|
execute: async function (
|
||||||
type: "DELETE_MESSAGES_FROM_GUILD" | "DELETE_CHANNELS_FROM_GUILD" | "DELETE_GUILD_FROM_MEMBER",
|
type:
|
||||||
|
| "GUILD_MEMBER_CHUNK"
|
||||||
|
| "GUILD_MEMBER_COUNT_DECREMENT"
|
||||||
|
| "GUILD_MEMBER_COUNT_INCREMENT"
|
||||||
|
| "DELETE_MESSAGES_FROM_GUILD"
|
||||||
|
| "DELETE_CHANNELS_FROM_GUILD"
|
||||||
|
| "DELETE_GUILD_FROM_MEMBER",
|
||||||
options: Record<string, any>
|
options: Record<string, any>
|
||||||
) {},
|
) {},
|
||||||
|
fetchAllMembersProcessingRequests: new Collection<string, Function>(),
|
||||||
guilds: {
|
guilds: {
|
||||||
get: async function (id: bigint): Promise<DiscordenoGuild | undefined> {
|
get: async function (id: bigint): Promise<DiscordenoGuild | undefined> {
|
||||||
return {} as any as DiscordenoGuild;
|
return {} as any as DiscordenoGuild;
|
||||||
@@ -233,7 +243,12 @@ export function createEventHandlers(events: Partial<EventHandlers>): EventHandle
|
|||||||
dispatchRequirements: events.dispatchRequirements ?? ignore,
|
dispatchRequirements: events.dispatchRequirements ?? ignore,
|
||||||
integrationCreate: events.integrationCreate ?? ignore,
|
integrationCreate: events.integrationCreate ?? ignore,
|
||||||
integrationDelete: events.integrationDelete ?? ignore,
|
integrationDelete: events.integrationDelete ?? ignore,
|
||||||
|
integrationUpdate: events.integrationUpdate ?? ignore,
|
||||||
interactionCreate: events.interactionCreate ?? ignore,
|
interactionCreate: events.interactionCreate ?? ignore,
|
||||||
|
inviteCreate: events.inviteCreate ?? ignore,
|
||||||
|
inviteDelete: events.inviteDelete ?? ignore,
|
||||||
|
guildMemberAdd: events.guildMemberAdd ?? ignore,
|
||||||
|
guildMemberRemove: events.guildMemberRemove ?? ignore,
|
||||||
channelCreate: events.channelCreate ?? ignore,
|
channelCreate: events.channelCreate ?? ignore,
|
||||||
voiceChannelLeave: events.voiceChannelLeave ?? ignore,
|
voiceChannelLeave: events.voiceChannelLeave ?? ignore,
|
||||||
channelDelete: events.channelDelete ?? ignore,
|
channelDelete: events.channelDelete ?? ignore,
|
||||||
@@ -246,7 +261,6 @@ export function createEventHandlers(events: Partial<EventHandlers>): EventHandle
|
|||||||
guildCreate: events.guildCreate ?? ignore,
|
guildCreate: events.guildCreate ?? ignore,
|
||||||
guildDelete: events.guildDelete ?? ignore,
|
guildDelete: events.guildDelete ?? ignore,
|
||||||
guildUpdate: events.guildUpdate ?? ignore,
|
guildUpdate: events.guildUpdate ?? ignore,
|
||||||
integrationsUpdate: events.integrationsUpdate ?? ignore,
|
|
||||||
raw: events.raw ?? ignore,
|
raw: events.raw ?? ignore,
|
||||||
stageInstanceCreate: events.stageInstanceCreate ?? ignore,
|
stageInstanceCreate: events.stageInstanceCreate ?? ignore,
|
||||||
stageInstanceDelete: events.stageInstanceDelete ?? ignore,
|
stageInstanceDelete: events.stageInstanceDelete ?? ignore,
|
||||||
@@ -476,7 +490,10 @@ export interface Transformers {
|
|||||||
role: typeof transformRole;
|
role: typeof transformRole;
|
||||||
voiceState: typeof transformVoiceState;
|
voiceState: typeof transformVoiceState;
|
||||||
interaction: typeof transformInteraction;
|
interaction: typeof transformInteraction;
|
||||||
integration: typeof transformIntegration,
|
integration: typeof transformIntegration;
|
||||||
|
invite: typeof transformInvite;
|
||||||
|
application: typeof transformApplication;
|
||||||
|
team: typeof transformTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTransformers(options: Partial<Transformers>) {
|
export function createTransformers(options: Partial<Transformers>) {
|
||||||
@@ -490,6 +507,9 @@ export function createTransformers(options: Partial<Transformers>) {
|
|||||||
role: options.role || transformRole,
|
role: options.role || transformRole,
|
||||||
voiceState: options.voiceState || transformVoiceState,
|
voiceState: options.voiceState || transformVoiceState,
|
||||||
integration: options.integration || transformIntegration,
|
integration: options.integration || transformIntegration,
|
||||||
|
invite: options.invite || transformInvite,
|
||||||
|
application: options.application || transformApplication,
|
||||||
|
team: options.team || transformTeam,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,7 +622,19 @@ export interface EventHandlers {
|
|||||||
interactionCreate: (bot: Bot, interaction: DiscordenoInteraction) => any;
|
interactionCreate: (bot: Bot, interaction: DiscordenoInteraction) => any;
|
||||||
integrationCreate: (bot: Bot, integration: DiscordenoIntegration) => any;
|
integrationCreate: (bot: Bot, integration: DiscordenoIntegration) => any;
|
||||||
integrationDelete: (bot: Bot, payload: { id: bigint; guildId: bigint; applicationId?: bigint }) => any;
|
integrationDelete: (bot: Bot, payload: { id: bigint; guildId: bigint; applicationId?: bigint }) => any;
|
||||||
integrationsUpdate: (bot: Bot, integration: DiscordenoIntegration) => any;
|
integrationUpdate: (bot: Bot, integration: DiscordenoIntegration) => any;
|
||||||
|
inviteCreate: (bot: Bot, invite: DiscordenoInvite) => any;
|
||||||
|
inviteDelete: (
|
||||||
|
bot: Bot,
|
||||||
|
payload: {
|
||||||
|
channelId: bigint;
|
||||||
|
guildId?: bigint;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
) => any;
|
||||||
|
guildMemberAdd: (bot: Bot, member: DiscordenoMember, user: DiscordenoUser) => any;
|
||||||
|
guildMemberRemove: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any;
|
||||||
|
guildMemberUpdate: (bot: Bot, member: DiscordenoMember, user: DiscordenoUser) => any;
|
||||||
channelCreate: (bot: Bot, channel: DiscordenoChannel) => any;
|
channelCreate: (bot: Bot, channel: DiscordenoChannel) => any;
|
||||||
dispatchRequirements: (bot: Bot, data: GatewayPayload, shardId: number) => any;
|
dispatchRequirements: (bot: Bot, data: GatewayPayload, shardId: number) => any;
|
||||||
voiceChannelLeave: (bot: Bot, voiceState: DiscordenoVoiceState, channel: DiscordenoChannel) => any;
|
voiceChannelLeave: (bot: Bot, voiceState: DiscordenoVoiceState, channel: DiscordenoChannel) => any;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import type { InviteCreate } from "../../types/invites/invite_create.ts";
|
import type { InviteCreate } from "../../types/invites/invite_create.ts";
|
||||||
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
|
|
||||||
export function handleInviteCreate(data: DiscordGatewayPayload) {
|
export function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||||
eventHandlers.inviteCreate?.(data.d as InviteCreate);
|
bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as SnakeCasedPropertiesDeep<InviteCreate>));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import type { InviteDelete } from "../../types/invites/invite_delete.ts";
|
import type { InviteDelete } from "../../types/invites/invite_delete.ts";
|
||||||
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
|
|
||||||
export function handleInviteDelete(data: DiscordGatewayPayload) {
|
export function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||||
eventHandlers.inviteDelete?.(data.d as InviteDelete);
|
const payload = data.d as SnakeCasedPropertiesDeep<InviteDelete>;
|
||||||
|
|
||||||
|
bot.events.inviteDelete(bot, {
|
||||||
|
/** The channel of the invite */
|
||||||
|
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||||
|
/** The guild of the invite */
|
||||||
|
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||||
|
/** The unique invite code */
|
||||||
|
code: payload.code,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,30 @@
|
|||||||
import { cache, cacheHandlers } from "../../cache.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
|
||||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import type { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
|
import type { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
|
||||||
|
|
||||||
export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMembersChunk;
|
const payload = data.d as SnakeCasedPropertiesDeep<GuildMembersChunk>;
|
||||||
|
|
||||||
const guildId = snowflakeToBigint(payload.guildId);
|
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||||
|
|
||||||
const members = await Promise.all(
|
await bot.cache.execute("GUILD_MEMBER_CHUNK", {
|
||||||
payload.members.map(async (member) => {
|
members: payload.members.map((m) => bot.transformers.member(bot, m, guildId)),
|
||||||
const discordenoMember = await structures.createDiscordenoMember(member, guildId);
|
users: payload.members.map((m) => bot.transformers.user(bot, m.user)),
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
});
|
||||||
|
|
||||||
return discordenoMember;
|
if (!payload.nonce) return;
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
||||||
if (payload.nonce) {
|
const resolve = bot.cache.fetchAllMembersProcessingRequests.get(payload.nonce);
|
||||||
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
|
|
||||||
if (!resolve) return;
|
if (!resolve) return;
|
||||||
|
|
||||||
if (payload.chunkIndex + 1 === payload.chunkCount) {
|
if (payload.chunk_index + 1 === payload.chunk_count) {
|
||||||
cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
|
bot.cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
|
||||||
// Only 1 chunk most likely is all members or users only request a small amount of users
|
return resolve("Finished chunking members");
|
||||||
if (payload.chunkCount === 1) {
|
}
|
||||||
return resolve(new Collection(members.map((m) => [m.id, m])));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve(await cacheHandlers.filter("GET_MEMBERS_IN_GUILD", { guildId }));
|
// TODO: add a helper function that runs await fetch
|
||||||
}
|
// await fetchMembers();
|
||||||
}
|
// const members = await bot.cache.members.findMany(guildId);
|
||||||
}
|
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
|
||||||
import { structures } from "../../structures/mod.ts";
|
|
||||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import type { GuildMemberAdd } from "../../types/members/guild_member_add.ts";
|
import type { GuildMemberAdd } from "../../types/members/guild_member_add.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
|
|
||||||
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
|
export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMemberAdd;
|
const payload = data.d as SnakeCasedPropertiesDeep<GuildMemberAdd>;
|
||||||
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||||
if (!guild) return;
|
const member = bot.transformers.member(bot, payload, guildId);
|
||||||
|
const user = bot.transformers.user(bot, payload.user);
|
||||||
|
|
||||||
guild.memberCount++;
|
await Promise.all([
|
||||||
const discordenoMember = await structures.createDiscordenoMember(payload, guild.id);
|
bot.cache.members.set(member.id, member),
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
bot.cache.users.set(user.id, user),
|
||||||
|
bot.cache.execute("GUILD_MEMBER_COUNT_INCREMENT", { guildId }),
|
||||||
|
]);
|
||||||
|
|
||||||
eventHandlers.guildMemberAdd?.(guild, discordenoMember);
|
bot.events.guildMemberAdd(bot, member, user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
|
||||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import type { GuildMemberRemove } from "../../types/members/guild_member_remove.ts";
|
import type { GuildMemberRemove } from "../../types/members/guild_member_remove.ts";
|
||||||
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
|
|
||||||
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
|
export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMemberRemove;
|
const payload = data.d as SnakeCasedPropertiesDeep<GuildMemberRemove>;
|
||||||
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||||
if (!guild) return;
|
const user = bot.transformers.user(bot, payload.user);
|
||||||
|
|
||||||
guild.memberCount--;
|
await Promise.all([
|
||||||
const member = await cacheHandlers.get("members", snowflakeToBigint(payload.user.id));
|
bot.cache.members.delete(user.id),
|
||||||
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
|
bot.cache.execute("GUILD_MEMBER_COUNT_DECREMENT", { guildId }),
|
||||||
|
]);
|
||||||
|
|
||||||
member?.guilds.delete(guild.id);
|
bot.events.guildMemberRemove(bot, user, guildId);
|
||||||
if (member && !member.guilds.size) {
|
|
||||||
await cacheHandlers.delete("members", member.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1,17 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
|
||||||
import { structures } from "../../structures/mod.ts";
|
|
||||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import type { GuildMemberUpdate } from "../../types/members/guild_member_update.ts";
|
import type { GuildMemberUpdate } from "../../types/members/guild_member_update.ts";
|
||||||
import { bigintToSnowflake, snowflakeToBigint } from "../../util/bigint.ts";
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
|
|
||||||
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMemberUpdate;
|
const payload = data.d as SnakeCasedPropertiesDeep<GuildMemberUpdate>;
|
||||||
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const cachedMember = await cacheHandlers.get("members", snowflakeToBigint(payload.user.id));
|
// TODO: IDK IF THIS IS BUT IS IT LURKER IN STAGE CHANNEL WHO ISN'T A MEMBER
|
||||||
const guildMember = cachedMember?.guilds.get(guild.id);
|
if (!payload.joined_at) return;
|
||||||
|
|
||||||
const newMemberData = {
|
bot.events.guildMemberUpdate(
|
||||||
...payload,
|
bot,
|
||||||
premiumSince: payload.premiumSince || undefined,
|
bot.transformers.member(bot, payload, bot.transformers.snowflake(payload.guild_id)),
|
||||||
joinedAt: new Date(guildMember?.joinedAt || Date.now()).toISOString(),
|
bot.transformers.user(bot, payload.user)
|
||||||
deaf: guildMember?.deaf || false,
|
);
|
||||||
mute: guildMember?.mute || false,
|
|
||||||
roles: payload.roles,
|
|
||||||
};
|
|
||||||
const discordenoMember = await structures.createDiscordenoMember(newMemberData, guild.id);
|
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
|
||||||
|
|
||||||
if (guildMember) {
|
|
||||||
if (guildMember.nick !== payload.nick) {
|
|
||||||
eventHandlers.nicknameUpdate?.(guild, discordenoMember, payload.nick!, guildMember.nick ?? undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.pending === false && guildMember.pending === true) {
|
|
||||||
eventHandlers.membershipScreeningPassed?.(guild, discordenoMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
const roleIds = guildMember.roles || [];
|
|
||||||
|
|
||||||
roleIds.forEach((id) => {
|
|
||||||
eventHandlers.debug?.("loop", `1. Running forEach loop in GUILD_MEMBER_UPDATE file.`);
|
|
||||||
if (!payload.roles.includes(bigintToSnowflake(id))) {
|
|
||||||
eventHandlers.roleLost?.(guild, discordenoMember, id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
payload.roles.forEach((id) => {
|
|
||||||
eventHandlers.debug?.("loop", `2. Running forEach loop in GUILD_MEMBER_UPDATE file.`);
|
|
||||||
if (!roleIds.includes(snowflakeToBigint(id))) {
|
|
||||||
eventHandlers.roleGained?.(guild, discordenoMember, snowflakeToBigint(id));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
eventHandlers.guildMemberUpdate?.(guild, discordenoMember, cachedMember);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { Bot } from "../bot.ts";
|
||||||
|
import { Application } from "../types/applications/application.ts";
|
||||||
|
import { DiscordApplicationFlags } from "../types/applications/application_flags.ts";
|
||||||
|
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||||
|
import { DiscordenoUser } from "./member.ts";
|
||||||
|
import { DiscordenoTeam } from "./team.ts";
|
||||||
|
|
||||||
|
export function transformApplication(bot: Bot, payload: SnakeCasedPropertiesDeep<Application>): DiscordenoApplication {
|
||||||
|
return {
|
||||||
|
name: payload.name,
|
||||||
|
description: payload.description,
|
||||||
|
rpcOrigins: payload.rpc_origins,
|
||||||
|
botPublic: payload.bot_public,
|
||||||
|
botRequireCodeGrant: payload.bot_require_code_grant,
|
||||||
|
termsOfServiceUrl: payload.terms_of_service_url,
|
||||||
|
privacyPolicyUrl: payload.privacy_policy_url,
|
||||||
|
summary: payload.summary,
|
||||||
|
verifyKey: payload.verify_key,
|
||||||
|
primarySkuId: payload.primary_sku_id,
|
||||||
|
slug: payload.slug,
|
||||||
|
coverImage: payload.cover_image,
|
||||||
|
flags: payload.flags,
|
||||||
|
|
||||||
|
id: bot.transformers.snowflake(payload.id),
|
||||||
|
icon: payload.icon ? bot.utils.iconHashToBigInt(payload.icon) : undefined,
|
||||||
|
owner: payload.owner ? bot.transformers.user(bot, payload.owner) : undefined,
|
||||||
|
team: payload.team ? bot.transformers.team(bot, payload.team) : undefined,
|
||||||
|
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DiscordenoApplication {
|
||||||
|
/** The id of the app */
|
||||||
|
id: bigint;
|
||||||
|
/** The name of the app */
|
||||||
|
name: string;
|
||||||
|
/** The icon hash of the app */
|
||||||
|
icon?: bigint;
|
||||||
|
/** The description of the app */
|
||||||
|
description: string;
|
||||||
|
/** An array of rpc origin urls, if rpc is enabled */
|
||||||
|
rpcOrigins?: string[];
|
||||||
|
/** When false only app owner can join the app's bot to guilds */
|
||||||
|
botPublic: boolean;
|
||||||
|
/** When true the app's bot will only join upon completion of the full oauth2 code grant flow */
|
||||||
|
botRequireCodeGrant: boolean;
|
||||||
|
/** The url of the app's terms of service */
|
||||||
|
termsOfServiceUrl?: string;
|
||||||
|
/** The url of the app's privacy policy */
|
||||||
|
privacyPolicyUrl?: string;
|
||||||
|
/** Partial user object containing info on the owner of the application */
|
||||||
|
owner?: Partial<DiscordenoUser>;
|
||||||
|
/** If this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku */
|
||||||
|
summary: string;
|
||||||
|
/** The hex encoded key for verification in interactions and the GameSDK's GetTicket */
|
||||||
|
verifyKey: string;
|
||||||
|
/** If the application belongs to a team, this will be a list of the members of that team */
|
||||||
|
team?: DiscordenoTeam;
|
||||||
|
/** If this application is a game sold on Discord, this field will be the guild to which it has been linked */
|
||||||
|
guildId?: bigint;
|
||||||
|
/** If this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists */
|
||||||
|
primarySkuId?: 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 will be the hash of the image on store embeds */
|
||||||
|
coverImage?: string;
|
||||||
|
/** The application's public flags */
|
||||||
|
flags: DiscordApplicationFlags;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Bot } from "../bot.ts";
|
||||||
|
import { InviteCreate, DiscordTargetTypes, User, Application } from "../types/mod.ts";
|
||||||
|
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||||
|
import { DiscordenoApplication } from "./application.ts";
|
||||||
|
import { DiscordenoUser } from "./member.ts";
|
||||||
|
|
||||||
|
export function transformInvite(bot: Bot, invite: SnakeCasedPropertiesDeep<InviteCreate>): DiscordenoInvite {
|
||||||
|
return {
|
||||||
|
/** The channel the invite is for */
|
||||||
|
channelId: bot.transformers.snowflake(invite.channel_id),
|
||||||
|
/** The unique invite code */
|
||||||
|
code: invite.code,
|
||||||
|
/** The time at which the invite was created */
|
||||||
|
createdAt: Date.parse(invite.created_at),
|
||||||
|
/** The guild of the invite */
|
||||||
|
guildId: invite.guild_id ? bot.transformers.snowflake(invite.guild_id) : undefined,
|
||||||
|
/** The user that created the invite */
|
||||||
|
inviter: invite.inviter ? bot.transformers.user(bot, invite.inviter) : undefined,
|
||||||
|
/** How long the invite is valid for (in seconds) */
|
||||||
|
maxAge: invite.max_age,
|
||||||
|
/** The maximum number of times the invite can be used */
|
||||||
|
maxUses: invite.max_uses,
|
||||||
|
/** The type of target for this voice channel invite */
|
||||||
|
targetType: invite.target_type,
|
||||||
|
/** The target user for this invite */
|
||||||
|
targetUser: invite.target_user ? bot.transformers.user(bot, invite.target_user) : undefined,
|
||||||
|
/** The embedded application to open for this voice channel embedded application invite */
|
||||||
|
targetApplication: invite.target_application
|
||||||
|
? bot.transformers.application(bot, invite.target_application)
|
||||||
|
: undefined,
|
||||||
|
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
|
||||||
|
temporary: invite.temporary,
|
||||||
|
/** How many times the invite has been used (always will be 0) */
|
||||||
|
uses: invite.uses,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DiscordenoInvite {
|
||||||
|
/** The channel the invite is for */
|
||||||
|
channelId: bigint;
|
||||||
|
/** The unique invite code */
|
||||||
|
code: string;
|
||||||
|
/** The time at which the invite was created */
|
||||||
|
createdAt: number;
|
||||||
|
/** The guild of the invite */
|
||||||
|
guildId?: bigint;
|
||||||
|
/** The user that created the invite */
|
||||||
|
inviter?: DiscordenoUser;
|
||||||
|
/** How long the invite is valid for (in seconds) */
|
||||||
|
maxAge: number;
|
||||||
|
/** The maximum number of times the invite can be used */
|
||||||
|
maxUses: number;
|
||||||
|
/** The type of target for this voice channel invite */
|
||||||
|
targetType: DiscordTargetTypes;
|
||||||
|
/** The target user for this invite */
|
||||||
|
targetUser?: DiscordenoUser;
|
||||||
|
/** The embedded application to open for this voice channel embedded application invite */
|
||||||
|
targetApplication?: Partial<DiscordenoApplication>;
|
||||||
|
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
|
||||||
|
temporary: boolean;
|
||||||
|
/** How many times the invite has been used (always will be 0) */
|
||||||
|
uses: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Bot } from "../bot.ts";
|
||||||
|
import { Team } from "../types/teams/team.ts";
|
||||||
|
import { DiscordTeamMembershipStates } from "../types/teams/team_membership_states.ts";
|
||||||
|
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||||
|
import { DiscordenoUser } from "./member.ts";
|
||||||
|
|
||||||
|
export function transformTeam(bot: Bot, payload: SnakeCasedPropertiesDeep<Team>): DiscordenoTeam {
|
||||||
|
const id = bot.transformers.snowflake(payload.id);
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: payload.name,
|
||||||
|
|
||||||
|
id,
|
||||||
|
icon: payload.icon ? bot.utils.iconHashToBigInt(payload.icon) : undefined,
|
||||||
|
ownerUserId: bot.transformers.snowflake(payload.owner_user_id),
|
||||||
|
members: payload.members.map((member) => ({
|
||||||
|
membershipState: member.membership_state,
|
||||||
|
// TODO: think about this seems useless to add ["*"] to everything
|
||||||
|
permissions: member.permissions,
|
||||||
|
// TODO: think about this seems useless to add another id here when its also on the one above
|
||||||
|
teamId: id,
|
||||||
|
user: bot.transformers.user(bot, member.user),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DiscordenoTeam {
|
||||||
|
/** A hash of the image of the team's icon */
|
||||||
|
icon?: bigint;
|
||||||
|
/** The unique id of the team */
|
||||||
|
id: bigint;
|
||||||
|
/** The members of the team */
|
||||||
|
members: {
|
||||||
|
/** The user's membership state on the team */
|
||||||
|
membershipState: DiscordTeamMembershipStates;
|
||||||
|
/** Will always be `["*"]` */
|
||||||
|
permissions: "*"[];
|
||||||
|
/** The id of the parent team of which they are a member */
|
||||||
|
teamId: bigint;
|
||||||
|
/** The avatar, discriminator, id, and username of the user */
|
||||||
|
user: Partial<DiscordenoUser>;
|
||||||
|
}[];
|
||||||
|
/** The name of the team */
|
||||||
|
name: string;
|
||||||
|
/** The user id of the current team owner */
|
||||||
|
ownerUserId: bigint;
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ export interface InviteCreate {
|
|||||||
/** The type of target for this voice channel invite */
|
/** The type of target for this voice channel invite */
|
||||||
targetType: DiscordTargetTypes;
|
targetType: DiscordTargetTypes;
|
||||||
/** The target user for this invite */
|
/** The target user for this invite */
|
||||||
targetUser?: Partial<User>;
|
targetUser?: User;
|
||||||
/** The embedded application to open for this voice channel embedded application invite */
|
/** The embedded application to open for this voice channel embedded application invite */
|
||||||
targetApplication?: Partial<Application>;
|
targetApplication?: Partial<Application>;
|
||||||
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
|
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
|
||||||
|
|||||||
Reference in New Issue
Block a user