diff --git a/mod.ts b/mod.ts index 679d419..83c4805 100644 --- a/mod.ts +++ b/mod.ts @@ -1,65 +1,2 @@ -export * from "./structures/Attachment.ts"; -export * from "./structures/Base.ts"; -export * from "./structures/Embed.ts"; -export * from "./structures/Emoji.ts"; -export * from "./structures/GuildEmoji.ts"; -export * from "./structures/Invite.ts"; -export * from "./structures/Member.ts"; -export * from "./structures/Message.ts"; -export * from "./structures/Permissions.ts"; -export * from "./structures/Role.ts"; -export * from "./structures/User.ts"; -export * from "./structures/WelcomeChannel.ts"; -export * from "./structures/WelcomeScreen.ts"; - -export * from "./structures/channels/BaseChannel.ts"; -export * from "./structures/channels/BaseVoiceChannel.ts"; -export * from "./structures/channels/ChannelFactory.ts"; -export * from "./structures/channels/DMChannel.ts"; -export * from "./structures/channels/GuildChannel.ts"; -export * from "./structures/channels/NewsChannel.ts"; -export * from "./structures/channels/TextChannel.ts"; -export * from "./structures/channels/ThreadChannel.ts"; -export * from "./structures/channels/StageChannel.ts"; -export * from "./structures/channels/VoiceChannel.ts"; - -export * from "./structures/components/ActionRowComponent.ts"; -export * from "./structures/components/ButtonComponent.ts"; -export * from "./structures/components/Component.ts"; -export * from "./structures/components/LinkButtonComponent.ts"; -export * from "./structures/components/SelectMenuComponent.ts"; -export * from "./structures/components/TextInputComponent.ts"; - -export * from "./structures/guilds/AnonymousGuild.ts"; -export * from "./structures/guilds/BaseGuild.ts"; -export * from "./structures/guilds/Guild.ts"; -export * from "./structures/guilds/InviteGuild.ts"; - -export * from "./structures/builders/EmbedBuilder.ts"; -export * from "./structures/builders/InputTextComponentBuilder.ts"; -export * from "./structures/builders/MessageActionRow.ts"; -export * from "./structures/builders/MessageButton.ts"; -export * from "./structures/builders/MessageSelectMenu.ts"; -export * from "./structures/builders/SelectMenuOptionBuilder.ts"; - -export * from "./structures/interactions/AutoCompleteInteraction.ts"; -export * from "./structures/interactions/BaseInteraction.ts"; -export * from "./structures/interactions/CommandInteraction.ts"; -export * from "./structures/interactions/CommandInteractionOptionResolver.ts"; -export * from "./structures/interactions/ComponentInteraction.ts"; -export * from "./structures/interactions/InteractionFactory.ts"; -export * from "./structures/interactions/ModalSubmitInteraction.ts"; -export * from "./structures/interactions/PingInteraction.ts"; - -export * from "./session/Session.ts"; - -export * from "./util/shared/flags.ts"; -export * from "./util/shared/images.ts"; -export * from "./util/Snowflake.ts"; -export * from "./util/urlToBase64.ts"; -export * from "./util/EventEmmiter.ts"; -export * from "./util/hash.ts"; -export * as Routes from "./util/Routes.ts"; -export * as Cdn from "./util/Cdn.ts"; - -export * from "./vendor/external.ts"; +export * from "./packages/biscuit/mod.ts"; +export * from "./packages/discordeno/mod.ts"; diff --git a/handlers/Actions.ts b/packages/biscuit/Actions.ts similarity index 92% rename from handlers/Actions.ts rename to packages/biscuit/Actions.ts index ce32b9a..6f3a0fd 100644 --- a/handlers/Actions.ts +++ b/packages/biscuit/Actions.ts @@ -14,7 +14,6 @@ import type { DiscordIntegration, DiscordIntegrationDelete, DiscordInteraction, - DiscordMemberWithUser, DiscordMessage, DiscordMessageDelete, DiscordMessageReactionAdd, @@ -28,21 +27,26 @@ import type { DiscordThreadListSync, DiscordUser, DiscordWebhookUpdate, -} from "../vendor/external.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { Channel } from "../structures/channels/ChannelFactory.ts"; -import type { Interaction } from "../structures/interactions/InteractionFactory.ts"; -import ChannelFactory from "../structures/channels/ChannelFactory.ts"; -import GuildChannel from "../structures/channels/GuildChannel.ts"; -import ThreadChannel from "../structures/channels/ThreadChannel.ts"; -import ThreadMember from "../structures/ThreadMember.ts"; -import Member from "../structures/Member.ts"; -import Message from "../structures/Message.ts"; -import User from "../structures/User.ts"; -import Integration from "../structures/Integration.ts"; -import Guild from "../structures/guilds/Guild.ts"; -import InteractionFactory from "../structures/interactions/InteractionFactory.ts"; +} from "../discordeno/mod.ts"; + +import type { Snowflake } from "./Snowflake.ts"; +import type { Session } from "./Session.ts"; +import type { Channel } from "./structures/channels.ts"; +import type { Interaction } from "./structures/interactions/InteractionFactory.ts"; + +import { + ChannelFactory, + GuildChannel, + ThreadChannel, +} from "./structures/channels.ts"; + +import ThreadMember from "./structures/ThreadMember.ts"; +import Member from "./structures/Member.ts"; +import Message from "./structures/Message.ts"; +import User from "./structures/User.ts"; +import Integration from "./structures/Integration.ts"; +import Guild from "./structures/guilds/Guild.ts"; +import InteractionFactory from "./structures/interactions/InteractionFactory.ts"; export type RawHandler = (...args: [Session, number, T]) => void; export type Handler = (...args: T) => unknown; diff --git a/util/Cdn.ts b/packages/biscuit/Cdn.ts similarity index 92% rename from util/Cdn.ts rename to packages/biscuit/Cdn.ts index 8b57ed8..21cfe6b 100644 --- a/util/Cdn.ts +++ b/packages/biscuit/Cdn.ts @@ -1,5 +1,5 @@ import type { Snowflake } from "./Snowflake.ts"; -import { baseEndpoints as Endpoints } from "../vendor/external.ts"; +import { baseEndpoints as Endpoints } from "../discordeno/mod.ts"; export function USER_AVATAR(userId: Snowflake, icon: string) { return `${Endpoints.CDN_URL}/avatars/${userId}/${icon}`; diff --git a/util/Routes.ts b/packages/biscuit/Routes.ts similarity index 100% rename from util/Routes.ts rename to packages/biscuit/Routes.ts diff --git a/session/Session.ts b/packages/biscuit/Session.ts similarity index 91% rename from session/Session.ts rename to packages/biscuit/Session.ts index cb82058..420d3d7 100644 --- a/session/Session.ts +++ b/packages/biscuit/Session.ts @@ -1,13 +1,13 @@ -import type { DiscordGetGatewayBot, GatewayBot, GatewayIntents } from "../vendor/external.ts"; -import type { DiscordGatewayPayload, Shard } from "../vendor/external.ts"; -import type { Events } from "../handlers/Actions.ts"; +import type { DiscordGetGatewayBot, GatewayBot, GatewayIntents } from "../discordeno/mod.ts"; +import type { DiscordGatewayPayload, Shard } from "../discordeno/mod.ts"; +import type { Events } from "./Actions.ts"; -import { Snowflake } from "../util/Snowflake.ts"; -import { EventEmitter } from "../util/EventEmmiter.ts"; -import { createGatewayManager, createRestManager, getBotIdFromToken } from "../vendor/external.ts"; +import { Snowflake } from "./Snowflake.ts"; +import { EventEmitter } from "./util/EventEmmiter.ts"; +import { createGatewayManager, createRestManager, getBotIdFromToken } from "../discordeno/mod.ts"; -import * as Routes from "../util/Routes.ts"; -import * as Actions from "../handlers/Actions.ts"; +import * as Routes from "./Routes.ts"; +import * as Actions from "./Actions.ts"; export type DiscordRawEventHandler = (shard: Shard, data: DiscordGatewayPayload) => unknown; diff --git a/util/Snowflake.ts b/packages/biscuit/Snowflake.ts similarity index 73% rename from util/Snowflake.ts rename to packages/biscuit/Snowflake.ts index 6509f3f..cbf100a 100644 --- a/util/Snowflake.ts +++ b/packages/biscuit/Snowflake.ts @@ -1,9 +1,10 @@ -// snowflake type +/** snowflake type */ export type Snowflake = string; +/** Discord epoch */ export const DiscordEpoch = 14200704e5; -// utilities for Snowflakes +/** utilities for Snowflakes */ export const Snowflake = { snowflakeToTimestamp(id: Snowflake) { return (Number(id) >> 22) + DiscordEpoch; diff --git a/packages/biscuit/Util.ts b/packages/biscuit/Util.ts new file mode 100644 index 0000000..f98a292 --- /dev/null +++ b/packages/biscuit/Util.ts @@ -0,0 +1,83 @@ +import type { ButtonBuilder, InputTextBuilder, SelectMenuBuilder } from "./mod.ts"; +import type { Permissions } from "./structures/Permissions.ts"; +import type { Snowflake } from "./Snowflake.ts"; + +/* + * @link https://discord.com/developers/docs/resources/channel#message-object-message-flags + */ +export enum MessageFlags { + /** this message has been published to subscribed channels (via Channel Following) */ + CrossPosted = 1 << 0, + /** this message originated from a message in another channel (via Channel Following) */ + IsCrosspost = 1 << 1, + /** do not include any embeds when serializing this message */ + SupressEmbeds = 1 << 2, + /** the source message for this crosspost has been deleted (via Channel Following) */ + SourceMessageDeleted = 1 << 3, + /** this message came from the urgent message system */ + Urgent = 1 << 4, + /** this message has an associated thread, with the same id as the message */ + HasThread = 1 << 5, + /** this message is only visible to the user who invoked the Interaction */ + Ephemeral = 1 << 6, + /** this message is an Interaction Response and the bot is "thinking" */ + Loading = 1 << 7, + /** this message failed to mention some roles and add their members to the thread */ + FailedToMentionSomeRolesInThread = 1 << 8, +} + +export type ComponentBuilder = + | InputTextBuilder + | SelectMenuBuilder + | ButtonBuilder; + +/*** + * Utility type + * */ +export type ComponentEmoji = { + id: Snowflake; + name: string; + animated?: boolean; +}; + + +/** + * Utility type + * */ +export interface PermissionsOverwrites { + id: Snowflake; + type: 0 | 1; + allow: Permissions; + deny: Permissions; +} + +/** + * @link https://discord.com/developers/docs/reference#image-formatting + */ +export type ImageFormat = "jpg" | "jpeg" | "png" | "webp" | "gif" | "json"; + +/** + * @link https://discord.com/developers/docs/reference#image-formatting + */ +export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096; + +/** + * Utility functions + * */ +export class Util { + static formatImageURL(url: string, size: ImageSize = 128, format?: ImageFormat) { + return `${url}.${format || (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`; + } + + static iconHashToBigInt(hash: string) { + return BigInt("0x" + (hash.startsWith("a_") ? `a${hash.substring(2)}` : `b${hash}`)); + } + + static iconBigintToHash(icon: bigint) { + const hash = icon.toString(16); + + return hash.startsWith("a") ? `a_${hash.substring(1)}` : hash.substring(1); + } +} + +export default Util; diff --git a/packages/biscuit/mod.ts b/packages/biscuit/mod.ts new file mode 100644 index 0000000..5d8d4de --- /dev/null +++ b/packages/biscuit/mod.ts @@ -0,0 +1,61 @@ +// structures +export * from "./structures/Attachment.ts"; +export * from "./structures/Base.ts"; +export * from "./structures/Embed.ts"; +export * from "./structures/Emoji.ts"; +export * from "./structures/GuildEmoji.ts"; +export * from "./structures/Invite.ts"; +export * from "./structures/Member.ts"; +export * from "./structures/Message.ts"; +export * from "./structures/Permissions.ts"; +export * from "./structures/Role.ts"; +export * from "./structures/User.ts"; +export * from "./structures/WelcomeChannel.ts"; +export * from "./structures/WelcomeScreen.ts"; + +// channels +export * from "./structures/channels.ts"; + +// components +export * from "./structures/components/ActionRowComponent.ts"; +export * from "./structures/components/ButtonComponent.ts"; +export * from "./structures/components/Component.ts"; +export * from "./structures/components/LinkButtonComponent.ts"; +export * from "./structures/components/SelectMenuComponent.ts"; +export * from "./structures/components/TextInputComponent.ts"; + +// guilds +export * from "./structures/guilds/AnonymousGuild.ts"; +export * from "./structures/guilds/BaseGuild.ts"; +export * from "./structures/guilds/Guild.ts"; +export * from "./structures/guilds/InviteGuild.ts"; + +// builders +export * from "./structures/builders/EmbedBuilder.ts"; +export * from "./structures/builders/InputTextComponentBuilder.ts"; +export * from "./structures/builders/MessageActionRow.ts"; +export * from "./structures/builders/MessageButton.ts"; +export * from "./structures/builders/MessageSelectMenu.ts"; +export * from "./structures/builders/SelectMenuOptionBuilder.ts"; + +// interactions +export * from "./structures/interactions/AutoCompleteInteraction.ts"; +export * from "./structures/interactions/BaseInteraction.ts"; +export * from "./structures/interactions/CommandInteraction.ts"; +export * from "./structures/interactions/CommandInteractionOptionResolver.ts"; +export * from "./structures/interactions/ComponentInteraction.ts"; +export * from "./structures/interactions/InteractionFactory.ts"; +export * from "./structures/interactions/ModalSubmitInteraction.ts"; +export * from "./structures/interactions/PingInteraction.ts"; + +// session +export * from "./Session.ts"; + +// util +export * from "./Util.ts"; +export * from "./util/urlToBase64.ts"; +export * from "./util/EventEmmiter.ts"; + +// routes +export * as Routes from "./Routes.ts"; +export * as Cdn from "./Cdn.ts"; diff --git a/structures/Attachment.ts b/packages/biscuit/structures/Attachment.ts similarity index 84% rename from structures/Attachment.ts rename to packages/biscuit/structures/Attachment.ts index 35a6a9b..cbad70a 100644 --- a/structures/Attachment.ts +++ b/packages/biscuit/structures/Attachment.ts @@ -1,7 +1,7 @@ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { DiscordAttachment } from "../vendor/external.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordAttachment } from "../../discordeno/mod.ts"; /** * Represents an attachment diff --git a/structures/Base.ts b/packages/biscuit/structures/Base.ts similarity index 64% rename from structures/Base.ts rename to packages/biscuit/structures/Base.ts index a999f5b..efee6c5 100644 --- a/structures/Base.ts +++ b/packages/biscuit/structures/Base.ts @@ -1,5 +1,5 @@ -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; /** * Represents a Discord data model diff --git a/structures/Embed.ts b/packages/biscuit/structures/Embed.ts similarity index 97% rename from structures/Embed.ts rename to packages/biscuit/structures/Embed.ts index 19b5de3..fc06763 100644 --- a/structures/Embed.ts +++ b/packages/biscuit/structures/Embed.ts @@ -1,4 +1,4 @@ -import type { DiscordEmbed, EmbedTypes } from "../vendor/external.ts"; +import type { DiscordEmbed, EmbedTypes } from "../../discordeno/mod.ts"; export interface Embed { title?: string; diff --git a/structures/Emoji.ts b/packages/biscuit/structures/Emoji.ts similarity index 74% rename from structures/Emoji.ts rename to packages/biscuit/structures/Emoji.ts index 93dfc92..0d503b3 100644 --- a/structures/Emoji.ts +++ b/packages/biscuit/structures/Emoji.ts @@ -1,6 +1,6 @@ -import type { Session } from "../session/Session.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { DiscordEmoji } from "../vendor/external.ts"; +import type { Session } from "../Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { DiscordEmoji } from "../../discordeno/mod.ts"; export class Emoji { constructor(session: Session, data: DiscordEmoji) { diff --git a/structures/GuildEmoji.ts b/packages/biscuit/structures/GuildEmoji.ts similarity index 86% rename from structures/GuildEmoji.ts rename to packages/biscuit/structures/GuildEmoji.ts index 6b3d2b3..56027c5 100644 --- a/structures/GuildEmoji.ts +++ b/packages/biscuit/structures/GuildEmoji.ts @@ -1,12 +1,12 @@ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { DiscordEmoji } from "../vendor/external.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordEmoji } from "../../discordeno/mod.ts"; import type { ModifyGuildEmoji } from "./guilds/Guild.ts"; import Guild from "./guilds/Guild.ts"; import Emoji from "./Emoji.ts"; import User from "./User.ts"; -import * as Routes from "../util/Routes.ts"; +import * as Routes from "../Routes.ts"; export class GuildEmoji extends Emoji implements Model { constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) { diff --git a/structures/Integration.ts b/packages/biscuit/structures/Integration.ts similarity index 94% rename from structures/Integration.ts rename to packages/biscuit/structures/Integration.ts index 673e48a..0fcca51 100644 --- a/structures/Integration.ts +++ b/packages/biscuit/structures/Integration.ts @@ -1,7 +1,7 @@ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { DiscordIntegration, IntegrationExpireBehaviors } from "../vendor/external.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordIntegration, IntegrationExpireBehaviors } from "../../discordeno/mod.ts"; import User from "./User.ts"; export interface IntegrationAccount { diff --git a/structures/Invite.ts b/packages/biscuit/structures/Invite.ts similarity index 95% rename from structures/Invite.ts rename to packages/biscuit/structures/Invite.ts index 5c511c2..5e79787 100644 --- a/structures/Invite.ts +++ b/packages/biscuit/structures/Invite.ts @@ -1,5 +1,5 @@ -import type { Session } from "../session/Session.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; import type { DiscordChannel, DiscordInvite, @@ -8,13 +8,13 @@ import type { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus, -} from "../vendor/external.ts"; -import { TargetTypes } from "../vendor/external.ts"; +} from "../../discordeno/mod.ts"; +import { TargetTypes } from "../../discordeno/mod.ts"; +import { GuildChannel } from "./channels.ts"; +import { Member } from "./Member.ts"; import InviteGuild from "./guilds/InviteGuild.ts"; import User from "./User.ts"; import Guild from "./guilds/Guild.ts"; -import { GuildChannel } from "./channels/GuildChannel.ts"; -import { Member } from "./Member.ts"; export interface InviteStageInstance { /** The members speaking in the Stage */ diff --git a/structures/Member.ts b/packages/biscuit/structures/Member.ts similarity index 83% rename from structures/Member.ts rename to packages/biscuit/structures/Member.ts index d0b0d92..4612319 100644 --- a/structures/Member.ts +++ b/packages/biscuit/structures/Member.ts @@ -1,14 +1,13 @@ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { DiscordMemberWithUser } from "../vendor/external.ts"; -import type { ImageFormat, ImageSize } from "../util/shared/images.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordMemberWithUser } from "../../discordeno/mod.ts" +import type { ImageFormat, ImageSize } from "../Util.ts"; import type { CreateGuildBan, ModifyGuildMember } from "./guilds/Guild.ts"; -import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts"; -import { formatImageURL } from "../util/shared/images.ts"; +import Util from "../Util.ts"; import User from "./User.ts"; import Guild from "./guilds/Guild.ts"; -import * as Routes from "../util/Routes.ts"; +import * as Routes from "../Routes.ts"; /** * Represents a guild member @@ -20,7 +19,7 @@ export class Member implements Model { this.session = session; this.user = new User(session, data.user); this.guildId = guildId; - this.avatarHash = data.avatar ? iconHashToBigInt(data.avatar) : undefined; + this.avatarHash = data.avatar ? Util.iconHashToBigInt(data.avatar) : undefined; this.nickname = data.nick ? data.nick : undefined; this.joinedTimestamp = Number.parseInt(data.joined_at); this.roles = data.roles; @@ -107,10 +106,10 @@ export class Member implements Model { if (!this.avatarHash) { url = Routes.USER_DEFAULT_AVATAR(Number(this.user.discriminator) % 5); } else { - url = Routes.USER_AVATAR(this.user.id, iconBigintToHash(this.avatarHash)); + url = Routes.USER_AVATAR(this.user.id, Util.iconBigintToHash(this.avatarHash)); } - return formatImageURL(url, options.size, options.format); + return Util.formatImageURL(url, options.size, options.format); } toString() { diff --git a/structures/Message.ts b/packages/biscuit/structures/Message.ts similarity index 94% rename from structures/Message.ts rename to packages/biscuit/structures/Message.ts index 9c9dd6d..e933364 100644 --- a/structures/Message.ts +++ b/packages/biscuit/structures/Message.ts @@ -1,5 +1,5 @@ import type { Model } from "./Base.ts"; -import type { Session } from "../session/Session.ts"; +import type { Session } from "../Session.ts"; import type { AllowedMentionsTypes, DiscordEmbed, @@ -8,19 +8,19 @@ import type { FileContent, MessageActivityTypes, MessageTypes, -} from "../vendor/external.ts"; +} from "../../discordeno/mod.ts"; import type { Component } from "./components/Component.ts"; -import type { GetReactions } from "../util/Routes.ts"; -import { MessageFlags } from "../util/shared/flags.ts"; -import { iconHashToBigInt } from "../util/hash.ts"; -import { Snowflake } from "../util/Snowflake.ts"; +import type { GetReactions } from "../Routes.ts"; +import { MessageFlags } from "../Util.ts"; +import { Snowflake } from "../Snowflake.ts"; +import { ThreadChannel } from "./channels.ts"; +import Util from "../Util.ts"; import User from "./User.ts"; import Member from "./Member.ts"; import Attachment from "./Attachment.ts"; import ComponentFactory from "./components/ComponentFactory.ts"; import MessageReaction from "./MessageReaction.ts"; -// import ThreadChannel from "./channels/ThreadChannel.ts"; -import * as Routes from "../util/Routes.ts"; +import * as Routes from "../Routes.ts"; /** * @link https://discord.com/developers/docs/resources/channel#allowed-mentions-object @@ -103,7 +103,7 @@ export class Message implements Model { this.embeds = data.embeds; if (data.thread && data.guild_id) { - // this.thread = new ThreadChannel(session, data.thread, data.guild_id); + this.thread = new ThreadChannel(session, data.thread, data.guild_id); } // webhook handling @@ -112,7 +112,7 @@ export class Message implements Model { id: data.webhook_id!, username: data.author.username, discriminator: data.author.discriminator, - avatar: data.author.avatar ? iconHashToBigInt(data.author.avatar) : undefined, + avatar: data.author.avatar ? Util.iconHashToBigInt(data.author.avatar) : undefined, }; } @@ -153,7 +153,7 @@ export class Message implements Model { attachments: Attachment[]; embeds: DiscordEmbed[]; member?: Member; - // thread?: ThreadChannel; + thread?: ThreadChannel; components: Component[]; webhook?: WebhookAuthor; @@ -186,6 +186,11 @@ export class Message implements Model { return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`; } + /** Compatibility with Discordeno */ + get isBot() { + return this.author.bot; + } + async pin() { await this.session.rest.runMethod( this.session.rest, diff --git a/structures/MessageReaction.ts b/packages/biscuit/structures/MessageReaction.ts similarity index 81% rename from structures/MessageReaction.ts rename to packages/biscuit/structures/MessageReaction.ts index 5decdf4..9692d7b 100644 --- a/structures/MessageReaction.ts +++ b/packages/biscuit/structures/MessageReaction.ts @@ -1,5 +1,5 @@ -import type { Session } from "../session/Session.ts"; -import type { DiscordReaction } from "../vendor/external.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordReaction } from "../../discordeno/mod.ts"; import Emoji from "./Emoji.ts"; /** diff --git a/structures/Permissions.ts b/packages/biscuit/structures/Permissions.ts similarity index 94% rename from structures/Permissions.ts rename to packages/biscuit/structures/Permissions.ts index c212686..3903b5f 100644 --- a/structures/Permissions.ts +++ b/packages/biscuit/structures/Permissions.ts @@ -1,4 +1,4 @@ -import { BitwisePermissionFlags } from "../vendor/external.ts"; +import { BitwisePermissionFlags } from "../../discordeno/mod.ts"; export type PermissionString = keyof typeof BitwisePermissionFlags; export type PermissionResolvable = diff --git a/structures/Role.ts b/packages/biscuit/structures/Role.ts similarity index 85% rename from structures/Role.ts rename to packages/biscuit/structures/Role.ts index 43ec61d..b0057cd 100644 --- a/structures/Role.ts +++ b/packages/biscuit/structures/Role.ts @@ -1,10 +1,10 @@ import type { Model } from "./Base.ts"; -import type { DiscordRole } from "../vendor/external.ts"; -import type { Session } from "../session/Session.ts"; -import { Snowflake } from "../util/Snowflake.ts"; -import { iconHashToBigInt } from "../util/hash.ts"; +import type { DiscordRole } from "../../discordeno/mod.ts"; +import type { Session } from "../Session.ts"; +import { Snowflake } from "../Snowflake.ts"; import Permissions from "./Permissions.ts"; -import Guild, { ModifyGuildRole } from "./guilds/Guild.ts"; +import Util from "../Util.ts"; +import Guild, { type ModifyGuildRole } from "./guilds/Guild.ts"; export class Role implements Model { constructor(session: Session, data: DiscordRole, guildId: Snowflake) { @@ -12,7 +12,7 @@ export class Role implements Model { this.id = data.id; this.guildId = guildId; this.hoist = data.hoist; - this.iconHash = data.icon ? iconHashToBigInt(data.icon) : undefined; + this.iconHash = data.icon ? Util.iconHashToBigInt(data.icon) : undefined; this.color = data.color; this.name = data.name; this.unicodeEmoji = data.unicode_emoji; diff --git a/structures/StageInstance.ts b/packages/biscuit/structures/StageInstance.ts similarity index 90% rename from structures/StageInstance.ts rename to packages/biscuit/structures/StageInstance.ts index 5c2b91e..b087228 100644 --- a/structures/StageInstance.ts +++ b/packages/biscuit/structures/StageInstance.ts @@ -1,8 +1,8 @@ import type { Model } from "./Base.ts"; -import type { Session } from "../session/Session.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { DiscordStageInstance as DiscordAutoClosingStageInstance } from "../vendor/external.ts"; -import * as Routes from "../util/Routes.ts"; +import type { Session } from "../Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { DiscordStageInstance as DiscordAutoClosingStageInstance } from "../../discordeno/mod.ts"; +import * as Routes from "../Routes.ts"; interface DiscordStageInstance extends DiscordAutoClosingStageInstance { privacy_level: PrivacyLevels; diff --git a/structures/ThreadMember.ts b/packages/biscuit/structures/ThreadMember.ts similarity index 84% rename from structures/ThreadMember.ts rename to packages/biscuit/structures/ThreadMember.ts index 7679d88..416f21e 100644 --- a/structures/ThreadMember.ts +++ b/packages/biscuit/structures/ThreadMember.ts @@ -1,8 +1,8 @@ import type { Model } from "./Base.ts"; -import type { Session } from "../session/Session.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { DiscordThreadMember } from "../vendor/external.ts"; -import * as Routes from "../util/Routes.ts"; +import type { Session } from "../Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { DiscordThreadMember } from "../../discordeno/mod.ts"; +import * as Routes from "../Routes.ts"; /** * A member that comes from a thread diff --git a/structures/User.ts b/packages/biscuit/structures/User.ts similarity index 66% rename from structures/User.ts rename to packages/biscuit/structures/User.ts index da8c5ee..89d029b 100644 --- a/structures/User.ts +++ b/packages/biscuit/structures/User.ts @@ -1,11 +1,10 @@ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { DiscordUser } from "../vendor/external.ts"; -import type { ImageFormat, ImageSize } from "../util/shared/images.ts"; -import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts"; -import { formatImageURL } from "../util/shared/images.ts"; -import * as Routes from "../util/Routes.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordUser } from "../../discordeno/mod.ts"; +import type { ImageFormat, ImageSize } from "../Util.ts"; +import Util from "../Util.ts"; +import * as Routes from "../Routes.ts"; /** * Represents a user @@ -18,7 +17,7 @@ export class User implements Model { this.username = data.username; this.discriminator = data.discriminator; - this.avatarHash = data.avatar ? iconHashToBigInt(data.avatar) : undefined; + this.avatarHash = data.avatar ? Util.iconHashToBigInt(data.avatar) : undefined; this.accentColor = data.accent_color; this.bot = !!data.bot; this.system = !!data.system; @@ -48,10 +47,10 @@ export class User implements Model { if (!this.avatarHash) { url = Routes.USER_DEFAULT_AVATAR(Number(this.discriminator) % 5); } else { - url = Routes.USER_AVATAR(this.id, iconBigintToHash(this.avatarHash)); + url = Routes.USER_AVATAR(this.id, Util.iconBigintToHash(this.avatarHash)); } - return formatImageURL(url, options.size, options.format); + return Util.formatImageURL(url, options.size, options.format); } toString() { diff --git a/structures/Webhook.ts b/packages/biscuit/structures/Webhook.ts similarity index 89% rename from structures/Webhook.ts rename to packages/biscuit/structures/Webhook.ts index 629ac36..574da23 100644 --- a/structures/Webhook.ts +++ b/packages/biscuit/structures/Webhook.ts @@ -1,13 +1,13 @@ import type { Model } from "./Base.ts"; -import type { Session } from "../session/Session.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { DiscordMessage, DiscordWebhook, WebhookTypes } from "../vendor/external.ts"; -import type { WebhookOptions } from "../util/Routes.ts"; +import type { Session } from "../Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { DiscordMessage, DiscordWebhook, WebhookTypes } from "../../discordeno/mod.ts"; +import type { WebhookOptions } from "../Routes.ts"; import type { CreateMessage } from "./Message.ts"; -import { iconHashToBigInt } from "../util/hash.ts"; +import Util from "../Util.ts"; import User from "./User.ts"; import Message from "./Message.ts"; -import * as Routes from "../util/Routes.ts"; +import * as Routes from "../Routes.ts"; export class Webhook implements Model { constructor(session: Session, data: DiscordWebhook) { @@ -17,7 +17,7 @@ export class Webhook implements Model { this.token = data.token; if (data.avatar) { - this.avatar = iconHashToBigInt(data.avatar); + this.avatar = Util.iconHashToBigInt(data.avatar); } if (data.user) { diff --git a/structures/WelcomeChannel.ts b/packages/biscuit/structures/WelcomeChannel.ts similarity index 82% rename from structures/WelcomeChannel.ts rename to packages/biscuit/structures/WelcomeChannel.ts index b1bcb5d..f98f54f 100644 --- a/structures/WelcomeChannel.ts +++ b/packages/biscuit/structures/WelcomeChannel.ts @@ -1,7 +1,7 @@ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { DiscordWelcomeScreenChannel } from "../vendor/external.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordWelcomeScreenChannel } from "../../discordeno/mod.ts"; import Emoji from "./Emoji.ts"; /** diff --git a/structures/WelcomeScreen.ts b/packages/biscuit/structures/WelcomeScreen.ts similarity index 84% rename from structures/WelcomeScreen.ts rename to packages/biscuit/structures/WelcomeScreen.ts index af4b85a..6aca4fc 100644 --- a/structures/WelcomeScreen.ts +++ b/packages/biscuit/structures/WelcomeScreen.ts @@ -1,5 +1,5 @@ -import type { Session } from "../session/Session.ts"; -import type { DiscordWelcomeScreen } from "../vendor/external.ts"; +import type { Session } from "../Session.ts"; +import type { DiscordWelcomeScreen } from "../../discordeno/mod.ts"; import WelcomeChannel from "./WelcomeChannel.ts"; /** diff --git a/structures/builders/EmbedBuilder.ts b/packages/biscuit/structures/builders/EmbedBuilder.ts similarity index 98% rename from structures/builders/EmbedBuilder.ts rename to packages/biscuit/structures/builders/EmbedBuilder.ts index 8e48e78..d98700f 100644 --- a/structures/builders/EmbedBuilder.ts +++ b/packages/biscuit/structures/builders/EmbedBuilder.ts @@ -1,4 +1,4 @@ -import type { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from "../../vendor/external.ts"; +import type { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from "../../../discordeno/mod.ts"; export interface EmbedFooter { text: string; diff --git a/structures/builders/InputTextComponentBuilder.ts b/packages/biscuit/structures/builders/InputTextComponentBuilder.ts similarity index 90% rename from structures/builders/InputTextComponentBuilder.ts rename to packages/biscuit/structures/builders/InputTextComponentBuilder.ts index 3bba80d..b4c7e98 100644 --- a/structures/builders/InputTextComponentBuilder.ts +++ b/packages/biscuit/structures/builders/InputTextComponentBuilder.ts @@ -1,4 +1,4 @@ -import { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from "../../vendor/external.ts"; +import type { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from "../../../discordeno/mod.ts"; export class InputTextBuilder { constructor() { diff --git a/structures/builders/MessageActionRow.ts b/packages/biscuit/structures/builders/MessageActionRow.ts similarity index 74% rename from structures/builders/MessageActionRow.ts rename to packages/biscuit/structures/builders/MessageActionRow.ts index 856929a..262f2fc 100644 --- a/structures/builders/MessageActionRow.ts +++ b/packages/biscuit/structures/builders/MessageActionRow.ts @@ -1,7 +1,7 @@ -import { MessageComponentTypes } from "../../vendor/external.ts"; -import { AnyComponentBuilder } from "../../util/builders.ts"; +import type { MessageComponentTypes } from "../../../discordeno/mod.ts"; +import type { ComponentBuilder } from "../../Util.ts"; -export class ActionRowBuilder { +export class ActionRowBuilder { constructor() { this.components = [] as T[]; this.type = 1; diff --git a/structures/builders/MessageButton.ts b/packages/biscuit/structures/builders/MessageButton.ts similarity index 83% rename from structures/builders/MessageButton.ts rename to packages/biscuit/structures/builders/MessageButton.ts index 4ef0910..943012b 100644 --- a/structures/builders/MessageButton.ts +++ b/packages/biscuit/structures/builders/MessageButton.ts @@ -1,5 +1,5 @@ -import { ButtonStyles, type DiscordButtonComponent, MessageComponentTypes } from "../../vendor/external.ts"; -import { ComponentEmoji } from "../../util/builders.ts"; +import type { ButtonStyles, DiscordButtonComponent, MessageComponentTypes } from "../../../discordeno/mod.ts"; +import type { ComponentEmoji } from "../../Util.ts"; export class ButtonBuilder { constructor() { diff --git a/structures/builders/MessageSelectMenu.ts b/packages/biscuit/structures/builders/MessageSelectMenu.ts similarity index 86% rename from structures/builders/MessageSelectMenu.ts rename to packages/biscuit/structures/builders/MessageSelectMenu.ts index a932131..b8f1229 100644 --- a/structures/builders/MessageSelectMenu.ts +++ b/packages/biscuit/structures/builders/MessageSelectMenu.ts @@ -1,5 +1,5 @@ -import { type DiscordSelectMenuComponent, MessageComponentTypes } from "../../vendor/external.ts"; -import { SelectMenuOptionBuilder } from "./SelectMenuOptionBuilder.ts"; +import type { DiscordSelectMenuComponent, MessageComponentTypes } from "../../../discordeno/mod.ts"; +import type { SelectMenuOptionBuilder } from "./SelectMenuOptionBuilder.ts"; export class SelectMenuBuilder { constructor() { diff --git a/structures/builders/SelectMenuOptionBuilder.ts b/packages/biscuit/structures/builders/SelectMenuOptionBuilder.ts similarity index 84% rename from structures/builders/SelectMenuOptionBuilder.ts rename to packages/biscuit/structures/builders/SelectMenuOptionBuilder.ts index ad84ff6..56a1b1f 100644 --- a/structures/builders/SelectMenuOptionBuilder.ts +++ b/packages/biscuit/structures/builders/SelectMenuOptionBuilder.ts @@ -1,5 +1,5 @@ -import type { DiscordSelectOption } from "../../vendor/external.ts"; -import type { ComponentEmoji } from "../../util/builders.ts"; +import type { DiscordSelectOption } from "../../../discordeno/mod.ts"; +import type { ComponentEmoji } from "../../Util.ts"; export class SelectMenuOptionBuilder { constructor() { diff --git a/structures/channels.ts b/packages/biscuit/structures/channels.ts similarity index 95% rename from structures/channels.ts rename to packages/biscuit/structures/channels.ts index 35f7a63..ee4bad8 100644 --- a/structures/channels.ts +++ b/packages/biscuit/structures/channels.ts @@ -1,7 +1,8 @@ /** Types */ import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import type { PermissionsOverwrites } from "../Util.ts"; /** External from vendor */ import { @@ -14,22 +15,21 @@ import { DiscordWebhook, TargetTypes, DiscordInviteMetadata, -DiscordThreadMember, -DiscordListArchivedThreads -} from "../vendor/external.ts"; + DiscordThreadMember, + DiscordListArchivedThreads +} from "../../discordeno/mod.ts"; /** Functions and others */ -import { calculateShardId } from "../vendor/gateway/calculateShardId.ts"; +import { calculateShardId } from "../../discordeno/gateway/calculateShardId.ts"; import { urlToBase64 } from "../util/urlToBase64.ts"; /** Classes and routes */ -import * as Routes from "../util/Routes.ts"; +import * as Routes from "../Routes.ts"; import Message, { CreateMessage, EditMessage, ReactionResolvable } from "./Message.ts"; import Invite from "./Invite.ts"; import Webhook from "./Webhook.ts"; import User from "./User.ts"; import ThreadMember from "./ThreadMember.ts"; -import { PermissionsOverwrites } from "../util/permissions.ts"; export abstract class BaseChannel implements Model { constructor(session: Session, data: DiscordChannel) { @@ -688,4 +688,4 @@ export class ChannelFactory { throw new Error("Channel was not implemented"); } } -} \ No newline at end of file +} diff --git a/structures/components/ActionRowComponent.ts b/packages/biscuit/structures/components/ActionRowComponent.ts similarity index 88% rename from structures/components/ActionRowComponent.ts rename to packages/biscuit/structures/components/ActionRowComponent.ts index 8825553..f14feac 100644 --- a/structures/components/ActionRowComponent.ts +++ b/packages/biscuit/structures/components/ActionRowComponent.ts @@ -1,7 +1,7 @@ -import type { Session } from "../../session/Session.ts"; -import type { DiscordComponent } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordComponent } from "../../../discordeno/mod.ts"; import type { ActionRowComponent, Component } from "./Component.ts"; -import { ButtonStyles, MessageComponentTypes } from "../../vendor/external.ts"; +import { ButtonStyles, MessageComponentTypes } from "../../../discordeno/mod.ts"; import BaseComponent from "./Component.ts"; import Button from "./ButtonComponent.ts"; import LinkButton from "./LinkButtonComponent.ts"; diff --git a/structures/components/ButtonComponent.ts b/packages/biscuit/structures/components/ButtonComponent.ts similarity index 82% rename from structures/components/ButtonComponent.ts rename to packages/biscuit/structures/components/ButtonComponent.ts index 903e6ec..c690d33 100644 --- a/structures/components/ButtonComponent.ts +++ b/packages/biscuit/structures/components/ButtonComponent.ts @@ -1,7 +1,7 @@ -import type { Session } from "../../session/Session.ts"; -import type { ButtonStyles, DiscordComponent } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { ButtonStyles, DiscordComponent } from "../../../discordeno/mod.ts"; import type { ButtonComponent } from "./Component.ts"; -import { MessageComponentTypes } from "../../vendor/external.ts"; +import { MessageComponentTypes } from "../../../discordeno/mod.ts"; import BaseComponent from "./Component.ts"; import Emoji from "../Emoji.ts"; diff --git a/structures/components/Component.ts b/packages/biscuit/structures/components/Component.ts similarity index 98% rename from structures/components/Component.ts rename to packages/biscuit/structures/components/Component.ts index 74e70d9..89d7b63 100644 --- a/structures/components/Component.ts +++ b/packages/biscuit/structures/components/Component.ts @@ -1,5 +1,5 @@ import type Emoji from "../Emoji.ts"; -import { ButtonStyles, MessageComponentTypes, TextStyles } from "../../vendor/external.ts"; +import { ButtonStyles, MessageComponentTypes, TextStyles } from "../../../discordeno/mod.ts"; export class BaseComponent { constructor(type: MessageComponentTypes) { diff --git a/structures/components/ComponentFactory.ts b/packages/biscuit/structures/components/ComponentFactory.ts similarity index 84% rename from structures/components/ComponentFactory.ts rename to packages/biscuit/structures/components/ComponentFactory.ts index 2a5d60a..9b4c51e 100644 --- a/structures/components/ComponentFactory.ts +++ b/packages/biscuit/structures/components/ComponentFactory.ts @@ -1,7 +1,7 @@ -import type { Session } from "../../session/Session.ts"; -import type { DiscordComponent } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordComponent } from "../../../discordeno/mod.ts" import type { Component } from "./Component.ts"; -import { ButtonStyles, MessageComponentTypes } from "../../vendor/external.ts"; +import { ButtonStyles, MessageComponentTypes } from "../../../discordeno/mod.ts"; import ActionRow from "./ActionRowComponent.ts"; import Button from "./ButtonComponent.ts"; import LinkButton from "./ButtonComponent.ts"; diff --git a/structures/components/LinkButtonComponent.ts b/packages/biscuit/structures/components/LinkButtonComponent.ts similarity index 80% rename from structures/components/LinkButtonComponent.ts rename to packages/biscuit/structures/components/LinkButtonComponent.ts index ad3e53b..d6375e9 100644 --- a/structures/components/LinkButtonComponent.ts +++ b/packages/biscuit/structures/components/LinkButtonComponent.ts @@ -1,7 +1,7 @@ -import type { Session } from "../../session/Session.ts"; -import type { ButtonStyles, DiscordComponent } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { ButtonStyles, DiscordComponent } from "../../../discordeno/mod.ts"; import type { LinkButtonComponent } from "./Component.ts"; -import { MessageComponentTypes } from "../../vendor/external.ts"; +import { MessageComponentTypes } from "../../../discordeno/mod.ts"; import BaseComponent from "./Component.ts"; import Emoji from "../Emoji.ts"; diff --git a/structures/components/SelectMenuComponent.ts b/packages/biscuit/structures/components/SelectMenuComponent.ts similarity index 86% rename from structures/components/SelectMenuComponent.ts rename to packages/biscuit/structures/components/SelectMenuComponent.ts index 846104b..25bb6d8 100644 --- a/structures/components/SelectMenuComponent.ts +++ b/packages/biscuit/structures/components/SelectMenuComponent.ts @@ -1,7 +1,7 @@ -import type { Session } from "../../session/Session.ts"; -import type { DiscordComponent } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordComponent } from "../../../discordeno/mod.ts"; import type { SelectMenuComponent, SelectMenuOption } from "./Component.ts"; -import { MessageComponentTypes } from "../../vendor/external.ts"; +import { MessageComponentTypes } from "../../../discordeno/mod.ts"; import BaseComponent from "./Component.ts"; import Emoji from "../Emoji.ts"; diff --git a/structures/components/TextInputComponent.ts b/packages/biscuit/structures/components/TextInputComponent.ts similarity index 83% rename from structures/components/TextInputComponent.ts rename to packages/biscuit/structures/components/TextInputComponent.ts index 27abfa3..1a7846b 100644 --- a/structures/components/TextInputComponent.ts +++ b/packages/biscuit/structures/components/TextInputComponent.ts @@ -1,7 +1,7 @@ -import type { Session } from "../../session/Session.ts"; -import type { DiscordComponent } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordComponent } from "../../../discordeno/mod.ts"; import type { TextInputComponent } from "./Component.ts"; -import { MessageComponentTypes, TextStyles } from "../../vendor/external.ts"; +import { MessageComponentTypes, TextStyles } from "../../../discordeno/mod.ts"; import BaseComponent from "./Component.ts"; export class TextInput extends BaseComponent implements TextInputComponent { diff --git a/structures/guilds/AnonymousGuild.ts b/packages/biscuit/structures/guilds/AnonymousGuild.ts similarity index 67% rename from structures/guilds/AnonymousGuild.ts rename to packages/biscuit/structures/guilds/AnonymousGuild.ts index 995078b..dd5715f 100644 --- a/structures/guilds/AnonymousGuild.ts +++ b/packages/biscuit/structures/guilds/AnonymousGuild.ts @@ -1,19 +1,18 @@ import type { Model } from "../Base.ts"; -import type { Session } from "../../session/Session.ts"; -import type { DiscordGuild, GuildNsfwLevel, VerificationLevels } from "../../vendor/external.ts"; -import type { ImageFormat, ImageSize } from "../../util/shared/images.ts"; -import { iconBigintToHash, iconHashToBigInt } from "../../util/hash.ts"; -import { formatImageURL } from "../../util/shared/images.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordGuild, GuildNsfwLevel, VerificationLevels } from "../../../discordeno/mod.ts"; +import type { ImageFormat, ImageSize } from "../../Util.ts"; +import Util from "../../Util.ts"; import BaseGuild from "./BaseGuild.ts"; -import * as Routes from "../../util/Routes.ts"; +import * as Routes from "../../Routes.ts"; export class AnonymousGuild extends BaseGuild implements Model { constructor(session: Session, data: Partial); // TODO: Improve this type (name and id are required) constructor(session: Session, data: DiscordGuild) { super(session, data); - this.splashHash = data.splash ? iconHashToBigInt(data.splash) : undefined; - this.bannerHash = data.banner ? iconHashToBigInt(data.banner) : undefined; + this.splashHash = data.splash ? Util.iconHashToBigInt(data.splash) : undefined; + this.bannerHash = data.banner ? Util.iconHashToBigInt(data.banner) : undefined; this.verificationLevel = data.verification_level; this.vanityUrlCode = data.vanity_url_code ? data.vanity_url_code : undefined; @@ -33,8 +32,8 @@ export class AnonymousGuild extends BaseGuild implements Model { splashURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) { if (this.splashHash) { - return formatImageURL( - Routes.GUILD_SPLASH(this.id, iconBigintToHash(this.splashHash)), + return Util.formatImageURL( + Routes.GUILD_SPLASH(this.id, Util.iconBigintToHash(this.splashHash)), options.size, options.format, ); @@ -44,7 +43,7 @@ export class AnonymousGuild extends BaseGuild implements Model { bannerURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) { if (this.bannerHash) { return formatImageURL( - Routes.GUILD_BANNER(this.id, iconBigintToHash(this.bannerHash)), + Routes.GUILD_BANNER(this.id, Util.iconBigintToHash(this.bannerHash)), options.size, options.format, ); diff --git a/structures/guilds/BaseGuild.ts b/packages/biscuit/structures/guilds/BaseGuild.ts similarity index 62% rename from structures/guilds/BaseGuild.ts rename to packages/biscuit/structures/guilds/BaseGuild.ts index 31dca44..f8ed183 100644 --- a/structures/guilds/BaseGuild.ts +++ b/packages/biscuit/structures/guilds/BaseGuild.ts @@ -1,12 +1,11 @@ import type { Model } from "../Base.ts"; -import type { Session } from "../../session/Session.ts"; -import type { DiscordGuild } from "../../vendor/external.ts"; -import type { ImageFormat, ImageSize } from "../../util/shared/images.ts"; -import { formatImageURL } from "../../util/shared/images.ts"; -import { iconBigintToHash, iconHashToBigInt } from "../../util/hash.ts"; -import { GuildFeatures } from "../../vendor/external.ts"; -import { Snowflake } from "../../util/Snowflake.ts"; -import * as Routes from "../../util/Routes.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordGuild } from "../../../discordeno/mod.ts"; +import type { ImageFormat, ImageSize } from "../../Util.ts"; +import { GuildFeatures } from "../../../discordeno/mod.ts"; +import { Snowflake } from "../../Snowflake.ts"; +import Util from "../../Util.ts"; +import * as Routes from "../../Routes.ts"; /** * Class for {@link Guild} and {@link AnonymousGuild} @@ -17,7 +16,7 @@ export abstract class BaseGuild implements Model { this.id = data.id; this.name = data.name; - this.iconHash = data.icon ? iconHashToBigInt(data.icon) : undefined; + this.iconHash = data.icon ? Util.iconHashToBigInt(data.icon) : undefined; this.features = data.features; } @@ -47,8 +46,8 @@ export abstract class BaseGuild implements Model { iconURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) { if (this.iconHash) { - return formatImageURL( - Routes.GUILD_ICON(this.id, iconBigintToHash(this.iconHash)), + return Util.formatImageURL( + Routes.GUILD_ICON(this.id, Util.iconBigintToHash(this.iconHash)), options.size, options.format, ); diff --git a/structures/guilds/Guild.ts b/packages/biscuit/structures/guilds/Guild.ts similarity index 94% rename from structures/guilds/Guild.ts rename to packages/biscuit/structures/guilds/Guild.ts index bae102c..53ea0a6 100644 --- a/structures/guilds/Guild.ts +++ b/packages/biscuit/structures/guilds/Guild.ts @@ -1,6 +1,6 @@ import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; +import type { Snowflake } from "../../Snowflake.ts"; +import type { Session } from "../../Session.ts"; import type { ChannelTypes, DiscordEmoji, @@ -14,23 +14,23 @@ import type { MakeRequired, SystemChannelFlags, VideoQualityModes, -} from "../../vendor/external.ts"; -import type { GetInvite } from "../../util/Routes.ts"; +} from "../../../discordeno/mod.ts"; +import type { GetInvite } from "../../Routes.ts"; import { DefaultMessageNotificationLevels, ExplicitContentFilterLevels, VerificationLevels, -} from "../../vendor/external.ts"; -import { iconBigintToHash, iconHashToBigInt } from "../../util/hash.ts"; +} from "../../../discordeno/mod.ts"; import { encode as _encode, urlToBase64 } from "../../util/urlToBase64.ts"; +import { ThreadChannel } from "../channels.ts"; +import Util from "../../Util.ts"; import Member from "../Member.ts"; import BaseGuild from "./BaseGuild.ts"; import Role from "../Role.ts"; import GuildEmoji from "../GuildEmoji.ts"; import Invite from "../Invite.ts"; import ThreadMember from "../ThreadMember.ts"; -import ThreadChannel from "../channels/ThreadChannel.ts"; -import * as Routes from "../../util/Routes.ts"; +import * as Routes from "../../Routes.ts"; export interface CreateRole { name?: string; @@ -200,8 +200,8 @@ export class Guild extends BaseGuild implements Model { constructor(session: Session, data: DiscordGuild) { super(session, data); - this.splashHash = data.splash ? iconHashToBigInt(data.splash) : undefined; - this.discoverySplashHash = data.discovery_splash ? iconHashToBigInt(data.discovery_splash) : undefined; + this.splashHash = data.splash ? Util.iconHashToBigInt(data.splash) : undefined; + this.discoverySplashHash = data.discovery_splash ? Util.iconHashToBigInt(data.discovery_splash) : undefined; this.ownerId = data.owner_id; this.widgetEnabled = !!data.widget_enabled; this.widgetChannelId = data.widget_channel_id ? data.widget_channel_id : undefined; @@ -282,7 +282,7 @@ export class Guild extends BaseGuild implements Model { if (typeof options.iconHash === "string") { icon = options.iconHash; } else { - icon = iconBigintToHash(options.iconHash); + icon = Util.iconBigintToHash(options.iconHash); } } @@ -519,7 +519,7 @@ export class Guild extends BaseGuild implements Model { verification_level: options.verificationLevel, icon: "iconURL" in options ? options.iconURL || urlToBase64(options.iconURL!) - : options.iconHash || iconBigintToHash(options.iconHash!), + : options.iconHash || Util.iconBigintToHash(options.iconHash!), channels: options.channels?.map((channel) => ({ name: channel.name, nsfw: channel.nsfw, @@ -561,17 +561,17 @@ export class Guild extends BaseGuild implements Model { verification_level: options.verificationLevel, icon: "iconURL" in options ? options.iconURL || urlToBase64(options.iconURL!) - : options.iconHash || iconBigintToHash(options.iconHash!), + : options.iconHash || Util.iconBigintToHash(options.iconHash!), // extra props splash: "splashURL" in options ? options.splashURL || urlToBase64(options.splashURL!) - : options.splashHash || iconBigintToHash(options.iconHash!), + : options.splashHash || Util.iconBigintToHash(options.iconHash!), banner: "bannerURL" in options ? options.bannerURL || urlToBase64(options.bannerURL!) - : options.bannerHash || iconBigintToHash(options.bannerHash!), + : options.bannerHash || Util.iconBigintToHash(options.bannerHash!), discovery_splash: "discoverySplashURL" in options ? options.discoverySplashURL || urlToBase64(options.discoverySplashURL!) - : options.discoverySplashHash || iconBigintToHash(options.discoverySplashHash!), + : options.discoverySplashHash || Util.iconBigintToHash(options.discoverySplashHash!), owner_id: options.ownerId, rules_channel_id: options.rulesChannelId, public_updates_channel_id: options.publicUpdatesChannelId, diff --git a/structures/guilds/InviteGuild.ts b/packages/biscuit/structures/guilds/InviteGuild.ts similarity index 80% rename from structures/guilds/InviteGuild.ts rename to packages/biscuit/structures/guilds/InviteGuild.ts index 85e3d50..761199c 100644 --- a/structures/guilds/InviteGuild.ts +++ b/packages/biscuit/structures/guilds/InviteGuild.ts @@ -1,6 +1,6 @@ import type { Model } from "../Base.ts"; -import type { Session } from "../../session/Session.ts"; -import type { DiscordGuild } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordGuild } from "../../../discordeno/mod.ts"; import AnonymousGuild from "./AnonymousGuild.ts"; import WelcomeScreen from "../WelcomeScreen.ts"; diff --git a/structures/interactions/AutoCompleteInteraction.ts b/packages/biscuit/structures/interactions/AutoCompleteInteraction.ts similarity index 81% rename from structures/interactions/AutoCompleteInteraction.ts rename to packages/biscuit/structures/interactions/AutoCompleteInteraction.ts index 7fe886e..9f61c06 100644 --- a/structures/interactions/AutoCompleteInteraction.ts +++ b/packages/biscuit/structures/interactions/AutoCompleteInteraction.ts @@ -1,11 +1,11 @@ import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ApplicationCommandTypes, DiscordInteraction, InteractionTypes } from "../../vendor/external.ts"; +import type { Snowflake } from "../../Snowflake.ts"; +import type { Session } from "../../Session.ts"; +import type { ApplicationCommandTypes, DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts"; import type { ApplicationCommandOptionChoice } from "./CommandInteraction.ts"; -import { InteractionResponseTypes } from "../../vendor/external.ts"; +import { InteractionResponseTypes } from "../../../discordeno/mod.ts"; import BaseInteraction from "./BaseInteraction.ts"; -import * as Routes from "../../util/Routes.ts"; +import * as Routes from "../../Routes.ts"; export class AutoCompleteInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { diff --git a/structures/interactions/BaseInteraction.ts b/packages/biscuit/structures/interactions/BaseInteraction.ts similarity index 89% rename from structures/interactions/BaseInteraction.ts rename to packages/biscuit/structures/interactions/BaseInteraction.ts index a93ca8f..880ba6a 100644 --- a/structures/interactions/BaseInteraction.ts +++ b/packages/biscuit/structures/interactions/BaseInteraction.ts @@ -1,10 +1,10 @@ import type { Model } from "../Base.ts"; -import type { Session } from "../../session/Session.ts"; -import type { DiscordInteraction } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordInteraction } from "../../../discordeno/mod.ts"; import type CommandInteraction from "./CommandInteraction.ts"; import type PingInteraction from "./PingInteraction.ts"; -import { InteractionTypes } from "../../vendor/external.ts"; -import { Snowflake } from "../../util/Snowflake.ts"; +import { InteractionTypes } from "../../../discordeno/mod.ts"; +import { Snowflake } from "../../Snowflake.ts"; import User from "../User.ts"; import Member from "../Member.ts"; import Permsisions from "../Permissions.ts"; diff --git a/structures/interactions/CommandInteraction.ts b/packages/biscuit/structures/interactions/CommandInteraction.ts similarity index 94% rename from structures/interactions/CommandInteraction.ts rename to packages/biscuit/structures/interactions/CommandInteraction.ts index 40bce4e..ea80ee9 100644 --- a/structures/interactions/CommandInteraction.ts +++ b/packages/biscuit/structures/interactions/CommandInteraction.ts @@ -1,15 +1,15 @@ import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; +import type { Snowflake } from "../../Snowflake.ts"; +import type { Session } from "../../Session.ts"; import type { ApplicationCommandTypes, DiscordInteraction, DiscordMemberWithUser, InteractionTypes, -} from "../../vendor/external.ts"; +} from "../../../discordeno/mod.ts"; import type { CreateMessage } from "../Message.ts"; -import type { MessageFlags } from "../../util/shared/flags.ts"; -import { InteractionResponseTypes } from "../../vendor/external.ts"; +import type { MessageFlags } from "../../Util.ts"; +import { InteractionResponseTypes } from "../../../discordeno/mod.ts"; import BaseInteraction from "./BaseInteraction.ts"; import CommandInteractionOptionResolver from "./CommandInteractionOptionResolver.ts"; import Attachment from "../Attachment.ts"; @@ -18,7 +18,7 @@ import Member from "../Member.ts"; import Message from "../Message.ts"; import Role from "../Role.ts"; import Webhook from "../Webhook.ts"; -import * as Routes from "../../util/Routes.ts"; +import * as Routes from "../../Routes.ts"; /** * @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response diff --git a/structures/interactions/CommandInteractionOptionResolver.ts b/packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts similarity index 98% rename from structures/interactions/CommandInteractionOptionResolver.ts rename to packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts index 0f5f848..8e1cde8 100644 --- a/structures/interactions/CommandInteractionOptionResolver.ts +++ b/packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts @@ -1,5 +1,5 @@ -import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from "../../vendor/external.ts"; -import { ApplicationCommandOptionTypes } from "../../vendor/external.ts"; +import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from "../../../discordeno/mod.ts"; +import { ApplicationCommandOptionTypes } from "../../../discordeno/mod.ts"; export function transformOasisInteractionDataOption(o: DiscordInteractionDataOption): CommandInteractionOption { const output: CommandInteractionOption = { ...o, Otherwise: o.value as string | boolean | number | undefined }; diff --git a/structures/interactions/ComponentInteraction.ts b/packages/biscuit/structures/interactions/ComponentInteraction.ts similarity index 86% rename from structures/interactions/ComponentInteraction.ts rename to packages/biscuit/structures/interactions/ComponentInteraction.ts index a85524f..c59b98e 100644 --- a/structures/interactions/ComponentInteraction.ts +++ b/packages/biscuit/structures/interactions/ComponentInteraction.ts @@ -1,8 +1,8 @@ import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { DiscordInteraction, InteractionTypes } from "../../vendor/external.ts"; -import { MessageComponentTypes } from "../../vendor/external.ts"; +import type { Snowflake } from "../../Snowflake.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts"; +import { MessageComponentTypes } from "../../../discordeno/mod.ts"; import BaseInteraction from "./BaseInteraction.ts"; import Message from "../Message.ts"; diff --git a/structures/interactions/InteractionFactory.ts b/packages/biscuit/structures/interactions/InteractionFactory.ts similarity index 87% rename from structures/interactions/InteractionFactory.ts rename to packages/biscuit/structures/interactions/InteractionFactory.ts index 386d23d..aeb5ab3 100644 --- a/structures/interactions/InteractionFactory.ts +++ b/packages/biscuit/structures/interactions/InteractionFactory.ts @@ -1,6 +1,6 @@ -import type { Session } from "../../session/Session.ts"; -import type { DiscordInteraction } from "../../vendor/external.ts"; -import { InteractionTypes } from "../../vendor/external.ts"; +import type { Session } from "../../Session.ts"; +import type { DiscordInteraction } from "../../../discordeno/mod.ts"; +import { InteractionTypes } from "../../../discordeno/mod.ts"; import CommandInteraction from "./CommandInteraction.ts"; import ComponentInteraction from "./ComponentInteraction.ts"; import PingInteraction from "./PingInteraction.ts"; diff --git a/structures/interactions/ModalSubmitInteraction.ts b/packages/biscuit/structures/interactions/ModalSubmitInteraction.ts similarity index 91% rename from structures/interactions/ModalSubmitInteraction.ts rename to packages/biscuit/structures/interactions/ModalSubmitInteraction.ts index 4d5f6df..fa7fa88 100644 --- a/structures/interactions/ModalSubmitInteraction.ts +++ b/packages/biscuit/structures/interactions/ModalSubmitInteraction.ts @@ -1,12 +1,12 @@ import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; +import type { Snowflake } from "../../Snowflake.ts"; +import type { Session } from "../../Session.ts"; import type { DiscordInteraction, DiscordMessageComponents, InteractionTypes, MessageComponentTypes, -} from "../../vendor/external.ts"; +} from "../../../discordeno/mod.ts"; import BaseInteraction from "./BaseInteraction.ts"; import Message from "../Message.ts"; diff --git a/structures/interactions/PingInteraction.ts b/packages/biscuit/structures/interactions/PingInteraction.ts similarity index 78% rename from structures/interactions/PingInteraction.ts rename to packages/biscuit/structures/interactions/PingInteraction.ts index a335f7c..7dc4774 100644 --- a/structures/interactions/PingInteraction.ts +++ b/packages/biscuit/structures/interactions/PingInteraction.ts @@ -1,10 +1,10 @@ import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ApplicationCommandTypes, DiscordInteraction, InteractionTypes } from "../../vendor/external.ts"; -import { InteractionResponseTypes } from "../../vendor/external.ts"; +import type { Snowflake } from "../../Snowflake.ts"; +import type { Session } from "../../Session.ts"; +import type { ApplicationCommandTypes, DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts"; +import { InteractionResponseTypes } from "../../../discordeno/mod.ts"; import BaseInteraction from "./BaseInteraction.ts"; -import * as Routes from "../../util/Routes.ts"; +import * as Routes from "../../Routes.ts"; export class PingInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { diff --git a/packages/biscuit/tests/deps.ts b/packages/biscuit/tests/deps.ts new file mode 100644 index 0000000..d927393 --- /dev/null +++ b/packages/biscuit/tests/deps.ts @@ -0,0 +1,2 @@ +export * from "../mod.ts"; +export * from "../../discordeno/mod.ts"; diff --git a/tests/mod.ts b/packages/biscuit/tests/mod.ts similarity index 100% rename from tests/mod.ts rename to packages/biscuit/tests/mod.ts diff --git a/util/EventEmmiter.ts b/packages/biscuit/util/EventEmmiter.ts similarity index 100% rename from util/EventEmmiter.ts rename to packages/biscuit/util/EventEmmiter.ts diff --git a/util/urlToBase64.ts b/packages/biscuit/util/urlToBase64.ts similarity index 74% rename from util/urlToBase64.ts rename to packages/biscuit/util/urlToBase64.ts index 94d4733..43b443c 100644 --- a/util/urlToBase64.ts +++ b/packages/biscuit/util/urlToBase64.ts @@ -7,71 +7,29 @@ export async function urlToBase64(url: string) { } // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// deno-fmt-ignore const base64abc = [ - "A", - "B", - "C", - "D", - "E", - "F", - "G", - "H", - "I", - "J", - "K", - "L", - "M", - "N", - "O", - "P", - "Q", - "R", - "S", - "T", - "U", - "V", - "W", - "X", - "Y", - "Z", - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "+", - "/", + "A", "B", "C", + "D", "E", "F", + "G", "H", "I", + "J", "K", "L", + "M", "N", "O", + "P", "Q", "R", + "S", "T", "U", + "V", "W", "X", + "Y", "Z", "a", + "b", "c", "d", + "e", "f", "g", + "h", "i", "j", + "k", "l", "m", + "n", "o", "p", + "q", "r", "s", + "t", "u", "v", + "w", "x", "y", + "z", "0", "1", + "2", "3", "4", + "5", "6", "7", + "8", "9", "+", "/", ]; /** diff --git a/vendor/gateway/README.md b/packages/discordeno/gateway/README.md similarity index 100% rename from vendor/gateway/README.md rename to packages/discordeno/gateway/README.md diff --git a/vendor/gateway/calculateShardId.ts b/packages/discordeno/gateway/calculateShardId.ts similarity index 100% rename from vendor/gateway/calculateShardId.ts rename to packages/discordeno/gateway/calculateShardId.ts diff --git a/vendor/gateway/manager/calculateTotalShards.ts b/packages/discordeno/gateway/manager/calculateTotalShards.ts similarity index 100% rename from vendor/gateway/manager/calculateTotalShards.ts rename to packages/discordeno/gateway/manager/calculateTotalShards.ts diff --git a/vendor/gateway/manager/calculateWorkerId.ts b/packages/discordeno/gateway/manager/calculateWorkerId.ts similarity index 100% rename from vendor/gateway/manager/calculateWorkerId.ts rename to packages/discordeno/gateway/manager/calculateWorkerId.ts diff --git a/vendor/gateway/manager/gatewayManager.ts b/packages/discordeno/gateway/manager/gatewayManager.ts similarity index 100% rename from vendor/gateway/manager/gatewayManager.ts rename to packages/discordeno/gateway/manager/gatewayManager.ts diff --git a/vendor/gateway/manager/mod.ts b/packages/discordeno/gateway/manager/mod.ts similarity index 100% rename from vendor/gateway/manager/mod.ts rename to packages/discordeno/gateway/manager/mod.ts diff --git a/vendor/gateway/manager/prepareBuckets.ts b/packages/discordeno/gateway/manager/prepareBuckets.ts similarity index 100% rename from vendor/gateway/manager/prepareBuckets.ts rename to packages/discordeno/gateway/manager/prepareBuckets.ts diff --git a/vendor/gateway/manager/resharder.ts b/packages/discordeno/gateway/manager/resharder.ts similarity index 100% rename from vendor/gateway/manager/resharder.ts rename to packages/discordeno/gateway/manager/resharder.ts diff --git a/vendor/gateway/manager/shardManager.ts b/packages/discordeno/gateway/manager/shardManager.ts similarity index 100% rename from vendor/gateway/manager/shardManager.ts rename to packages/discordeno/gateway/manager/shardManager.ts diff --git a/vendor/gateway/manager/spawnShards.ts b/packages/discordeno/gateway/manager/spawnShards.ts similarity index 100% rename from vendor/gateway/manager/spawnShards.ts rename to packages/discordeno/gateway/manager/spawnShards.ts diff --git a/vendor/gateway/manager/stop.ts b/packages/discordeno/gateway/manager/stop.ts similarity index 100% rename from vendor/gateway/manager/stop.ts rename to packages/discordeno/gateway/manager/stop.ts diff --git a/vendor/gateway/manager/tellWorkerToIdentify.ts b/packages/discordeno/gateway/manager/tellWorkerToIdentify.ts similarity index 100% rename from vendor/gateway/manager/tellWorkerToIdentify.ts rename to packages/discordeno/gateway/manager/tellWorkerToIdentify.ts diff --git a/vendor/gateway/mod.ts b/packages/discordeno/gateway/mod.ts similarity index 100% rename from vendor/gateway/mod.ts rename to packages/discordeno/gateway/mod.ts diff --git a/vendor/gateway/shard/calculateSafeRequests.ts b/packages/discordeno/gateway/shard/calculateSafeRequests.ts similarity index 100% rename from vendor/gateway/shard/calculateSafeRequests.ts rename to packages/discordeno/gateway/shard/calculateSafeRequests.ts diff --git a/vendor/gateway/shard/close.ts b/packages/discordeno/gateway/shard/close.ts similarity index 100% rename from vendor/gateway/shard/close.ts rename to packages/discordeno/gateway/shard/close.ts diff --git a/vendor/gateway/shard/connect.ts b/packages/discordeno/gateway/shard/connect.ts similarity index 100% rename from vendor/gateway/shard/connect.ts rename to packages/discordeno/gateway/shard/connect.ts diff --git a/vendor/gateway/shard/createShard.ts b/packages/discordeno/gateway/shard/createShard.ts similarity index 100% rename from vendor/gateway/shard/createShard.ts rename to packages/discordeno/gateway/shard/createShard.ts diff --git a/vendor/gateway/shard/deps.ts b/packages/discordeno/gateway/shard/deps.ts similarity index 100% rename from vendor/gateway/shard/deps.ts rename to packages/discordeno/gateway/shard/deps.ts diff --git a/vendor/gateway/shard/handleClose.ts b/packages/discordeno/gateway/shard/handleClose.ts similarity index 100% rename from vendor/gateway/shard/handleClose.ts rename to packages/discordeno/gateway/shard/handleClose.ts diff --git a/vendor/gateway/shard/handleMessage.ts b/packages/discordeno/gateway/shard/handleMessage.ts similarity index 100% rename from vendor/gateway/shard/handleMessage.ts rename to packages/discordeno/gateway/shard/handleMessage.ts diff --git a/vendor/gateway/shard/identify.ts b/packages/discordeno/gateway/shard/identify.ts similarity index 100% rename from vendor/gateway/shard/identify.ts rename to packages/discordeno/gateway/shard/identify.ts diff --git a/vendor/gateway/shard/isOpen.ts b/packages/discordeno/gateway/shard/isOpen.ts similarity index 100% rename from vendor/gateway/shard/isOpen.ts rename to packages/discordeno/gateway/shard/isOpen.ts diff --git a/vendor/gateway/shard/mod.ts b/packages/discordeno/gateway/shard/mod.ts similarity index 100% rename from vendor/gateway/shard/mod.ts rename to packages/discordeno/gateway/shard/mod.ts diff --git a/vendor/gateway/shard/resume.ts b/packages/discordeno/gateway/shard/resume.ts similarity index 100% rename from vendor/gateway/shard/resume.ts rename to packages/discordeno/gateway/shard/resume.ts diff --git a/vendor/gateway/shard/send.ts b/packages/discordeno/gateway/shard/send.ts similarity index 100% rename from vendor/gateway/shard/send.ts rename to packages/discordeno/gateway/shard/send.ts diff --git a/vendor/gateway/shard/shutdown.ts b/packages/discordeno/gateway/shard/shutdown.ts similarity index 100% rename from vendor/gateway/shard/shutdown.ts rename to packages/discordeno/gateway/shard/shutdown.ts diff --git a/vendor/gateway/shard/startHeartbeating.ts b/packages/discordeno/gateway/shard/startHeartbeating.ts similarity index 100% rename from vendor/gateway/shard/startHeartbeating.ts rename to packages/discordeno/gateway/shard/startHeartbeating.ts diff --git a/vendor/gateway/shard/stopHeartbeating.ts b/packages/discordeno/gateway/shard/stopHeartbeating.ts similarity index 100% rename from vendor/gateway/shard/stopHeartbeating.ts rename to packages/discordeno/gateway/shard/stopHeartbeating.ts diff --git a/vendor/gateway/shard/types.ts b/packages/discordeno/gateway/shard/types.ts similarity index 100% rename from vendor/gateway/shard/types.ts rename to packages/discordeno/gateway/shard/types.ts diff --git a/vendor/external.ts b/packages/discordeno/mod.ts similarity index 100% rename from vendor/external.ts rename to packages/discordeno/mod.ts diff --git a/vendor/rest/README.md b/packages/discordeno/rest/README.md similarity index 100% rename from vendor/rest/README.md rename to packages/discordeno/rest/README.md diff --git a/vendor/rest/checkRateLimits.ts b/packages/discordeno/rest/checkRateLimits.ts similarity index 100% rename from vendor/rest/checkRateLimits.ts rename to packages/discordeno/rest/checkRateLimits.ts diff --git a/vendor/rest/cleanupQueues.ts b/packages/discordeno/rest/cleanupQueues.ts similarity index 100% rename from vendor/rest/cleanupQueues.ts rename to packages/discordeno/rest/cleanupQueues.ts diff --git a/vendor/rest/convertRestError.ts b/packages/discordeno/rest/convertRestError.ts similarity index 100% rename from vendor/rest/convertRestError.ts rename to packages/discordeno/rest/convertRestError.ts diff --git a/vendor/rest/createRequestBody.ts b/packages/discordeno/rest/createRequestBody.ts similarity index 100% rename from vendor/rest/createRequestBody.ts rename to packages/discordeno/rest/createRequestBody.ts diff --git a/vendor/rest/mod.ts b/packages/discordeno/rest/mod.ts similarity index 100% rename from vendor/rest/mod.ts rename to packages/discordeno/rest/mod.ts diff --git a/vendor/rest/processGlobalQueue.ts b/packages/discordeno/rest/processGlobalQueue.ts similarity index 100% rename from vendor/rest/processGlobalQueue.ts rename to packages/discordeno/rest/processGlobalQueue.ts diff --git a/vendor/rest/processQueue.ts b/packages/discordeno/rest/processQueue.ts similarity index 100% rename from vendor/rest/processQueue.ts rename to packages/discordeno/rest/processQueue.ts diff --git a/vendor/rest/processRateLimitedPaths.ts b/packages/discordeno/rest/processRateLimitedPaths.ts similarity index 100% rename from vendor/rest/processRateLimitedPaths.ts rename to packages/discordeno/rest/processRateLimitedPaths.ts diff --git a/vendor/rest/processRequest.ts b/packages/discordeno/rest/processRequest.ts similarity index 100% rename from vendor/rest/processRequest.ts rename to packages/discordeno/rest/processRequest.ts diff --git a/vendor/rest/processRequestHeaders.ts b/packages/discordeno/rest/processRequestHeaders.ts similarity index 100% rename from vendor/rest/processRequestHeaders.ts rename to packages/discordeno/rest/processRequestHeaders.ts diff --git a/vendor/rest/rest.ts b/packages/discordeno/rest/rest.ts similarity index 100% rename from vendor/rest/rest.ts rename to packages/discordeno/rest/rest.ts diff --git a/vendor/rest/restManager.ts b/packages/discordeno/rest/restManager.ts similarity index 100% rename from vendor/rest/restManager.ts rename to packages/discordeno/rest/restManager.ts diff --git a/vendor/rest/runMethod.ts b/packages/discordeno/rest/runMethod.ts similarity index 100% rename from vendor/rest/runMethod.ts rename to packages/discordeno/rest/runMethod.ts diff --git a/vendor/rest/runProxyMethod.ts b/packages/discordeno/rest/runProxyMethod.ts similarity index 100% rename from vendor/rest/runProxyMethod.ts rename to packages/discordeno/rest/runProxyMethod.ts diff --git a/vendor/rest/sendRequest.ts b/packages/discordeno/rest/sendRequest.ts similarity index 100% rename from vendor/rest/sendRequest.ts rename to packages/discordeno/rest/sendRequest.ts diff --git a/vendor/rest/simplifyUrl.ts b/packages/discordeno/rest/simplifyUrl.ts similarity index 100% rename from vendor/rest/simplifyUrl.ts rename to packages/discordeno/rest/simplifyUrl.ts diff --git a/vendor/types/discord.ts b/packages/discordeno/types/discord.ts similarity index 100% rename from vendor/types/discord.ts rename to packages/discordeno/types/discord.ts diff --git a/vendor/types/mod.ts b/packages/discordeno/types/mod.ts similarity index 100% rename from vendor/types/mod.ts rename to packages/discordeno/types/mod.ts diff --git a/vendor/types/shared.ts b/packages/discordeno/types/shared.ts similarity index 100% rename from vendor/types/shared.ts rename to packages/discordeno/types/shared.ts diff --git a/vendor/util/bucket.ts b/packages/discordeno/util/bucket.ts similarity index 100% rename from vendor/util/bucket.ts rename to packages/discordeno/util/bucket.ts diff --git a/vendor/util/collection.ts b/packages/discordeno/util/collection.ts similarity index 100% rename from vendor/util/collection.ts rename to packages/discordeno/util/collection.ts diff --git a/vendor/util/constants.ts b/packages/discordeno/util/constants.ts similarity index 100% rename from vendor/util/constants.ts rename to packages/discordeno/util/constants.ts diff --git a/vendor/util/delay.ts b/packages/discordeno/util/delay.ts similarity index 100% rename from vendor/util/delay.ts rename to packages/discordeno/util/delay.ts diff --git a/vendor/util/mod.ts b/packages/discordeno/util/mod.ts similarity index 100% rename from vendor/util/mod.ts rename to packages/discordeno/util/mod.ts diff --git a/vendor/util/token.ts b/packages/discordeno/util/token.ts similarity index 100% rename from vendor/util/token.ts rename to packages/discordeno/util/token.ts diff --git a/vendor/zlib.js b/packages/discordeno/zlib.js similarity index 100% rename from vendor/zlib.js rename to packages/discordeno/zlib.js diff --git a/structures/channels/BaseChannel.ts b/structures/channels/BaseChannel.ts deleted file mode 100644 index deb1809..0000000 --- a/structures/channels/BaseChannel.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { DiscordChannel } from "../../vendor/external.ts"; -import type TextChannel from "./TextChannel.ts"; -import type VoiceChannel from "./VoiceChannel.ts"; -import type DMChannel from "./DMChannel.ts"; -import type NewsChannel from "./NewsChannel.ts"; -import type ThreadChannel from "./ThreadChannel.ts"; -import type StageChannel from "./StageChannel.ts"; -import { ChannelTypes } from "../../vendor/external.ts"; -import { textBasedChannels } from "./TextChannel.ts"; - -export abstract class BaseChannel implements Model { - constructor(session: Session, data: DiscordChannel) { - this.id = data.id; - this.session = session; - this.name = data.name; - this.type = data.type; - } - readonly id: Snowflake; - readonly session: Session; - - name?: string; - type: ChannelTypes; - - isText(): this is TextChannel { - return textBasedChannels.includes(this.type); - } - - isVoice(): this is VoiceChannel { - return this.type === ChannelTypes.GuildVoice; - } - - isDM(): this is DMChannel { - return this.type === ChannelTypes.DM; - } - - isNews(): this is NewsChannel { - return this.type === ChannelTypes.GuildNews; - } - - isThread(): this is ThreadChannel { - return this.type === ChannelTypes.GuildPublicThread || this.type === ChannelTypes.GuildPrivateThread; - } - - isStage(): this is StageChannel { - return this.type === ChannelTypes.GuildStageVoice; - } - - toString(): string { - return `<#${this.id}>`; - } -} - -export default BaseChannel; diff --git a/structures/channels/BaseVoiceChannel.ts b/structures/channels/BaseVoiceChannel.ts deleted file mode 100644 index 7f7cfbe..0000000 --- a/structures/channels/BaseVoiceChannel.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ChannelTypes, DiscordChannel, VideoQualityModes } from "../../vendor/external.ts"; -import { GatewayOpcodes } from "../../vendor/external.ts"; -import { calculateShardId } from "../../vendor/gateway/calculateShardId.ts"; -import GuildChannel from "./GuildChannel.ts"; - -/** - * @link https://discord.com/developers/docs/topics/gateway#update-voice-state - */ -export interface UpdateVoiceState { - guildId: string; - channelId?: string; - selfMute: boolean; - selfDeaf: boolean; -} - -export abstract class BaseVoiceChannel extends GuildChannel { - constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { - super(session, data, guildId); - this.bitRate = data.bitrate; - this.userLimit = data.user_limit ?? 0; - this.videoQuality = data.video_quality_mode; - this.nsfw = !!data.nsfw; - this.type = data.type as number; - - if (data.rtc_region) { - this.rtcRegion = data.rtc_region; - } - } - override type: ChannelTypes.GuildVoice | ChannelTypes.GuildStageVoice; - bitRate?: number; - userLimit: number; - rtcRegion?: Snowflake; - - videoQuality?: VideoQualityModes; - nsfw: boolean; - - /** - * This function was gathered from Discordeno it may not work - */ - async connect(options?: UpdateVoiceState) { - const shardId = calculateShardId(this.session.gateway, BigInt(super.guildId)); - const shard = this.session.gateway.manager.shards.get(shardId); - - if (!shard) { - throw new Error(`Shard (id: ${shardId} not found`); - } - - await shard.send({ - op: GatewayOpcodes.VoiceStateUpdate, - d: { - guild_id: super.guildId, - channel_id: super.id, - self_mute: Boolean(options?.selfMute), - self_deaf: options?.selfDeaf ?? true, - }, - }); - } -} - -export default BaseVoiceChannel; diff --git a/structures/channels/ChannelFactory.ts b/structures/channels/ChannelFactory.ts deleted file mode 100644 index 31a1578..0000000 --- a/structures/channels/ChannelFactory.ts +++ /dev/null @@ -1,43 +0,0 @@ -import type { Session } from "../../session/Session.ts"; -import type { DiscordChannel } from "../../vendor/external.ts"; -import { ChannelTypes } from "../../vendor/external.ts"; -import { textBasedChannels } from "./TextChannel.ts"; -import TextChannel from "./TextChannel.ts"; -import VoiceChannel from "./VoiceChannel.ts"; -import DMChannel from "./DMChannel.ts"; -import NewsChannel from "./NewsChannel.ts"; -import ThreadChannel from "./ThreadChannel.ts"; -import StageChannel from "./StageChannel.ts"; - -export type Channel = - | TextChannel - | VoiceChannel - | DMChannel - | NewsChannel - | ThreadChannel - | StageChannel; - -export class ChannelFactory { - static from(session: Session, channel: DiscordChannel): Channel { - switch (channel.type) { - case ChannelTypes.GuildPublicThread: - case ChannelTypes.GuildPrivateThread: - return new ThreadChannel(session, channel, channel.guild_id!); - case ChannelTypes.GuildNews: - return new NewsChannel(session, channel, channel.guild_id!); - case ChannelTypes.DM: - return new DMChannel(session, channel); - case ChannelTypes.GuildVoice: - return new VoiceChannel(session, channel, channel.guild_id!); - case ChannelTypes.GuildStageVoice: - return new StageChannel(session, channel, channel.guild_id!); - default: - if (textBasedChannels.includes(channel.type)) { - return new TextChannel(session, channel); - } - throw new Error("Channel was not implemented"); - } - } -} - -export default ChannelFactory; diff --git a/structures/channels/DMChannel.ts b/structures/channels/DMChannel.ts deleted file mode 100644 index ad94a05..0000000 --- a/structures/channels/DMChannel.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type { Model } from "../Base.ts"; -import type { Session } from "../../session/Session.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { ChannelTypes, DiscordChannel } from "../../vendor/external.ts"; -import TextChannel from "./TextChannel.ts"; -import BaseChannel from "./BaseChannel.ts"; -import User from "../User.ts"; -import * as Routes from "../../util/Routes.ts"; - -export class DMChannel extends BaseChannel implements Model { - constructor(session: Session, data: DiscordChannel) { - super(session, data); - this.user = new User(this.session, data.recipents!.find((r) => r.id !== this.session.botId)!); - this.type = data.type as ChannelTypes.DM | ChannelTypes.GroupDm; - if (data.last_message_id) { - this.lastMessageId = data.last_message_id; - } - } - - override type: ChannelTypes.DM | ChannelTypes.GroupDm; - user: User; - lastMessageId?: Snowflake; - - async close() { - const channel = await this.session.rest.runMethod( - this.session.rest, - "DELETE", - Routes.CHANNEL(this.id), - ); - - return new DMChannel(this.session, channel); - } -} - -TextChannel.applyTo(DMChannel); - -export interface DMChannel extends Omit, Omit {} - -export default DMChannel; diff --git a/structures/channels/GuildChannel.ts b/structures/channels/GuildChannel.ts deleted file mode 100644 index d2b93a5..0000000 --- a/structures/channels/GuildChannel.ts +++ /dev/null @@ -1,187 +0,0 @@ -import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { PermissionsOverwrites } from "../../util/permissions.ts"; -import type { Session } from "../../session/Session.ts"; -import type { - ChannelTypes, - DiscordChannel, - DiscordInviteMetadata, - DiscordListArchivedThreads, - VideoQualityModes, -} from "../../vendor/external.ts"; -import type { ListArchivedThreads } from "../../util/Routes.ts"; -import BaseChannel from "./BaseChannel.ts"; -import VoiceChannel from "./VoiceChannel.ts"; -import NewsChannel from "./NewsChannel.ts"; -import StageChannel from "./StageChannel.ts"; -import ThreadMember from "../ThreadMember.ts"; -import Invite from "../Invite.ts"; -import * as Routes from "../../util/Routes.ts"; -import { Channel, ChannelFactory } from "./ChannelFactory.ts"; - -/** - * Represent the options object to create a thread channel - * @link https://discord.com/developers/docs/resources/channel#start-thread-without-message - */ -export interface ThreadCreateOptions { - name: string; - autoArchiveDuration?: 60 | 1440 | 4320 | 10080; - type: 10 | 11 | 12; - invitable?: boolean; - rateLimitPerUser?: number; - reason?: string; -} - -/** - * Representations of the objects to edit a guild channel - * @link https://discord.com/developers/docs/resources/channel#modify-channel-json-params-guild-channel - */ -export interface EditGuildChannelOptions { - name?: string; - position?: number; - permissionOverwrites?: PermissionsOverwrites[]; -} - -export interface EditNewsChannelOptions extends EditGuildChannelOptions { - type?: ChannelTypes.GuildNews | ChannelTypes.GuildText; - topic?: string | null; - nfsw?: boolean | null; - parentId?: Snowflake | null; - defaultAutoArchiveDuration?: number | null; -} - -export interface EditGuildTextChannelOptions extends EditNewsChannelOptions { - rateLimitPerUser?: number | null; -} - -export interface EditStageChannelOptions extends EditGuildChannelOptions { - bitrate?: number | null; - rtcRegion?: Snowflake | null; -} - -export interface EditVoiceChannelOptions extends EditStageChannelOptions { - nsfw?: boolean | null; - userLimit?: number | null; - parentId?: Snowflake | null; - videoQualityMode?: VideoQualityModes | null; -} - -/** - * Represents the option object to create a thread channel from a message - * @link https://discord.com/developers/docs/resources/channel#start-thread-from-message - */ -export interface ThreadCreateOptions { - name: string; - autoArchiveDuration?: 60 | 1440 | 4320 | 10080; - rateLimitPerUser?: number; - messageId: Snowflake; -} - -export class GuildChannel extends BaseChannel implements Model { - constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { - super(session, data); - this.type = data.type as number; - this.guildId = guildId; - this.position = data.position; - data.topic ? this.topic = data.topic : null; - data.parent_id ? this.parentId = data.parent_id : undefined; - } - - override type: Exclude; - guildId: Snowflake; - topic?: string; - position?: number; - parentId?: Snowflake; - - async fetchInvites(): Promise { - const invites = await this.session.rest.runMethod( - this.session.rest, - "GET", - Routes.CHANNEL_INVITES(this.id), - ); - - return invites.map((invite) => new Invite(this.session, invite)); - } - - async edit(options: EditNewsChannelOptions): Promise; - async edit(options: EditStageChannelOptions): Promise; - async edit(options: EditVoiceChannelOptions): Promise; - async edit( - options: EditGuildTextChannelOptions | EditNewsChannelOptions | EditVoiceChannelOptions, - ): Promise { - const channel = await this.session.rest.runMethod( - this.session.rest, - "PATCH", - Routes.CHANNEL(this.id), - { - name: options.name, - type: "type" in options ? options.type : undefined, - position: options.position, - topic: "topic" in options ? options.topic : undefined, - nsfw: "nfsw" in options ? options.nfsw : undefined, - rate_limit_per_user: "rateLimitPerUser" in options ? options.rateLimitPerUser : undefined, - bitrate: "bitrate" in options ? options.bitrate : undefined, - user_limit: "userLimit" in options ? options.userLimit : undefined, - permissions_overwrites: options.permissionOverwrites, - parent_id: "parentId" in options ? options.parentId : undefined, - rtc_region: "rtcRegion" in options ? options.rtcRegion : undefined, - video_quality_mode: "videoQualityMode" in options ? options.videoQualityMode : undefined, - default_auto_archive_duration: "defaultAutoArchiveDuration" in options - ? options.defaultAutoArchiveDuration - : undefined, - }, - ); - return ChannelFactory.from(this.session, channel); - } - - /* - async getArchivedThreads(options: ListArchivedThreads & { type: "public" | "private" | "privateJoinedThreads" }) { - let func: (channelId: Snowflake, options: ListArchivedThreads) => string; - - switch (options.type) { - case "public": - func = Routes.THREAD_ARCHIVED_PUBLIC; - break; - case "private": - func = Routes.THREAD_START_PRIVATE; - break; - case "privateJoinedThreads": - func = Routes.THREAD_ARCHIVED_PRIVATE_JOINED; - break; - } - - const { threads, members, has_more } = await this.session.rest.runMethod( - this.session.rest, - "GET", - func(this.id, options), - ); - - return { - threads: Object.fromEntries( - threads.map((thread) => [thread.id, new ThreadChannel(this.session, thread, this.id)]), - ) as Record, - members: Object.fromEntries( - members.map((threadMember) => [threadMember.id, new ThreadMember(this.session, threadMember)]), - ) as Record, - hasMore: has_more, - }; - } - - async createThread(options: ThreadCreateOptions): Promise { - const thread = await this.session.rest.runMethod( - this.session.rest, - "POST", - "messageId" in options - ? Routes.THREAD_START_PUBLIC(this.id, options.messageId) - : Routes.THREAD_START_PRIVATE(this.id), - { - name: options.name, - auto_archive_duration: options.autoArchiveDuration, - }, - ); - - return new ThreadChannel(this.session, thread, thread.guild_id ?? this.guildId); - }*/ -} - -export default GuildChannel; diff --git a/structures/channels/NewsChannel.ts b/structures/channels/NewsChannel.ts deleted file mode 100644 index a21ae61..0000000 --- a/structures/channels/NewsChannel.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ChannelTypes, DiscordChannel } from "../../vendor/external.ts"; -import GuildChannel from "./GuildChannel.ts"; -import Message from "../Message.ts"; -import TextChannel from "./TextChannel.ts"; - -export class NewsChannel extends GuildChannel { - constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { - super(session, data, guildId); - this.type = data.type as ChannelTypes.GuildNews; - this.defaultAutoArchiveDuration = data.default_auto_archive_duration; - } - - override type: ChannelTypes.GuildNews; - defaultAutoArchiveDuration?: number; - - crosspostMessage(messageId: Snowflake): Promise { - return Message.prototype.crosspost.call({ id: messageId, channelId: this.id, session: this.session }); - } - - get publishMessage() { - return this.crosspostMessage; - } -} - -TextChannel.applyTo(NewsChannel); - -export interface NewsChannel extends TextChannel, GuildChannel {} - -export default NewsChannel; diff --git a/structures/channels/StageChannel.ts b/structures/channels/StageChannel.ts deleted file mode 100644 index 41b49f7..0000000 --- a/structures/channels/StageChannel.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ChannelTypes, DiscordChannel } from "../../vendor/external.ts"; -import BaseVoiceChannel from "./BaseVoiceChannel.ts"; - -export class StageChannel extends BaseVoiceChannel { - constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { - super(session, data, guildId); - this.type = data.type as number; - this.topic = data.topic ? data.topic : undefined; - } - override type: ChannelTypes.GuildStageVoice; - topic?: string; -} - -export default StageChannel; diff --git a/structures/channels/TextChannel.ts b/structures/channels/TextChannel.ts deleted file mode 100644 index e2ae955..0000000 --- a/structures/channels/TextChannel.ts +++ /dev/null @@ -1,230 +0,0 @@ -// deno-lint-ignore-file ban-types -import type { Session } from "../../session/Session.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { GetMessagesOptions, GetReactions } from "../../util/Routes.ts"; -import type { - DiscordChannel, - DiscordInvite, - DiscordMessage, - DiscordWebhook, - TargetTypes, -} from "../../vendor/external.ts"; -import type { CreateMessage, EditMessage, ReactionResolvable } from "../Message.ts"; -import { ChannelTypes } from "../../vendor/external.ts"; -import { urlToBase64 } from "../../util/urlToBase64.ts"; -import Message from "../Message.ts"; -import Invite from "../Invite.ts"; -import Webhook from "../Webhook.ts"; -import * as Routes from "../../util/Routes.ts"; - -/** - * Represents the options object to create an invitation - * @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params - */ -export interface DiscordInviteOptions { - maxAge?: number; - maxUses?: number; - unique?: boolean; - temporary: boolean; - reason?: string; - targetType?: TargetTypes; - targetUserId?: Snowflake; - targetApplicationId?: Snowflake; -} - -export interface CreateWebhook { - name: string; - avatar?: string; - reason?: string; -} - -export const textBasedChannels = [ - ChannelTypes.DM, - ChannelTypes.GroupDm, - ChannelTypes.GuildPrivateThread, - ChannelTypes.GuildPublicThread, - ChannelTypes.GuildNews, - ChannelTypes.GuildVoice, - ChannelTypes.GuildText, -]; - -export type TextBasedChannels = - | ChannelTypes.DM - | ChannelTypes.GroupDm - | ChannelTypes.GuildPrivateThread - | ChannelTypes.GuildPublicThread - | ChannelTypes.GuildNews - | ChannelTypes.GuildVoice - | ChannelTypes.GuildText; - -export class TextChannel { - constructor(session: Session, data: DiscordChannel) { - this.session = session; - this.id = data.id; - this.name = data.name; - this.type = data.type as number; - this.rateLimitPerUser = data.rate_limit_per_user ?? 0; - this.nsfw = !!data.nsfw ?? false; - - if (data.last_message_id) { - this.lastMessageId = data.last_message_id; - } - - if (data.last_pin_timestamp) { - this.lastPinTimestamp = data.last_pin_timestamp; - } - } - - readonly session: Session; - readonly id: Snowflake; - name?: string; - type: TextBasedChannels; - lastMessageId?: Snowflake; - lastPinTimestamp?: string; - rateLimitPerUser: number; - nsfw: boolean; - - /** - * Mixin - */ - static applyTo(klass: Function, ignore: Array = []) { - const methods: Array = [ - "fetchPins", - "createInvite", - "fetchMessages", - "sendTyping", - "pinMessage", - "unpinMessage", - "addReaction", - "removeReaction", - "nukeReactions", - "fetchPins", - "sendMessage", - "editMessage", - "createWebhook", - ]; - - for (const method of methods) { - if (ignore.includes(method)) continue; - - klass.prototype[method] = TextChannel.prototype[method]; - } - } - - async fetchPins(): Promise { - const messages = await this.session.rest.runMethod( - this.session.rest, - "GET", - Routes.CHANNEL_PINS(this.id), - ); - return messages[0] ? messages.map((x: DiscordMessage) => new Message(this.session, x)) : []; - } - - async createInvite(options?: DiscordInviteOptions) { - const invite = await this.session.rest.runMethod( - this.session.rest, - "POST", - Routes.CHANNEL_INVITES(this.id), - options - ? { - max_age: options.maxAge, - max_uses: options.maxUses, - temporary: options.temporary, - unique: options.unique, - target_type: options.targetType, - target_user_id: options.targetUserId, - target_application_id: options.targetApplicationId, - } - : {}, - ); - - return new Invite(this.session, invite); - } - - async fetchMessages(options?: GetMessagesOptions): Promise { - if (options?.limit! > 100) throw Error("Values must be between 0-100"); - const messages = await this.session.rest.runMethod( - this.session.rest, - "GET", - Routes.CHANNEL_MESSAGES(this.id, options), - ); - return messages[0] ? messages.map((x) => new Message(this.session, x)) : []; - } - - async sendTyping() { - await this.session.rest.runMethod( - this.session.rest, - "POST", - Routes.CHANNEL_TYPING(this.id), - ); - } - - async pinMessage(messageId: Snowflake) { - await Message.prototype.pin.call({ id: messageId, channelId: this.id, session: this.session }); - } - - async unpinMessage(messageId: Snowflake) { - await Message.prototype.unpin.call({ id: messageId, channelId: this.id, session: this.session }); - } - - async addReaction(messageId: Snowflake, reaction: ReactionResolvable) { - await Message.prototype.addReaction.call( - { channelId: this.id, id: messageId, session: this.session }, - reaction, - ); - } - - async removeReaction(messageId: Snowflake, reaction: ReactionResolvable, options?: { userId: Snowflake }) { - await Message.prototype.removeReaction.call( - { channelId: this.id, id: messageId, session: this.session }, - reaction, - options, - ); - } - - async removeReactionEmoji(messageId: Snowflake, reaction: ReactionResolvable) { - await Message.prototype.removeReactionEmoji.call( - { channelId: this.id, id: messageId, session: this.session }, - reaction, - ); - } - - async nukeReactions(messageId: Snowflake) { - await Message.prototype.nukeReactions.call({ channelId: this.id, id: messageId }); - } - - async fetchReactions(messageId: Snowflake, reaction: ReactionResolvable, options?: GetReactions) { - const users = await Message.prototype.fetchReactions.call( - { channelId: this.id, id: messageId, session: this.session }, - reaction, - options, - ); - - return users; - } - - sendMessage(options: CreateMessage) { - return Message.prototype.reply.call({ channelId: this.id, session: this.session }, options); - } - - editMessage(messageId: Snowflake, options: EditMessage) { - return Message.prototype.edit.call({ channelId: this.id, id: messageId, session: this.session }, options); - } - - async createWebhook(options: CreateWebhook) { - const webhook = await this.session.rest.runMethod( - this.session.rest, - "POST", - Routes.CHANNEL_WEBHOOKS(this.id), - { - name: options.name, - avatar: options.avatar ? urlToBase64(options.avatar) : undefined, - reason: options.reason, - }, - ); - - return new Webhook(this.session, webhook); - } -} - -export default TextChannel; diff --git a/structures/channels/ThreadChannel.ts b/structures/channels/ThreadChannel.ts deleted file mode 100644 index 0bb036d..0000000 --- a/structures/channels/ThreadChannel.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ChannelTypes, DiscordChannel, DiscordThreadMember } from "../../vendor/external.ts"; -import GuildChannel from "./GuildChannel.ts"; -import TextChannel from "./TextChannel.ts"; -import ThreadMember from "../ThreadMember.ts"; -import * as Routes from "../../util/Routes.ts"; - -export class ThreadChannel extends GuildChannel implements Model { - constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { - super(session, data, guildId); - this.type = data.type as number; - this.archived = !!data.thread_metadata?.archived; - this.archiveTimestamp = data.thread_metadata?.archive_timestamp; - this.autoArchiveDuration = data.thread_metadata?.auto_archive_duration; - this.locked = !!data.thread_metadata?.locked; - this.messageCount = data.message_count; - this.memberCount = data.member_count; - this.ownerId = data.owner_id; - - if (data.member) { - this.member = new ThreadMember(session, data.member); - } - } - - override type: ChannelTypes.GuildNewsThread | ChannelTypes.GuildPrivateThread | ChannelTypes.GuildPublicThread; - archived?: boolean; - archiveTimestamp?: string; - autoArchiveDuration?: number; - locked?: boolean; - messageCount?: number; - memberCount?: number; - member?: ThreadMember; - ownerId?: Snowflake; - - async joinThread() { - await this.session.rest.runMethod( - this.session.rest, - "PUT", - Routes.THREAD_ME(this.id), - ); - } - - async addToThread(guildMemberId: Snowflake) { - await this.session.rest.runMethod( - this.session.rest, - "PUT", - Routes.THREAD_USER(this.id, guildMemberId), - ); - } - - async leaveToThread(guildMemberId: Snowflake) { - await this.session.rest.runMethod( - this.session.rest, - "DELETE", - Routes.THREAD_USER(this.id, guildMemberId), - ); - } - - removeMember(memberId: Snowflake = this.session.botId) { - return ThreadMember.prototype.quitThread.call({ id: this.id, session: this.session }, memberId); - } - - fetchMember(memberId: Snowflake = this.session.botId) { - return ThreadMember.prototype.fetchMember.call({ id: this.id, session: this.session }, memberId); - } - - async fetchMembers(): Promise { - const members = await this.session.rest.runMethod( - this.session.rest, - "GET", - Routes.THREAD_MEMBERS(this.id), - ); - - return members.map((threadMember) => new ThreadMember(this.session, threadMember)); - } -} - -TextChannel.applyTo(ThreadChannel); - -export interface ThreadChannel extends Omit, Omit {} - -export default ThreadChannel; diff --git a/structures/channels/VoiceChannel.ts b/structures/channels/VoiceChannel.ts deleted file mode 100644 index 670e5fd..0000000 --- a/structures/channels/VoiceChannel.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { Snowflake } from "../../util/Snowflake.ts"; -import type { Session } from "../../session/Session.ts"; -import type { ChannelTypes, DiscordChannel } from "../../vendor/external.ts"; -import BaseVoiceChannel from "./BaseVoiceChannel.ts"; -import TextChannel from "./TextChannel.ts"; - -export class VoiceChannel extends BaseVoiceChannel { - constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { - super(session, data, guildId); - this.type = data.type as number; - } - override type: ChannelTypes.GuildVoice; -} - -export interface VoiceChannel extends TextChannel, BaseVoiceChannel {} - -TextChannel.applyTo(VoiceChannel); - -export default VoiceChannel; diff --git a/tests/deps.ts b/tests/deps.ts deleted file mode 100644 index 4dda9d8..0000000 --- a/tests/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "../mod.ts"; diff --git a/util/builders.ts b/util/builders.ts deleted file mode 100644 index 19c9e8c..0000000 --- a/util/builders.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ButtonBuilder, InputTextBuilder, SelectMenuBuilder } from "../mod.ts"; -import { Snowflake } from "./Snowflake.ts"; - -export type AnyComponentBuilder = InputTextBuilder | SelectMenuBuilder | ButtonBuilder; -export type ComponentEmoji = { - id: Snowflake; - name: string; - animated?: boolean; -}; diff --git a/util/hash.ts b/util/hash.ts deleted file mode 100644 index 960adfd..0000000 --- a/util/hash.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Memory optimizations - * All credits to the Discordeno authors - */ - -export function iconHashToBigInt(hash: string) { - return BigInt("0x" + (hash.startsWith("a_") ? `a${hash.substring(2)}` : `b${hash}`)); -} - -export function iconBigintToHash(icon: bigint) { - const hash = icon.toString(16); - - return hash.startsWith("a") ? `a_${hash.substring(1)}` : hash.substring(1); -} diff --git a/util/permissions.ts b/util/permissions.ts deleted file mode 100644 index e19f5ea..0000000 --- a/util/permissions.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Snowflake } from "./Snowflake.ts"; -import { Permissions } from "../structures/Permissions.ts"; - -export interface PermissionsOverwrites { - id: Snowflake; - type: 0 | 1; - allow: Permissions; - deny: Permissions; -} diff --git a/util/shared/flags.ts b/util/shared/flags.ts deleted file mode 100644 index 226a25e..0000000 --- a/util/shared/flags.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @link https://discord.com/developers/docs/resources/channel#message-object-message-flags - */ -export enum MessageFlags { - /** this message has been published to subscribed channels (via Channel Following) */ - CrossPosted = 1 << 0, - /** this message originated from a message in another channel (via Channel Following) */ - IsCrosspost = 1 << 1, - /** do not include any embeds when serializing this message */ - SupressEmbeds = 1 << 2, - /** the source message for this crosspost has been deleted (via Channel Following) */ - SourceMessageDeleted = 1 << 3, - /** this message came from the urgent message system */ - Urgent = 1 << 4, - /** this message has an associated thread, with the same id as the message */ - HasThread = 1 << 5, - /** this message is only visible to the user who invoked the Interaction */ - Ephemeral = 1 << 6, - /** this message is an Interaction Response and the bot is "thinking" */ - Loading = 1 << 7, - /** this message failed to mention some roles and add their members to the thread */ - FailedToMentionSomeRolesInThread = 1 << 8, -} diff --git a/util/shared/images.ts b/util/shared/images.ts deleted file mode 100644 index f5a0524..0000000 --- a/util/shared/images.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @link https://discord.com/developers/docs/reference#image-formatting - */ -export type ImageFormat = "jpg" | "jpeg" | "png" | "webp" | "gif" | "json"; - -/** - * @link https://discord.com/developers/docs/reference#image-formatting - */ -export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096; - -/** Help format an image url */ -export function formatImageURL(url: string, size: ImageSize = 128, format?: ImageFormat) { - return `${url}.${format || (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`; -}