This commit is contained in:
Yuzu 2022-07-17 20:29:36 -05:00
parent 94852eae76
commit 94cfd9805c
19 changed files with 195 additions and 147 deletions

View File

@ -4,8 +4,8 @@
"entry": "./mod.ts", "entry": "./mod.ts",
"description": "A brand new bleeding edge non bloated Discord library", "description": "A brand new bleeding edge non bloated Discord library",
"homepage": "https://github.com/oasisjs/biscuit", "homepage": "https://github.com/oasisjs/biscuit",
"version": "0.1.1", "version": "0.2.0",
"releaseType": "patch", "releaseType": "minor",
"unstable": false, "unstable": false,
"unlisted": false, "unlisted": false,
"files": [ "files": [

View File

@ -1,29 +1,29 @@
import type { Snowflake } from "./Snowflake.ts"; import type { Snowflake } from "./Snowflake.ts";
import { baseEndpoints as Endpoints } from "../discordeno/mod.ts"; import { baseEndpoints as Endpoints } from "../discordeno/mod.ts";
export function USER_AVATAR(userId: Snowflake, icon: string): string { export function USER_AVATAR(userId: Snowflake, icon: string): string {
return `${Endpoints.CDN_URL}/avatars/${userId}/${icon}`; return `${Endpoints.CDN_URL}/avatars/${userId}/${icon}`;
} }
export function EMOJI_URL(id: Snowflake, animated = false): string { export function EMOJI_URL(id: Snowflake, animated = false): string {
return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`; return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`;
} }
export function USER_DEFAULT_AVATAR( export function USER_DEFAULT_AVATAR(
/** user discriminator */ /** user discriminator */
altIcon: number, altIcon: number,
): string { ): string {
return `${Endpoints.CDN_URL}/embed/avatars/${altIcon}.png`; return `${Endpoints.CDN_URL}/embed/avatars/${altIcon}.png`;
} }
export function GUILD_BANNER(guildId: Snowflake, icon: string): string { export function GUILD_BANNER(guildId: Snowflake, icon: string): string {
return `${Endpoints.CDN_URL}/banners/${guildId}/${icon}`; return `${Endpoints.CDN_URL}/banners/${guildId}/${icon}`;
} }
export function GUILD_SPLASH(guildId: Snowflake, icon: string): string { export function GUILD_SPLASH(guildId: Snowflake, icon: string): string {
return `${Endpoints.CDN_URL}/splashes/${guildId}/${icon}`; return `${Endpoints.CDN_URL}/splashes/${guildId}/${icon}`;
} }
export function GUILD_ICON(guildId: Snowflake, icon: string): string { export function GUILD_ICON(guildId: Snowflake, icon: string): string {
return `${Endpoints.CDN_URL}/icons/${guildId}/${icon}`; return `${Endpoints.CDN_URL}/icons/${guildId}/${icon}`;
} }

View File

@ -8,7 +8,7 @@ export function USER(userId?: Snowflake): string {
return `/users/${userId}`; return `/users/${userId}`;
} }
export function GATEWAY_BOT(): string { export function GATEWAY_BOT(): string {
return "/gateway/bot"; return "/gateway/bot";
} }
@ -31,28 +31,28 @@ export interface GetMessagesOptions {
limit?: number; limit?: number;
} }
export function CHANNEL(channelId: Snowflake): string { export function CHANNEL(channelId: Snowflake): string {
return `/channels/${channelId}`; return `/channels/${channelId}`;
} }
export function CHANNEL_INVITES(channelId: Snowflake): string { export function CHANNEL_INVITES(channelId: Snowflake): string {
return `/channels/${channelId}/invites`; return `/channels/${channelId}/invites`;
} }
export function CHANNEL_TYPING(channelId: Snowflake): string { export function CHANNEL_TYPING(channelId: Snowflake): string {
return `/channels/${channelId}/typing`; return `/channels/${channelId}/typing`;
} }
export function CHANNEL_CREATE_THREAD(channelId: Snowflake): string { export function CHANNEL_CREATE_THREAD(channelId: Snowflake): string {
return `/channels/${channelId}/threads`; return `/channels/${channelId}/threads`;
} }
export function MESSAGE_CREATE_THREAD(channelId: Snowflake, messageId: Snowflake): string { export function MESSAGE_CREATE_THREAD(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/threads`; return `/channels/${channelId}/messages/${messageId}/threads`;
} }
/** used to send messages */ /** used to send messages */
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions): string { export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions): string {
let url = `/channels/${channelId}/messages?`; let url = `/channels/${channelId}/messages?`;
if (options) { if (options) {
@ -66,17 +66,17 @@ export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOpti
} }
/** used to edit messages */ /** used to edit messages */
export function CHANNEL_MESSAGE(channelId: Snowflake, messageId: Snowflake): string { export function CHANNEL_MESSAGE(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}`; return `/channels/${channelId}/messages/${messageId}`;
} }
/** used to kick members */ /** used to kick members */
export function GUILD_MEMBER(guildId: Snowflake, userId: Snowflake): string { export function GUILD_MEMBER(guildId: Snowflake, userId: Snowflake): string {
return `/guilds/${guildId}/members/${userId}`; return `/guilds/${guildId}/members/${userId}`;
} }
/** used to ban members */ /** used to ban members */
export function GUILD_BAN(guildId: Snowflake, userId: Snowflake): string { export function GUILD_BAN(guildId: Snowflake, userId: Snowflake): string {
return `/guilds/${guildId}/bans/${userId}`; return `/guilds/${guildId}/bans/${userId}`;
} }
@ -87,7 +87,7 @@ export interface GetBans {
} }
/** used to unban members */ /** used to unban members */
export function GUILD_BANS(guildId: Snowflake, options?: GetBans): string { export function GUILD_BANS(guildId: Snowflake, options?: GetBans): string {
let url = `/guilds/${guildId}/bans?`; let url = `/guilds/${guildId}/bans?`;
if (options) { if (options) {
@ -99,11 +99,11 @@ export function GUILD_BANS(guildId: Snowflake, options?: GetBans): string {
return url; return url;
} }
export function GUILD_ROLE(guildId: Snowflake, roleId: Snowflake): string { export function GUILD_ROLE(guildId: Snowflake, roleId: Snowflake): string {
return `/guilds/${guildId}/roles/${roleId}`; return `/guilds/${guildId}/roles/${roleId}`;
} }
export function GUILD_ROLES(guildId: Snowflake): string { export function GUILD_ROLES(guildId: Snowflake): string {
return `/guilds/${guildId}/roles`; return `/guilds/${guildId}/roles`;
} }
@ -111,11 +111,11 @@ export function USER_DM() {
return `/users/@me/channels`; return `/users/@me/channels`;
} }
export function GUILD_EMOJIS(guildId: Snowflake): string { export function GUILD_EMOJIS(guildId: Snowflake): string {
return `/guilds/${guildId}/emojis`; return `/guilds/${guildId}/emojis`;
} }
export function GUILD_EMOJI(guildId: Snowflake, emojiId: Snowflake): string { export function GUILD_EMOJI(guildId: Snowflake, emojiId: Snowflake): string {
return `/guilds/${guildId}/emojis/${emojiId}`; return `/guilds/${guildId}/emojis/${emojiId}`;
} }
@ -125,18 +125,18 @@ export interface GetInvite {
scheduledEventId?: Snowflake; scheduledEventId?: Snowflake;
} }
export function GUILDS(): string { export function GUILDS(): string {
return `/guilds`; return `/guilds`;
} }
export function AUTO_MODERATION_RULES(guildId: Snowflake, ruleId?: Snowflake): string { export function AUTO_MODERATION_RULES(guildId: Snowflake, ruleId?: Snowflake): string {
if (ruleId) { if (ruleId) {
return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`; return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
} }
return `/guilds/${guildId}/auto-moderation/rules`; return `/guilds/${guildId}/auto-moderation/rules`;
} }
export function INVITE(inviteCode: string, options?: GetInvite): string { export function INVITE(inviteCode: string, options?: GetInvite): string {
let url = `/invites/${inviteCode}?`; let url = `/invites/${inviteCode}?`;
if (options) { if (options) {
@ -148,11 +148,11 @@ export function INVITE(inviteCode: string, options?: GetInvite): string {
return url; return url;
} }
export function GUILD_INVITES(guildId: Snowflake): string { export function GUILD_INVITES(guildId: Snowflake): string {
return `/guilds/${guildId}/invites`; return `/guilds/${guildId}/invites`;
} }
export function INTERACTION_ID_TOKEN(interactionId: Snowflake, token: string): string { export function INTERACTION_ID_TOKEN(interactionId: Snowflake, token: string): string {
return `/interactions/${interactionId}/${token}/callback`; return `/interactions/${interactionId}/${token}/callback`;
} }
@ -170,7 +170,7 @@ export function WEBHOOK_MESSAGE(
webhookId: Snowflake, webhookId: Snowflake,
token: string, token: string,
messageId: Snowflake, messageId: Snowflake,
options?: { threadId?: Snowflake } options?: { threadId?: Snowflake },
): string { ): string {
let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`; let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
@ -181,7 +181,7 @@ export function WEBHOOK_MESSAGE(
return url; return url;
} }
export function WEBHOOK_TOKEN(webhookId: Snowflake, token?: string): string { export function WEBHOOK_TOKEN(webhookId: Snowflake, token?: string): string {
if (!token) return `/webhooks/${webhookId}`; if (!token) return `/webhooks/${webhookId}`;
return `/webhooks/${webhookId}/${token}`; return `/webhooks/${webhookId}/${token}`;
} }
@ -191,7 +191,7 @@ export interface WebhookOptions {
threadId?: Snowflake; threadId?: Snowflake;
} }
export function WEBHOOK(webhookId: Snowflake, token: string, options?: WebhookOptions): string { export function WEBHOOK(webhookId: Snowflake, token: string, options?: WebhookOptions): string {
let url = `/webhooks/${webhookId}/${token}`; let url = `/webhooks/${webhookId}/${token}`;
if (options?.wait) url += `?wait=${options.wait}`; if (options?.wait) url += `?wait=${options.wait}`;
@ -201,7 +201,7 @@ export function WEBHOOK(webhookId: Snowflake, token: string, options?: WebhookOp
return url; return url;
} }
export function USER_NICK(guildId: Snowflake): string { export function USER_NICK(guildId: Snowflake): string {
return `/guilds/${guildId}/members/@me`; return `/guilds/${guildId}/members/@me`;
} }
@ -213,7 +213,7 @@ export interface GetGuildPruneCountQuery {
includeRoles?: Snowflake | Snowflake[]; includeRoles?: Snowflake | Snowflake[];
} }
export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuery): string { export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuery): string {
let url = `/guilds/${guildId}/prune?`; let url = `/guilds/${guildId}/prune?`;
if (options?.days) url += `days=${options.days}`; if (options?.days) url += `days=${options.days}`;
@ -222,15 +222,15 @@ export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuer
return url; return url;
} }
export function CHANNEL_PIN(channelId: Snowflake, messageId: Snowflake): string { export function CHANNEL_PIN(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/pins/${messageId}`; return `/channels/${channelId}/pins/${messageId}`;
} }
export function CHANNEL_PINS(channelId: Snowflake): string { export function CHANNEL_PINS(channelId: Snowflake): string {
return `/channels/${channelId}/pins`; return `/channels/${channelId}/pins`;
} }
export function CHANNEL_MESSAGE_REACTION_ME(channelId: Snowflake, messageId: Snowflake, emoji: string): string { export function CHANNEL_MESSAGE_REACTION_ME(channelId: Snowflake, messageId: Snowflake, emoji: string): string {
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`; return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
} }
@ -260,7 +260,7 @@ export function CHANNEL_MESSAGE_REACTION(
messageId: Snowflake, messageId: Snowflake,
emoji: string, emoji: string,
options?: GetReactions, options?: GetReactions,
): string { ): string {
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`; let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
if (options?.after) url += `after=${options.after}`; if (options?.after) url += `after=${options.after}`;
@ -269,27 +269,27 @@ export function CHANNEL_MESSAGE_REACTION(
return url; return url;
} }
export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake): string { export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/crosspost`; return `/channels/${channelId}/messages/${messageId}/crosspost`;
} }
export function GUILD_MEMBER_ROLE(guildId: Snowflake, memberId: Snowflake, roleId: Snowflake): string { export function GUILD_MEMBER_ROLE(guildId: Snowflake, memberId: Snowflake, roleId: Snowflake): string {
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`; return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
} }
export function CHANNEL_WEBHOOKS(channelId: Snowflake): string { export function CHANNEL_WEBHOOKS(channelId: Snowflake): string {
return `/channels/${channelId}/webhooks`; return `/channels/${channelId}/webhooks`;
} }
export function THREAD_START_PUBLIC(channelId: Snowflake, messageId: Snowflake): string { export function THREAD_START_PUBLIC(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/threads`; return `/channels/${channelId}/messages/${messageId}/threads`;
} }
export function THREAD_START_PRIVATE(channelId: Snowflake): string { export function THREAD_START_PRIVATE(channelId: Snowflake): string {
return `/channels/${channelId}/threads`; return `/channels/${channelId}/threads`;
} }
export function THREAD_ACTIVE(guildId: Snowflake): string { export function THREAD_ACTIVE(guildId: Snowflake): string {
return `/guilds/${guildId}/threads/active`; return `/guilds/${guildId}/threads/active`;
} }
@ -298,23 +298,23 @@ export interface ListArchivedThreads {
limit?: number; limit?: number;
} }
export function THREAD_ME(channelId: Snowflake): string { export function THREAD_ME(channelId: Snowflake): string {
return `/channels/${channelId}/thread-members/@me`; return `/channels/${channelId}/thread-members/@me`;
} }
export function THREAD_MEMBERS(channelId: Snowflake): string { export function THREAD_MEMBERS(channelId: Snowflake): string {
return `/channels/${channelId}/thread-members`; return `/channels/${channelId}/thread-members`;
} }
export function THREAD_USER(channelId: Snowflake, userId: Snowflake): string { export function THREAD_USER(channelId: Snowflake, userId: Snowflake): string {
return `/channels/${channelId}/thread-members/${userId}`; return `/channels/${channelId}/thread-members/${userId}`;
} }
export function THREAD_ARCHIVED(channelId: Snowflake): string { export function THREAD_ARCHIVED(channelId: Snowflake): string {
return `/channels/${channelId}/threads/archived`; return `/channels/${channelId}/threads/archived`;
} }
export function THREAD_ARCHIVED_PUBLIC(channelId: Snowflake, options?: ListArchivedThreads): string { export function THREAD_ARCHIVED_PUBLIC(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/threads/archived/public?`; let url = `/channels/${channelId}/threads/archived/public?`;
if (options) { if (options) {
@ -325,7 +325,7 @@ export function THREAD_ARCHIVED_PUBLIC(channelId: Snowflake, options?: ListArchi
return url; return url;
} }
export function THREAD_ARCHIVED_PRIVATE(channelId: Snowflake, options?: ListArchivedThreads): string { export function THREAD_ARCHIVED_PRIVATE(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/threads/archived/private?`; let url = `/channels/${channelId}/threads/archived/private?`;
if (options) { if (options) {
@ -336,7 +336,7 @@ export function THREAD_ARCHIVED_PRIVATE(channelId: Snowflake, options?: ListArch
return url; return url;
} }
export function THREAD_ARCHIVED_PRIVATE_JOINED(channelId: Snowflake, options?: ListArchivedThreads): string { export function THREAD_ARCHIVED_PRIVATE_JOINED(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/users/@me/threads/archived/private?`; let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
if (options) { if (options) {
@ -347,29 +347,33 @@ export function THREAD_ARCHIVED_PRIVATE_JOINED(channelId: Snowflake, options?: L
return url; return url;
} }
export function FORUM_START(channelId: Snowflake): string { export function FORUM_START(channelId: Snowflake): string {
return `/channels/${channelId}/threads?has_message=true`; return `/channels/${channelId}/threads?has_message=true`;
} }
export function STAGE_INSTANCES(): string { export function STAGE_INSTANCES(): string {
return `/stage-instances`; return `/stage-instances`;
} }
export function STAGE_INSTANCE(channelId: Snowflake): string { export function STAGE_INSTANCE(channelId: Snowflake): string {
return `/stage-instances/${channelId}`; return `/stage-instances/${channelId}`;
} }
export function APPLICATION_COMMANDS(appId: Snowflake, commandId?: Snowflake): string { export function APPLICATION_COMMANDS(appId: Snowflake, commandId?: Snowflake): string {
if (commandId) return `/applications/${appId}/commands/${commandId}`; if (commandId) return `/applications/${appId}/commands/${commandId}`;
return `/applications/${appId}/commands`; return `/applications/${appId}/commands`;
} }
export function GUILD_APPLICATION_COMMANDS(appId: Snowflake, guildId: Snowflake, commandId?: Snowflake): string { export function GUILD_APPLICATION_COMMANDS(appId: Snowflake, guildId: Snowflake, commandId?: Snowflake): string {
if (commandId) return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`; if (commandId) return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`;
return `/applications/${appId}/guilds/${guildId}/commands`; return `/applications/${appId}/guilds/${guildId}/commands`;
} }
export function GUILD_APPLICATION_COMMANDS_PERMISSIONS(appId: Snowflake, guildId: Snowflake, commandId?: Snowflake): string { export function GUILD_APPLICATION_COMMANDS_PERMISSIONS(
appId: Snowflake,
guildId: Snowflake,
commandId?: Snowflake,
): string {
if (commandId) return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`; if (commandId) return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`;
return `/applications/${appId}/guilds/${guildId}/commands/permissions`; return `/applications/${appId}/guilds/${guildId}/commands/permissions`;
} }
@ -378,7 +382,7 @@ export function APPLICATION_COMMANDS_LOCALIZATIONS(
appId: Snowflake, appId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
withLocalizations?: boolean, withLocalizations?: boolean,
): string { ): string {
let url = `/applications/${appId}/commands/${commandId}?`; let url = `/applications/${appId}/commands/${commandId}?`;
if (withLocalizations !== undefined) { if (withLocalizations !== undefined) {
@ -393,7 +397,7 @@ export function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS(
guildId: Snowflake, guildId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
withLocalizations?: boolean, withLocalizations?: boolean,
): string { ): string {
let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`; let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`;
if (withLocalizations !== undefined) { if (withLocalizations !== undefined) {
@ -403,15 +407,15 @@ export function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS(
return url; return url;
} }
export function STICKER(id: Snowflake): string { export function STICKER(id: Snowflake): string {
return `stickers/${id}`; return `stickers/${id}`;
} }
export function STICKER_PACKS(): string { export function STICKER_PACKS(): string {
return `stickers-packs`; return `stickers-packs`;
} }
export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): string { export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): string {
if (stickerId) return `/guilds/${guildId}/stickers/${stickerId}`; if (stickerId) return `/guilds/${guildId}/stickers/${stickerId}`;
return `/guilds/${guildId}/stickers`; return `/guilds/${guildId}/stickers`;
} }

View File

@ -201,11 +201,11 @@ export class Session extends EventEmitter {
return super.emit(event, ...params); return super.emit(event, ...params);
} }
async editProfile(nick?: string, avatarURL?: string | null ): Promise<User> { async editProfile(nick?: string, avatarURL?: string | null): Promise<User> {
const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL; const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL;
const user = await this.rest.runMethod<DiscordUser>(this.rest, 'PATCH', Routes.USER(), { const user = await this.rest.runMethod<DiscordUser>(this.rest, "PATCH", Routes.USER(), {
username: nick, username: nick,
avatar: avatar avatar: avatar,
}); });
return new User(this, user); return new User(this, user);
} }
@ -273,7 +273,10 @@ export class Session extends EventEmitter {
return new User(this, user); return new User(this, user);
} }
createApplicationCommand(options: CreateApplicationCommand | CreateContextApplicationCommand, guildId?: Snowflake): Promise<DiscordApplicationCommand> { createApplicationCommand(
options: CreateApplicationCommand | CreateContextApplicationCommand,
guildId?: Snowflake,
): Promise<DiscordApplicationCommand> {
return this.rest.runMethod<DiscordApplicationCommand>( return this.rest.runMethod<DiscordApplicationCommand>(
this.rest, this.rest,
"POST", "POST",
@ -353,7 +356,10 @@ export class Session extends EventEmitter {
); );
} }
fetchApplicationCommandPermission(guildId: Snowflake, id: Snowflake): Promise<DiscordGuildApplicationCommandPermissions> { fetchApplicationCommandPermission(
guildId: Snowflake,
id: Snowflake,
): Promise<DiscordGuildApplicationCommandPermissions> {
return this.rest.runMethod<DiscordGuildApplicationCommandPermissions>( return this.rest.runMethod<DiscordGuildApplicationCommandPermissions>(
this.rest, this.rest,
"GET", "GET",

View File

@ -41,7 +41,7 @@ export interface AllowedMentions {
/** /**
* @link https://github.com/denoland/deno_doc/blob/main/lib/types.d.ts * @link https://github.com/denoland/deno_doc/blob/main/lib/types.d.ts
* channelId is optional when creating a reply, but will always be present when receiving an event/response that includes this data model. * channelId is optional when creating a reply, but will always be present when receiving an event/response that includes this data model.
* */ */
export interface CreateMessageReference { export interface CreateMessageReference {
messageId: Snowflake; messageId: Snowflake;
channelId?: Snowflake; channelId?: Snowflake;
@ -82,7 +82,7 @@ export type EmojiResolvable = string | {
/** /**
* A partial {@link User} to represent the author of a message sent by a webhook * A partial {@link User} to represent the author of a message sent by a webhook
* */ */
export interface WebhookAuthor { export interface WebhookAuthor {
id: string; id: string;
username: string; username: string;
@ -108,7 +108,7 @@ export class Message implements Model {
users: data.mentions?.map((user) => new User(session, user)) ?? [], users: data.mentions?.map((user) => new User(session, user)) ?? [],
roleIds: data.mention_roles ?? [], roleIds: data.mention_roles ?? [],
channels: data.mention_channels?.map((channel) => ChannelFactory.from(session, channel)) ?? [], channels: data.mention_channels?.map((channel) => ChannelFactory.from(session, channel)) ?? [],
} };
if (!data.webhook_id) { if (!data.webhook_id) {
this.author = new User(session, data.author); this.author = new User(session, data.author);
@ -335,7 +335,7 @@ export class Message implements Model {
/** /**
* Pins this message * Pins this message
* */ */
async pin(): Promise<void> { async pin(): Promise<void> {
await this.session.rest.runMethod<undefined>( await this.session.rest.runMethod<undefined>(
this.session.rest, this.session.rest,
@ -346,7 +346,7 @@ export class Message implements Model {
/** /**
* Unpins this message * Unpins this message
* */ */
async unpin(): Promise<void> { async unpin(): Promise<void> {
await this.session.rest.runMethod<undefined>( await this.session.rest.runMethod<undefined>(
this.session.rest, this.session.rest,
@ -487,7 +487,7 @@ export class Message implements Model {
/** /**
* same as Message.removeReaction but removes using a unicode emoji * same as Message.removeReaction but removes using a unicode emoji
* */ */
async removeReactionEmoji(reaction: EmojiResolvable): Promise<void> { async removeReactionEmoji(reaction: EmojiResolvable): Promise<void> {
const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`;

View File

@ -1,7 +1,7 @@
import type { Model } from "./Base.ts"; import type { Model } from "./Base.ts";
import type { Snowflake } from "../Snowflake.ts"; import type { Snowflake } from "../Snowflake.ts";
import type { Session } from "../Session.ts"; import type { Session } from "../Session.ts";
import type { DiscordUser, UserFlags, PremiumTypes } from "../../discordeno/mod.ts"; import type { DiscordUser, PremiumTypes, UserFlags } from "../../discordeno/mod.ts";
import type { ImageFormat, ImageSize } from "../Util.ts"; import type { ImageFormat, ImageSize } from "../Util.ts";
import Util from "../Util.ts"; import Util from "../Util.ts";
import * as Routes from "../Routes.ts"; import * as Routes from "../Routes.ts";

View File

@ -1,10 +1,17 @@
import type { Model } from "./Base.ts"; import type { Model } from "./Base.ts";
import type { Session } from "../Session.ts"; import type { Session } from "../Session.ts";
import type { Snowflake } from "../Snowflake.ts"; import type { Snowflake } from "../Snowflake.ts";
import type { DiscordMessageComponents, DiscordEmbed, DiscordMessage, DiscordWebhook, FileContent, WebhookTypes } from "../../discordeno/mod.ts"; import type {
DiscordEmbed,
DiscordMessage,
DiscordMessageComponents,
DiscordWebhook,
FileContent,
WebhookTypes,
} from "../../discordeno/mod.ts";
import type { WebhookOptions } from "../Routes.ts"; import type { WebhookOptions } from "../Routes.ts";
import type { Attachment } from "./Attachment.ts"; import type { Attachment } from "./Attachment.ts";
import type { CreateMessage, AllowedMentions } from "./Message.ts"; import type { AllowedMentions, CreateMessage } from "./Message.ts";
import Util from "../Util.ts"; import Util from "../Util.ts";
import User from "./User.ts"; import User from "./User.ts";
import Message from "./Message.ts"; import Message from "./Message.ts";
@ -12,7 +19,7 @@ import * as Routes from "../Routes.ts";
/** /**
* @link https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params * @link https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params
* */ */
export interface EditWebhookMessage { export interface EditWebhookMessage {
content?: string; content?: string;
embeds?: DiscordEmbed[]; embeds?: DiscordEmbed[];
@ -60,7 +67,9 @@ export class Webhook implements Model {
guildId?: Snowflake; guildId?: Snowflake;
user?: User; user?: User;
async execute(options?: WebhookOptions & CreateMessage & { avatarUrl?: string; username?: string }): Promise<(Message | undefined)> { async execute(
options?: WebhookOptions & CreateMessage & { avatarUrl?: string; username?: string },
): Promise<(Message | undefined)> {
if (!this.token) { if (!this.token) {
return; return;
} }
@ -88,7 +97,7 @@ export class Webhook implements Model {
}), }),
}); });
return (options?.wait ?? true) ? new Message(this.session, await(message)) : undefined; return (options?.wait ?? true) ? new Message(this.session, await (message)) : undefined;
} }
async fetch(): Promise<Webhook> { async fetch(): Promise<Webhook> {
@ -127,7 +136,10 @@ export class Webhook implements Model {
); );
} }
async editMessage(messageId?: Snowflake, options?: EditWebhookMessage & { threadId?: Snowflake }): Promise<Message> { async editMessage(
messageId?: Snowflake,
options?: EditWebhookMessage & { threadId?: Snowflake },
): Promise<Message> {
if (!this.token) { if (!this.token) {
throw new Error("No token found"); throw new Error("No token found");
} }
@ -162,7 +174,7 @@ export class Webhook implements Model {
ephemeral: attachment.ephemeral, ephemeral: attachment.ephemeral,
}; };
}), }),
} },
); );
return new Message(this.session, message); return new Message(this.session, message);

View File

@ -12,22 +12,22 @@ export class SelectMenuOptionBuilder {
return this; return this;
} }
setValue(value: string): SelectMenuOptionBuilder { setValue(value: string): SelectMenuOptionBuilder {
this.#data.value = value; this.#data.value = value;
return this; return this;
} }
setDescription(description: string): SelectMenuOptionBuilder { setDescription(description: string): SelectMenuOptionBuilder {
this.#data.description = description; this.#data.description = description;
return this; return this;
} }
setDefault(Default = true): SelectMenuOptionBuilder { setDefault(Default = true): SelectMenuOptionBuilder {
this.#data.default = Default; this.#data.default = Default;
return this; return this;
} }
setEmoji(emoji: ComponentEmoji): SelectMenuOptionBuilder { setEmoji(emoji: ComponentEmoji): SelectMenuOptionBuilder {
this.#data.emoji = emoji; this.#data.emoji = emoji;
return this; return this;
} }

View File

@ -17,10 +17,8 @@ export class TextInput extends BaseComponent implements TextInputComponent {
this.placeholder = data.placeholder; this.placeholder = data.placeholder;
this.value = data.value; this.value = data.value;
this.minLength = data.min_length; this.minLength = data.min_length;
this.maxLength = data.max_length; this.maxLength = data.max_length;
} }
readonly session: Session; readonly session: Session;

View File

@ -23,7 +23,7 @@ import { Snowflake } from "../Snowflake.ts";
import Util from "../Util.ts"; import Util from "../Util.ts";
import * as Routes from "../Routes.ts"; import * as Routes from "../Routes.ts";
import WelcomeScreen from "./WelcomeScreen.ts"; import WelcomeScreen from "./WelcomeScreen.ts";
import { GuildChannel, ThreadChannel, ReturnThreadsArchive } from "./channels.ts"; import { GuildChannel, ReturnThreadsArchive, ThreadChannel } from "./channels.ts";
import ThreadMember from "./ThreadMember.ts"; import ThreadMember from "./ThreadMember.ts";
import Member from "./Member.ts"; import Member from "./Member.ts";
import Role from "./Role.ts"; import Role from "./Role.ts";
@ -320,7 +320,7 @@ export class Guild extends BaseGuild implements Model {
this.vefificationLevel = data.verification_level; this.vefificationLevel = data.verification_level;
this.defaultMessageNotificationLevel = data.default_message_notifications; this.defaultMessageNotificationLevel = data.default_message_notifications;
this.explicitContentFilterLevel = data.explicit_content_filter; this.explicitContentFilterLevel = data.explicit_content_filter;
this.premiumTier = data.premium_tier this.premiumTier = data.premium_tier;
this.members = new Map( this.members = new Map(
data.members?.map((member) => [data.id, new Member(session, { ...member, user: member.user! }, data.id)]), data.members?.map((member) => [data.id, new Member(session, { ...member, user: member.user! }, data.id)]),
@ -628,7 +628,7 @@ export class Guild extends BaseGuild implements Model {
return result.pruned; return result.pruned;
} }
async getActiveThreads(): Promise<Omit<ReturnThreadsArchive, 'hasMore'>> { async getActiveThreads(): Promise<Omit<ReturnThreadsArchive, "hasMore">> {
const { threads, members } = await this.session.rest.runMethod<DiscordListActiveThreads>( const { threads, members } = await this.session.rest.runMethod<DiscordListActiveThreads>(
this.session.rest, this.session.rest,
"GET", "GET",

View File

@ -1,10 +1,6 @@
import type { Model } from "../Base.ts"; import type { Model } from "../Base.ts";
import type { Session } from "../../Session.ts"; import type { Session } from "../../Session.ts";
import type { import type { DiscordInteraction, DiscordMessage, DiscordMessageComponents } from "../../../discordeno/mod.ts";
DiscordInteraction,
DiscordMessage,
DiscordMessageComponents,
} from "../../../discordeno/mod.ts";
import type CommandInteraction from "./CommandInteraction.ts"; import type CommandInteraction from "./CommandInteraction.ts";
import type PingInteraction from "./PingInteraction.ts"; import type PingInteraction from "./PingInteraction.ts";
import type ComponentInteraction from "./ComponentInteraction.ts"; import type ComponentInteraction from "./ComponentInteraction.ts";
@ -13,7 +9,7 @@ import type AutoCompleteInteraction from "./AutoCompleteInteraction.ts";
import type { CreateMessage } from "../Message.ts"; import type { CreateMessage } from "../Message.ts";
import type { MessageFlags } from "../../Util.ts"; import type { MessageFlags } from "../../Util.ts";
import type { EditWebhookMessage } from "../Webhook.ts"; import type { EditWebhookMessage } from "../Webhook.ts";
import { InteractionTypes, InteractionResponseTypes } from "../../../discordeno/mod.ts"; import { InteractionResponseTypes, InteractionTypes } from "../../../discordeno/mod.ts";
import { Snowflake } from "../../Snowflake.ts"; import { Snowflake } from "../../Snowflake.ts";
import User from "../User.ts"; import User from "../User.ts";
import Member from "../Member.ts"; import Member from "../Member.ts";
@ -22,7 +18,6 @@ import Permsisions from "../Permissions.ts";
import Webhook from "../Webhook.ts"; import Webhook from "../Webhook.ts";
import * as Routes from "../../Routes.ts"; import * as Routes from "../../Routes.ts";
/** /**
* @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response * @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response
*/ */
@ -157,7 +152,7 @@ export abstract class BaseInteraction implements Model {
}; };
}), }),
message_id: options.messageId, message_id: options.messageId,
} },
); );
if (!message || !options.messageId) { if (!message || !options.messageId) {
@ -184,7 +179,7 @@ export abstract class BaseInteraction implements Model {
token: this.token, token: this.token,
}, },
messageId, messageId,
options options,
); );
return message; return message;
@ -194,10 +189,10 @@ export abstract class BaseInteraction implements Model {
await Webhook.prototype.deleteMessage.call( await Webhook.prototype.deleteMessage.call(
{ {
id: this.session.applicationId, id: this.session.applicationId,
token: this.token token: this.token,
}, },
messageId, messageId,
options options,
); );
} }
@ -208,7 +203,7 @@ export abstract class BaseInteraction implements Model {
token: this.token, token: this.token,
}, },
messageId, messageId,
options options,
); );
return message; return message;
@ -219,7 +214,9 @@ export abstract class BaseInteraction implements Model {
// deno-fmt-ignore // deno-fmt-ignore
async respond(resp: InteractionResponse): Promise<Message | undefined>; async respond(resp: InteractionResponse): Promise<Message | undefined>;
async respond(resp: { with: InteractionApplicationCommandCallbackData }): Promise<Message | undefined>; async respond(resp: { with: InteractionApplicationCommandCallbackData }): Promise<Message | undefined>;
async respond(resp: InteractionResponse | { with: InteractionApplicationCommandCallbackData }): Promise<Message | undefined> { async respond(
resp: InteractionResponse | { with: InteractionApplicationCommandCallbackData },
): Promise<Message | undefined> {
const options = "with" in resp ? resp.with : resp.data; const options = "with" in resp ? resp.with : resp.data;
const type = "type" in resp ? resp.type : InteractionResponseTypes.ChannelMessageWithSource; const type = "type" in resp ? resp.type : InteractionResponseTypes.ChannelMessageWithSource;

View File

@ -86,7 +86,7 @@ export class CommandInteractionOptionResolver {
properties: Array<keyof CommandInteractionOption>, properties: Array<keyof CommandInteractionOption>,
required: boolean, required: boolean,
): CommandInteractionOption | void { ): CommandInteractionOption | void {
const option: (CommandInteractionOption | undefined) = this.get(name, required); const option: CommandInteractionOption | undefined = this.get(name, required);
if (!option) { if (!option) {
return; return;
@ -106,7 +106,7 @@ export class CommandInteractionOptionResolver {
get(name: string | number, required: true): CommandInteractionOption; get(name: string | number, required: true): CommandInteractionOption;
get(name: string | number, required: boolean): CommandInteractionOption | undefined; get(name: string | number, required: boolean): CommandInteractionOption | undefined;
get(name: string | number, required?: boolean) { get(name: string | number, required?: boolean) {
const option: (CommandInteractionOption | undefined) = this.hoistedOptions.find((o) => const option: CommandInteractionOption | undefined = this.hoistedOptions.find((o) =>
typeof name === "number" ? o.name === name.toString() : o.name === name typeof name === "number" ? o.name === name.toString() : o.name === name
); );
@ -125,7 +125,12 @@ export class CommandInteractionOptionResolver {
getString(name: string | number, required: true): string; getString(name: string | number, required: true): string;
getString(name: string | number, required?: boolean): string | undefined; getString(name: string | number, required?: boolean): string | undefined;
getString(name: string | number, required = false) { getString(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.String, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.String,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -134,7 +139,12 @@ export class CommandInteractionOptionResolver {
getNumber(name: string | number, required: true): number; getNumber(name: string | number, required: true): number;
getNumber(name: string | number, required?: boolean): number | undefined; getNumber(name: string | number, required?: boolean): number | undefined;
getNumber(name: string | number, required = false) { getNumber(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Number, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.Number,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -143,7 +153,12 @@ export class CommandInteractionOptionResolver {
getInteger(name: string | number, required: true): number; getInteger(name: string | number, required: true): number;
getInteger(name: string | number, required?: boolean): number | undefined; getInteger(name: string | number, required?: boolean): number | undefined;
getInteger(name: string | number, required = false) { getInteger(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Integer, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.Integer,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -152,7 +167,12 @@ export class CommandInteractionOptionResolver {
getBoolean(name: string | number, required: true): boolean; getBoolean(name: string | number, required: true): boolean;
getBoolean(name: string | number, required?: boolean): boolean | undefined; getBoolean(name: string | number, required?: boolean): boolean | undefined;
getBoolean(name: string | number, required = false) { getBoolean(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Boolean, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.Boolean,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -161,7 +181,9 @@ export class CommandInteractionOptionResolver {
getUser(name: string | number, required: true): bigint; getUser(name: string | number, required: true): bigint;
getUser(name: string | number, required?: boolean): bigint | undefined; getUser(name: string | number, required?: boolean): bigint | undefined;
getUser(name: string | number, required = false) { getUser(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.User, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(name, ApplicationCommandOptionTypes.User, [
"Otherwise",
], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -170,7 +192,12 @@ export class CommandInteractionOptionResolver {
getChannel(name: string | number, required: true): bigint; getChannel(name: string | number, required: true): bigint;
getChannel(name: string | number, required?: boolean): bigint | undefined; getChannel(name: string | number, required?: boolean): bigint | undefined;
getChannel(name: string | number, required = false) { getChannel(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Channel, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.Channel,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -179,7 +206,12 @@ export class CommandInteractionOptionResolver {
getMentionable(name: string | number, required: true): string; getMentionable(name: string | number, required: true): string;
getMentionable(name: string | number, required?: boolean): string | undefined; getMentionable(name: string | number, required?: boolean): string | undefined;
getMentionable(name: string | number, required = false) { getMentionable(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Mentionable, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.Mentionable,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -188,7 +220,9 @@ export class CommandInteractionOptionResolver {
getRole(name: string | number, required: true): bigint; getRole(name: string | number, required: true): bigint;
getRole(name: string | number, required?: boolean): bigint | undefined; getRole(name: string | number, required?: boolean): bigint | undefined;
getRole(name: string | number, required = false) { getRole(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Role, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(name, ApplicationCommandOptionTypes.Role, [
"Otherwise",
], required);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
@ -197,14 +231,19 @@ export class CommandInteractionOptionResolver {
getAttachment(name: string | number, required: true): string; getAttachment(name: string | number, required: true): string;
getAttachment(name: string | number, required?: boolean): string | undefined; getAttachment(name: string | number, required?: boolean): string | undefined;
getAttachment(name: string | number, required = false) { getAttachment(name: string | number, required = false) {
const option: (CommandInteractionOption | void) = this.getTypedOption(name, ApplicationCommandOptionTypes.Attachment, ["Otherwise"], required); const option: CommandInteractionOption | void = this.getTypedOption(
name,
ApplicationCommandOptionTypes.Attachment,
["Otherwise"],
required,
);
return option?.Otherwise ?? undefined; return option?.Otherwise ?? undefined;
} }
/** searches for the focused option */ /** searches for the focused option */
getFocused(full = false): string | number | bigint | boolean | undefined | CommandInteractionOption { getFocused(full = false): string | number | bigint | boolean | undefined | CommandInteractionOption {
const focusedOption: (CommandInteractionOption | void) = this.hoistedOptions.find((option) => option.focused); const focusedOption: CommandInteractionOption | void = this.hoistedOptions.find((option) => option.focused);
if (!focusedOption) { if (!focusedOption) {
throw new TypeError("No option found"); throw new TypeError("No option found");

View File

@ -2,7 +2,7 @@ import type { Model } from "../Base.ts";
import type { Snowflake } from "../../Snowflake.ts"; import type { Snowflake } from "../../Snowflake.ts";
import type { Session } from "../../Session.ts"; import type { Session } from "../../Session.ts";
import type { DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts"; import type { DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts";
import { MessageComponentTypes, InteractionResponseTypes } from "../../../discordeno/mod.ts"; import { InteractionResponseTypes, MessageComponentTypes } from "../../../discordeno/mod.ts";
import BaseInteraction from "./BaseInteraction.ts"; import BaseInteraction from "./BaseInteraction.ts";
import Message from "../Message.ts"; import Message from "../Message.ts";

View File

@ -12,14 +12,14 @@ import ModalSubmitInteraction from "./ModalSubmitInteraction.ts";
/** /**
* @link https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object-message-interaction-structure * @link https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object-message-interaction-structure
* */ */
export interface MessageInteraction { export interface MessageInteraction {
/** id of the interaction */ /** id of the interaction */
id: Snowflake; id: Snowflake;
/** type of interaction */ /** type of interaction */
type: InteractionTypes type: InteractionTypes;
/** name of the application command, including subcommands and subcommand groups */ /** name of the application command, including subcommands and subcommand groups */
name: string name: string;
/** user who invoked the interaction */ /** user who invoked the interaction */
user: User; user: User;
/** member who invoked the interaction in the guild */ /** member who invoked the interaction in the guild */
@ -49,7 +49,11 @@ export class InteractionFactory {
} }
} }
static fromMessage(session: Session, interaction: DiscordMessageInteraction, _guildId?: Snowflake): MessageInteraction { static fromMessage(
session: Session,
interaction: DiscordMessageInteraction,
_guildId?: Snowflake,
): MessageInteraction {
const obj = { const obj = {
id: interaction.id, id: interaction.id,
type: interaction.type, type: interaction.type,

View File

@ -1,4 +1,3 @@
import type { Session, Snowflake } from "./deps.ts"; import type { Session, Snowflake } from "./deps.ts";
export class Collection<V> extends Map<Snowflake, V> { export class Collection<V> extends Map<Snowflake, V> {

View File

@ -1,10 +1,4 @@
import type { import type { ChannelInGuild, ChannelTypes, ChannelWithMessagesInGuild, DiscordChannel, Snowflake } from "./deps.ts";
ChannelInGuild,
ChannelWithMessagesInGuild,
ChannelTypes,
DiscordChannel,
Snowflake,
} from "./deps.ts";
import type { CachedMessage } from "./messages.ts"; import type { CachedMessage } from "./messages.ts";
import type { CachedGuild } from "./guilds.ts"; import type { CachedGuild } from "./guilds.ts";
import type { SessionCache } from "./mod.ts"; import type { SessionCache } from "./mod.ts";
@ -30,9 +24,12 @@ export interface CachedDMChannel extends DMChannel {
export function channelBootstrapper(cache: SessionCache, channel: DiscordChannel) { export function channelBootstrapper(cache: SessionCache, channel: DiscordChannel) {
if (!channel.guild_id) { if (!channel.guild_id) {
cache.dms.set(channel.id, Object.assign(new DMChannel(cache.session, channel), { cache.dms.set(
messages: new Collection<CachedMessage>(cache.session), channel.id,
})) Object.assign(new DMChannel(cache.session, channel), {
messages: new Collection<CachedMessage>(cache.session),
}),
);
return; return;
} }
@ -47,24 +44,23 @@ export function channelBootstrapper(cache: SessionCache, channel: DiscordChannel
guildId: channel.guild_id!, guildId: channel.guild_id!,
get guild(): CachedGuild { get guild(): CachedGuild {
return cache.guilds.get(this.guildId)!; return cache.guilds.get(this.guildId)!;
} },
}, },
), ),
); );
} else { } else {
guild.channels.set( guild.channels.set(
channel.id, channel.id,
<CachedGuildChannel>Object.assign( <CachedGuildChannel> Object.assign(
ChannelFactory.fromGuildChannel(cache.session, channel), ChannelFactory.fromGuildChannel(cache.session, channel),
{ {
guildId: channel.guild_id!, guildId: channel.guild_id!,
get guild(): CachedGuild { get guild(): CachedGuild {
return cache.guilds.get(this.guildId)!; return cache.guilds.get(this.guildId)!;
} },
} },
), ),
); );
} }
}); });
} }

View File

@ -1,7 +1,4 @@
import type { import type { DiscordGuild, DiscordMemberWithUser } from "./deps.ts";
DiscordGuild,
DiscordMemberWithUser,
} from "./deps.ts";
import type { SessionCache } from "./mod.ts"; import type { SessionCache } from "./mod.ts";
import type { CachedMember } from "./members.ts"; import type { CachedMember } from "./members.ts";
import type { CachedUser } from "./users.ts"; import type { CachedUser } from "./users.ts";

View File

@ -1,11 +1,11 @@
import type { import type {
DiscordEmoji, DiscordEmoji,
DiscordMessage,
DiscordMemberWithUser, DiscordMemberWithUser,
DiscordMessage,
DiscordMessageReactionAdd, DiscordMessageReactionAdd,
DiscordMessageReactionRemove, DiscordMessageReactionRemove,
DiscordMessageReactionRemoveAll, DiscordMessageReactionRemoveAll,
Snowflake Snowflake,
} from "./deps.ts"; } from "./deps.ts";
import type { CachedUser } from "./users.ts"; import type { CachedUser } from "./users.ts";
import type { SessionCache } from "./mod.ts"; import type { SessionCache } from "./mod.ts";

View File

@ -7,11 +7,7 @@ import { memberBootstrapper } from "./members.ts";
import { userBootstrapper } from "./users.ts"; import { userBootstrapper } from "./users.ts";
import { channelBootstrapper } from "./channels.ts"; import { channelBootstrapper } from "./channels.ts";
import { guildBootstrapper } from "./guilds.ts"; import { guildBootstrapper } from "./guilds.ts";
import { import { messageBootstrapper, reactionBootstrapper, reactionBootstrapperDeletions } from "./messages.ts";
messageBootstrapper,
reactionBootstrapper,
reactionBootstrapperDeletions
} from "./messages.ts";
export const cache_sym = Symbol("@cache"); export const cache_sym = Symbol("@cache");