diff --git a/README.md b/README.md index ad19a31..736083d 100644 --- a/README.md +++ b/README.md @@ -42,18 +42,18 @@ that you should not make software that does things it is not supposed to do. ### Example bot (TS/JS) ```js -import Biscuit, { GatewayIntents } from "@oasisjs/biscuit"; +import Biscuit, { GatewayIntents } from '@oasisjs/biscuit'; const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; -const session = new Biscuit({ token: "your token", intents }); +const session = new Biscuit({ token: 'your token', intents }); -session.on("ready", ({ user }) => { - console.log("Logged in as:", user.username); +session.on('ready', ({ user }) => { + console.log('Logged in as:', user.username); }); -session.on("messageCreate", (message) => { - if (message.content.startsWith("!ping")) { - message.reply({ content: "pong!" }); +session.on('messageCreate', (message) => { + if (message.content.startsWith('!ping')) { + message.reply({ content: 'pong!' }); } }); diff --git a/biscuit.js b/biscuit.js new file mode 100644 index 0000000..3e47f82 --- /dev/null +++ b/biscuit.js @@ -0,0 +1,6527 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file +// This code was bundled using `deno bundle` and it's not recommended to edit it manually + +function calculateTotalShards(gateway) { + if (gateway.manager.totalShards < 100) return gateway.manager.totalShards; + return Math.ceil(gateway.manager.totalShards / (gateway.gatewayBot.sessionStartLimit.maxConcurrency === 1 ? 16 : gateway.gatewayBot.sessionStartLimit.maxConcurrency)) * gateway.gatewayBot.sessionStartLimit.maxConcurrency; +} +function calculateWorkerId(manager, shardId) { + let workerId = Math.floor(shardId / manager.shardsPerWorker); + if (workerId >= manager.totalWorkers) { + workerId = manager.totalWorkers - 1; + } + return workerId; +} +function spawnShards(gateway) { + gateway.prepareBuckets(); + gateway.buckets.forEach((bucket, bucketId)=>{ + for (const worker of bucket.workers){ + for (const shardId of worker.queue){ + gateway.tellWorkerToIdentify(worker.id, shardId, bucketId).catch(console.error); + } + } + }); +} +function delay(ms) { + return new Promise((res)=>setTimeout(()=>{ + res(); + }, ms)); +} +function createLeakyBucket({ max , refillInterval , refillAmount , tokens , waiting , ...rest }) { + return { + max, + refillInterval, + refillAmount: refillAmount > max ? max : refillAmount, + lastRefill: performance.now(), + allowAcquire: true, + nextRefill: function() { + return nextRefill(this); + }, + tokens: function() { + return updateTokens(this); + }, + acquire: async function(amount, highPriority) { + return await acquire(this, amount, highPriority); + }, + tokensState: tokens ?? max, + waiting: waiting ?? [], + ...rest + }; +} +function updateTokens(bucket) { + const timePassed = performance.now() - bucket.lastRefill; + const missedRefills = Math.floor(timePassed / bucket.refillInterval); + bucket.tokensState = Math.min(bucket.tokensState + bucket.refillAmount * missedRefills, bucket.max); + bucket.lastRefill += bucket.refillInterval * missedRefills; + return bucket.tokensState; +} +function nextRefill(bucket) { + updateTokens(bucket); + return performance.now() - bucket.lastRefill + bucket.refillInterval; +} +async function acquire(bucket, amount, highPriority = false) { + if (!bucket.allowAcquire) { + await new Promise((resolve)=>{ + if (highPriority) { + bucket.waiting.unshift(resolve); + } else { + bucket.waiting.push(resolve); + } + }); + if (!bucket.allowAcquire) { + return await acquire(bucket, amount); + } + } + bucket.allowAcquire = false; + let currentTokens = updateTokens(bucket); + if (currentTokens < amount) { + const tokensNeeded = amount - currentTokens; + let refillsNeeded = Math.ceil(tokensNeeded / bucket.refillAmount); + const waitTime = bucket.refillInterval * refillsNeeded; + await delay(waitTime); + updateTokens(bucket); + } + const toSubtract = amount % bucket.refillAmount || amount; + bucket.tokensState -= toSubtract; + bucket.allowAcquire = true; + bucket.waiting.shift()?.(); +} +function prepareBuckets(gateway) { + for(let i = 0; i < gateway.gatewayBot.sessionStartLimit.maxConcurrency; ++i){ + gateway.buckets.set(i, { + workers: [], + leak: createLeakyBucket({ + max: 1, + refillAmount: 1, + refillInterval: gateway.spawnShardDelay + }) + }); + } + for(let shardId = gateway.firstShardId; shardId <= gateway.lastShardId; ++shardId){ + if (shardId >= gateway.manager.totalShards) { + throw new Error(`Shard (id: ${shardId}) is bigger or equal to the used amount of used shards which is ${gateway.manager.totalShards}`); + } + const bucketId = shardId % gateway.gatewayBot.sessionStartLimit.maxConcurrency; + const bucket = gateway.buckets.get(bucketId); + if (!bucket) { + throw new Error(`Shard (id: ${shardId}) got assigned to an illegal bucket id: ${bucketId}, expected a bucket id between 0 and ${gateway.gatewayBot.sessionStartLimit.maxConcurrency - 1}`); + } + const workerId = gateway.calculateWorkerId(shardId); + const worker = bucket.workers.find((w)=>w.id === workerId); + if (worker) { + worker.queue.push(shardId); + } else { + bucket.workers.push({ + id: workerId, + queue: [ + shardId + ] + }); + } + } +} +async function tellWorkerToIdentify(gateway, _workerId, shardId, _bucketId) { + return await gateway.manager.identify(shardId); +} +var PremiumTypes; +(function(PremiumTypes) { + PremiumTypes[PremiumTypes["None"] = 0] = "None"; + PremiumTypes[PremiumTypes["NitroClassic"] = 1] = "NitroClassic"; + PremiumTypes[PremiumTypes["Nitro"] = 2] = "Nitro"; +})(PremiumTypes || (PremiumTypes = {})); +var UserFlags; +(function(UserFlags) { + UserFlags[UserFlags["DiscordEmployee"] = 1] = "DiscordEmployee"; + UserFlags[UserFlags["PartneredServerOwner"] = 2] = "PartneredServerOwner"; + UserFlags[UserFlags["HypeSquadEventsMember"] = 4] = "HypeSquadEventsMember"; + UserFlags[UserFlags["BugHunterLevel1"] = 8] = "BugHunterLevel1"; + UserFlags[UserFlags["HouseBravery"] = 64] = "HouseBravery"; + UserFlags[UserFlags["HouseBrilliance"] = 128] = "HouseBrilliance"; + UserFlags[UserFlags["HouseBalance"] = 256] = "HouseBalance"; + UserFlags[UserFlags["EarlySupporter"] = 512] = "EarlySupporter"; + UserFlags[UserFlags["TeamUser"] = 1024] = "TeamUser"; + UserFlags[UserFlags["BugHunterLevel2"] = 16384] = "BugHunterLevel2"; + UserFlags[UserFlags["VerifiedBot"] = 65536] = "VerifiedBot"; + UserFlags[UserFlags["EarlyVerifiedBotDeveloper"] = 131072] = "EarlyVerifiedBotDeveloper"; + UserFlags[UserFlags["DiscordCertifiedModerator"] = 262144] = "DiscordCertifiedModerator"; + UserFlags[UserFlags["BotHttpInteractions"] = 524288] = "BotHttpInteractions"; +})(UserFlags || (UserFlags = {})); +var ChannelFlags; +(function(ChannelFlags) { + ChannelFlags[ChannelFlags["None"] = 0] = "None"; + ChannelFlags[ChannelFlags["Pinned"] = 2] = "Pinned"; +})(ChannelFlags || (ChannelFlags = {})); +var IntegrationExpireBehaviors; +(function(IntegrationExpireBehaviors) { + IntegrationExpireBehaviors[IntegrationExpireBehaviors["RemoveRole"] = 0] = "RemoveRole"; + IntegrationExpireBehaviors[IntegrationExpireBehaviors["Kick"] = 1] = "Kick"; +})(IntegrationExpireBehaviors || (IntegrationExpireBehaviors = {})); +var VisibilityTypes; +(function(VisibilityTypes) { + VisibilityTypes[VisibilityTypes["None"] = 0] = "None"; + VisibilityTypes[VisibilityTypes["Everyone"] = 1] = "Everyone"; +})(VisibilityTypes || (VisibilityTypes = {})); +var TeamMembershipStates; +(function(TeamMembershipStates) { + TeamMembershipStates[TeamMembershipStates["Invited"] = 1] = "Invited"; + TeamMembershipStates[TeamMembershipStates["Accepted"] = 2] = "Accepted"; +})(TeamMembershipStates || (TeamMembershipStates = {})); +var ApplicationFlags; +(function(ApplicationFlags) { + ApplicationFlags[ApplicationFlags["GatewayPresence"] = 4096] = "GatewayPresence"; + ApplicationFlags[ApplicationFlags["GatewayPresenceLimited"] = 8192] = "GatewayPresenceLimited"; + ApplicationFlags[ApplicationFlags["GatewayGuildMembers"] = 16384] = "GatewayGuildMembers"; + ApplicationFlags[ApplicationFlags["GatewayGuildMembersLimited"] = 32768] = "GatewayGuildMembersLimited"; + ApplicationFlags[ApplicationFlags["VerificationPendingGuildLimit"] = 65536] = "VerificationPendingGuildLimit"; + ApplicationFlags[ApplicationFlags["Embedded"] = 131072] = "Embedded"; + ApplicationFlags[ApplicationFlags["GatewayMessageCount"] = 262144] = "GatewayMessageCount"; + ApplicationFlags[ApplicationFlags["GatewayMessageContentLimited"] = 524288] = "GatewayMessageContentLimited"; +})(ApplicationFlags || (ApplicationFlags = {})); +var MessageComponentTypes; +(function(MessageComponentTypes) { + MessageComponentTypes[MessageComponentTypes["ActionRow"] = 1] = "ActionRow"; + MessageComponentTypes[MessageComponentTypes["Button"] = 2] = "Button"; + MessageComponentTypes[MessageComponentTypes["SelectMenu"] = 3] = "SelectMenu"; + MessageComponentTypes[MessageComponentTypes["InputText"] = 4] = "InputText"; +})(MessageComponentTypes || (MessageComponentTypes = {})); +var TextStyles; +(function(TextStyles) { + TextStyles[TextStyles["Short"] = 1] = "Short"; + TextStyles[TextStyles["Paragraph"] = 2] = "Paragraph"; +})(TextStyles || (TextStyles = {})); +var ButtonStyles; +(function(ButtonStyles) { + ButtonStyles[ButtonStyles["Primary"] = 1] = "Primary"; + ButtonStyles[ButtonStyles["Secondary"] = 2] = "Secondary"; + ButtonStyles[ButtonStyles["Success"] = 3] = "Success"; + ButtonStyles[ButtonStyles["Danger"] = 4] = "Danger"; + ButtonStyles[ButtonStyles["Link"] = 5] = "Link"; +})(ButtonStyles || (ButtonStyles = {})); +var AllowedMentionsTypes; +(function(AllowedMentionsTypes) { + AllowedMentionsTypes["RoleMentions"] = "roles"; + AllowedMentionsTypes["UserMentions"] = "users"; + AllowedMentionsTypes["EveryoneMentions"] = "everyone"; +})(AllowedMentionsTypes || (AllowedMentionsTypes = {})); +var WebhookTypes; +(function(WebhookTypes) { + WebhookTypes[WebhookTypes["Incoming"] = 1] = "Incoming"; + WebhookTypes[WebhookTypes["ChannelFollower"] = 2] = "ChannelFollower"; + WebhookTypes[WebhookTypes["Application"] = 3] = "Application"; +})(WebhookTypes || (WebhookTypes = {})); +var DefaultMessageNotificationLevels; +(function(DefaultMessageNotificationLevels) { + DefaultMessageNotificationLevels[DefaultMessageNotificationLevels["AllMessages"] = 0] = "AllMessages"; + DefaultMessageNotificationLevels[DefaultMessageNotificationLevels["OnlyMentions"] = 1] = "OnlyMentions"; +})(DefaultMessageNotificationLevels || (DefaultMessageNotificationLevels = {})); +var ExplicitContentFilterLevels; +(function(ExplicitContentFilterLevels) { + ExplicitContentFilterLevels[ExplicitContentFilterLevels["Disabled"] = 0] = "Disabled"; + ExplicitContentFilterLevels[ExplicitContentFilterLevels["MembersWithoutRoles"] = 1] = "MembersWithoutRoles"; + ExplicitContentFilterLevels[ExplicitContentFilterLevels["AllMembers"] = 2] = "AllMembers"; +})(ExplicitContentFilterLevels || (ExplicitContentFilterLevels = {})); +var VerificationLevels; +(function(VerificationLevels) { + VerificationLevels[VerificationLevels["None"] = 0] = "None"; + VerificationLevels[VerificationLevels["Low"] = 1] = "Low"; + VerificationLevels[VerificationLevels["Medium"] = 2] = "Medium"; + VerificationLevels[VerificationLevels["High"] = 3] = "High"; + VerificationLevels[VerificationLevels["VeryHigh"] = 4] = "VeryHigh"; +})(VerificationLevels || (VerificationLevels = {})); +var GuildFeatures; +(function(GuildFeatures) { + GuildFeatures["InviteSplash"] = "INVITE_SPLASH"; + GuildFeatures["VipRegions"] = "VIP_REGIONS"; + GuildFeatures["VanityUrl"] = "VANITY_URL"; + GuildFeatures["Verified"] = "VERIFIED"; + GuildFeatures["Partnered"] = "PARTNERED"; + GuildFeatures["Community"] = "COMMUNITY"; + GuildFeatures["Commerce"] = "COMMERCE"; + GuildFeatures["News"] = "NEWS"; + GuildFeatures["Discoverable"] = "DISCOVERABLE"; + GuildFeatures["DiscoverableDisabled"] = "DISCOVERABLE_DISABLED"; + GuildFeatures["Feature"] = "FEATURABLE"; + GuildFeatures["AnimatedIcon"] = "ANIMATED_ICON"; + GuildFeatures["Banner"] = "BANNER"; + GuildFeatures["WelcomeScreenEnabled"] = "WELCOME_SCREEN_ENABLED"; + GuildFeatures["MemberVerificationGateEnabled"] = "MEMBER_VERIFICATION_GATE_ENABLED"; + GuildFeatures["PreviewEnabled"] = "PREVIEW_ENABLED"; + GuildFeatures["TicketedEventsEnabled"] = "TICKETED_EVENTS_ENABLED"; + GuildFeatures["MonetizationEnabled"] = "MONETIZATION_ENABLED"; + GuildFeatures["MoreStickers"] = "MORE_STICKERS"; + GuildFeatures["PrivateThreads"] = "PRIVATE_THREADS"; + GuildFeatures["RoleIcons"] = "ROLE_ICONS"; + GuildFeatures["AutoModeration"] = "AUTO_MODERATION"; +})(GuildFeatures || (GuildFeatures = {})); +var MfaLevels; +(function(MfaLevels) { + MfaLevels[MfaLevels["None"] = 0] = "None"; + MfaLevels[MfaLevels["Elevated"] = 1] = "Elevated"; +})(MfaLevels || (MfaLevels = {})); +var SystemChannelFlags; +(function(SystemChannelFlags) { + SystemChannelFlags[SystemChannelFlags["SuppressJoinNotifications"] = 1] = "SuppressJoinNotifications"; + SystemChannelFlags[SystemChannelFlags["SuppressPremiumSubscriptions"] = 2] = "SuppressPremiumSubscriptions"; + SystemChannelFlags[SystemChannelFlags["SuppressGuildReminderNotifications"] = 4] = "SuppressGuildReminderNotifications"; + SystemChannelFlags[SystemChannelFlags["SuppressJoinNotificationReplies"] = 8] = "SuppressJoinNotificationReplies"; +})(SystemChannelFlags || (SystemChannelFlags = {})); +var PremiumTiers; +(function(PremiumTiers) { + PremiumTiers[PremiumTiers["None"] = 0] = "None"; + PremiumTiers[PremiumTiers["Tier1"] = 1] = "Tier1"; + PremiumTiers[PremiumTiers["Tier2"] = 2] = "Tier2"; + PremiumTiers[PremiumTiers["Tier3"] = 3] = "Tier3"; +})(PremiumTiers || (PremiumTiers = {})); +var GuildNsfwLevel; +(function(GuildNsfwLevel) { + GuildNsfwLevel[GuildNsfwLevel["Default"] = 0] = "Default"; + GuildNsfwLevel[GuildNsfwLevel["Explicit"] = 1] = "Explicit"; + GuildNsfwLevel[GuildNsfwLevel["Safe"] = 2] = "Safe"; + GuildNsfwLevel[GuildNsfwLevel["AgeRestricted"] = 3] = "AgeRestricted"; +})(GuildNsfwLevel || (GuildNsfwLevel = {})); +var ChannelTypes; +(function(ChannelTypes) { + ChannelTypes[ChannelTypes["GuildText"] = 0] = "GuildText"; + ChannelTypes[ChannelTypes["DM"] = 1] = "DM"; + ChannelTypes[ChannelTypes["GuildVoice"] = 2] = "GuildVoice"; + ChannelTypes[ChannelTypes["GroupDm"] = 3] = "GroupDm"; + ChannelTypes[ChannelTypes["GuildCategory"] = 4] = "GuildCategory"; + ChannelTypes[ChannelTypes["GuildNews"] = 5] = "GuildNews"; + ChannelTypes[ChannelTypes["GuildNewsThread"] = 10] = "GuildNewsThread"; + ChannelTypes[ChannelTypes["GuildPublicThread"] = 11] = "GuildPublicThread"; + ChannelTypes[ChannelTypes["GuildPrivateThread"] = 12] = "GuildPrivateThread"; + ChannelTypes[ChannelTypes["GuildStageVoice"] = 13] = "GuildStageVoice"; + ChannelTypes[ChannelTypes["GuildDirectory"] = 14] = "GuildDirectory"; + ChannelTypes[ChannelTypes["GuildForum"] = 15] = "GuildForum"; +})(ChannelTypes || (ChannelTypes = {})); +var OverwriteTypes; +(function(OverwriteTypes) { + OverwriteTypes[OverwriteTypes["Role"] = 0] = "Role"; + OverwriteTypes[OverwriteTypes["Member"] = 1] = "Member"; +})(OverwriteTypes || (OverwriteTypes = {})); +var VideoQualityModes; +(function(VideoQualityModes) { + VideoQualityModes[VideoQualityModes["Auto"] = 1] = "Auto"; + VideoQualityModes[VideoQualityModes["Full"] = 2] = "Full"; +})(VideoQualityModes || (VideoQualityModes = {})); +var ActivityTypes; +(function(ActivityTypes) { + ActivityTypes[ActivityTypes["Game"] = 0] = "Game"; + ActivityTypes[ActivityTypes["Streaming"] = 1] = "Streaming"; + ActivityTypes[ActivityTypes["Listening"] = 2] = "Listening"; + ActivityTypes[ActivityTypes["Watching"] = 3] = "Watching"; + ActivityTypes[ActivityTypes["Custom"] = 4] = "Custom"; + ActivityTypes[ActivityTypes["Competing"] = 5] = "Competing"; +})(ActivityTypes || (ActivityTypes = {})); +var MessageTypes; +(function(MessageTypes) { + MessageTypes[MessageTypes["Default"] = 0] = "Default"; + MessageTypes[MessageTypes["RecipientAdd"] = 1] = "RecipientAdd"; + MessageTypes[MessageTypes["RecipientRemove"] = 2] = "RecipientRemove"; + MessageTypes[MessageTypes["Call"] = 3] = "Call"; + MessageTypes[MessageTypes["ChannelNameChange"] = 4] = "ChannelNameChange"; + MessageTypes[MessageTypes["ChannelIconChange"] = 5] = "ChannelIconChange"; + MessageTypes[MessageTypes["ChannelPinnedMessage"] = 6] = "ChannelPinnedMessage"; + MessageTypes[MessageTypes["GuildMemberJoin"] = 7] = "GuildMemberJoin"; + MessageTypes[MessageTypes["UserPremiumGuildSubscription"] = 8] = "UserPremiumGuildSubscription"; + MessageTypes[MessageTypes["UserPremiumGuildSubscriptionTier1"] = 9] = "UserPremiumGuildSubscriptionTier1"; + MessageTypes[MessageTypes["UserPremiumGuildSubscriptionTier2"] = 10] = "UserPremiumGuildSubscriptionTier2"; + MessageTypes[MessageTypes["UserPremiumGuildSubscriptionTier3"] = 11] = "UserPremiumGuildSubscriptionTier3"; + MessageTypes[MessageTypes["ChannelFollowAdd"] = 12] = "ChannelFollowAdd"; + MessageTypes[MessageTypes["GuildDiscoveryDisqualified"] = 14] = "GuildDiscoveryDisqualified"; + MessageTypes[MessageTypes["GuildDiscoveryRequalified"] = 15] = "GuildDiscoveryRequalified"; + MessageTypes[MessageTypes["GuildDiscoveryGracePeriodInitialWarning"] = 16] = "GuildDiscoveryGracePeriodInitialWarning"; + MessageTypes[MessageTypes["GuildDiscoveryGracePeriodFinalWarning"] = 17] = "GuildDiscoveryGracePeriodFinalWarning"; + MessageTypes[MessageTypes["ThreadCreated"] = 18] = "ThreadCreated"; + MessageTypes[MessageTypes["Reply"] = 19] = "Reply"; + MessageTypes[MessageTypes["ChatInputCommand"] = 20] = "ChatInputCommand"; + MessageTypes[MessageTypes["ThreadStarterMessage"] = 21] = "ThreadStarterMessage"; + MessageTypes[MessageTypes["GuildInviteReminder"] = 22] = "GuildInviteReminder"; + MessageTypes[MessageTypes["ContextMenuCommand"] = 23] = "ContextMenuCommand"; + MessageTypes[MessageTypes["AutoModerationAction"] = 24] = "AutoModerationAction"; +})(MessageTypes || (MessageTypes = {})); +var MessageActivityTypes; +(function(MessageActivityTypes) { + MessageActivityTypes[MessageActivityTypes["Join"] = 1] = "Join"; + MessageActivityTypes[MessageActivityTypes["Spectate"] = 2] = "Spectate"; + MessageActivityTypes[MessageActivityTypes["Listen"] = 3] = "Listen"; + MessageActivityTypes[MessageActivityTypes["JoinRequest"] = 4] = "JoinRequest"; +})(MessageActivityTypes || (MessageActivityTypes = {})); +var StickerTypes; +(function(StickerTypes) { + StickerTypes[StickerTypes["Standard"] = 1] = "Standard"; + StickerTypes[StickerTypes["Guild"] = 2] = "Guild"; +})(StickerTypes || (StickerTypes = {})); +var StickerFormatTypes; +(function(StickerFormatTypes) { + StickerFormatTypes[StickerFormatTypes["Png"] = 1] = "Png"; + StickerFormatTypes[StickerFormatTypes["APng"] = 2] = "APng"; + StickerFormatTypes[StickerFormatTypes["Lottie"] = 3] = "Lottie"; +})(StickerFormatTypes || (StickerFormatTypes = {})); +var InteractionTypes; +(function(InteractionTypes) { + InteractionTypes[InteractionTypes["Ping"] = 1] = "Ping"; + InteractionTypes[InteractionTypes["ApplicationCommand"] = 2] = "ApplicationCommand"; + InteractionTypes[InteractionTypes["MessageComponent"] = 3] = "MessageComponent"; + InteractionTypes[InteractionTypes["ApplicationCommandAutocomplete"] = 4] = "ApplicationCommandAutocomplete"; + InteractionTypes[InteractionTypes["ModalSubmit"] = 5] = "ModalSubmit"; +})(InteractionTypes || (InteractionTypes = {})); +var ApplicationCommandOptionTypes; +(function(ApplicationCommandOptionTypes) { + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["SubCommand"] = 1] = "SubCommand"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["SubCommandGroup"] = 2] = "SubCommandGroup"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["String"] = 3] = "String"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Integer"] = 4] = "Integer"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Boolean"] = 5] = "Boolean"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["User"] = 6] = "User"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Channel"] = 7] = "Channel"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Role"] = 8] = "Role"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Mentionable"] = 9] = "Mentionable"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Number"] = 10] = "Number"; + ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["Attachment"] = 11] = "Attachment"; +})(ApplicationCommandOptionTypes || (ApplicationCommandOptionTypes = {})); +var AuditLogEvents; +(function(AuditLogEvents) { + AuditLogEvents[AuditLogEvents["GuildUpdate"] = 1] = "GuildUpdate"; + AuditLogEvents[AuditLogEvents["ChannelCreate"] = 10] = "ChannelCreate"; + AuditLogEvents[AuditLogEvents["ChannelUpdate"] = 11] = "ChannelUpdate"; + AuditLogEvents[AuditLogEvents["ChannelDelete"] = 12] = "ChannelDelete"; + AuditLogEvents[AuditLogEvents["ChannelOverwriteCreate"] = 13] = "ChannelOverwriteCreate"; + AuditLogEvents[AuditLogEvents["ChannelOverwriteUpdate"] = 14] = "ChannelOverwriteUpdate"; + AuditLogEvents[AuditLogEvents["ChannelOverwriteDelete"] = 15] = "ChannelOverwriteDelete"; + AuditLogEvents[AuditLogEvents["MemberKick"] = 20] = "MemberKick"; + AuditLogEvents[AuditLogEvents["MemberPrune"] = 21] = "MemberPrune"; + AuditLogEvents[AuditLogEvents["MemberBanAdd"] = 22] = "MemberBanAdd"; + AuditLogEvents[AuditLogEvents["MemberBanRemove"] = 23] = "MemberBanRemove"; + AuditLogEvents[AuditLogEvents["MemberUpdate"] = 24] = "MemberUpdate"; + AuditLogEvents[AuditLogEvents["MemberRoleUpdate"] = 25] = "MemberRoleUpdate"; + AuditLogEvents[AuditLogEvents["MemberMove"] = 26] = "MemberMove"; + AuditLogEvents[AuditLogEvents["MemberDisconnect"] = 27] = "MemberDisconnect"; + AuditLogEvents[AuditLogEvents["BotAdd"] = 28] = "BotAdd"; + AuditLogEvents[AuditLogEvents["RoleCreate"] = 30] = "RoleCreate"; + AuditLogEvents[AuditLogEvents["RoleUpdate"] = 31] = "RoleUpdate"; + AuditLogEvents[AuditLogEvents["RoleDelete"] = 32] = "RoleDelete"; + AuditLogEvents[AuditLogEvents["InviteCreate"] = 40] = "InviteCreate"; + AuditLogEvents[AuditLogEvents["InviteUpdate"] = 41] = "InviteUpdate"; + AuditLogEvents[AuditLogEvents["InviteDelete"] = 42] = "InviteDelete"; + AuditLogEvents[AuditLogEvents["WebhookCreate"] = 50] = "WebhookCreate"; + AuditLogEvents[AuditLogEvents["WebhookUpdate"] = 51] = "WebhookUpdate"; + AuditLogEvents[AuditLogEvents["WebhookDelete"] = 52] = "WebhookDelete"; + AuditLogEvents[AuditLogEvents["EmojiCreate"] = 60] = "EmojiCreate"; + AuditLogEvents[AuditLogEvents["EmojiUpdate"] = 61] = "EmojiUpdate"; + AuditLogEvents[AuditLogEvents["EmojiDelete"] = 62] = "EmojiDelete"; + AuditLogEvents[AuditLogEvents["MessageDelete"] = 72] = "MessageDelete"; + AuditLogEvents[AuditLogEvents["MessageBulkDelete"] = 73] = "MessageBulkDelete"; + AuditLogEvents[AuditLogEvents["MessagePin"] = 74] = "MessagePin"; + AuditLogEvents[AuditLogEvents["MessageUnpin"] = 75] = "MessageUnpin"; + AuditLogEvents[AuditLogEvents["IntegrationCreate"] = 80] = "IntegrationCreate"; + AuditLogEvents[AuditLogEvents["IntegrationUpdate"] = 81] = "IntegrationUpdate"; + AuditLogEvents[AuditLogEvents["IntegrationDelete"] = 82] = "IntegrationDelete"; + AuditLogEvents[AuditLogEvents["StageInstanceCreate"] = 83] = "StageInstanceCreate"; + AuditLogEvents[AuditLogEvents["StageInstanceUpdate"] = 84] = "StageInstanceUpdate"; + AuditLogEvents[AuditLogEvents["StageInstanceDelete"] = 85] = "StageInstanceDelete"; + AuditLogEvents[AuditLogEvents["StickerCreate"] = 90] = "StickerCreate"; + AuditLogEvents[AuditLogEvents["StickerUpdate"] = 91] = "StickerUpdate"; + AuditLogEvents[AuditLogEvents["StickerDelete"] = 92] = "StickerDelete"; + AuditLogEvents[AuditLogEvents["GuildScheduledEventCreate"] = 100] = "GuildScheduledEventCreate"; + AuditLogEvents[AuditLogEvents["GuildScheduledEventUpdate"] = 101] = "GuildScheduledEventUpdate"; + AuditLogEvents[AuditLogEvents["GuildScheduledEventDelete"] = 102] = "GuildScheduledEventDelete"; + AuditLogEvents[AuditLogEvents["ThreadCreate"] = 110] = "ThreadCreate"; + AuditLogEvents[AuditLogEvents["ThreadUpdate"] = 111] = "ThreadUpdate"; + AuditLogEvents[AuditLogEvents["ThreadDelete"] = 112] = "ThreadDelete"; + AuditLogEvents[AuditLogEvents["ApplicationCommandPermissionUpdate"] = 121] = "ApplicationCommandPermissionUpdate"; + AuditLogEvents[AuditLogEvents["AutoModerationRuleCreate"] = 140] = "AutoModerationRuleCreate"; + AuditLogEvents[AuditLogEvents["AutoModerationRuleUpdate"] = 141] = "AutoModerationRuleUpdate"; + AuditLogEvents[AuditLogEvents["AutoModerationRuleDelete"] = 142] = "AutoModerationRuleDelete"; + AuditLogEvents[AuditLogEvents["AutoModerationBlockMessage"] = 143] = "AutoModerationBlockMessage"; +})(AuditLogEvents || (AuditLogEvents = {})); +var ScheduledEventPrivacyLevel; +(function(ScheduledEventPrivacyLevel) { + ScheduledEventPrivacyLevel[ScheduledEventPrivacyLevel["GuildOnly"] = 2] = "GuildOnly"; +})(ScheduledEventPrivacyLevel || (ScheduledEventPrivacyLevel = {})); +var ScheduledEventEntityType; +(function(ScheduledEventEntityType) { + ScheduledEventEntityType[ScheduledEventEntityType["StageInstance"] = 1] = "StageInstance"; + ScheduledEventEntityType[ScheduledEventEntityType["Voice"] = 2] = "Voice"; + ScheduledEventEntityType[ScheduledEventEntityType["External"] = 3] = "External"; +})(ScheduledEventEntityType || (ScheduledEventEntityType = {})); +var ScheduledEventStatus; +(function(ScheduledEventStatus) { + ScheduledEventStatus[ScheduledEventStatus["Scheduled"] = 1] = "Scheduled"; + ScheduledEventStatus[ScheduledEventStatus["Active"] = 2] = "Active"; + ScheduledEventStatus[ScheduledEventStatus["Completed"] = 3] = "Completed"; + ScheduledEventStatus[ScheduledEventStatus["Canceled"] = 4] = "Canceled"; +})(ScheduledEventStatus || (ScheduledEventStatus = {})); +var TargetTypes; +(function(TargetTypes) { + TargetTypes[TargetTypes["Stream"] = 1] = "Stream"; + TargetTypes[TargetTypes["EmbeddedApplication"] = 2] = "EmbeddedApplication"; +})(TargetTypes || (TargetTypes = {})); +var ApplicationCommandTypes; +(function(ApplicationCommandTypes) { + ApplicationCommandTypes[ApplicationCommandTypes["ChatInput"] = 1] = "ChatInput"; + ApplicationCommandTypes[ApplicationCommandTypes["User"] = 2] = "User"; + ApplicationCommandTypes[ApplicationCommandTypes["Message"] = 3] = "Message"; +})(ApplicationCommandTypes || (ApplicationCommandTypes = {})); +var ApplicationCommandPermissionTypes; +(function(ApplicationCommandPermissionTypes) { + ApplicationCommandPermissionTypes[ApplicationCommandPermissionTypes["Role"] = 1] = "Role"; + ApplicationCommandPermissionTypes[ApplicationCommandPermissionTypes["User"] = 2] = "User"; + ApplicationCommandPermissionTypes[ApplicationCommandPermissionTypes["Channel"] = 3] = "Channel"; +})(ApplicationCommandPermissionTypes || (ApplicationCommandPermissionTypes = {})); +var ActivityFlags; +(function(ActivityFlags) { + ActivityFlags[ActivityFlags["Instance"] = 1] = "Instance"; + ActivityFlags[ActivityFlags["Join"] = 2] = "Join"; + ActivityFlags[ActivityFlags["Spectate"] = 4] = "Spectate"; + ActivityFlags[ActivityFlags["JoinRequest"] = 8] = "JoinRequest"; + ActivityFlags[ActivityFlags["Sync"] = 16] = "Sync"; + ActivityFlags[ActivityFlags["Play"] = 32] = "Play"; + ActivityFlags[ActivityFlags["PartyPrivacyFriends"] = 64] = "PartyPrivacyFriends"; + ActivityFlags[ActivityFlags["PartyPrivacyVoiceChannel"] = 128] = "PartyPrivacyVoiceChannel"; + ActivityFlags[ActivityFlags["Embedded"] = 256] = "Embedded"; +})(ActivityFlags || (ActivityFlags = {})); +var BitwisePermissionFlags; +(function(BitwisePermissionFlags) { + BitwisePermissionFlags[BitwisePermissionFlags["CREATE_INSTANT_INVITE"] = 0x0000000000000001] = "CREATE_INSTANT_INVITE"; + BitwisePermissionFlags[BitwisePermissionFlags["KICK_MEMBERS"] = 0x0000000000000002] = "KICK_MEMBERS"; + BitwisePermissionFlags[BitwisePermissionFlags["BAN_MEMBERS"] = 0x0000000000000004] = "BAN_MEMBERS"; + BitwisePermissionFlags[BitwisePermissionFlags["ADMINISTRATOR"] = 0x0000000000000008] = "ADMINISTRATOR"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_CHANNELS"] = 0x0000000000000010] = "MANAGE_CHANNELS"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_GUILD"] = 0x0000000000000020] = "MANAGE_GUILD"; + BitwisePermissionFlags[BitwisePermissionFlags["ADD_REACTIONS"] = 0x0000000000000040] = "ADD_REACTIONS"; + BitwisePermissionFlags[BitwisePermissionFlags["VIEW_AUDIT_LOG"] = 0x0000000000000080] = "VIEW_AUDIT_LOG"; + BitwisePermissionFlags[BitwisePermissionFlags["PRIORITY_SPEAKER"] = 0x0000000000000100] = "PRIORITY_SPEAKER"; + BitwisePermissionFlags[BitwisePermissionFlags["STREAM"] = 0x0000000000000200] = "STREAM"; + BitwisePermissionFlags[BitwisePermissionFlags["VIEW_CHANNEL"] = 0x0000000000000400] = "VIEW_CHANNEL"; + BitwisePermissionFlags[BitwisePermissionFlags["SEND_MESSAGES"] = 0x0000000000000800] = "SEND_MESSAGES"; + BitwisePermissionFlags[BitwisePermissionFlags["SEND_TTS_MESSAGES"] = 0x0000000000001000] = "SEND_TTS_MESSAGES"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_MESSAGES"] = 0x0000000000002000] = "MANAGE_MESSAGES"; + BitwisePermissionFlags[BitwisePermissionFlags["EMBED_LINKS"] = 0x0000000000004000] = "EMBED_LINKS"; + BitwisePermissionFlags[BitwisePermissionFlags["ATTACH_FILES"] = 0x0000000000008000] = "ATTACH_FILES"; + BitwisePermissionFlags[BitwisePermissionFlags["READ_MESSAGE_HISTORY"] = 0x0000000000010000] = "READ_MESSAGE_HISTORY"; + BitwisePermissionFlags[BitwisePermissionFlags["MENTION_EVERYONE"] = 0x0000000000020000] = "MENTION_EVERYONE"; + BitwisePermissionFlags[BitwisePermissionFlags["USE_EXTERNAL_EMOJIS"] = 0x0000000000040000] = "USE_EXTERNAL_EMOJIS"; + BitwisePermissionFlags[BitwisePermissionFlags["VIEW_GUILD_INSIGHTS"] = 0x0000000000080000] = "VIEW_GUILD_INSIGHTS"; + BitwisePermissionFlags[BitwisePermissionFlags["CONNECT"] = 0x0000000000100000] = "CONNECT"; + BitwisePermissionFlags[BitwisePermissionFlags["SPEAK"] = 0x0000000000200000] = "SPEAK"; + BitwisePermissionFlags[BitwisePermissionFlags["MUTE_MEMBERS"] = 0x0000000000400000] = "MUTE_MEMBERS"; + BitwisePermissionFlags[BitwisePermissionFlags["DEAFEN_MEMBERS"] = 0x0000000000800000] = "DEAFEN_MEMBERS"; + BitwisePermissionFlags[BitwisePermissionFlags["MOVE_MEMBERS"] = 0x0000000001000000] = "MOVE_MEMBERS"; + BitwisePermissionFlags[BitwisePermissionFlags["USE_VAD"] = 0x0000000002000000] = "USE_VAD"; + BitwisePermissionFlags[BitwisePermissionFlags["CHANGE_NICKNAME"] = 0x0000000004000000] = "CHANGE_NICKNAME"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_NICKNAMES"] = 0x0000000008000000] = "MANAGE_NICKNAMES"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_ROLES"] = 0x0000000010000000] = "MANAGE_ROLES"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_WEBHOOKS"] = 0x0000000020000000] = "MANAGE_WEBHOOKS"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_EMOJIS"] = 0x0000000040000000] = "MANAGE_EMOJIS"; + BitwisePermissionFlags[BitwisePermissionFlags["USE_SLASH_COMMANDS"] = 0x0000000080000000] = "USE_SLASH_COMMANDS"; + BitwisePermissionFlags[BitwisePermissionFlags["REQUEST_TO_SPEAK"] = 0x0000000100000000] = "REQUEST_TO_SPEAK"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_EVENTS"] = 0x0000000200000000] = "MANAGE_EVENTS"; + BitwisePermissionFlags[BitwisePermissionFlags["MANAGE_THREADS"] = 0x0000000400000000] = "MANAGE_THREADS"; + BitwisePermissionFlags[BitwisePermissionFlags["CREATE_PUBLIC_THREADS"] = 0x0000000800000000] = "CREATE_PUBLIC_THREADS"; + BitwisePermissionFlags[BitwisePermissionFlags["CREATE_PRIVATE_THREADS"] = 0x0000001000000000] = "CREATE_PRIVATE_THREADS"; + BitwisePermissionFlags[BitwisePermissionFlags["USE_EXTERNAL_STICKERS"] = 0x0000002000000000] = "USE_EXTERNAL_STICKERS"; + BitwisePermissionFlags[BitwisePermissionFlags["SEND_MESSAGES_IN_THREADS"] = 0x0000004000000000] = "SEND_MESSAGES_IN_THREADS"; + BitwisePermissionFlags[BitwisePermissionFlags["USE_EMBEDDED_ACTIVITIES"] = 0x0000008000000000] = "USE_EMBEDDED_ACTIVITIES"; + BitwisePermissionFlags[BitwisePermissionFlags["MODERATE_MEMBERS"] = 0x0000010000000000] = "MODERATE_MEMBERS"; +})(BitwisePermissionFlags || (BitwisePermissionFlags = {})); +var VoiceOpcodes; +(function(VoiceOpcodes) { + VoiceOpcodes[VoiceOpcodes["Identify"] = 0] = "Identify"; + VoiceOpcodes[VoiceOpcodes["SelectProtocol"] = 1] = "SelectProtocol"; + VoiceOpcodes[VoiceOpcodes["Ready"] = 2] = "Ready"; + VoiceOpcodes[VoiceOpcodes["Heartbeat"] = 3] = "Heartbeat"; + VoiceOpcodes[VoiceOpcodes["SessionDescription"] = 4] = "SessionDescription"; + VoiceOpcodes[VoiceOpcodes["Speaking"] = 5] = "Speaking"; + VoiceOpcodes[VoiceOpcodes["HeartbeatACK"] = 6] = "HeartbeatACK"; + VoiceOpcodes[VoiceOpcodes["Resume"] = 7] = "Resume"; + VoiceOpcodes[VoiceOpcodes["Hello"] = 8] = "Hello"; + VoiceOpcodes[VoiceOpcodes["Resumed"] = 9] = "Resumed"; + VoiceOpcodes[VoiceOpcodes["ClientDisconnect"] = 13] = "ClientDisconnect"; +})(VoiceOpcodes || (VoiceOpcodes = {})); +var VoiceCloseEventCodes; +(function(VoiceCloseEventCodes) { + VoiceCloseEventCodes[VoiceCloseEventCodes["UnknownOpcode"] = 4001] = "UnknownOpcode"; + VoiceCloseEventCodes[VoiceCloseEventCodes["FailedToDecodePayload"] = 4002] = "FailedToDecodePayload"; + VoiceCloseEventCodes[VoiceCloseEventCodes["NotAuthenticated"] = 4003] = "NotAuthenticated"; + VoiceCloseEventCodes[VoiceCloseEventCodes["AuthenticationFailed"] = 4004] = "AuthenticationFailed"; + VoiceCloseEventCodes[VoiceCloseEventCodes["AlreadyAuthenticated"] = 4005] = "AlreadyAuthenticated"; + VoiceCloseEventCodes[VoiceCloseEventCodes["SessionNoLongerValid"] = 4006] = "SessionNoLongerValid"; + VoiceCloseEventCodes[VoiceCloseEventCodes["SessionTimedOut"] = 4009] = "SessionTimedOut"; + VoiceCloseEventCodes[VoiceCloseEventCodes["ServerNotFound"] = 4011] = "ServerNotFound"; + VoiceCloseEventCodes[VoiceCloseEventCodes["UnknownProtocol"] = 4012] = "UnknownProtocol"; + VoiceCloseEventCodes[VoiceCloseEventCodes["Disconnect"] = 4014] = "Disconnect"; + VoiceCloseEventCodes[VoiceCloseEventCodes["VoiceServerCrashed"] = 4015] = "VoiceServerCrashed"; + VoiceCloseEventCodes[VoiceCloseEventCodes["UnknownEncryptionMode"] = 4016] = "UnknownEncryptionMode"; +})(VoiceCloseEventCodes || (VoiceCloseEventCodes = {})); +var RpcErrorCodes; +(function(RpcErrorCodes) { + RpcErrorCodes[RpcErrorCodes["UnknownError"] = 1000] = "UnknownError"; + RpcErrorCodes[RpcErrorCodes["InvalidPayload"] = 4000] = "InvalidPayload"; + RpcErrorCodes[RpcErrorCodes["InvalidCommand"] = 4002] = "InvalidCommand"; + RpcErrorCodes[RpcErrorCodes["InvalidGuild"] = 4003] = "InvalidGuild"; + RpcErrorCodes[RpcErrorCodes["InvalidEvent"] = 4004] = "InvalidEvent"; + RpcErrorCodes[RpcErrorCodes["InvalidChannel"] = 4005] = "InvalidChannel"; + RpcErrorCodes[RpcErrorCodes["InvalidPermissions"] = 4006] = "InvalidPermissions"; + RpcErrorCodes[RpcErrorCodes["InvalidClientId"] = 4007] = "InvalidClientId"; + RpcErrorCodes[RpcErrorCodes["InvalidOrigin"] = 4008] = "InvalidOrigin"; + RpcErrorCodes[RpcErrorCodes["InvalidToken"] = 4009] = "InvalidToken"; + RpcErrorCodes[RpcErrorCodes["InvalidUser"] = 4010] = "InvalidUser"; + RpcErrorCodes[RpcErrorCodes["OAuth2Error"] = 5000] = "OAuth2Error"; + RpcErrorCodes[RpcErrorCodes["SelectChannelTimedOut"] = 5001] = "SelectChannelTimedOut"; + RpcErrorCodes[RpcErrorCodes["GetGuildTimedOut"] = 5002] = "GetGuildTimedOut"; + RpcErrorCodes[RpcErrorCodes["SelectVoiceForceRequired"] = 5003] = "SelectVoiceForceRequired"; + RpcErrorCodes[RpcErrorCodes["CaptureShortcutAlreadyListening"] = 5004] = "CaptureShortcutAlreadyListening"; +})(RpcErrorCodes || (RpcErrorCodes = {})); +var RpcCloseEventCodes; +(function(RpcCloseEventCodes) { + RpcCloseEventCodes[RpcCloseEventCodes["InvalidClientId"] = 4000] = "InvalidClientId"; + RpcCloseEventCodes[RpcCloseEventCodes["InvalidOrigin"] = 4001] = "InvalidOrigin"; + RpcCloseEventCodes[RpcCloseEventCodes["RateLimited"] = 4002] = "RateLimited"; + RpcCloseEventCodes[RpcCloseEventCodes["TokenRevoked"] = 4003] = "TokenRevoked"; + RpcCloseEventCodes[RpcCloseEventCodes["InvalidVersion"] = 4004] = "InvalidVersion"; + RpcCloseEventCodes[RpcCloseEventCodes["InvalidEncoding"] = 4005] = "InvalidEncoding"; +})(RpcCloseEventCodes || (RpcCloseEventCodes = {})); +var HTTPResponseCodes; +(function(HTTPResponseCodes) { + HTTPResponseCodes[HTTPResponseCodes["Ok"] = 200] = "Ok"; + HTTPResponseCodes[HTTPResponseCodes["Created"] = 201] = "Created"; + HTTPResponseCodes[HTTPResponseCodes["NoContent"] = 204] = "NoContent"; + HTTPResponseCodes[HTTPResponseCodes["NotModified"] = 304] = "NotModified"; + HTTPResponseCodes[HTTPResponseCodes["BadRequest"] = 400] = "BadRequest"; + HTTPResponseCodes[HTTPResponseCodes["Unauthorized"] = 401] = "Unauthorized"; + HTTPResponseCodes[HTTPResponseCodes["Forbidden"] = 403] = "Forbidden"; + HTTPResponseCodes[HTTPResponseCodes["NotFound"] = 404] = "NotFound"; + HTTPResponseCodes[HTTPResponseCodes["MethodNotAllowed"] = 405] = "MethodNotAllowed"; + HTTPResponseCodes[HTTPResponseCodes["TooManyRequests"] = 429] = "TooManyRequests"; + HTTPResponseCodes[HTTPResponseCodes["GatewayUnavailable"] = 502] = "GatewayUnavailable"; +})(HTTPResponseCodes || (HTTPResponseCodes = {})); +var GatewayCloseEventCodes; +(function(GatewayCloseEventCodes) { + GatewayCloseEventCodes[GatewayCloseEventCodes["NormalClosure"] = 1000] = "NormalClosure"; + GatewayCloseEventCodes[GatewayCloseEventCodes["UnknownError"] = 4000] = "UnknownError"; + GatewayCloseEventCodes[GatewayCloseEventCodes["UnknownOpcode"] = 4001] = "UnknownOpcode"; + GatewayCloseEventCodes[GatewayCloseEventCodes["DecodeError"] = 4002] = "DecodeError"; + GatewayCloseEventCodes[GatewayCloseEventCodes["NotAuthenticated"] = 4003] = "NotAuthenticated"; + GatewayCloseEventCodes[GatewayCloseEventCodes["AuthenticationFailed"] = 4004] = "AuthenticationFailed"; + GatewayCloseEventCodes[GatewayCloseEventCodes["AlreadyAuthenticated"] = 4005] = "AlreadyAuthenticated"; + GatewayCloseEventCodes[GatewayCloseEventCodes["InvalidSeq"] = 4007] = "InvalidSeq"; + GatewayCloseEventCodes[GatewayCloseEventCodes["RateLimited"] = 4008] = "RateLimited"; + GatewayCloseEventCodes[GatewayCloseEventCodes["SessionTimedOut"] = 4009] = "SessionTimedOut"; + GatewayCloseEventCodes[GatewayCloseEventCodes["InvalidShard"] = 4010] = "InvalidShard"; + GatewayCloseEventCodes[GatewayCloseEventCodes["ShardingRequired"] = 4011] = "ShardingRequired"; + GatewayCloseEventCodes[GatewayCloseEventCodes["InvalidApiVersion"] = 4012] = "InvalidApiVersion"; + GatewayCloseEventCodes[GatewayCloseEventCodes["InvalidIntents"] = 4013] = "InvalidIntents"; + GatewayCloseEventCodes[GatewayCloseEventCodes["DisallowedIntents"] = 4014] = "DisallowedIntents"; +})(GatewayCloseEventCodes || (GatewayCloseEventCodes = {})); +var InviteTargetTypes; +(function(InviteTargetTypes) { + InviteTargetTypes[InviteTargetTypes["Stream"] = 1] = "Stream"; + InviteTargetTypes[InviteTargetTypes["EmbeddedApplication"] = 2] = "EmbeddedApplication"; +})(InviteTargetTypes || (InviteTargetTypes = {})); +var GatewayOpcodes; +(function(GatewayOpcodes) { + GatewayOpcodes[GatewayOpcodes["Dispatch"] = 0] = "Dispatch"; + GatewayOpcodes[GatewayOpcodes["Heartbeat"] = 1] = "Heartbeat"; + GatewayOpcodes[GatewayOpcodes["Identify"] = 2] = "Identify"; + GatewayOpcodes[GatewayOpcodes["PresenceUpdate"] = 3] = "PresenceUpdate"; + GatewayOpcodes[GatewayOpcodes["VoiceStateUpdate"] = 4] = "VoiceStateUpdate"; + GatewayOpcodes[GatewayOpcodes["Resume"] = 6] = "Resume"; + GatewayOpcodes[GatewayOpcodes["Reconnect"] = 7] = "Reconnect"; + GatewayOpcodes[GatewayOpcodes["RequestGuildMembers"] = 8] = "RequestGuildMembers"; + GatewayOpcodes[GatewayOpcodes["InvalidSession"] = 9] = "InvalidSession"; + GatewayOpcodes[GatewayOpcodes["Hello"] = 10] = "Hello"; + GatewayOpcodes[GatewayOpcodes["HeartbeatACK"] = 11] = "HeartbeatACK"; +})(GatewayOpcodes || (GatewayOpcodes = {})); +var GatewayIntents; +(function(GatewayIntents) { + GatewayIntents[GatewayIntents["Guilds"] = 1] = "Guilds"; + GatewayIntents[GatewayIntents["GuildMembers"] = 2] = "GuildMembers"; + GatewayIntents[GatewayIntents["GuildBans"] = 4] = "GuildBans"; + GatewayIntents[GatewayIntents["GuildEmojis"] = 8] = "GuildEmojis"; + GatewayIntents[GatewayIntents["GuildIntegrations"] = 16] = "GuildIntegrations"; + GatewayIntents[GatewayIntents["GuildWebhooks"] = 32] = "GuildWebhooks"; + GatewayIntents[GatewayIntents["GuildInvites"] = 64] = "GuildInvites"; + GatewayIntents[GatewayIntents["GuildVoiceStates"] = 128] = "GuildVoiceStates"; + GatewayIntents[GatewayIntents["GuildPresences"] = 256] = "GuildPresences"; + GatewayIntents[GatewayIntents["GuildMessages"] = 512] = "GuildMessages"; + GatewayIntents[GatewayIntents["GuildMessageReactions"] = 1024] = "GuildMessageReactions"; + GatewayIntents[GatewayIntents["GuildMessageTyping"] = 2048] = "GuildMessageTyping"; + GatewayIntents[GatewayIntents["DirectMessages"] = 4096] = "DirectMessages"; + GatewayIntents[GatewayIntents["DirectMessageReactions"] = 8192] = "DirectMessageReactions"; + GatewayIntents[GatewayIntents["DirectMessageTyping"] = 16384] = "DirectMessageTyping"; + GatewayIntents[GatewayIntents["MessageContent"] = 32768] = "MessageContent"; + GatewayIntents[GatewayIntents["GuildScheduledEvents"] = 65536] = "GuildScheduledEvents"; + GatewayIntents[GatewayIntents["AutoModerationConfiguration"] = 1048576] = "AutoModerationConfiguration"; + GatewayIntents[GatewayIntents["AutoModerationExecution"] = 2097152] = "AutoModerationExecution"; +})(GatewayIntents || (GatewayIntents = {})); +var InteractionResponseTypes; +(function(InteractionResponseTypes) { + InteractionResponseTypes[InteractionResponseTypes["Pong"] = 1] = "Pong"; + InteractionResponseTypes[InteractionResponseTypes["ChannelMessageWithSource"] = 4] = "ChannelMessageWithSource"; + InteractionResponseTypes[InteractionResponseTypes["DeferredChannelMessageWithSource"] = 5] = "DeferredChannelMessageWithSource"; + InteractionResponseTypes[InteractionResponseTypes["DeferredUpdateMessage"] = 6] = "DeferredUpdateMessage"; + InteractionResponseTypes[InteractionResponseTypes["UpdateMessage"] = 7] = "UpdateMessage"; + InteractionResponseTypes[InteractionResponseTypes["ApplicationCommandAutocompleteResult"] = 8] = "ApplicationCommandAutocompleteResult"; + InteractionResponseTypes[InteractionResponseTypes["Modal"] = 9] = "Modal"; +})(InteractionResponseTypes || (InteractionResponseTypes = {})); +var Errors; +(function(Errors) { + Errors["BOTS_HIGHEST_ROLE_TOO_LOW"] = "BOTS_HIGHEST_ROLE_TOO_LOW"; + Errors["CHANNEL_NOT_FOUND"] = "CHANNEL_NOT_FOUND"; + Errors["CHANNEL_NOT_IN_GUILD"] = "CHANNEL_NOT_IN_GUILD"; + Errors["CHANNEL_NOT_TEXT_BASED"] = "CHANNEL_NOT_TEXT_BASED"; + Errors["CHANNEL_NOT_STAGE_VOICE"] = "CHANNEL_NOT_STAGE_VOICE"; + Errors["MESSAGE_MAX_LENGTH"] = "MESSAGE_MAX_LENGTH"; + Errors["RULES_CHANNEL_CANNOT_BE_DELETED"] = "RULES_CHANNEL_CANNOT_BE_DELETED"; + Errors["UPDATES_CHANNEL_CANNOT_BE_DELETED"] = "UPDATES_CHANNEL_CANNOT_BE_DELETED"; + Errors["INVALID_TOPIC_LENGTH"] = "INVALID_TOPIC_LENGTH"; + Errors["GUILD_NOT_DISCOVERABLE"] = "GUILD_NOT_DISCOVERABLE"; + Errors["GUILD_WIDGET_NOT_ENABLED"] = "GUILD_WIDGET_NOT_ENABLED"; + Errors["GUILD_NOT_FOUND"] = "GUILD_NOT_FOUND"; + Errors["MEMBER_NOT_FOUND"] = "MEMBER_NOT_FOUND"; + Errors["MEMBER_NOT_IN_VOICE_CHANNEL"] = "MEMBER_NOT_IN_VOICE_CHANNEL"; + Errors["MEMBER_SEARCH_LIMIT_TOO_HIGH"] = "MEMBER_SEARCH_LIMIT_TOO_HIGH"; + Errors["MEMBER_SEARCH_LIMIT_TOO_LOW"] = "MEMBER_SEARCH_LIMIT_TOO_LOW"; + Errors["PRUNE_MAX_DAYS"] = "PRUNE_MAX_DAYS"; + Errors["ROLE_NOT_FOUND"] = "ROLE_NOT_FOUND"; + Errors["INVALID_THREAD_PARENT_CHANNEL_TYPE"] = "INVALID_THREAD_PARENT_CHANNEL_TYPE"; + Errors["GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS"] = "GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS"; + Errors["NOT_A_THREAD_CHANNEL"] = "NOT_A_THREAD_CHANNEL"; + Errors["MISSING_MANAGE_THREADS_AND_NOT_MEMBER"] = "MISSING_MANAGE_THREADS_AND_NOT_MEMBER"; + Errors["CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD"] = "CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD"; + Errors["HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS"] = "HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS"; + Errors["INVALID_GET_MESSAGES_LIMIT"] = "INVALID_GET_MESSAGES_LIMIT"; + Errors["DELETE_MESSAGES_MIN"] = "DELETE_MESSAGES_MIN"; + Errors["PRUNE_MIN_DAYS"] = "PRUNE_MIN_DAYS"; + Errors["INVALID_SLASH_DESCRIPTION"] = "INVALID_SLASH_DESCRIPTION"; + Errors["INVALID_SLASH_NAME"] = "INVALID_SLASH_NAME"; + Errors["INVALID_SLASH_OPTIONS"] = "INVALID_SLASH_OPTIONS"; + Errors["INVALID_SLASH_OPTIONS_CHOICES"] = "INVALID_SLASH_OPTIONS_CHOICES"; + Errors["TOO_MANY_SLASH_OPTIONS"] = "TOO_MANY_SLASH_OPTIONS"; + Errors["INVALID_SLASH_OPTION_CHOICE_NAME"] = "INVALID_SLASH_OPTION_CHOICE_NAME"; + Errors["INVALID_SLASH_OPTIONS_CHOICE_VALUE_TYPE"] = "INVALID_SLASH_OPTIONS_CHOICE_VALUE_TYPE"; + Errors["TOO_MANY_SLASH_OPTION_CHOICES"] = "TOO_MANY_SLASH_OPTION_CHOICES"; + Errors["ONLY_STRING_OR_INTEGER_OPTIONS_CAN_HAVE_CHOICES"] = "ONLY_STRING_OR_INTEGER_OPTIONS_CAN_HAVE_CHOICES"; + Errors["INVALID_SLASH_OPTION_NAME"] = "INVALID_SLASH_OPTION_NAME"; + Errors["INVALID_SLASH_OPTION_DESCRIPTION"] = "INVALID_SLASH_OPTION_DESCRIPTION"; + Errors["INVALID_CONTEXT_MENU_COMMAND_NAME"] = "INVALID_CONTEXT_MENU_COMMAND_NAME"; + Errors["INVALID_CONTEXT_MENU_COMMAND_DESCRIPTION"] = "INVALID_CONTEXT_MENU_COMMAND_DESCRIPTION"; + Errors["INVALID_WEBHOOK_NAME"] = "INVALID_WEBHOOK_NAME"; + Errors["INVALID_WEBHOOK_OPTIONS"] = "INVALID_WEBHOOK_OPTIONS"; + Errors["MISSING_ADD_REACTIONS"] = "MISSING_ADD_REACTIONS"; + Errors["MISSING_ADMINISTRATOR"] = "MISSING_ADMINISTRATOR"; + Errors["MISSING_ATTACH_FILES"] = "MISSING_ATTACH_FILES"; + Errors["MISSING_BAN_MEMBERS"] = "MISSING_BAN_MEMBERS"; + Errors["MISSING_CHANGE_NICKNAME"] = "MISSING_CHANGE_NICKNAME"; + Errors["MISSING_CONNECT"] = "MISSING_CONNECT"; + Errors["MISSING_CREATE_INSTANT_INVITE"] = "MISSING_CREATE_INSTANT_INVITE"; + Errors["MISSING_DEAFEN_MEMBERS"] = "MISSING_DEAFEN_MEMBERS"; + Errors["MISSING_EMBED_LINKS"] = "MISSING_EMBED_LINKS"; + Errors["MISSING_INTENT_GUILD_MEMBERS"] = "MISSING_INTENT_GUILD_MEMBERS"; + Errors["MISSING_KICK_MEMBERS"] = "MISSING_KICK_MEMBERS"; + Errors["MISSING_MANAGE_CHANNELS"] = "MISSING_MANAGE_CHANNELS"; + Errors["MISSING_MANAGE_EMOJIS"] = "MISSING_MANAGE_EMOJIS"; + Errors["MISSING_MANAGE_GUILD"] = "MISSING_MANAGE_GUILD"; + Errors["MISSING_MANAGE_MESSAGES"] = "MISSING_MANAGE_MESSAGES"; + Errors["MISSING_MANAGE_NICKNAMES"] = "MISSING_MANAGE_NICKNAMES"; + Errors["MISSING_MANAGE_ROLES"] = "MISSING_MANAGE_ROLES"; + Errors["MISSING_MANAGE_WEBHOOKS"] = "MISSING_MANAGE_WEBHOOKS"; + Errors["MISSING_MENTION_EVERYONE"] = "MISSING_MENTION_EVERYONE"; + Errors["MISSING_MOVE_MEMBERS"] = "MISSING_MOVE_MEMBERS"; + Errors["MISSING_MUTE_MEMBERS"] = "MISSING_MUTE_MEMBERS"; + Errors["MISSING_PRIORITY_SPEAKER"] = "MISSING_PRIORITY_SPEAKER"; + Errors["MISSING_READ_MESSAGE_HISTORY"] = "MISSING_READ_MESSAGE_HISTORY"; + Errors["MISSING_SEND_MESSAGES"] = "MISSING_SEND_MESSAGES"; + Errors["MISSING_SEND_TTS_MESSAGES"] = "MISSING_SEND_TTS_MESSAGES"; + Errors["MISSING_SPEAK"] = "MISSING_SPEAK"; + Errors["MISSING_STREAM"] = "MISSING_STREAM"; + Errors["MISSING_USE_VAD"] = "MISSING_USE_VAD"; + Errors["MISSING_USE_EXTERNAL_EMOJIS"] = "MISSING_USE_EXTERNAL_EMOJIS"; + Errors["MISSING_VIEW_AUDIT_LOG"] = "MISSING_VIEW_AUDIT_LOG"; + Errors["MISSING_VIEW_CHANNEL"] = "MISSING_VIEW_CHANNEL"; + Errors["MISSING_VIEW_GUILD_INSIGHTS"] = "MISSING_VIEW_GUILD_INSIGHTS"; + Errors["NICKNAMES_MAX_LENGTH"] = "NICKNAMES_MAX_LENGTH"; + Errors["USERNAME_INVALID_CHARACTER"] = "USERNAME_INVALID_CHARACTER"; + Errors["USERNAME_INVALID_USERNAME"] = "USERNAME_INVALID_USERNAME"; + Errors["USERNAME_MAX_LENGTH"] = "USERNAME_MAX_LENGTH"; + Errors["USERNAME_MIN_LENGTH"] = "USERNAME_MIN_LENGTH"; + Errors["NONCE_TOO_LONG"] = "NONCE_TOO_LONG"; + Errors["INVITE_MAX_AGE_INVALID"] = "INVITE_MAX_AGE_INVALID"; + Errors["INVITE_MAX_USES_INVALID"] = "INVITE_MAX_USES_INVALID"; + Errors["RATE_LIMIT_RETRY_MAXED"] = "RATE_LIMIT_RETRY_MAXED"; + Errors["REQUEST_CLIENT_ERROR"] = "REQUEST_CLIENT_ERROR"; + Errors["REQUEST_SERVER_ERROR"] = "REQUEST_SERVER_ERROR"; + Errors["REQUEST_UNKNOWN_ERROR"] = "REQUEST_UNKNOWN_ERROR"; + Errors["TOO_MANY_COMPONENTS"] = "TOO_MANY_COMPONENTS"; + Errors["TOO_MANY_ACTION_ROWS"] = "TOO_MANY_ACTION_ROWS"; + Errors["LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID"] = "LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID"; + Errors["COMPONENT_LABEL_TOO_BIG"] = "COMPONENT_LABEL_TOO_BIG"; + Errors["COMPONENT_CUSTOM_ID_TOO_BIG"] = "COMPONENT_CUSTOM_ID_TOO_BIG"; + Errors["BUTTON_REQUIRES_CUSTOM_ID"] = "BUTTON_REQUIRES_CUSTOM_ID"; + Errors["COMPONENT_SELECT_MUST_BE_ALONE"] = "COMPONENT_SELECT_MUST_BE_ALONE"; + Errors["COMPONENT_PLACEHOLDER_TOO_BIG"] = "COMPONENT_PLACEHOLDER_TOO_BIG"; + Errors["COMPONENT_SELECT_MIN_VALUE_TOO_LOW"] = "COMPONENT_SELECT_MIN_VALUE_TOO_LOW"; + Errors["COMPONENT_SELECT_MIN_VALUE_TOO_MANY"] = "COMPONENT_SELECT_MIN_VALUE_TOO_MANY"; + Errors["COMPONENT_SELECT_MAX_VALUE_TOO_LOW"] = "COMPONENT_SELECT_MAX_VALUE_TOO_LOW"; + Errors["COMPONENT_SELECT_MAX_VALUE_TOO_MANY"] = "COMPONENT_SELECT_MAX_VALUE_TOO_MANY"; + Errors["COMPONENT_SELECT_OPTIONS_TOO_LOW"] = "COMPONENT_SELECT_OPTIONS_TOO_LOW"; + Errors["COMPONENT_SELECT_OPTIONS_TOO_MANY"] = "COMPONENT_SELECT_OPTIONS_TOO_MANY"; + Errors["SELECT_OPTION_LABEL_TOO_BIG"] = "SELECT_OPTION_LABEL_TOO_BIG"; + Errors["SELECT_OPTION_VALUE_TOO_BIG"] = "SELECT_OPTION_VALUE_TOO_BIG"; + Errors["SELECT_OPTION_TOO_MANY_DEFAULTS"] = "SELECT_OPTION_TOO_MANY_DEFAULTS"; + Errors["COMPONENT_SELECT_MIN_HIGHER_THAN_MAX"] = "COMPONENT_SELECT_MIN_HIGHER_THAN_MAX"; + Errors["CANNOT_ADD_USER_TO_ARCHIVED_THREADS"] = "CANNOT_ADD_USER_TO_ARCHIVED_THREADS"; + Errors["CANNOT_LEAVE_ARCHIVED_THREAD"] = "CANNOT_LEAVE_ARCHIVED_THREAD"; + Errors["CANNOT_REMOVE_FROM_ARCHIVED_THREAD"] = "CANNOT_REMOVE_FROM_ARCHIVED_THREAD"; + Errors["YOU_CAN_NOT_DM_THE_BOT_ITSELF"] = "YOU_CAN_NOT_DM_THE_BOT_ITSELF"; +})(Errors || (Errors = {})); +var Locales; +(function(Locales) { + Locales["Danish"] = "da"; + Locales["German"] = "de"; + Locales["EnglishUk"] = "en-GB"; + Locales["EnglishUs"] = "en-US"; + Locales["Spanish"] = "es-ES"; + Locales["French"] = "fr"; + Locales["Croatian"] = "hr"; + Locales["Italian"] = "it"; + Locales["Lithuanian"] = "lt"; + Locales["Hungarian"] = "hu"; + Locales["Dutch"] = "nl"; + Locales["Norwegian"] = "no"; + Locales["Polish"] = "pl"; + Locales["PortugueseBrazilian"] = "pt-BR"; + Locales["RomanianRomania"] = "ro"; + Locales["Finnish"] = "fi"; + Locales["Swedish"] = "sv-SE"; + Locales["Vietnamese"] = "vi"; + Locales["Turkish"] = "tr"; + Locales["Czech"] = "cs"; + Locales["Greek"] = "el"; + Locales["Bulgarian"] = "bg"; + Locales["Russian"] = "ru"; + Locales["Ukrainian"] = "uk"; + Locales["Hindi"] = "hi"; + Locales["Thai"] = "th"; + Locales["ChineseChina"] = "zh-CN"; + Locales["Japanese"] = "ja"; + Locales["ChineseTaiwan"] = "zh-TW"; + Locales["Korean"] = "ko"; +})(Locales || (Locales = {})); +const GATEWAY_RATE_LIMIT_RESET_INTERVAL = 60_000; +var ShardState; +(function(ShardState) { + ShardState[ShardState["Connected"] = 0] = "Connected"; + ShardState[ShardState["Connecting"] = 1] = "Connecting"; + ShardState[ShardState["Disconnected"] = 2] = "Disconnected"; + ShardState[ShardState["Unidentified"] = 3] = "Unidentified"; + ShardState[ShardState["Identifying"] = 4] = "Identifying"; + ShardState[ShardState["Resuming"] = 5] = "Resuming"; + ShardState[ShardState["Offline"] = 6] = "Offline"; +})(ShardState || (ShardState = {})); +var ShardSocketCloseCodes; +(function(ShardSocketCloseCodes) { + ShardSocketCloseCodes[ShardSocketCloseCodes["Shutdown"] = 3000] = "Shutdown"; + ShardSocketCloseCodes[ShardSocketCloseCodes["ResumeClosingOldConnection"] = 3024] = "ResumeClosingOldConnection"; + ShardSocketCloseCodes[ShardSocketCloseCodes["ZombiedConnection"] = 3010] = "ZombiedConnection"; + ShardSocketCloseCodes[ShardSocketCloseCodes["TestingFinished"] = 3064] = "TestingFinished"; + ShardSocketCloseCodes[ShardSocketCloseCodes["Resharded"] = 3065] = "Resharded"; + ShardSocketCloseCodes[ShardSocketCloseCodes["ReIdentifying"] = 3066] = "ReIdentifying"; +})(ShardSocketCloseCodes || (ShardSocketCloseCodes = {})); +async function identify(shard) { + if (shard.state === ShardState.Connected) { + shard.close(ShardSocketCloseCodes.ReIdentifying, "Re-identifying closure of old connection."); + } + shard.state = ShardState.Identifying; + shard.events.identifying?.(shard); + if (!shard.isOpen()) { + await shard.connect(); + } + await shard.requestIdentify(); + shard.send({ + op: GatewayOpcodes.Identify, + d: { + token: `Bot ${shard.gatewayConfig.token}`, + compress: shard.gatewayConfig.compress, + properties: shard.gatewayConfig.properties, + intents: shard.gatewayConfig.intents, + shard: [ + shard.id, + shard.totalShards + ], + presence: await shard.makePresence?.(shard.id) + } + }, true); + return new Promise((resolve)=>{ + shard.resolves.set("READY", ()=>{ + shard.events.identified?.(shard); + resolve(); + }); + shard.resolves.set("INVALID_SESSION", ()=>{ + shard.resolves.delete("READY"); + resolve(); + }); + }); +} +const BTYPE = Object.freeze({ + UNCOMPRESSED: 0, + FIXED: 1, + DYNAMIC: 2 +}); +const LENGTH_EXTRA_BIT_LEN = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 3, + 3, + 3, + 3, + 4, + 4, + 4, + 4, + 5, + 5, + 5, + 5, + 0, +]; +const LENGTH_EXTRA_BIT_BASE = [ + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 13, + 15, + 17, + 19, + 23, + 27, + 31, + 35, + 43, + 51, + 59, + 67, + 83, + 99, + 115, + 131, + 163, + 195, + 227, + 258, +]; +const DISTANCE_EXTRA_BIT_BASE = [ + 1, + 2, + 3, + 4, + 5, + 7, + 9, + 13, + 17, + 25, + 33, + 49, + 65, + 97, + 129, + 193, + 257, + 385, + 513, + 769, + 1025, + 1537, + 2049, + 3073, + 4097, + 6145, + 8193, + 12289, + 16385, + 24577, +]; +const DISTANCE_EXTRA_BIT_LEN = [ + 0, + 0, + 0, + 0, + 1, + 1, + 2, + 2, + 3, + 3, + 4, + 4, + 5, + 5, + 6, + 6, + 7, + 7, + 8, + 8, + 9, + 9, + 10, + 10, + 11, + 11, + 12, + 12, + 13, + 13, +]; +const CODELEN_VALUES = [ + 16, + 17, + 18, + 0, + 8, + 7, + 9, + 6, + 10, + 5, + 11, + 4, + 12, + 3, + 13, + 2, + 14, + 1, + 15, +]; +function generateHuffmanTable(codelenValues) { + const codelens = Object.keys(codelenValues); + let codelen = 0; + let codelenMax = 0; + let codelenMin = Number.MAX_SAFE_INTEGER; + codelens.forEach((key)=>{ + codelen = Number(key); + if (codelenMax < codelen) codelenMax = codelen; + if (codelenMin > codelen) codelenMin = codelen; + }); + let code = 0; + let values; + const bitlenTables = {}; + for(let bitlen = codelenMin; bitlen <= codelenMax; bitlen++){ + values = codelenValues[bitlen]; + if (values === undefined) values = []; + values.sort((a, b)=>{ + if (a < b) return -1; + if (a > b) return 1; + return 0; + }); + const table = {}; + values.forEach((value)=>{ + table[code] = value; + code++; + }); + bitlenTables[bitlen] = table; + code <<= 1; + } + return bitlenTables; +} +function makeFixedHuffmanCodelenValues() { + const codelenValues = {}; + codelenValues[7] = []; + codelenValues[8] = []; + codelenValues[9] = []; + for(let i = 0; i <= 287; i++){ + i <= 143 ? codelenValues[8].push(i) : i <= 255 ? codelenValues[9].push(i) : i <= 279 ? codelenValues[7].push(i) : codelenValues[8].push(i); + } + return codelenValues; +} +class BitReadStream { + buffer; + bufferIndex; + nowBits; + nowBitsLength = 0; + isEnd = false; + constructor(buffer, offset = 0){ + this.buffer = buffer; + this.bufferIndex = offset; + this.nowBits = buffer[offset]; + this.nowBitsLength = 8; + } + read() { + if (this.isEnd) throw new Error("Lack of data length"); + const bit = this.nowBits & 1; + if (this.nowBitsLength > 1) { + this.nowBitsLength--; + this.nowBits >>= 1; + } else { + this.bufferIndex++; + if (this.bufferIndex < this.buffer.length) { + this.nowBits = this.buffer[this.bufferIndex]; + this.nowBitsLength = 8; + } else { + this.nowBitsLength = 0; + this.isEnd = true; + } + } + return bit; + } + readRange(length) { + while(this.nowBitsLength <= length){ + this.nowBits |= this.buffer[++this.bufferIndex] << this.nowBitsLength; + this.nowBitsLength += 8; + } + const bits = this.nowBits & (1 << length) - 1; + this.nowBits >>>= length; + this.nowBitsLength -= length; + return bits; + } + readRangeCoded(length) { + let bits = 0; + for(let i = 0; i < length; i++){ + bits <<= 1; + bits |= this.read(); + } + return bits; + } +} +class Uint8WriteStream { + index = 0; + buffer; + length; + _extendedSize; + constructor(extendedSize){ + this.buffer = new Uint8Array(extendedSize); + this.length = extendedSize; + this._extendedSize = extendedSize; + } + write(value) { + if (this.length <= this.index) { + this.length += this._extendedSize; + const newBuffer = new Uint8Array(this.length); + const nowSize = this.buffer.length; + for(let i = 0; i < nowSize; i++){ + newBuffer[i] = this.buffer[i]; + } + this.buffer = newBuffer; + } + this.buffer[this.index] = value; + this.index++; + } +} +const FIXED_HUFFMAN_TABLE = generateHuffmanTable(makeFixedHuffmanCodelenValues()); +function inflate(input, offset = 0) { + const buffer = new Uint8WriteStream(input.length * 10); + const stream = new BitReadStream(input, offset); + let bFinal = 0; + let bType = 0; + while(bFinal !== 1){ + bFinal = stream.readRange(1); + bType = stream.readRange(2); + if (bType === BTYPE.UNCOMPRESSED) { + inflateUncompressedBlock(stream, buffer); + } else if (bType === BTYPE.FIXED) { + inflateFixedBlock(stream, buffer); + } else if (bType === BTYPE.DYNAMIC) { + inflateDynamicBlock(stream, buffer); + } else { + throw new Error("Not supported BTYPE : " + bType); + } + if (bFinal === 0 && stream.isEnd) { + throw new Error("Data length is insufficient"); + } + } + return buffer.buffer.subarray(0, buffer.index); +} +function inflateUncompressedBlock(stream, buffer) { + if (stream.nowBitsLength < 8) { + stream.readRange(stream.nowBitsLength); + } + const LEN = stream.readRange(8) | stream.readRange(8) << 8; + const NLEN = stream.readRange(8) | stream.readRange(8) << 8; + if (LEN + NLEN !== 65535) { + throw new Error("Data is corrupted"); + } + for(let i = 0; i < LEN; i++){ + buffer.write(stream.readRange(8)); + } +} +function inflateFixedBlock(stream, buffer) { + const tables = FIXED_HUFFMAN_TABLE; + const codelens = Object.keys(tables); + let codelen = 0; + let codelenMax = 0; + let codelenMin = Number.MAX_SAFE_INTEGER; + codelens.forEach((key)=>{ + codelen = Number(key); + if (codelenMax < codelen) codelenMax = codelen; + if (codelenMin > codelen) codelenMin = codelen; + }); + let code = 0; + let value; + let repeatLengthCode; + let repeatLengthValue; + let repeatLengthExt; + let repeatDistanceCode; + let repeatDistanceValue; + let repeatDistanceExt; + let repeatStartIndex; + while(!stream.isEnd){ + value = undefined; + codelen = codelenMin; + code = stream.readRangeCoded(codelenMin); + while(true){ + value = tables[codelen][code]; + if (value !== undefined) { + break; + } + if (codelenMax <= codelen) { + throw new Error("Data is corrupted"); + } + codelen++; + code <<= 1; + code |= stream.read(); + } + if (value < 256) { + buffer.write(value); + continue; + } + if (value === 256) { + break; + } + repeatLengthCode = value - 257; + repeatLengthValue = LENGTH_EXTRA_BIT_BASE[repeatLengthCode]; + repeatLengthExt = LENGTH_EXTRA_BIT_LEN[repeatLengthCode]; + if (0 < repeatLengthExt) { + repeatLengthValue += stream.readRange(repeatLengthExt); + } + repeatDistanceCode = stream.readRangeCoded(5); + repeatDistanceValue = DISTANCE_EXTRA_BIT_BASE[repeatDistanceCode]; + repeatDistanceExt = DISTANCE_EXTRA_BIT_LEN[repeatDistanceCode]; + if (0 < repeatDistanceExt) { + repeatDistanceValue += stream.readRange(repeatDistanceExt); + } + repeatStartIndex = buffer.index - repeatDistanceValue; + for(let i = 0; i < repeatLengthValue; i++){ + buffer.write(buffer.buffer[repeatStartIndex + i]); + } + } +} +function inflateDynamicBlock(stream, buffer) { + const HLIT = stream.readRange(5) + 257; + const HDIST = stream.readRange(5) + 1; + const HCLEN = stream.readRange(4) + 4; + let codelenCodelen = 0; + const codelenCodelenValues = {}; + for(let i = 0; i < HCLEN; i++){ + codelenCodelen = stream.readRange(3); + if (codelenCodelen === 0) { + continue; + } + if (!codelenCodelenValues[codelenCodelen]) { + codelenCodelenValues[codelenCodelen] = []; + } + codelenCodelenValues[codelenCodelen].push(CODELEN_VALUES[i]); + } + const codelenHuffmanTables = generateHuffmanTable(codelenCodelenValues); + const codelenCodelens = Object.keys(codelenHuffmanTables); + let codelenCodelenMax = 0; + let codelenCodelenMin = Number.MAX_SAFE_INTEGER; + codelenCodelens.forEach((key)=>{ + codelenCodelen = Number(key); + if (codelenCodelenMax < codelenCodelen) codelenCodelenMax = codelenCodelen; + if (codelenCodelenMin > codelenCodelen) codelenCodelenMin = codelenCodelen; + }); + const dataCodelenValues = {}; + const distanceCodelenValues = {}; + let codelenCode = 0; + let runlengthCode; + let repeat = 0; + let codelen = 0; + const codesNumber = HLIT + HDIST; + for(let i1 = 0; i1 < codesNumber;){ + runlengthCode = undefined; + codelenCodelen = codelenCodelenMin; + codelenCode = stream.readRangeCoded(codelenCodelenMin); + while(true){ + runlengthCode = codelenHuffmanTables[codelenCodelen][codelenCode]; + if (runlengthCode !== undefined) { + break; + } + if (codelenCodelenMax <= codelenCodelen) { + throw new Error("Data is corrupted"); + } + codelenCodelen++; + codelenCode <<= 1; + codelenCode |= stream.read(); + } + if (runlengthCode === 16) { + repeat = 3 + stream.readRange(2); + } else if (runlengthCode === 17) { + repeat = 3 + stream.readRange(3); + codelen = 0; + } else if (runlengthCode === 18) { + repeat = 11 + stream.readRange(7); + codelen = 0; + } else { + repeat = 1; + codelen = runlengthCode; + } + if (codelen <= 0) { + i1 += repeat; + } else { + while(repeat){ + if (i1 < HLIT) { + if (!dataCodelenValues[codelen]) { + dataCodelenValues[codelen] = []; + } + dataCodelenValues[codelen].push(i1++); + } else { + if (!distanceCodelenValues[codelen]) { + distanceCodelenValues[codelen] = []; + } + distanceCodelenValues[codelen].push((i1++) - HLIT); + } + repeat--; + } + } + } + const dataHuffmanTables = generateHuffmanTable(dataCodelenValues); + const distanceHuffmanTables = generateHuffmanTable(distanceCodelenValues); + const dataCodelens = Object.keys(dataHuffmanTables); + let dataCodelen = 0; + let dataCodelenMax = 0; + let dataCodelenMin = Number.MAX_SAFE_INTEGER; + dataCodelens.forEach((key)=>{ + dataCodelen = Number(key); + if (dataCodelenMax < dataCodelen) dataCodelenMax = dataCodelen; + if (dataCodelenMin > dataCodelen) dataCodelenMin = dataCodelen; + }); + const distanceCodelens = Object.keys(distanceHuffmanTables); + let distanceCodelen = 0; + let distanceCodelenMax = 0; + let distanceCodelenMin = Number.MAX_SAFE_INTEGER; + distanceCodelens.forEach((key)=>{ + distanceCodelen = Number(key); + if (distanceCodelenMax < distanceCodelen) { + distanceCodelenMax = distanceCodelen; + } + if (distanceCodelenMin > distanceCodelen) { + distanceCodelenMin = distanceCodelen; + } + }); + let dataCode = 0; + let data; + let repeatLengthCode; + let repeatLengthValue; + let repeatLengthExt; + let repeatDistanceCode; + let repeatDistanceValue; + let repeatDistanceExt; + let repeatDistanceCodeCodelen; + let repeatDistanceCodeCode; + let repeatStartIndex; + while(!stream.isEnd){ + data = undefined; + dataCodelen = dataCodelenMin; + dataCode = stream.readRangeCoded(dataCodelenMin); + while(true){ + data = dataHuffmanTables[dataCodelen][dataCode]; + if (data !== undefined) { + break; + } + if (dataCodelenMax <= dataCodelen) { + throw new Error("Data is corrupted"); + } + dataCodelen++; + dataCode <<= 1; + dataCode |= stream.read(); + } + if (data < 256) { + buffer.write(data); + continue; + } + if (data === 256) { + break; + } + repeatLengthCode = data - 257; + repeatLengthValue = LENGTH_EXTRA_BIT_BASE[repeatLengthCode]; + repeatLengthExt = LENGTH_EXTRA_BIT_LEN[repeatLengthCode]; + if (0 < repeatLengthExt) { + repeatLengthValue += stream.readRange(repeatLengthExt); + } + repeatDistanceCode = undefined; + repeatDistanceCodeCodelen = distanceCodelenMin; + repeatDistanceCodeCode = stream.readRangeCoded(distanceCodelenMin); + while(true){ + repeatDistanceCode = distanceHuffmanTables[repeatDistanceCodeCodelen][repeatDistanceCodeCode]; + if (repeatDistanceCode !== undefined) { + break; + } + if (distanceCodelenMax <= repeatDistanceCodeCodelen) { + throw new Error("Data is corrupted"); + } + repeatDistanceCodeCodelen++; + repeatDistanceCodeCode <<= 1; + repeatDistanceCodeCode |= stream.read(); + } + repeatDistanceValue = DISTANCE_EXTRA_BIT_BASE[repeatDistanceCode]; + repeatDistanceExt = DISTANCE_EXTRA_BIT_LEN[repeatDistanceCode]; + if (0 < repeatDistanceExt) { + repeatDistanceValue += stream.readRange(repeatDistanceExt); + } + repeatStartIndex = buffer.index - repeatDistanceValue; + for(let i2 = 0; i2 < repeatLengthValue; i2++){ + buffer.write(buffer.buffer[repeatStartIndex + i2]); + } + } +} +function inflate1(input) { + const stream = new BitReadStream(input); + const CM = stream.readRange(4); + if (CM !== 8) { + throw new Error("Not compressed by deflate"); + } + stream.readRange(4); + stream.readRange(5); + stream.readRange(1); + stream.readRange(2); + return inflate(input, 2); +} +const decoder = new TextDecoder(); +async function handleMessage(shard, message_) { + let message = message_.data; + if (shard.gatewayConfig.compress && message instanceof Blob) { + message = decoder.decode(inflate1(new Uint8Array(await message.arrayBuffer()))); + } + if (typeof message !== "string") return; + const messageData = JSON.parse(message); + switch(messageData.op){ + case GatewayOpcodes.Heartbeat: + { + if (!shard.isOpen()) return; + shard.heart.lastBeat = Date.now(); + shard.socket?.send(JSON.stringify({ + op: GatewayOpcodes.Heartbeat, + d: shard.previousSequenceNumber + })); + shard.events.heartbeat?.(shard); + break; + } + case GatewayOpcodes.Hello: + { + const interval = messageData.d.heartbeat_interval; + shard.startHeartbeating(interval); + if (shard.state !== ShardState.Resuming) { + shard.bucket = createLeakyBucket({ + max: shard.calculateSafeRequests(), + refillInterval: GATEWAY_RATE_LIMIT_RESET_INTERVAL, + refillAmount: shard.calculateSafeRequests(), + waiting: shard.bucket.waiting + }); + } + shard.events.hello?.(shard); + break; + } + case GatewayOpcodes.HeartbeatACK: + { + shard.heart.acknowledged = true; + shard.heart.lastAck = Date.now(); + if (shard.heart.lastBeat) { + shard.heart.rtt = shard.heart.lastAck - shard.heart.lastBeat; + } + shard.events.heartbeatAck?.(shard); + break; + } + case GatewayOpcodes.Reconnect: + { + shard.events.requestedReconnect?.(shard); + await shard.resume(); + break; + } + case GatewayOpcodes.InvalidSession: + { + const resumable = messageData.d; + shard.events.invalidSession?.(shard, resumable); + await delay(Math.floor((Math.random() * 4 + 1) * 1000)); + shard.resolves.get("INVALID_SESSION")?.(messageData); + shard.resolves.delete("INVALID_SESSION"); + if (!resumable) { + await shard.identify(); + break; + } + await shard.resume(); + break; + } + } + if (messageData.t === "RESUMED") { + shard.state = ShardState.Connected; + shard.events.resumed?.(shard); + shard.offlineSendQueue.map((resolve)=>resolve()); + shard.resolves.get("RESUMED")?.(messageData); + shard.resolves.delete("RESUMED"); + } else if (messageData.t === "READY") { + const payload = messageData.d; + shard.sessionId = payload.session_id; + shard.state = ShardState.Connected; + shard.offlineSendQueue.map((resolve)=>resolve()); + shard.resolves.get("READY")?.(messageData); + shard.resolves.delete("READY"); + } + if (messageData.s !== null) { + shard.previousSequenceNumber = messageData.s; + } + shard.events.message?.(shard, messageData); +} +function startHeartbeating(shard, interval) { + shard.heart.interval = interval; + if ([ + ShardState.Disconnected, + ShardState.Offline + ].includes(shard.state)) { + shard.state = ShardState.Unidentified; + } + const jitter = Math.ceil(shard.heart.interval * (Math.random() || 0.5)); + shard.heart.timeoutId = setTimeout(()=>{ + shard.socket?.send(JSON.stringify({ + op: GatewayOpcodes.Heartbeat, + d: shard.previousSequenceNumber + })); + shard.heart.lastBeat = Date.now(); + shard.heart.acknowledged = false; + shard.heart.intervalId = setInterval(async ()=>{ + if (!shard.heart.acknowledged) { + shard.close(ShardSocketCloseCodes.ZombiedConnection, "Zombied connection, did not receive an heartbeat ACK in time."); + return await shard.identify(); + } + shard.heart.acknowledged = false; + shard.socket?.send(JSON.stringify({ + op: GatewayOpcodes.Heartbeat, + d: shard.previousSequenceNumber + })); + shard.heart.lastBeat = Date.now(); + shard.events.heartbeat?.(shard); + }, shard.heart.interval); + }, jitter); +} +function stopHeartbeating(shard) { + clearInterval(shard.heart.intervalId); + clearTimeout(shard.heart.timeoutId); +} +async function resume(shard) { + if (shard.isOpen()) { + shard.close(ShardSocketCloseCodes.ResumeClosingOldConnection, "Reconnecting the shard, closing old connection."); + } + if (!shard.sessionId) { + return await shard.identify(); + } + shard.state = ShardState.Resuming; + await shard.connect(); + shard.send({ + op: GatewayOpcodes.Resume, + d: { + token: `Bot ${shard.gatewayConfig.token}`, + session_id: shard.sessionId, + seq: shard.previousSequenceNumber ?? 0 + } + }, true); + return new Promise((resolve)=>{ + shard.resolves.set("RESUMED", ()=>resolve()); + shard.resolves.set("INVALID_SESSION", ()=>{ + shard.resolves.delete("RESUMED"); + resolve(); + }); + }); +} +function calculateSafeRequests(shard) { + const safeRequests = shard.maxRequestsPerRateLimitTick - Math.ceil(shard.rateLimitResetInterval / shard.heart.interval) * 2; + return safeRequests < 0 ? 0 : safeRequests; +} +async function checkOffline(shard, highPriority) { + if (!shard.isOpen()) { + await new Promise((resolve)=>{ + if (highPriority) { + shard.offlineSendQueue.unshift(resolve); + } else { + shard.offlineSendQueue.push(resolve); + } + }); + } +} +async function send(shard, message, highPriority) { + await checkOffline(shard, highPriority); + await shard.bucket.acquire(1, highPriority); + await checkOffline(shard, highPriority); + shard.socket?.send(JSON.stringify(message)); +} +async function handleClose(shard, close) { + shard.stopHeartbeating(); + switch(close.code){ + case ShardSocketCloseCodes.TestingFinished: + { + shard.state = ShardState.Offline; + shard.events.disconnected?.(shard); + return; + } + case ShardSocketCloseCodes.Shutdown: + case ShardSocketCloseCodes.ReIdentifying: + case ShardSocketCloseCodes.Resharded: + case ShardSocketCloseCodes.ResumeClosingOldConnection: + case ShardSocketCloseCodes.ZombiedConnection: + { + shard.state = ShardState.Disconnected; + shard.events.disconnected?.(shard); + return; + } + case GatewayCloseEventCodes.UnknownOpcode: + case GatewayCloseEventCodes.NotAuthenticated: + case GatewayCloseEventCodes.InvalidSeq: + case GatewayCloseEventCodes.RateLimited: + case GatewayCloseEventCodes.SessionTimedOut: + { + shard.state = ShardState.Identifying; + shard.events.disconnected?.(shard); + return await shard.identify(); + } + case GatewayCloseEventCodes.AuthenticationFailed: + case GatewayCloseEventCodes.InvalidShard: + case GatewayCloseEventCodes.ShardingRequired: + case GatewayCloseEventCodes.InvalidApiVersion: + case GatewayCloseEventCodes.InvalidIntents: + case GatewayCloseEventCodes.DisallowedIntents: + { + shard.state = ShardState.Offline; + shard.events.disconnected?.(shard); + throw new Error(close.reason || "Discord gave no reason! GG! You broke Discord!"); + } + case GatewayCloseEventCodes.UnknownError: + case GatewayCloseEventCodes.DecodeError: + case GatewayCloseEventCodes.AlreadyAuthenticated: + default: + { + shard.state = ShardState.Resuming; + shard.events.disconnected?.(shard); + return await shard.resume(); + } + } +} +async function connect(shard) { + let gotHello = false; + if (![ + ShardState.Identifying, + ShardState.Resuming + ].includes(shard.state)) { + shard.state = ShardState.Connecting; + } + shard.events.connecting?.(shard); + const socket = new WebSocket(`${shard.gatewayConfig.url}/?v=${shard.gatewayConfig.version}&encoding=json`); + shard.socket = socket; + socket.onerror = (event)=>console.log({ + error: event + }); + socket.onclose = (event)=>shard.handleClose(event); + socket.onmessage = (message)=>{ + gotHello = true; + shard.handleMessage(message); + }; + return new Promise((resolve)=>{ + socket.onopen = ()=>{ + setTimeout(()=>{ + if (!gotHello) { + shard.handleMessage({ + data: JSON.stringify({ + t: null, + s: null, + op: 10, + d: { + heartbeat_interval: 41250 + } + }) + }); + } + }, 250); + if (![ + ShardState.Identifying, + ShardState.Resuming + ].includes(shard.state)) { + shard.state = ShardState.Unidentified; + } + shard.events.connected?.(shard); + resolve(); + }; + }); +} +function close(shard, code, reason) { + if (shard.socket?.readyState !== WebSocket.OPEN) return; + return shard.socket?.close(code, reason); +} +async function shutdown(shard) { + shard.close(ShardSocketCloseCodes.Shutdown, "Shard shutting down."); + shard.state = ShardState.Offline; +} +function isOpen(shard) { + return shard.socket?.readyState === WebSocket.OPEN; +} +const BASE_URL = "https://discord.com/api"; +const DISCORDENO_VERSION = "13.0.0-rc45"; +const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`; +const IMAGE_BASE_URL = "https://cdn.discordapp.com"; +const baseEndpoints = { + BASE_URL: `${BASE_URL}/v${10}`, + CDN_URL: IMAGE_BASE_URL +}; +function createShard(options) { + const calculateSafeRequestsOverwritten = options.calculateSafeRequests ?? calculateSafeRequests; + const closeOverwritten = options.close ?? close; + const connectOverwritten = options.connect ?? connect; + const identifyOverwritten = options.identify ?? identify; + const sendOverwritten = options.send ?? send; + const shutdownOverwritten = options.shutdown ?? shutdown; + const resumeOverwritten = options.resume ?? resume; + const handleCloseOverwritten = options.handleClose ?? handleClose; + const handleMessageOverwritten = options.handleMessage ?? handleMessage; + const isOpenOverwritten = options.isOpen ?? isOpen; + const startHeartbeatingOverwritten = options.startHeartbeating ?? startHeartbeating; + const stopHeartbeatingOverwritten = options.stopHeartbeating ?? stopHeartbeating; + return { + gatewayConfig: { + compress: options.gatewayConfig.compress ?? false, + intents: options.gatewayConfig.intents ?? 0, + properties: { + os: options.gatewayConfig?.properties?.os ?? "linux", + browser: options.gatewayConfig?.properties?.browser ?? "Discordeno", + device: options.gatewayConfig?.properties?.device ?? "Discordeno" + }, + token: options.gatewayConfig.token, + url: options.gatewayConfig.url ?? "wss://gateway.discord.gg", + version: options.gatewayConfig.version ?? 10 + }, + heart: { + acknowledged: false, + interval: 45000 + }, + id: options.id, + maxRequestsPerRateLimitTick: 120, + previousSequenceNumber: options.previousSequenceNumber || null, + rateLimitResetInterval: 60_000, + sessionId: undefined, + socket: undefined, + state: ShardState.Offline, + totalShards: options.totalShards, + events: options.events ?? {}, + calculateSafeRequests: function() { + return calculateSafeRequestsOverwritten(this); + }, + close: function(code, reason) { + return closeOverwritten(this, code, reason); + }, + connect: async function() { + return await connectOverwritten(this); + }, + identify: async function() { + return await identifyOverwritten(this); + }, + isOpen: function() { + return isOpenOverwritten(this); + }, + makePresence: options.makePresence, + resume: async function() { + return await resumeOverwritten(this); + }, + send: async function(message, highPriority = false) { + return await sendOverwritten(this, message, highPriority); + }, + shutdown: async function() { + return await shutdownOverwritten(this); + }, + bucket: createLeakyBucket({ + max: 120, + refillInterval: 60_000, + refillAmount: 120 + }), + handleClose: async function(close) { + return await handleCloseOverwritten(this, close); + }, + handleMessage: async function(message) { + return await handleMessageOverwritten(this, message); + }, + requestIdentify: async function() { + return await options.requestIdentify(this.id); + }, + offlineSendQueue: [], + resolves: new Map(), + startHeartbeating: function(interval) { + return startHeartbeatingOverwritten(this, interval); + }, + stopHeartbeating: function() { + return stopHeartbeatingOverwritten(this); + } + }; +} +function createShardManager(options) { + return { + createShardOptions: { + ...options.createShardOptions, + events: { + ...options.createShardOptions?.events, + message: options.createShardOptions?.events?.message ?? options.handleMessage + } + }, + gatewayConfig: options.gatewayConfig, + shards: new Map(options.shardIds.map((shardId)=>{ + const shard = createShard({ + ...options.createShardOptions, + id: shardId, + totalShards: options.totalShards, + gatewayConfig: options.gatewayConfig, + requestIdentify: async function() { + return await options.requestIdentify(shardId); + } + }); + return [ + shardId, + shard + ]; + })), + totalShards: options.totalShards, + identify: async function(shardId) { + let shard = this.shards.get(shardId); + if (!shard) { + shard = createShard({ + ...this.createShardOptions, + id: shardId, + totalShards: this.totalShards, + gatewayConfig: this.gatewayConfig, + requestIdentify: async function() { + return await options.requestIdentify(shardId); + } + }); + this.shards.set(shardId, shard); + } + return await shard.identify(); + }, + kill: async function(shardId) { + const shard = this.shards.get(shardId); + if (!shard) return; + this.shards.delete(shardId); + return await shard.shutdown(); + }, + requestIdentify: options.requestIdentify + }; +} +async function stop(gateway, code, reason) { + gateway.manager.shards.forEach((shard)=>shard.close(code, reason)); + await delay(5000); +} +function createGatewayManager(options) { + const prepareBucketsOverwritten = options.prepareBuckets ?? prepareBuckets; + const spawnShardsOverwritten = options.spawnShards ?? spawnShards; + const stopOverwritten = options.stop ?? stop; + const tellWorkerToIdentifyOverwritten = options.tellWorkerToIdentify ?? tellWorkerToIdentify; + const calculateTotalShardsOverwritten = options.calculateTotalShards ?? calculateTotalShards; + const calculateWorkerIdOverwritten = options.calculateWorkerId ?? calculateWorkerId; + const totalShards = (options.totalShards ?? options.gatewayBot.shards) ?? 1; + const gatewayManager = { + buckets: new Map(), + firstShardId: options.firstShardId ?? 0, + gatewayBot: options.gatewayBot, + lastShardId: (options.lastShardId ?? totalShards - 1) ?? 1, + manager: {}, + spawnShardDelay: options.spawnShardDelay ?? 5300, + shardsPerWorker: options.shardsPerWorker ?? 25, + totalWorkers: options.totalWorkers ?? 4, + prepareBuckets: function() { + return prepareBucketsOverwritten(this); + }, + spawnShards: function() { + return spawnShardsOverwritten(this); + }, + stop: function(code, reason) { + return stopOverwritten(this, code, reason); + }, + tellWorkerToIdentify: function(workerId, shardId, bucketId) { + return tellWorkerToIdentifyOverwritten(this, workerId, shardId, bucketId); + }, + debug: options.debug || function() {}, + calculateTotalShards: function() { + return calculateTotalShardsOverwritten(this); + }, + calculateWorkerId: function(shardId) { + return calculateWorkerIdOverwritten(this, shardId); + } + }; + gatewayManager.manager = createShardManager({ + createShardOptions: options.createShardOptions, + gatewayConfig: options.gatewayConfig, + shardIds: [], + totalShards, + handleMessage: function(shard, message) { + return options.handleDiscordPayload(shard, message); + }, + requestIdentify: async (shardId)=>{ + await gatewayManager.buckets.get(shardId % gatewayManager.gatewayBot.sessionStartLimit.maxConcurrency).leak.acquire(1); + } + }); + return gatewayManager; +} +function checkRateLimits(rest, url) { + const ratelimited = rest.rateLimitedPaths.get(url); + const global = rest.rateLimitedPaths.get("global"); + const now = Date.now(); + if (ratelimited && now < ratelimited.resetTimestamp) { + return ratelimited.resetTimestamp - now; + } + if (global && now < global.resetTimestamp) { + return global.resetTimestamp - now; + } + return false; +} +function cleanupQueues(rest) { + for (const [key, queue] of rest.pathQueues){ + rest.debug(`[REST - cleanupQueues] Running for of loop. ${key}`); + if (queue.requests.length) continue; + rest.pathQueues.delete(key); + } + if (!rest.pathQueues.size) rest.processingQueue = false; +} +function createRequestBody(rest, options) { + const headers = { + "user-agent": USER_AGENT + }; + if (!options.unauthorized) headers["authorization"] = `Bot ${rest.token}`; + if (options.headers) { + for(const key in options.headers){ + headers[key.toLowerCase()] = options.headers[key]; + } + } + if (options.method === "GET") { + options.body = undefined; + } + if (options.body?.reason) { + headers["X-Audit-Log-Reason"] = encodeURIComponent(options.body.reason); + options.body.reason = undefined; + } + if (options.body?.file) { + if (!Array.isArray(options.body.file)) { + options.body.file = [ + options.body.file + ]; + } + const form = new FormData(); + for(let i = 0; i < options.body.file.length; i++){ + form.append(`file${i}`, options.body.file[i].blob, options.body.file[i].name); + } + form.append("payload_json", JSON.stringify({ + ...options.body, + file: undefined + })); + options.body.file = form; + } else if (options.body && ![ + "GET", + "DELETE" + ].includes(options.method)) { + headers["Content-Type"] = "application/json"; + } + return { + headers, + body: options.body?.file ?? JSON.stringify(options.body), + method: options.method + }; +} +async function processGlobalQueue(rest) { + if (!rest.globalQueue.length) return; + if (rest.globalQueueProcessing) return; + rest.globalQueueProcessing = true; + while(rest.globalQueue.length){ + if (rest.globallyRateLimited) { + setTimeout(()=>{ + rest.debug(`[REST - processGlobalQueue] Globally rate limited, running setTimeout.`); + rest.processGlobalQueue(rest); + }, 1000); + break; + } + if (rest.invalidRequests === rest.maxInvalidRequests - rest.invalidRequestsSafetyAmount) { + setTimeout(()=>{ + const time = rest.invalidRequestsInterval - (Date.now() - rest.invalidRequestFrozenAt); + rest.debug(`[REST - processGlobalQueue] Freeze global queue because of invalid requests. Time Remaining: ${time / 1000} seconds.`); + rest.processGlobalQueue(rest); + }, 1000); + break; + } + const request = rest.globalQueue.shift(); + if (!request) continue; + const urlResetIn = rest.checkRateLimits(rest, request.basicURL); + const bucketResetIn = request.payload.bucketId ? rest.checkRateLimits(rest, request.payload.bucketId) : false; + if (urlResetIn || bucketResetIn) { + setTimeout(()=>{ + rest.debug(`[REST - processGlobalQueue] rate limited, running setTimeout.`); + rest.globalQueue.unshift(request); + rest.processGlobalQueue(rest); + }, urlResetIn || bucketResetIn); + continue; + } + await rest.sendRequest(rest, { + url: request.urlToUse, + method: request.request.method, + bucketId: request.payload.bucketId, + reject: request.request.reject, + respond: request.request.respond, + retryCount: request.payload.retryCount ?? 0, + payload: rest.createRequestBody(rest, { + method: request.request.method, + body: request.payload.body + }) + }).catch(()=>null); + } + rest.globalQueueProcessing = false; +} +function processQueue(rest, id) { + const queue = rest.pathQueues.get(id); + if (!queue) return; + while(queue.requests.length){ + rest.debug(`[REST - processQueue] Running while loop.`); + const queuedRequest = queue.requests[0]; + if (!queuedRequest) break; + const basicURL = rest.simplifyUrl(queuedRequest.request.url, queuedRequest.request.method); + const urlResetIn = rest.checkRateLimits(rest, basicURL); + if (urlResetIn) { + if (!queue.isWaiting) { + queue.isWaiting = true; + setTimeout(()=>{ + queue.isWaiting = false; + rest.debug(`[REST - processQueue] rate limited, running setTimeout.`); + rest.processQueue(rest, id); + }, urlResetIn); + } + break; + } + const bucketResetIn = queuedRequest.payload.bucketId ? rest.checkRateLimits(rest, queuedRequest.payload.bucketId) : false; + if (bucketResetIn) continue; + rest.debug(`[REST - Add To Global Queue] ${JSON.stringify(queuedRequest.payload)}`); + rest.globalQueue.push({ + ...queuedRequest, + urlToUse: queuedRequest.request.url, + basicURL + }); + rest.processGlobalQueue(rest); + queue.requests.shift(); + } + rest.cleanupQueues(rest); +} +function processRateLimitedPaths(rest) { + const now = Date.now(); + for (const [key, value] of rest.rateLimitedPaths.entries()){ + rest.debug(`[REST - processRateLimitedPaths] Running for of loop. ${value.resetTimestamp - now}`); + if (value.resetTimestamp > now) continue; + rest.rateLimitedPaths.delete(key); + if (key === "global") rest.globallyRateLimited = false; + } + if (!rest.rateLimitedPaths.size) { + rest.processingRateLimitedPaths = false; + } else { + rest.processingRateLimitedPaths = true; + setTimeout(()=>{ + rest.debug(`[REST - processRateLimitedPaths] Running setTimeout.`); + rest.processRateLimitedPaths(rest); + }, 1000); + } +} +function processRequest(rest, request, payload) { + const route = request.url.substring(request.url.indexOf("api/")); + const parts = route.split("/"); + parts.shift(); + if (parts[0]?.startsWith("v")) parts.shift(); + request.url = `${BASE_URL}/v${rest.version}/${parts.join("/")}`; + parts.shift(); + const url = rest.simplifyUrl(request.url, request.method); + const queue = rest.pathQueues.get(url); + if (queue) { + queue.requests.push({ + request, + payload + }); + } else { + rest.pathQueues.set(url, { + isWaiting: false, + requests: [ + { + request, + payload + }, + ] + }); + rest.processQueue(rest, url); + } +} +function processRequestHeaders(rest, url, headers) { + let rateLimited = false; + const remaining = headers.get("x-ratelimit-remaining"); + const retryAfter = headers.get("x-ratelimit-reset-after"); + const reset = Date.now() + Number(retryAfter) * 1000; + const global = headers.get("x-ratelimit-global"); + const bucketId = headers.get("x-ratelimit-bucket") || undefined; + if (remaining === "0") { + rateLimited = true; + rest.rateLimitedPaths.set(url, { + url, + resetTimestamp: reset, + bucketId + }); + if (bucketId) { + rest.rateLimitedPaths.set(bucketId, { + url, + resetTimestamp: reset, + bucketId + }); + } + } + if (global) { + const retryAfter1 = headers.get("retry-after"); + const globalReset = Date.now() + Number(retryAfter1) * 1000; + rest.debug(`[REST = Globally Rate Limited] URL: ${url} | Global Rest: ${globalReset}`); + rest.globallyRateLimited = true; + rateLimited = true; + rest.rateLimitedPaths.set("global", { + url: "global", + resetTimestamp: globalReset, + bucketId + }); + if (bucketId) { + rest.rateLimitedPaths.set(bucketId, { + url: "global", + resetTimestamp: globalReset, + bucketId + }); + } + } + if (rateLimited && !rest.processingRateLimitedPaths) { + rest.processRateLimitedPaths(rest); + } + return rateLimited ? bucketId : undefined; +} +function convertRestError(errorStack, data) { + errorStack.message = `[${data.status}] ${data.error}\n${data.body}`; + return errorStack; +} +async function runMethod(rest, method, route, body, options) { + rest.debug(`[REST - RequestCreate] Method: ${method} | URL: ${route} | Retry Count: ${options?.retryCount ?? 0} | Bucket ID: ${options?.bucketId} | Body: ${JSON.stringify(body)}`); + const errorStack = new Error("Location:"); + Error.captureStackTrace?.(errorStack); + if (!baseEndpoints.BASE_URL.startsWith(BASE_URL) && route[0] === "/") { + const result = await fetch(`${baseEndpoints.BASE_URL}${route}`, { + body: body ? JSON.stringify(body) : undefined, + headers: { + Authorization: rest.secretKey, + "Content-Type": "application/json" + }, + method + }).catch((error)=>{ + errorStack.message = error?.message; + console.error(error); + throw errorStack; + }); + if (!result.ok) { + errorStack.message = result.statusText; + rest.debug(`[ERROR] ${errorStack.message}`); + await result.text(); + throw errorStack; + } + return result.status !== 204 ? await result.json() : undefined; + } + return new Promise((resolve, reject)=>{ + rest.processRequest(rest, { + url: route[0] === "/" ? `${BASE_URL}/v${10}${route}` : route, + method, + reject: (data)=>{ + const restError = rest.convertRestError(errorStack, data); + reject(restError); + }, + respond: (data)=>resolve(data.status !== 204 ? JSON.parse(data.body ?? "{}") : undefined) + }, { + bucketId: options?.bucketId, + body: body, + retryCount: options?.retryCount ?? 0, + headers: options?.headers + }); + }); +} +function simplifyUrl(url, method) { + let route = url.replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, function(match, p) { + return [ + "channels", + "guilds" + ].includes(p) ? match : `/${p}/skillzPrefersID`; + }).replace(/\/reactions\/[^/]+/g, "/reactions/skillzPrefersID"); + if (route.includes("/reactions")) { + route = route.substring(0, route.indexOf("/reactions") + "/reactions".length); + } + if (method === "DELETE" && route.endsWith("/messages/skillzPrefersID")) { + route = method + route; + } + return route; +} +function removeTokenPrefix(token, type = "REST") { + if (!token) throw new Error(`The ${type} was not given a token. Please provide a token and try again.`); + if (!token.startsWith("Bot ")) return token; + return token.substring(token.indexOf(" ") + 1); +} +function getBotIdFromToken(token) { + return BigInt(atob(token.split(".")[0])); +} +async function sendRequest(rest, options) { + try { + rest.debug(`[REST - fetching] URL: ${options.url} | ${JSON.stringify(options)}`); + const newURL = options.url.startsWith(BASE_URL) ? options.url : `${BASE_URL}/v${rest.version}/${options.url}`; + rest.debug(`[REST - url data] URL: ${newURL}`); + const response = await fetch(new Request(newURL, { + method: options.method, + headers: options.payload?.headers, + body: options.payload?.body + })); + rest.debug(`[REST - fetched] URL: ${options.url} | ${JSON.stringify(options)}`); + const bucketIdFromHeaders = rest.processRequestHeaders(rest, rest.simplifyUrl(options.url, options.method), response.headers); + if (bucketIdFromHeaders) { + options.bucketId = bucketIdFromHeaders; + } + if (response.status < 200 || response.status >= 400) { + rest.debug(`[REST - httpError] Payload: ${JSON.stringify(options)} | Response: ${JSON.stringify(response)}`); + let error = "REQUEST_UNKNOWN_ERROR"; + switch(response.status){ + case HTTPResponseCodes.BadRequest: + error = "The options was improperly formatted, or the server couldn't understand it."; + break; + case HTTPResponseCodes.Unauthorized: + error = "The Authorization header was missing or invalid."; + break; + case HTTPResponseCodes.Forbidden: + error = "The Authorization token you passed did not have permission to the resource."; + break; + case HTTPResponseCodes.NotFound: + error = "The resource at the location specified doesn't exist."; + break; + case HTTPResponseCodes.MethodNotAllowed: + error = "The HTTP method used is not valid for the location specified."; + break; + case HTTPResponseCodes.GatewayUnavailable: + error = "There was not a gateway available to process your options. Wait a bit and retry."; + break; + } + if (rest.invalidRequestErrorStatuses.includes(response.status) && !(response.status === 429 && response.headers.get("X-RateLimit-Scope"))) { + ++rest.invalidRequests; + if (!rest.invalidRequestsTimeoutId) { + rest.invalidRequestsTimeoutId = setTimeout(()=>{ + rest.debug(`[REST - processGlobalQueue] Resetting invalid optionss counter in setTimeout.`); + rest.invalidRequests = 0; + rest.invalidRequestsTimeoutId = 0; + }, rest.invalidRequestsInterval); + } + } + if (response.status !== 429) { + options.reject?.({ + ok: false, + status: response.status, + error, + body: response.type ? JSON.stringify(await response.json()) : undefined + }); + throw new Error(JSON.stringify({ + ok: false, + status: response.status, + error, + body: response.type ? JSON.stringify(await response.json()) : undefined + })); + } else { + if (options.retryCount && (options.retryCount++) >= rest.maxRetryCount) { + rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`); + options.reject?.({ + ok: false, + status: response.status, + error: "The options was rate limited and it maxed out the retries limit." + }); + return; + } + } + } + if (response.status === 204) { + rest.debug(`[REST - FetchSuccess] URL: ${options.url} | ${JSON.stringify(options)}`); + options.respond?.({ + ok: true, + status: 204 + }); + return; + } else { + const json = JSON.stringify(await response.json()); + rest.debug(`[REST - fetchSuccess] ${JSON.stringify(options)}`); + options.respond?.({ + ok: true, + status: 200, + body: json + }); + return JSON.parse(json); + } + } catch (error1) { + rest.debug(`[REST - fetchFailed] Payload: ${JSON.stringify(options)} | Error: ${error1}`); + options.reject?.({ + ok: false, + status: 599, + error: "Internal Proxy Error" + }); + throw new Error("Something went wrong in sendRequest", { + cause: error1 + }); + } +} +function createRestManager(options) { + const version = options.version || 10; + if (options.customUrl) { + baseEndpoints.BASE_URL = `${options.customUrl}/v${version}`; + } + return { + invalidRequests: 0, + maxInvalidRequests: 10000, + invalidRequestsInterval: 600000, + invalidRequestsTimeoutId: 0, + invalidRequestsSafetyAmount: 1, + invalidRequestFrozenAt: 0, + invalidRequestErrorStatuses: [ + 401, + 403, + 429 + ], + version, + token: removeTokenPrefix(options.token), + maxRetryCount: options.maxRetryCount || 10, + secretKey: options.secretKey || "discordeno_best_lib_ever", + customUrl: options.customUrl || "", + pathQueues: new Map(), + processingQueue: false, + processingRateLimitedPaths: false, + globallyRateLimited: false, + globalQueue: [], + globalQueueProcessing: false, + rateLimitedPaths: new Map(), + debug: options.debug || function(_text) {}, + checkRateLimits: options.checkRateLimits || checkRateLimits, + cleanupQueues: options.cleanupQueues || cleanupQueues, + processQueue: options.processQueue || processQueue, + processRateLimitedPaths: options.processRateLimitedPaths || processRateLimitedPaths, + processRequestHeaders: options.processRequestHeaders || processRequestHeaders, + processRequest: options.processRequest || processRequest, + createRequestBody: options.createRequestBody || createRequestBody, + runMethod: options.runMethod || runMethod, + simplifyUrl: options.simplifyUrl || simplifyUrl, + processGlobalQueue: options.processGlobalQueue || processGlobalQueue, + convertRestError: options.convertRestError || convertRestError, + sendRequest: options.sendRequest || sendRequest + }; +} +var AutoModerationEventTypes; +(function(AutoModerationEventTypes) { + AutoModerationEventTypes[AutoModerationEventTypes["MessageSend"] = 1] = "MessageSend"; +})(AutoModerationEventTypes || (AutoModerationEventTypes = {})); +var AutoModerationTriggerTypes; +(function(AutoModerationTriggerTypes) { + AutoModerationTriggerTypes[AutoModerationTriggerTypes["Keyword"] = 1] = "Keyword"; + AutoModerationTriggerTypes[AutoModerationTriggerTypes["HarmfulLink"] = 2] = "HarmfulLink"; + AutoModerationTriggerTypes[AutoModerationTriggerTypes["Spam"] = 3] = "Spam"; + AutoModerationTriggerTypes[AutoModerationTriggerTypes["KeywordPreset"] = 4] = "KeywordPreset"; +})(AutoModerationTriggerTypes || (AutoModerationTriggerTypes = {})); +var DiscordAutoModerationRuleTriggerMetadataPresets; +(function(DiscordAutoModerationRuleTriggerMetadataPresets) { + DiscordAutoModerationRuleTriggerMetadataPresets[DiscordAutoModerationRuleTriggerMetadataPresets["Profanity"] = 1] = "Profanity"; + DiscordAutoModerationRuleTriggerMetadataPresets[DiscordAutoModerationRuleTriggerMetadataPresets["SexualContent"] = 2] = "SexualContent"; + DiscordAutoModerationRuleTriggerMetadataPresets[DiscordAutoModerationRuleTriggerMetadataPresets["Slurs"] = 3] = "Slurs"; +})(DiscordAutoModerationRuleTriggerMetadataPresets || (DiscordAutoModerationRuleTriggerMetadataPresets = {})); +var AutoModerationActionType; +(function(AutoModerationActionType) { + AutoModerationActionType[AutoModerationActionType["BlockMessage"] = 1] = "BlockMessage"; + AutoModerationActionType[AutoModerationActionType["SendAlertMessage"] = 2] = "SendAlertMessage"; + AutoModerationActionType[AutoModerationActionType["Timeout"] = 3] = "Timeout"; +})(AutoModerationActionType || (AutoModerationActionType = {})); +class Permissions { + static Flags = BitwisePermissionFlags; + bitfield; + constructor(bitfield){ + this.bitfield = Permissions.resolve(bitfield); + } + has(bit) { + if (this.bitfield & BigInt(Permissions.Flags.ADMINISTRATOR)) { + return true; + } + return !!(this.bitfield & Permissions.resolve(bit)); + } + static resolve(bit) { + switch(typeof bit){ + case "bigint": + return bit; + case "number": + return BigInt(bit); + case "string": + return BigInt(Permissions.Flags[bit]); + case "object": + return Permissions.resolve(bit.map((p)=>BigInt(Permissions.Flags[p])).reduce((acc, cur)=>acc | cur, 0n)); + default: + throw new TypeError(`Cannot resolve permission: ${bit}`); + } + } +} +class EventEmitter { + listeners = new Map(); + #addListener(event, func) { + this.listeners.set(event, this.listeners.get(event) || []); + this.listeners.get(event)?.push(func); + return this; + } + on(event, func) { + return this.#addListener(event, func); + } + #removeListener(event1, func1) { + if (this.listeners.has(event1)) { + const listener = this.listeners.get(event1); + if (listener?.includes(func1)) { + listener.splice(listener.indexOf(func1), 1); + if (listener.length === 0) { + this.listeners.delete(event1); + } + } + } + return this; + } + off(event, func) { + return this.#removeListener(event, func); + } + once(event, func) { + const closure = ()=>{ + func(); + this.off(event, func); + }; + const listener = this.listeners.get(event) ?? []; + listener.push(closure); + return this; + } + emit(event, ...args) { + const listener = this.listeners.get(event); + if (!listener) { + return false; + } + listener.forEach((f)=>f(...args)); + return true; + } + listenerCount(eventName) { + return this.listeners.get(eventName)?.length ?? 0; + } + rawListeners(eventName) { + return this.listeners.get(eventName); + } +} +var MessageFlags; +(function(MessageFlags) { + MessageFlags[MessageFlags["CrossPosted"] = 1] = "CrossPosted"; + MessageFlags[MessageFlags["IsCrosspost"] = 2] = "IsCrosspost"; + MessageFlags[MessageFlags["SupressEmbeds"] = 4] = "SupressEmbeds"; + MessageFlags[MessageFlags["SourceMessageDeleted"] = 8] = "SourceMessageDeleted"; + MessageFlags[MessageFlags["Urgent"] = 16] = "Urgent"; + MessageFlags[MessageFlags["HasThread"] = 32] = "HasThread"; + MessageFlags[MessageFlags["Ephemeral"] = 64] = "Ephemeral"; + MessageFlags[MessageFlags["Loading"] = 128] = "Loading"; + MessageFlags[MessageFlags["FailedToMentionSomeRolesInThread"] = 256] = "FailedToMentionSomeRolesInThread"; +})(MessageFlags || (MessageFlags = {})); +class Util { + static formatImageURL(url, size = 128, format) { + return `${url}.${format || (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`; + } + static iconHashToBigInt(hash) { + return BigInt("0x" + (hash.startsWith("a_") ? `a${hash.substring(2)}` : `b${hash}`)); + } + static iconBigintToHash(icon) { + const hash = icon.toString(16); + return hash.startsWith("a") ? `a_${hash.substring(1)}` : hash.substring(1); + } +} +function USER_AVATAR(userId, icon) { + return `${baseEndpoints.CDN_URL}/avatars/${userId}/${icon}`; +} +function EMOJI_URL(id, animated = false) { + return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`; +} +function USER_DEFAULT_AVATAR(altIcon) { + return `${baseEndpoints.CDN_URL}/embed/avatars/${altIcon}.png`; +} +function GUILD_BANNER(guildId, icon) { + return `${baseEndpoints.CDN_URL}/banners/${guildId}/${icon}`; +} +function GUILD_SPLASH(guildId, icon) { + return `${baseEndpoints.CDN_URL}/splashes/${guildId}/${icon}`; +} +function GUILD_ICON(guildId, icon) { + return `${baseEndpoints.CDN_URL}/icons/${guildId}/${icon}`; +} +function USER(userId) { + if (!userId) return "/users/@me"; + return `/users/${userId}`; +} +function GATEWAY_BOT() { + return "/gateway/bot"; +} +function CHANNEL(channelId) { + return `/channels/${channelId}`; +} +function CHANNEL_INVITES(channelId) { + return `/channels/${channelId}/invites`; +} +function CHANNEL_TYPING(channelId) { + return `/channels/${channelId}/typing`; +} +function CHANNEL_MESSAGES(channelId, options) { + let url = `/channels/${channelId}/messages?`; + if (options) { + if (options.after) url += `after=${options.after}`; + if (options.before) url += `&before=${options.before}`; + if (options.around) url += `&around=${options.around}`; + if (options.limit) url += `&limit=${options.limit}`; + } + return url; +} +function CHANNEL_MESSAGE(channelId, messageId) { + return `/channels/${channelId}/messages/${messageId}`; +} +function GUILD_MEMBER(guildId, userId) { + return `/guilds/${guildId}/members/${userId}`; +} +function GUILD_BAN(guildId, userId) { + return `/guilds/${guildId}/bans/${userId}`; +} +function GUILD_ROLE(guildId, roleId) { + return `/guilds/${guildId}/roles/${roleId}`; +} +function GUILD_ROLES(guildId) { + return `/guilds/${guildId}/roles`; +} +function USER_GUILDS(guildId) { + if (guildId) return `/users/@me/guilds/${guildId}`; + return `/users/@me/guilds/`; +} +function GUILD_EMOJIS(guildId) { + return `/guilds/${guildId}/emojis`; +} +function GUILD_EMOJI(guildId, emojiId) { + return `/guilds/${guildId}/emojis/${emojiId}`; +} +function GUILDS(guildId) { + if (guildId) return `/guilds/${guildId}`; + return `/guilds`; +} +function INVITE(inviteCode, options) { + let url = `/invites/${inviteCode}?`; + if (options) { + if (options.withCounts) url += `with_counts=${options.withCounts}`; + if (options.withExpiration) url += `&with_expiration=${options.withExpiration}`; + if (options.scheduledEventId) url += `&guild_scheduled_event_id=${options.scheduledEventId}`; + } + return url; +} +function GUILD_INVITES(guildId) { + return `/guilds/${guildId}/invites`; +} +function INTERACTION_ID_TOKEN(interactionId, token) { + return `/interactions/${interactionId}/${token}/callback`; +} +function WEBHOOK_MESSAGE_ORIGINAL(webhookId, token, options) { + let url = `/webhooks/${webhookId}/${token}/messages/@original?`; + if (options) { + if (options.threadId) url += `threadId=${options.threadId}`; + } + return url; +} +function WEBHOOK_MESSAGE(webhookId, token, messageId, options) { + let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`; + if (options) { + if (options.threadId) url += `threadId=${options.threadId}`; + } + return url; +} +function WEBHOOK_TOKEN(webhookId, token) { + if (!token) return `/webhooks/${webhookId}`; + return `/webhooks/${webhookId}/${token}`; +} +function WEBHOOK(webhookId, token, options) { + let url = `/webhooks/${webhookId}/${token}`; + if (options?.wait) url += `?wait=${options.wait}`; + if (options?.threadId) url += `?threadId=${options.threadId}`; + if (options?.wait && options.threadId) url += `?wait=${options.wait}&threadId=${options.threadId}`; + return url; +} +function USER_NICK(guildId) { + return `/guilds/${guildId}/members/@me`; +} +function GUILD_PRUNE(guildId, options) { + let url = `/guilds/${guildId}/prune?`; + if (options?.days) url += `days=${options.days}`; + if (options?.includeRoles) url += `&include_roles=${options.includeRoles}`; + return url; +} +function CHANNEL_PIN(channelId, messageId) { + return `/channels/${channelId}/pins/${messageId}`; +} +function CHANNEL_PINS(channelId) { + return `/channels/${channelId}/pins`; +} +function CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, emoji) { + return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`; +} +function CHANNEL_MESSAGE_REACTION_USER(channelId, messageId, emoji, userId) { + return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`; +} +function CHANNEL_MESSAGE_REACTIONS(channelId, messageId) { + return `/channels/${channelId}/messages/${messageId}/reactions`; +} +function CHANNEL_MESSAGE_REACTION(channelId, messageId, emoji, options) { + let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`; + if (options?.after) url += `after=${options.after}`; + if (options?.limit) url += `&limit=${options.limit}`; + return url; +} +function CHANNEL_MESSAGE_CROSSPOST(channelId, messageId) { + return `/channels/${channelId}/messages/${messageId}/crosspost`; +} +function GUILD_MEMBER_ROLE(guildId, memberId, roleId) { + return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`; +} +function CHANNEL_WEBHOOKS(channelId) { + return `/channels/${channelId}/webhooks`; +} +function THREAD_START_PUBLIC(channelId, messageId) { + return `/channels/${channelId}/messages/${messageId}/threads`; +} +function THREAD_START_PRIVATE(channelId) { + return `/channels/${channelId}/threads`; +} +function THREAD_ACTIVE(guildId) { + return `/guilds/${guildId}/threads/active`; +} +function THREAD_ME(channelId) { + return `/channels/${channelId}/thread-members/@me`; +} +function THREAD_MEMBERS(channelId) { + return `/channels/${channelId}/thread-members`; +} +function THREAD_USER(channelId, userId) { + return `/channels/${channelId}/thread-members/${userId}`; +} +function THREAD_ARCHIVED_PUBLIC(channelId, options) { + let url = `/channels/${channelId}/threads/archived/public?`; + if (options) { + if (options.before) url += `before=${new Date(options.before).toISOString()}`; + if (options.limit) url += `&limit=${options.limit}`; + } + return url; +} +function THREAD_ARCHIVED_PRIVATE_JOINED(channelId, options) { + let url = `/channels/${channelId}/users/@me/threads/archived/private?`; + if (options) { + if (options.before) url += `before=${new Date(options.before).toISOString()}`; + if (options.limit) url += `&limit=${options.limit}`; + } + return url; +} +function STAGE_INSTANCE(channelId) { + return `/stage-instances/${channelId}`; +} +function APPLICATION_COMMANDS(appId, commandId) { + if (commandId) return `/applications/${appId}/commands/${commandId}`; + return `/applications/${appId}/commands`; +} +function GUILD_APPLICATION_COMMANDS(appId, guildId, commandId) { + if (commandId) return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`; + return `/applications/${appId}/guilds/${guildId}/commands`; +} +function GUILD_APPLICATION_COMMANDS_PERMISSIONS(appId, guildId, commandId) { + if (commandId) return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`; + return `/applications/${appId}/guilds/${guildId}/commands/permissions`; +} +function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS(appId, guildId, commandId, withLocalizations) { + let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`; + if (withLocalizations !== undefined) { + url += `with_localizations=${withLocalizations}`; + } + return url; +} +function STICKER_PACKS() { + return `stickers-packs`; +} +class User { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.username = data.username; + this.discriminator = data.discriminator; + this.avatarHash = data.avatar ? Util.iconHashToBigInt(data.avatar) : undefined; + this.accentColor = data.accent_color; + this.bot = !!data.bot; + this.system = !!data.system; + this.banner = data.banner ? Util.iconHashToBigInt(data.banner) : undefined; + this.mfaEnabled = !!data.mfa_enabled; + this.locale = data.locale; + this.email = data.email ? data.email : undefined; + this.verified = data.verified; + this.flags = data.flags; + } + session; + id; + username; + discriminator; + avatarHash; + accentColor; + bot; + system; + banner; + mfaEnabled; + locale; + email; + flags; + verified; + premiumType; + publicFlags; + get tag() { + return `${this.username}#${this.discriminator}}`; + } + fetch() { + return this.session.fetchUser(this.id); + } + avatarURL(options = { + size: 128 + }) { + let url; + if (!this.avatarHash) { + url = USER_DEFAULT_AVATAR(Number(this.discriminator) % 5); + } else { + url = USER_AVATAR(this.id, Util.iconBigintToHash(this.avatarHash)); + } + return Util.formatImageURL(url, options.size, options.format); + } + toString() { + return `<@${this.id}>`; + } +} +async function urlToBase64(url) { + const buffer = await fetch(url).then((res)=>res.arrayBuffer()); + const imageStr = encode(buffer); + const type = url.substring(url.lastIndexOf(".") + 1); + return `data:image/${type};base64,${imageStr}`; +} +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", + "+", + "/", +]; +function encode(data) { + const uint8 = typeof data === "string" ? new TextEncoder().encode(data) : data instanceof Uint8Array ? data : new Uint8Array(data); + let result = "", i; + const l = uint8.length; + for(i = 2; i < l; i += 3){ + result += base64abc[uint8[i - 2] >> 2]; + result += base64abc[(uint8[i - 2] & 0x03) << 4 | uint8[i - 1] >> 4]; + result += base64abc[(uint8[i - 1] & 0x0f) << 2 | uint8[i] >> 6]; + result += base64abc[uint8[i] & 0x3f]; + } + if (i === l + 1) { + result += base64abc[uint8[i - 2] >> 2]; + result += base64abc[(uint8[i - 2] & 0x03) << 4]; + result += "=="; + } + if (i === l) { + result += base64abc[uint8[i - 2] >> 2]; + result += base64abc[(uint8[i - 2] & 0x03) << 4 | uint8[i - 1] >> 4]; + result += base64abc[(uint8[i - 1] & 0x0f) << 2]; + result += "="; + } + return result; +} +class AutoModerationRule { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.guildId = data.guild_id; + this.name = data.name; + this.creatorId = data.creator_id; + this.eventType = data.event_type; + this.triggerType = data.trigger_type; + this.triggerMetadata = { + keywordFilter: data.trigger_metadata.keyword_filter, + presets: data.trigger_metadata.presets + }; + this.actions = data.actions.map((action)=>Object.create({ + type: action.type, + metadata: { + channelId: action.metadata.channel_id, + durationSeconds: action.metadata.duration_seconds + } + })); + this.enabled = !!data.enabled; + this.exemptRoles = data.exempt_roles; + this.exemptChannels = data.exempt_channels; + } + session; + id; + guildId; + name; + creatorId; + eventType; + triggerType; + triggerMetadata; + actions; + enabled; + exemptRoles; + exemptChannels; +} +class AutoModerationExecution { + constructor(session, data){ + this.session = session; + this.guildId = data.guild_id; + this.action = Object.create({ + type: data.action.type, + metadata: { + channelId: data.action.metadata.channel_id, + durationSeconds: data.action.metadata.duration_seconds + } + }); + this.ruleId = data.rule_id; + this.ruleTriggerType = data.rule_trigger_type; + this.userId = data.user_id; + this.content = data.content; + if (data.channel_id) { + this.channelId = data.channel_id; + } + if (data.message_id) { + this.messageId = data.message_id; + } + if (data.alert_system_message_id) { + this.alertSystemMessageId = data.alert_system_message_id; + } + if (data.matched_keyword) { + this.matchedKeyword = data.matched_keyword; + } + if (data.matched_content) { + this.matched_content = data.matched_content; + } + } + session; + guildId; + action; + ruleId; + ruleTriggerType; + userId; + channelId; + messageId; + alertSystemMessageId; + content; + matchedKeyword; + matched_content; +} +const Snowflake = { + snowflakeToTimestamp (id) { + return (Number(id) >> 22) + 14200704e5; + } +}; +function transformOasisInteractionDataOption(o) { + const output = { + ...o, + Otherwise: o.value + }; + switch(o.type){ + case ApplicationCommandOptionTypes.String: + output.String = o.value; + break; + case ApplicationCommandOptionTypes.Number: + output.Number = o.value; + break; + case ApplicationCommandOptionTypes.Integer: + output.Integer = o.value; + break; + case ApplicationCommandOptionTypes.Boolean: + output.Boolean = o.value; + break; + case ApplicationCommandOptionTypes.Role: + output.Role = BigInt(o.value); + break; + case ApplicationCommandOptionTypes.User: + output.User = BigInt(o.value); + break; + case ApplicationCommandOptionTypes.Channel: + output.Channel = BigInt(o.value); + break; + case ApplicationCommandOptionTypes.Mentionable: + case ApplicationCommandOptionTypes.SubCommand: + case ApplicationCommandOptionTypes.SubCommandGroup: + default: + output.Otherwise = o.value; + } + return output; +} +class CommandInteractionOptionResolver { + #subcommand; + #group; + hoistedOptions; + resolved; + constructor(options, resolved){ + this.hoistedOptions = options?.map(transformOasisInteractionDataOption) ?? []; + if (this.hoistedOptions[0]?.type === ApplicationCommandOptionTypes.SubCommandGroup) { + this.#group = this.hoistedOptions[0].name; + this.hoistedOptions = (this.hoistedOptions[0].options ?? []).map(transformOasisInteractionDataOption); + } + if (this.hoistedOptions[0]?.type === ApplicationCommandOptionTypes.SubCommand) { + this.#subcommand = this.hoistedOptions[0].name; + this.hoistedOptions = (this.hoistedOptions[0].options ?? []).map(transformOasisInteractionDataOption); + } + this.resolved = resolved; + } + getTypedOption(name, type, properties, required) { + const option = this.get(name, required); + if (!option) { + return; + } + if (option.type !== type) {} + if (required === true && properties.every((prop)=>typeof option[prop] === "undefined")) { + throw new TypeError(`Properties ${properties.join(", ")} are missing in option ${name}`); + } + return option; + } + get(name, required) { + const option = this.hoistedOptions.find((o)=>typeof name === "number" ? o.name === name.toString() : o.name === name); + if (!option) { + if (required && name in this.hoistedOptions.map((o)=>o.name)) { + throw new TypeError("Option marked as required was undefined"); + } + return; + } + return option; + } + getString(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.String, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getNumber(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Number, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getInteger(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Integer, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getBoolean(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Boolean, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getUser(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.User, [ + "Otherwise", + ], required); + return option?.Otherwise ?? undefined; + } + getChannel(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Channel, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getMentionable(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Mentionable, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getRole(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Role, [ + "Otherwise", + ], required); + return option?.Otherwise ?? undefined; + } + getAttachment(name, required = false) { + const option = this.getTypedOption(name, ApplicationCommandOptionTypes.Attachment, [ + "Otherwise" + ], required); + return option?.Otherwise ?? undefined; + } + getFocused(full = false) { + const focusedOption = this.hoistedOptions.find((option)=>option.focused); + if (!focusedOption) { + throw new TypeError("No option found"); + } + return full ? focusedOption : focusedOption.Otherwise; + } + getSubCommand(required = true) { + if (required && !this.#subcommand) { + throw new TypeError("Option marked as required was undefined"); + } + return [ + this.#subcommand, + this.hoistedOptions + ]; + } + getSubCommandGroup(required = false) { + if (required && !this.#group) { + throw new TypeError("Option marked as required was undefined"); + } + return [ + this.#group, + this.hoistedOptions + ]; + } +} +class Attachment { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.contentType = data.content_type ? data.content_type : undefined; + this.attachment = data.url; + this.proxyUrl = data.proxy_url; + this.name = data.filename; + this.size = data.size; + this.height = data.height ? data.height : undefined; + this.width = data.width ? data.width : undefined; + this.ephemeral = !!data.ephemeral; + } + session; + id; + contentType; + attachment; + proxyUrl; + name; + size; + height; + width; + ephemeral; +} +class Emoji { + constructor(session, data){ + this.id = data.id; + this.name = data.name; + this.animated = !!data.animated; + this.available = !!data.available; + this.requireColons = !!data.require_colons; + this.session = session; + } + id; + session; + name; + animated; + available; + requireColons; +} +class WelcomeChannel { + constructor(session, data){ + this.session = session; + this.channelId = data.channel_id; + this.description = data.description; + this.emoji = new Emoji(session, { + name: data.emoji_name ? data.emoji_name : undefined, + id: data.emoji_id ? data.emoji_id : undefined + }); + } + session; + channelId; + description; + emoji; + get id() { + return this.channelId; + } +} +class WelcomeScreen { + constructor(session, data){ + this.session = session; + this.welcomeChannels = data.welcome_channels.map((welcomeChannel)=>new WelcomeChannel(session, welcomeChannel)); + if (data.description) { + this.description = data.description; + } + } + session; + description; + welcomeChannels; +} +class ThreadMember { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.flags = data.flags; + this.timestamp = Date.parse(data.join_timestamp); + } + session; + id; + flags; + timestamp; + get threadId() { + return this.id; + } + async quitThread(memberId = this.session.botId) { + await this.session.rest.runMethod(this.session.rest, "DELETE", THREAD_USER(this.id, memberId)); + } + async fetchMember(memberId = this.session.botId) { + const member = await this.session.rest.runMethod(this.session.rest, "GET", THREAD_USER(this.id, memberId)); + return new ThreadMember(this.session, member); + } +} +function NewTeam(session, data) { + return { + icon: data.icon ? data.icon : undefined, + id: data.id, + members: data.members.map((member)=>{ + return { + membershipState: member.membership_state, + permissions: member.permissions, + teamId: member.team_id, + user: new User(session, member.user) + }; + }), + ownerUserId: data.owner_user_id, + name: data.name + }; +} +class Application { + constructor(session, data){ + this.id = data.id; + this.session = session; + this.name = data.name; + this.icon = data.icon || undefined; + this.description = data.description; + this.rpcOrigins = data.rpc_origins; + this.botPublic = data.bot_public; + this.botRequireCodeGrant = data.bot_require_code_grant; + this.termsOfServiceURL = data.terms_of_service_url; + this.privacyPolicyURL = data.privacy_policy_url; + this.owner = data.owner ? new User(session, data.owner) : undefined; + this.summary = ""; + this.verifyKey = data.verify_key; + this.team = data.team ? NewTeam(session, data.team) : undefined; + this.guildId = data.guild_id; + this.coverImage = data.cover_image; + this.tags = data.tags; + this.installParams = data.install_params; + this.customInstallURL = data.custom_install_url; + } + session; + id; + name; + icon; + description; + rpcOrigins; + botPublic; + botRequireCodeGrant; + termsOfServiceURL; + privacyPolicyURL; + owner; + summary; + verifyKey; + team; + guildId; + primarySkuId; + slug; + coverImage; + flags; + tags; + installParams; + customInstallURL; +} +class BaseComponent { + constructor(type){ + this.type = type; + } + type; + isActionRow() { + return this.type === MessageComponentTypes.ActionRow; + } + isButton() { + return this.type === MessageComponentTypes.Button; + } + isSelectMenu() { + return this.type === MessageComponentTypes.SelectMenu; + } + isTextInput() { + return this.type === MessageComponentTypes.InputText; + } +} +class Button extends BaseComponent { + constructor(session, data){ + super(data.type); + this.session = session; + this.type = data.type; + this.customId = data.custom_id; + this.label = data.label; + this.style = data.style; + this.disabled = data.disabled; + if (data.emoji) { + this.emoji = new Emoji(session, data.emoji); + } + } + session; + type; + customId; + label; + style; + disabled; + emoji; +} +class LinkButton extends BaseComponent { + constructor(session, data){ + super(data.type); + this.session = session; + this.type = data.type; + this.url = data.url; + this.label = data.label; + this.style = data.style; + this.disabled = data.disabled; + if (data.emoji) { + this.emoji = new Emoji(session, data.emoji); + } + } + session; + type; + url; + label; + style; + disabled; + emoji; +} +class SelectMenu extends BaseComponent { + constructor(session, data){ + super(data.type); + this.session = session; + this.type = data.type; + this.customId = data.custom_id; + this.options = data.options.map((option)=>{ + return { + label: option.label, + description: option.description, + emoji: option.emoji || new Emoji(session, option.emoji), + value: option.value + }; + }); + this.placeholder = data.placeholder; + this.minValues = data.min_values; + this.maxValues = data.max_values; + this.disabled = data.disabled; + } + session; + type; + customId; + options; + placeholder; + minValues; + maxValues; + disabled; +} +class TextInput extends BaseComponent { + constructor(session, data){ + super(data.type); + this.session = session; + this.type = data.type; + this.customId = data.custom_id; + this.label = data.label; + this.style = data.style; + this.placeholder = data.placeholder; + this.value = data.value; + this.minLength = data.min_length; + this.maxLength = data.max_length; + } + session; + type; + style; + customId; + label; + placeholder; + value; + minLength; + maxLength; +} +class ActionRow extends BaseComponent { + constructor(session, data){ + super(data.type); + this.session = session; + this.type = data.type; + this.components = data.components.map((component)=>{ + switch(component.type){ + case MessageComponentTypes.Button: + if (component.style === ButtonStyles.Link) { + return new LinkButton(session, component); + } + return new Button(session, component); + case MessageComponentTypes.SelectMenu: + return new SelectMenu(session, component); + case MessageComponentTypes.InputText: + return new TextInput(session, component); + case MessageComponentTypes.ActionRow: + throw new Error("Cannot have an action row inside an action row"); + } + }); + } + session; + type; + components; +} +class ComponentFactory { + static from(session, component) { + switch(component.type){ + case MessageComponentTypes.ActionRow: + return new ActionRow(session, component); + case MessageComponentTypes.Button: + if (component.style === ButtonStyles.Link) return new Button(session, component); + return new Button(session, component); + case MessageComponentTypes.SelectMenu: + return new SelectMenu(session, component); + case MessageComponentTypes.InputText: + return new TextInput(session, component); + } + } +} +function calculateShardId(gateway, guildId) { + if (gateway.manager.totalShards === 1) return 0; + return Number((guildId >> 22n) % BigInt(gateway.manager.totalShards - 1)); +} +class Member { + constructor(session, data, guildId){ + this.session = session; + this.user = new User(session, data.user); + this.guildId = guildId; + this.avatarHash = data.avatar ? Util.iconHashToBigInt(data.avatar) : undefined; + this.nickname = data.nick ? data.nick : undefined; + this.premiumSince = data.premium_since ? Number.parseInt(data.premium_since) : undefined; + this.joinedTimestamp = Number.parseInt(data.joined_at); + this.roles = data.roles; + this.deaf = !!data.deaf; + this.mute = !!data.mute; + this.pending = !!data.pending; + this.communicationDisabledUntilTimestamp = data.communication_disabled_until ? Number.parseInt(data.communication_disabled_until) : undefined; + } + session; + user; + guildId; + avatarHash; + nickname; + premiumSince; + joinedTimestamp; + roles; + deaf; + mute; + pending; + communicationDisabledUntilTimestamp; + get id() { + return this.user.id; + } + get nicknameOrUsername() { + return this.nickname ?? this.user.username; + } + get joinedAt() { + return new Date(this.joinedTimestamp); + } + async ban(options) { + await Guild.prototype.banMember.call({ + id: this.guildId, + session: this.session + }, this.user.id, options); + return this; + } + async kick(options) { + await Guild.prototype.kickMember.call({ + id: this.guildId, + session: this.session + }, this.user.id, options); + return this; + } + async unban() { + await Guild.prototype.unbanMember.call({ + id: this.guildId, + session: this.session + }, this.user.id); + } + async edit(options) { + const member = await Guild.prototype.editMember.call({ + id: this.guildId, + session: this.session + }, this.user.id, options); + return member; + } + async addRole(roleId, options = {}) { + await Guild.prototype.addRole.call({ + id: this.guildId, + session: this.session + }, this.user.id, roleId, options); + } + async removeRole(roleId, options = {}) { + await Guild.prototype.removeRole.call({ + id: this.guildId, + session: this.session + }, this.user.id, roleId, options); + } + avatarURL(options = { + size: 128 + }) { + let url; + if (this.user.bot) { + return this.user.avatarURL(); + } + if (!this.avatarHash) { + url = USER_DEFAULT_AVATAR(Number(this.user.discriminator) % 5); + } else { + url = USER_AVATAR(this.user.id, Util.iconBigintToHash(this.avatarHash)); + } + return Util.formatImageURL(url, options.size, options.format); + } + toString() { + return `<@!${this.user.id}>`; + } +} +function NewMessageReactionAdd(session, data) { + return { + userId: data.user_id, + channelId: data.channel_id, + messageId: data.message_id, + guildId: data.guild_id, + member: data.member ? new Member(session, data.member, data.guild_id || "") : undefined, + emoji: new Emoji(session, data.emoji) + }; +} +class BaseChannel { + constructor(session, data){ + this.id = data.id; + this.session = session; + this.name = data.name; + this.type = data.type; + } + id; + session; + name; + type; + isText() { + return textBasedChannels.includes(this.type); + } + isVoice() { + return this.type === ChannelTypes.GuildVoice; + } + isDM() { + return this.type === ChannelTypes.DM; + } + isNews() { + return this.type === ChannelTypes.GuildNews; + } + isThread() { + return this.type === ChannelTypes.GuildPublicThread || this.type === ChannelTypes.GuildPrivateThread; + } + isStage() { + return this.type === ChannelTypes.GuildStageVoice; + } + toString() { + return `<#${this.id}>`; + } +} +class Webhook { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.type = data.type; + this.token = data.token; + if (data.avatar) { + this.avatar = Util.iconHashToBigInt(data.avatar); + } + if (data.user) { + this.user = new User(session, data.user); + } + if (data.guild_id) { + this.guildId = data.guild_id; + } + if (data.channel_id) { + this.channelId = data.channel_id; + } + if (data.application_id) { + this.applicationId = data.application_id; + } + } + session; + id; + type; + token; + avatar; + applicationId; + channelId; + guildId; + user; + async execute(options) { + if (!this.token) { + return; + } + const data = { + content: options?.content, + embeds: options?.embeds, + tts: options?.tts, + allowed_mentions: options?.allowedMentions, + components: options?.components, + file: options?.files + }; + const message = this.session.rest.sendRequest(this.session.rest, { + url: WEBHOOK(this.id, this.token, { + wait: options?.wait, + threadId: options?.threadId + }), + method: "POST", + payload: this.session.rest.createRequestBody(this.session.rest, { + method: "POST", + body: { + ...data + } + }) + }); + return options?.wait ?? true ? new Message(this.session, await message) : undefined; + } + async fetch() { + const message = await this.session.rest.runMethod(this.session.rest, "GET", WEBHOOK_TOKEN(this.id, this.token)); + return new Webhook(this.session, message); + } + async fetchMessage(messageId, options) { + if (!this.token) { + return; + } + const message = await this.session.rest.runMethod(this.session.rest, "GET", WEBHOOK_MESSAGE(this.id, this.token, messageId, options)); + return new Message(this.session, message); + } + async deleteMessage(messageId, options) { + if (!this.token) { + throw new Error("No token found"); + } + await this.session.rest.runMethod(this.session.rest, "DELETE", WEBHOOK_MESSAGE(this.id, this.token, messageId, options)); + } + async editMessage(messageId, options) { + if (!this.token) { + throw new Error("No token found"); + } + const message = await this.session.rest.runMethod(this.session.rest, "PATCH", messageId ? WEBHOOK_MESSAGE(this.id, this.token, messageId) : WEBHOOK_MESSAGE_ORIGINAL(this.id, this.token), { + content: options?.content, + embeds: options?.embeds, + file: options?.files, + components: options?.components, + allowed_mentions: options?.allowedMentions && { + parse: options?.allowedMentions.parse, + replied_user: options?.allowedMentions.repliedUser, + users: options?.allowedMentions.users, + roles: options?.allowedMentions.roles + }, + attachments: options?.attachments?.map((attachment)=>{ + return { + id: attachment.id, + filename: attachment.name, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.attachment, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width, + ephemeral: attachment.ephemeral + }; + }) + }); + return new Message(this.session, message); + } +} +class MessageReaction { + constructor(session, data){ + this.session = session; + this.me = data.me; + this.count = data.count; + this.emoji = new Emoji(session, data.emoji); + } + session; + me; + count; + emoji; +} +class Message { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.type = data.type; + this.channelId = data.channel_id; + this.guildId = data.guild_id; + this.applicationId = data.application_id; + this.mentions = { + users: data.mentions?.map((user)=>new User(session, user)) ?? [], + roleIds: data.mention_roles ?? [], + channels: data.mention_channels?.map((channel)=>ChannelFactory.from(session, channel)) ?? [] + }; + if (!data.webhook_id) { + this.author = new User(session, data.author); + } + this.flags = data.flags; + this.pinned = !!data.pinned; + this.tts = !!data.tts; + this.content = data.content; + this.nonce = data.nonce; + this.mentionEveryone = data.mention_everyone; + this.timestamp = Date.parse(data.timestamp); + this.editedTimestamp = data.edited_timestamp ? Date.parse(data.edited_timestamp) : undefined; + this.reactions = data.reactions?.map((react)=>new MessageReaction(session, react)) ?? []; + this.attachments = data.attachments.map((attachment)=>new Attachment(session, attachment)); + this.embeds = data.embeds; + if (data.interaction) { + this.interaction = InteractionFactory.fromMessage(session, data.interaction, data.guild_id); + } + if (data.thread && data.guild_id) { + this.thread = new ThreadChannel(session, data.thread, data.guild_id); + } + if (data.webhook_id && data.author.discriminator === "0000") { + this.webhook = { + id: data.webhook_id, + username: data.author.username, + discriminator: data.author.discriminator, + avatar: data.author.avatar ? Util.iconHashToBigInt(data.author.avatar) : undefined + }; + } + if (data.guild_id && data.member && !this.isWebhookMessage()) { + this.member = new Member(session, { + ...data.member, + user: data.author + }, data.guild_id); + } + this.components = data.components?.map((component)=>ComponentFactory.from(session, component)) ?? []; + if (data.activity) { + this.activity = { + partyId: data.activity.party_id, + type: data.activity.type + }; + } + if (data.sticker_items) { + this.stickers = data.sticker_items.map((si)=>{ + return { + id: si.id, + name: si.name, + formatType: si.format_type + }; + }); + } + if (data.application) { + const application = { + id: data.application.id, + icon: data.application.icon ? data.application.icon : undefined, + name: data.application.name, + guildId: data.application.guild_id, + flags: data.application.flags, + botPublic: data.application.bot_public, + owner: data.application.owner ? new User(session, data.application.owner) : undefined, + botRequireCodeGrant: data.application.bot_require_code_grant, + coverImage: data.application.cover_image, + customInstallURL: data.application.custom_install_url, + description: data.application.description, + installParams: data.application.install_params, + tags: data.application.tags, + verifyKey: data.application.verify_key, + team: data.application.team ? NewTeam(session, data.application.team) : undefined, + primarySkuId: data.application.primary_sku_id, + privacyPolicyURL: data.application.privacy_policy_url, + rpcOrigins: data.application.rpc_origins, + slug: data.application.slug + }; + Object.setPrototypeOf(application, Application.prototype); + this.application = application; + } + } + session; + id; + type; + channelId; + guildId; + applicationId; + mentions; + interaction; + author; + flags; + pinned; + tts; + content; + nonce; + mentionEveryone; + timestamp; + editedTimestamp; + stickers; + reactions; + attachments; + embeds; + member; + thread; + components; + webhook; + application; + activity; + get createdTimestamp() { + return Snowflake.snowflakeToTimestamp(this.id); + } + get createdAt() { + return new Date(this.createdTimestamp); + } + get sentAt() { + return new Date(this.timestamp); + } + get editedAt() { + return this.editedTimestamp ? new Date(this.editedTimestamp) : undefined; + } + get edited() { + return this.editedTimestamp; + } + get url() { + return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`; + } + get isBot() { + return this.author.bot; + } + async pin() { + await this.session.rest.runMethod(this.session.rest, "PUT", CHANNEL_PIN(this.channelId, this.id)); + } + async unpin() { + await this.session.rest.runMethod(this.session.rest, "DELETE", CHANNEL_PIN(this.channelId, this.id)); + } + async edit(options) { + const message = await this.session.rest.runMethod(this.session.rest, "POST", CHANNEL_MESSAGE(this.id, this.channelId), { + content: options.content, + allowed_mentions: { + parse: options.allowedMentions?.parse, + roles: options.allowedMentions?.roles, + users: options.allowedMentions?.users, + replied_user: options.allowedMentions?.repliedUser + }, + flags: options.flags, + embeds: options.embeds + }); + return message; + } + async suppressEmbeds(suppress = true) { + if (this.flags === MessageFlags.SupressEmbeds && suppress === false) { + return; + } + const message = await this.edit({ + flags: MessageFlags.SupressEmbeds + }); + return message; + } + async delete({ reason }) { + await this.session.rest.runMethod(this.session.rest, "DELETE", CHANNEL_MESSAGE(this.channelId, this.id), { + reason + }); + return this; + } + async reply(options) { + const message = await this.session.rest.runMethod(this.session.rest, "POST", CHANNEL_MESSAGES(this.channelId), { + content: options.content, + file: options.files, + allowed_mentions: { + parse: options.allowedMentions?.parse, + roles: options.allowedMentions?.roles, + users: options.allowedMentions?.users, + replied_user: options.allowedMentions?.repliedUser + }, + message_reference: options.messageReference ? { + message_id: options.messageReference.messageId, + channel_id: options.messageReference.channelId, + guild_id: options.messageReference.guildId, + fail_if_not_exists: options.messageReference.failIfNotExists ?? true + } : undefined, + embeds: options.embeds, + tts: options.tts, + components: options.components + }); + return new Message(this.session, message); + } + get react() { + return this.addReaction; + } + async addReaction(reaction) { + const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + await this.session.rest.runMethod(this.session.rest, "PUT", CHANNEL_MESSAGE_REACTION_ME(this.channelId, this.id, r), {}); + } + async removeReaction(reaction, options) { + const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + await this.session.rest.runMethod(this.session.rest, "DELETE", options?.userId ? CHANNEL_MESSAGE_REACTION_USER(this.channelId, this.id, r, options.userId) : CHANNEL_MESSAGE_REACTION_ME(this.channelId, this.id, r)); + } + async fetchReactions(reaction, options) { + const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + const users = await this.session.rest.runMethod(this.session.rest, "GET", CHANNEL_MESSAGE_REACTION(this.channelId, this.id, encodeURIComponent(r), options)); + return users.map((user)=>new User(this.session, user)); + } + async removeReactionEmoji(reaction) { + const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + await this.session.rest.runMethod(this.session.rest, "DELETE", CHANNEL_MESSAGE_REACTION(this.channelId, this.id, r)); + } + async nukeReactions() { + await this.session.rest.runMethod(this.session.rest, "DELETE", CHANNEL_MESSAGE_REACTIONS(this.channelId, this.id)); + } + async crosspost() { + const message = await this.session.rest.runMethod(this.session.rest, "POST", CHANNEL_MESSAGE_CROSSPOST(this.channelId, this.id)); + return new Message(this.session, message); + } + async fetch() { + const message = await this.session.rest.runMethod(this.session.rest, "GET", CHANNEL_MESSAGE(this.channelId, this.id)); + if (!message?.id) return; + return new Message(this.session, message); + } + get publish() { + return this.crosspost; + } + inGuild() { + return !!this.guildId; + } + isWebhookMessage() { + return !!this.webhook; + } +} +class BaseGuild { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.name = data.name; + this.iconHash = data.icon ? Util.iconHashToBigInt(data.icon) : undefined; + this.features = data.features; + } + session; + id; + name; + iconHash; + features; + get createdTimestamp() { + return Snowflake.snowflakeToTimestamp(this.id); + } + get createdAt() { + return new Date(this.createdTimestamp); + } + get partnered() { + return this.features.includes(GuildFeatures.Partnered); + } + get verified() { + return this.features.includes(GuildFeatures.Verified); + } + iconURL(options = { + size: 128 + }) { + if (this.iconHash) { + return Util.formatImageURL(GUILD_ICON(this.id, Util.iconBigintToHash(this.iconHash)), options.size, options.format); + } + } + toString() { + return this.name; + } +} +function NewInviteCreate(session, invite) { + return { + channelId: invite.channel_id, + code: invite.code, + createdAt: invite.created_at, + guildId: invite.guild_id, + inviter: invite.inviter ? new User(session, invite.inviter) : undefined, + maxAge: invite.max_age, + maxUses: invite.max_uses, + targetType: invite.target_type, + targetUser: invite.target_user ? new User(session, invite.target_user) : undefined, + targetApplication: invite.target_application && new Application(session, invite.target_application), + temporary: invite.temporary, + uses: invite.uses + }; +} +class Role { + constructor(session, data, guildId){ + this.session = session; + this.id = data.id; + this.guildId = guildId; + this.hoist = data.hoist; + this.iconHash = data.icon ? Util.iconHashToBigInt(data.icon) : undefined; + this.color = data.color; + this.name = data.name; + this.unicodeEmoji = data.unicode_emoji; + this.mentionable = data.mentionable; + this.managed = data.managed; + this.permissions = new Permissions(BigInt(data.permissions)); + } + session; + id; + guildId; + hoist; + iconHash; + color; + name; + unicodeEmoji; + mentionable; + managed; + permissions; + get createdTimestamp() { + return Snowflake.snowflakeToTimestamp(this.id); + } + get createdAt() { + return new Date(this.createdTimestamp); + } + get hexColor() { + return `#${this.color.toString(16).padStart(6, "0")}`; + } + async delete() { + await Guild.prototype.deleteRole.call({ + id: this.guildId, + session: this.session + }, this.id); + } + async edit(options) { + const role = await Guild.prototype.editRole.call({ + id: this.guildId, + session: this.session + }, this.id, options); + return role; + } + async add(memberId, options = {}) { + await Guild.prototype.addRole.call({ + id: this.guildId, + session: this.session + }, memberId, this.id, options); + } + async remove(memberId, options = {}) { + await Guild.prototype.removeRole.call({ + id: this.guildId, + session: this.session + }, memberId, this.id, options); + } + toString() { + switch(this.id){ + case this.guildId: + return "@everyone"; + default: + return `<@&${this.id}>`; + } + } +} +class GuildEmoji extends Emoji { + constructor(session, data, guildId){ + super(session, data); + this.guildId = guildId; + this.roles = data.roles; + this.user = data.user ? new User(this.session, data.user) : undefined; + this.managed = !!data.managed; + this.id = super.id; + } + guildId; + roles; + user; + managed; + id; + async edit(options) { + const emoji = await Guild.prototype.editEmoji.call({ + id: this.guildId, + session: this.session + }, this.id, options); + return emoji; + } + async delete({ reason } = {}) { + await Guild.prototype.deleteEmoji.call({ + id: this.guildId, + session: this.session + }, this.id, { + reason + }); + return this; + } + get url() { + return EMOJI_URL(this.id, this.animated); + } +} +class InteractionFactory { + static from(session, interaction) { + switch(interaction.type){ + case InteractionTypes.Ping: + return new PingInteraction(session, interaction); + case InteractionTypes.ApplicationCommand: + return new CommandInteraction(session, interaction); + case InteractionTypes.MessageComponent: + return new ComponentInteraction(session, interaction); + case InteractionTypes.ApplicationCommandAutocomplete: + return new AutoCompleteInteraction(session, interaction); + case InteractionTypes.ModalSubmit: + return new ModalSubmitInteraction(session, interaction); + } + } + static fromMessage(session, interaction, _guildId) { + const obj = { + id: interaction.id, + type: interaction.type, + name: interaction.name, + user: new User(session, interaction.user) + }; + return obj; + } +} +class BaseInteraction { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.token = data.token; + this.type = data.type; + this.guildId = data.guild_id; + this.channelId = data.channel_id; + this.applicationId = data.application_id; + this.version = data.version; + const perms = data.app_permissions; + if (perms) { + this.appPermissions = new Permissions(BigInt(perms)); + } + if (!data.guild_id) { + this.user = new User(session, data.user); + } else { + this.member = new Member(session, data.member, data.guild_id); + } + } + session; + id; + token; + type; + guildId; + channelId; + applicationId; + user; + member; + appPermissions; + version; + responded = false; + get createdTimestamp() { + return Snowflake.snowflakeToTimestamp(this.id); + } + get createdAt() { + return new Date(this.createdTimestamp); + } + isCommand() { + return this.type === InteractionTypes.ApplicationCommand; + } + isAutoComplete() { + return this.type === InteractionTypes.ApplicationCommandAutocomplete; + } + isComponent() { + return this.type === InteractionTypes.MessageComponent; + } + isPing() { + return this.type === InteractionTypes.Ping; + } + isModalSubmit() { + return this.type === InteractionTypes.ModalSubmit; + } + inGuild() { + return !!this.guildId; + } + async editReply(options) { + const message = await this.session.rest.runMethod(this.session.rest, "PATCH", options.messageId ? WEBHOOK_MESSAGE(this.id, this.token, options.messageId) : WEBHOOK_MESSAGE_ORIGINAL(this.id, this.token), { + content: options.content, + embeds: options.embeds, + file: options.files, + components: options.components, + allowed_mentions: options.allowedMentions && { + parse: options.allowedMentions.parse, + replied_user: options.allowedMentions.repliedUser, + users: options.allowedMentions.users, + roles: options.allowedMentions.roles + }, + attachments: options.attachments?.map((attachment)=>{ + return { + id: attachment.id, + filename: attachment.name, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.attachment, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width + }; + }), + message_id: options.messageId + }); + if (!message || !options.messageId) { + return message; + } + return new Message(this.session, message); + } + async sendFollowUp(options) { + const message = await Webhook.prototype.execute.call({ + id: this.applicationId, + token: this.token, + session: this.session + }, options); + return message; + } + async editFollowUp(messageId, options) { + const message = await Webhook.prototype.editMessage.call({ + id: this.session.applicationId, + token: this.token + }, messageId, options); + return message; + } + async deleteFollowUp(messageId, options) { + await Webhook.prototype.deleteMessage.call({ + id: this.session.applicationId, + token: this.token + }, messageId, options); + } + async fetchFollowUp(messageId, options) { + const message = await Webhook.prototype.fetchMessage.call({ + id: this.session.applicationId, + token: this.token + }, messageId, options); + return message; + } + async respond(resp) { + const options = "with" in resp ? resp.with : resp.data; + const type = "type" in resp ? resp.type : InteractionResponseTypes.ChannelMessageWithSource; + const data = { + content: options?.content, + custom_id: options?.customId, + file: options?.files, + allowed_mentions: options?.allowedMentions, + flags: options?.flags, + chocies: options?.choices, + embeds: options?.embeds, + title: options?.title, + components: options?.components + }; + if (!this.responded) { + await this.session.rest.sendRequest(this.session.rest, { + url: INTERACTION_ID_TOKEN(this.id, this.token), + method: "POST", + payload: this.session.rest.createRequestBody(this.session.rest, { + method: "POST", + body: { + type, + data, + file: options?.files + }, + headers: { + "Authorization": "" + } + }) + }); + this.responded = true; + return; + } + return this.sendFollowUp(data); + } + async respondWith(resp) { + const m = await this.respond({ + with: resp + }); + return m; + } + async defer() { + await this.respond({ + type: InteractionResponseTypes.DeferredChannelMessageWithSource + }); + } + async autocomplete() { + await this.respond({ + type: InteractionResponseTypes.ApplicationCommandAutocompleteResult + }); + } +} +class CommandInteraction extends BaseInteraction { + constructor(session, data){ + super(session, data); + this.type = data.type; + this.commandId = data.data.id; + this.commandName = data.data.name; + this.commandType = data.data.type; + this.commandGuildId = data.data.guild_id; + this.options = new CommandInteractionOptionResolver(data.data.options ?? []); + this.resolved = { + users: new Map(), + members: new Map(), + roles: new Map(), + attachments: new Map(), + messages: new Map() + }; + if (data.data.resolved?.users) { + for (const [id, u] of Object.entries(data.data.resolved.users)){ + this.resolved.users.set(id, new User(session, u)); + } + } + if (data.data.resolved?.members && !!super.guildId) { + for (const [id1, m] of Object.entries(data.data.resolved.members)){ + this.resolved.members.set(id1, new Member(session, m, super.guildId)); + } + } + if (data.data.resolved?.roles && !!super.guildId) { + for (const [id2, r] of Object.entries(data.data.resolved.roles)){ + this.resolved.roles.set(id2, new Role(session, r, super.guildId)); + } + } + if (data.data.resolved?.attachments) { + for (const [id3, a] of Object.entries(data.data.resolved.attachments)){ + this.resolved.attachments.set(id3, new Attachment(session, a)); + } + } + if (data.data.resolved?.messages) { + for (const [id4, m1] of Object.entries(data.data.resolved.messages)){ + this.resolved.messages.set(id4, new Message(session, m1)); + } + } + } + type; + commandId; + commandName; + commandType; + commandGuildId; + resolved; + options; +} +class ComponentInteraction extends BaseInteraction { + constructor(session, data){ + super(session, data); + this.type = data.type; + this.componentType = data.data.component_type; + this.customId = data.data.custom_id; + this.targetId = data.data.target_id; + this.values = data.data.values; + this.message = new Message(session, data.message); + } + type; + componentType; + customId; + targetId; + values; + message; + isButton() { + return this.componentType === MessageComponentTypes.Button; + } + isActionRow() { + return this.componentType === MessageComponentTypes.ActionRow; + } + isTextInput() { + return this.componentType === MessageComponentTypes.InputText; + } + isSelectMenu() { + return this.componentType === MessageComponentTypes.SelectMenu; + } + async deferUpdate() { + await this.respond({ + type: InteractionResponseTypes.DeferredUpdateMessage + }); + } +} +class ModalSubmitInteraction extends BaseInteraction { + constructor(session, data){ + super(session, data); + this.type = data.type; + this.componentType = data.data.component_type; + this.customId = data.data.custom_id; + this.targetId = data.data.target_id; + this.values = data.data.values; + this.components = data.data?.components?.map(ModalSubmitInteraction.transformComponent); + if (data.message) { + this.message = new Message(session, data.message); + } + } + type; + componentType; + customId; + targetId; + values; + message; + components; + static transformComponent(component) { + return { + type: component.type, + components: component.components.map((component)=>{ + return { + customId: component.custom_id, + value: component.value + }; + }) + }; + } + inMessage() { + return !!this.message; + } +} +class PingInteraction extends BaseInteraction { + constructor(session, data){ + super(session, data); + this.type = data.type; + this.commandId = data.data.id; + this.commandName = data.data.name; + this.commandType = data.data.type; + this.commandGuildId = data.data.guild_id; + } + type; + commandId; + commandName; + commandType; + commandGuildId; + async pong() { + await this.session.rest.runMethod(this.session.rest, "POST", INTERACTION_ID_TOKEN(this.id, this.token), { + type: InteractionResponseTypes.Pong + }); + } +} +class AutoCompleteInteraction extends BaseInteraction { + constructor(session, data){ + super(session, data); + this.type = data.type; + this.commandId = data.data.id; + this.commandName = data.data.name; + this.commandType = data.data.type; + this.commandGuildId = data.data.guild_id; + } + type; + commandId; + commandName; + commandType; + commandGuildId; + async respondWithChoices(choices) { + await this.session.rest.runMethod(this.session.rest, "POST", INTERACTION_ID_TOKEN(this.id, this.token), { + data: { + choices + }, + type: InteractionResponseTypes.ApplicationCommandAutocompleteResult + }); + } +} +const textBasedChannels = [ + ChannelTypes.DM, + ChannelTypes.GroupDm, + ChannelTypes.GuildPrivateThread, + ChannelTypes.GuildPublicThread, + ChannelTypes.GuildNews, + ChannelTypes.GuildVoice, + ChannelTypes.GuildText, +]; +class TextChannel { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.name = data.name; + this.type = data.type; + 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; + } + } + session; + id; + name; + type; + lastMessageId; + lastPinTimestamp; + rateLimitPerUser; + nsfw; + static applyTo(klass, ignore = []) { + const methods = [ + "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() { + const messages = await this.session.rest.runMethod(this.session.rest, "GET", CHANNEL_PINS(this.id)); + return messages[0] ? messages.map((x)=>new Message(this.session, x)) : []; + } + async createInvite(options) { + const invite = await this.session.rest.runMethod(this.session.rest, "POST", 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) { + if (options?.limit > 100) throw Error("Values must be between 0-100"); + const messages = await this.session.rest.runMethod(this.session.rest, "GET", 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", CHANNEL_TYPING(this.id)); + } + async pinMessage(messageId) { + await Message.prototype.pin.call({ + id: messageId, + channelId: this.id, + session: this.session + }); + } + async unpinMessage(messageId) { + await Message.prototype.unpin.call({ + id: messageId, + channelId: this.id, + session: this.session + }); + } + async addReaction(messageId, reaction) { + await Message.prototype.addReaction.call({ + channelId: this.id, + id: messageId, + session: this.session + }, reaction); + } + async removeReaction(messageId, reaction, options) { + await Message.prototype.removeReaction.call({ + channelId: this.id, + id: messageId, + session: this.session + }, reaction, options); + } + async removeReactionEmoji(messageId, reaction) { + await Message.prototype.removeReactionEmoji.call({ + channelId: this.id, + id: messageId, + session: this.session + }, reaction); + } + async nukeReactions(messageId) { + await Message.prototype.nukeReactions.call({ + channelId: this.id, + id: messageId + }); + } + async fetchReactions(messageId, reaction, options) { + const users = await Message.prototype.fetchReactions.call({ + channelId: this.id, + id: messageId, + session: this.session + }, reaction, options); + return users; + } + sendMessage(options) { + return Message.prototype.reply.call({ + channelId: this.id, + session: this.session + }, options); + } + editMessage(messageId, options) { + return Message.prototype.edit.call({ + channelId: this.id, + id: messageId, + session: this.session + }, options); + } + async createWebhook(options) { + const webhook = await this.session.rest.runMethod(this.session.rest, "POST", CHANNEL_WEBHOOKS(this.id), { + name: options.name, + avatar: options.avatar ? urlToBase64(options.avatar) : undefined, + reason: options.reason + }); + return new Webhook(this.session, webhook); + } +} +class GuildChannel extends BaseChannel { + constructor(session, data, guildId){ + super(session, data); + this.type = data.type; + this.guildId = guildId; + this.position = data.position; + data.topic ? this.topic = data.topic : null; + data.parent_id ? this.parentId = data.parent_id : undefined; + } + type; + guildId; + topic; + position; + parentId; + async fetchInvites() { + const invites = await this.session.rest.runMethod(this.session.rest, "GET", CHANNEL_INVITES(this.id)); + return invites.map((invite)=>new Invite(this.session, invite)); + } + async edit(options) { + const channel = await this.session.rest.runMethod(this.session.rest, "PATCH", 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) { + let func; + switch(options.type){ + case "public": + func = THREAD_ARCHIVED_PUBLIC; + break; + case "private": + func = THREAD_START_PRIVATE; + break; + case "privateJoinedThreads": + func = 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) + ])), + members: Object.fromEntries(members.map((threadMember)=>[ + threadMember.id, + new ThreadMember(this.session, threadMember) + ])), + hasMore: has_more + }; + } + async createThread(options) { + const thread = await this.session.rest.runMethod(this.session.rest, "POST", "messageId" in options ? THREAD_START_PUBLIC(this.id, options.messageId) : THREAD_START_PRIVATE(this.id), { + name: options.name, + auto_archive_duration: options.autoArchiveDuration + }); + return new ThreadChannel(this.session, thread, thread.guild_id ?? this.guildId); + } +} +class BaseVoiceChannel extends GuildChannel { + constructor(session, data, guildId){ + 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; + if (data.rtc_region) { + this.rtcRegion = data.rtc_region; + } + } + type; + bitRate; + userLimit; + rtcRegion; + videoQuality; + nsfw; + async connect(options) { + 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 + } + }); + } +} +class DMChannel extends BaseChannel { + constructor(session, data){ + super(session, data); + this.user = new User(this.session, data.recipents.find((r)=>r.id !== this.session.botId)); + this.type = data.type; + if (data.last_message_id) { + this.lastMessageId = data.last_message_id; + } + } + type; + user; + lastMessageId; + async close() { + const channel = await this.session.rest.runMethod(this.session.rest, "DELETE", CHANNEL(this.id)); + return new DMChannel(this.session, channel); + } +} +TextChannel.applyTo(DMChannel); +class VoiceChannel extends BaseVoiceChannel { + constructor(session, data, guildId){ + super(session, data, guildId); + this.type = data.type; + } + type; +} +TextChannel.applyTo(VoiceChannel); +class NewsChannel extends GuildChannel { + constructor(session, data, guildId){ + super(session, data, guildId); + this.type = data.type; + this.defaultAutoArchiveDuration = data.default_auto_archive_duration; + } + type; + defaultAutoArchiveDuration; + crosspostMessage(messageId) { + return Message.prototype.crosspost.call({ + id: messageId, + channelId: this.id, + session: this.session + }); + } + get publishMessage() { + return this.crosspostMessage; + } +} +TextChannel.applyTo(NewsChannel); +class StageChannel extends BaseVoiceChannel { + constructor(session, data, guildId){ + super(session, data, guildId); + this.type = data.type; + this.topic = data.topic ? data.topic : undefined; + } + type; + topic; +} +class ThreadChannel extends GuildChannel { + constructor(session, data, guildId){ + super(session, data, guildId); + this.type = data.type; + 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); + } + } + type; + archived; + archiveTimestamp; + autoArchiveDuration; + locked; + messageCount; + memberCount; + member; + ownerId; + async joinThread() { + await this.session.rest.runMethod(this.session.rest, "PUT", THREAD_ME(this.id)); + } + async addToThread(guildMemberId) { + await this.session.rest.runMethod(this.session.rest, "PUT", THREAD_USER(this.id, guildMemberId)); + } + async leaveToThread(guildMemberId) { + await this.session.rest.runMethod(this.session.rest, "DELETE", THREAD_USER(this.id, guildMemberId)); + } + removeMember(memberId = this.session.botId) { + return ThreadMember.prototype.quitThread.call({ + id: this.id, + session: this.session + }, memberId); + } + fetchMember(memberId = this.session.botId) { + return ThreadMember.prototype.fetchMember.call({ + id: this.id, + session: this.session + }, memberId); + } + async fetchMembers() { + const members = await this.session.rest.runMethod(this.session.rest, "GET", THREAD_MEMBERS(this.id)); + return members.map((threadMember)=>new ThreadMember(this.session, threadMember)); + } +} +TextChannel.applyTo(ThreadChannel); +class GuildTextChannel extends GuildChannel { + constructor(session, data, guildId){ + super(session, data, guildId); + this.type = data.type; + } + type; +} +TextChannel.applyTo(GuildTextChannel); +class ChannelFactory { + static fromGuildChannel(session, channel) { + switch(channel.type){ + case ChannelTypes.GuildPublicThread: + case ChannelTypes.GuildPrivateThread: + return new ThreadChannel(session, channel, channel.guild_id); + case ChannelTypes.GuildText: + return new GuildTextChannel(session, channel, channel.guild_id); + case ChannelTypes.GuildNews: + return new NewsChannel(session, channel, channel.guild_id); + case ChannelTypes.GuildVoice: + return new VoiceChannel(session, channel, channel.guild_id); + case ChannelTypes.GuildStageVoice: + return new StageChannel(session, channel, channel.guild_id); + default: + throw new Error("Channel was not implemented"); + } + } + static from(session, channel) { + switch(channel.type){ + case ChannelTypes.GuildPublicThread: + case ChannelTypes.GuildPrivateThread: + return new ThreadChannel(session, channel, channel.guild_id); + case ChannelTypes.GuildText: + return new GuildTextChannel(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"); + } + } +} +class AnonymousGuild extends BaseGuild { + constructor(session, data){ + super(session, data); + 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; + this.nsfwLevel = data.nsfw_level; + this.description = data.description ? data.description : undefined; + this.premiumSubscriptionCount = data.premium_subscription_count; + } + splashHash; + bannerHash; + verificationLevel; + vanityUrlCode; + nsfwLevel; + description; + premiumSubscriptionCount; + splashURL(options = { + size: 128 + }) { + if (this.splashHash) { + return Util.formatImageURL(GUILD_SPLASH(this.id, Util.iconBigintToHash(this.splashHash)), options.size, options.format); + } + } + bannerURL(options = { + size: 128 + }) { + if (this.bannerHash) { + return Util.formatImageURL(GUILD_BANNER(this.id, Util.iconBigintToHash(this.bannerHash)), options.size, options.format); + } + } +} +class InviteGuild extends AnonymousGuild { + constructor(session, data){ + super(session, data); + if (data.welcome_screen) { + this.welcomeScreen = new WelcomeScreen(session, data.welcome_screen); + } + } + welcomeScreen; +} +class Guild extends BaseGuild { + constructor(session, data){ + super(session, data); + 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; + this.vefificationLevel = data.verification_level; + this.defaultMessageNotificationLevel = data.default_message_notifications; + this.explicitContentFilterLevel = data.explicit_content_filter; + this.premiumTier = data.premium_tier; + this.members = new Map(data.members?.map((member)=>[ + data.id, + new Member(session, { + ...member, + user: member.user + }, data.id) + ])); + this.roles = new Map(data.roles.map((role)=>[ + data.id, + new Role(session, role, data.id) + ])); + this.emojis = new Map(data.emojis.map((guildEmoji)=>[ + guildEmoji.id, + new GuildEmoji(session, guildEmoji, data.id) + ])); + this.channels = new Map(data.channels?.map((guildChannel)=>[ + guildChannel.id, + new GuildChannel(session, guildChannel, data.id) + ])); + } + splashHash; + discoverySplashHash; + ownerId; + widgetEnabled; + widgetChannelId; + vefificationLevel; + defaultMessageNotificationLevel; + explicitContentFilterLevel; + premiumTier; + members; + roles; + emojis; + channels; + get maxEmojis() { + switch(this.premiumTier){ + case 1: + return 100; + case 2: + return 150; + case 3: + return 250; + default: + return 50; + } + } + get maxStickers() { + switch(this.premiumTier){ + case 1: + return 15; + case 2: + return 30; + case 3: + return 60; + default: + return 5; + } + } + async editBotNickname(options) { + const result = await this.session.rest.runMethod(this.session.rest, "PATCH", USER_NICK(this.id), options); + return result?.nick; + } + async createEmoji(options) { + if (options.image && !options.image.startsWith("data:image/")) { + options.image = await urlToBase64(options.image); + } + const emoji = await this.session.rest.runMethod(this.session.rest, "POST", GUILD_EMOJIS(this.id), options); + return new GuildEmoji(this.session, emoji, this.id); + } + async deleteEmoji(id, { reason } = {}) { + await this.session.rest.runMethod(this.session.rest, "DELETE", GUILD_EMOJI(this.id, id), { + reason + }); + } + async editEmoji(id, options) { + const emoji = await this.session.rest.runMethod(this.session.rest, "PATCH", GUILD_EMOJI(this.id, id), options); + return new GuildEmoji(this.session, emoji, this.id); + } + async createRole(options) { + let icon; + if (options.iconHash) { + if (typeof options.iconHash === "string") { + icon = options.iconHash; + } else { + icon = Util.iconBigintToHash(options.iconHash); + } + } + const role = await this.session.rest.runMethod(this.session.rest, "PUT", GUILD_ROLES(this.id), { + name: options.name, + color: options.color, + icon, + unicode_emoji: options.unicodeEmoji, + hoist: options.hoist, + mentionable: options.mentionable + }); + return new Role(this.session, role, this.id); + } + async deleteRole(roleId) { + await this.session.rest.runMethod(this.session.rest, "DELETE", GUILD_ROLE(this.id, roleId)); + } + async editRole(roleId, options) { + const role = await this.session.rest.runMethod(this.session.rest, "PATCH", GUILD_ROLE(this.id, roleId), { + name: options.name, + color: options.color, + hoist: options.hoist, + mentionable: options.mentionable + }); + return new Role(this.session, role, this.id); + } + async addRole(memberId, roleId, { reason } = {}) { + await this.session.rest.runMethod(this.session.rest, "PUT", GUILD_MEMBER_ROLE(this.id, memberId, roleId), { + reason + }); + } + async removeRole(memberId, roleId, { reason } = {}) { + await this.session.rest.runMethod(this.session.rest, "DELETE", GUILD_MEMBER_ROLE(this.id, memberId, roleId), { + reason + }); + } + async moveRoles(options) { + const roles = await this.session.rest.runMethod(this.session.rest, "PATCH", GUILD_ROLES(this.id), options); + return roles.map((role)=>new Role(this.session, role, this.id)); + } + async deleteInvite(inviteCode) { + await this.session.rest.runMethod(this.session.rest, "DELETE", INVITE(inviteCode), {}); + } + async fetchInvite(inviteCode, options) { + const inviteMetadata = await this.session.rest.runMethod(this.session.rest, "GET", INVITE(inviteCode, options)); + return new Invite(this.session, inviteMetadata); + } + async fetchInvites() { + const invites = await this.session.rest.runMethod(this.session.rest, "GET", GUILD_INVITES(this.id)); + return invites.map((invite)=>new Invite(this.session, invite)); + } + async banMember(memberId, options) { + await this.session.rest.runMethod(this.session.rest, "PUT", GUILD_BAN(this.id, memberId), options ? { + delete_message_days: options.deleteMessageDays, + reason: options.reason + } : {}); + } + async kickMember(memberId, { reason }) { + await this.session.rest.runMethod(this.session.rest, "DELETE", GUILD_MEMBER(this.id, memberId), { + reason + }); + } + async unbanMember(memberId) { + await this.session.rest.runMethod(this.session.rest, "DELETE", GUILD_BAN(this.id, memberId)); + } + async editMember(memberId, options) { + const member = await this.session.rest.runMethod(this.session.rest, "PATCH", GUILD_MEMBER(this.id, memberId), { + nick: options.nick, + roles: options.roles, + mute: options.mute, + deaf: options.deaf, + channel_id: options.channelId, + communication_disabled_until: options.communicationDisabledUntil ? new Date(options.communicationDisabledUntil).toISOString() : undefined + }); + return new Member(this.session, member, this.id); + } + async pruneMembers(options) { + const result = await this.session.rest.runMethod(this.session.rest, "POST", GUILD_PRUNE(this.id), { + days: options.days, + compute_prune_count: options.computePruneCount, + include_roles: options.includeRoles + }); + return result.pruned; + } + async getPruneCount() { + const result = await this.session.rest.runMethod(this.session.rest, "GET", GUILD_PRUNE(this.id)); + return result.pruned; + } + async getActiveThreads() { + const { threads , members } = await this.session.rest.runMethod(this.session.rest, "GET", THREAD_ACTIVE(this.id)); + return { + threads: Object.fromEntries(threads.map((thread)=>[ + thread.id, + new ThreadChannel(this.session, thread, this.id) + ])), + members: Object.fromEntries(members.map((threadMember)=>[ + threadMember.id, + new ThreadMember(this.session, threadMember) + ])) + }; + } + async delete() { + await this.session.rest.runMethod(this.session.rest, "DELETE", GUILDS(this.id)); + } + async leave() { + await this.session.rest.runMethod(this.session.rest, "DELETE", USER_GUILDS(this.id)); + } + static async create(session, options) { + const guild = await session.rest.runMethod(session.rest, "POST", GUILDS(), { + name: options.name, + afk_channel_id: options.afkChannelId, + afk_timeout: options.afkTimeout, + default_message_notifications: options.defaultMessageNotifications, + explicit_content_filter: options.explicitContentFilter, + system_channel_flags: options.systemChannelFlags, + verification_level: options.verificationLevel, + icon: "iconURL" in options ? options.iconURL && urlToBase64(options.iconURL) : options.iconHash && Util.iconBigintToHash(options.iconHash), + channels: options.channels?.map((channel)=>({ + name: channel.name, + nsfw: channel.nsfw, + id: channel.id, + bitrate: channel.bitrate, + parent_id: channel.parentId, + permission_overwrites: channel.permissionOverwrites, + rtc_region: channel.rtcRegion, + user_limit: channel.userLimit, + video_quality_mode: channel.videoQualityMode, + rate_limit_per_user: channel.rateLimitPerUser + })), + roles: options.roles?.map((role)=>({ + name: role.name, + id: role.id, + color: role.color, + mentionable: role.mentionable, + hoist: role.hoist, + position: role.position, + unicode_emoji: role.unicodeEmoji, + icon: options.iconURL && urlToBase64(options.iconURL) + })) + }); + return new Guild(session, guild); + } + setSplash(splashURL) { + return this.edit({ + splashURL + }); + } + setBanner(bannerURL) { + return this.edit({ + bannerURL + }); + } + setDiscoverySplash(discoverySplashURL) { + return this.edit({ + discoverySplashURL + }); + } + async edit(options) { + const guild = await this.session.rest.runMethod(this.session.rest, "PATCH", GUILDS(), { + name: options.name, + afk_channel_id: options.afkChannelId, + afk_timeout: options.afkTimeout, + default_message_notifications: options.defaultMessageNotifications, + explicit_content_filter: options.explicitContentFilter, + system_channel_flags: options.systemChannelFlags, + verification_level: options.verificationLevel, + icon: "iconURL" in options ? options.iconURL && urlToBase64(options.iconURL) : options.iconHash && Util.iconBigintToHash(options.iconHash), + splash: "splashURL" in options ? options.splashURL && urlToBase64(options.splashURL) : options.iconHash && Util.iconBigintToHash(options.iconHash), + banner: "bannerURL" in options ? options.bannerURL && urlToBase64(options.bannerURL) : options.bannerHash && Util.iconBigintToHash(options.bannerHash), + discovery_splash: "discoverySplashURL" in options ? options.discoverySplashURL && urlToBase64(options.discoverySplashURL) : options.discoverySplashHash && Util.iconBigintToHash(options.discoverySplashHash), + owner_id: options.ownerId, + rules_channel_id: options.rulesChannelId, + public_updates_channel_id: options.publicUpdatesChannelId, + preferred_locale: options.preferredLocale, + features: options.features, + description: options.description, + premiumProgressBarEnabled: options.premiumProgressBarEnabled + }); + return new Guild(this.session, guild); + } +} +class Invite { + constructor(session, data){ + this.session = session; + this.guild = data.guild ? new InviteGuild(session, data.guild) : undefined; + this.approximateMemberCount = data.approximate_member_count ? data.approximate_member_count : undefined; + this.approximatePresenceCount = data.approximate_presence_count ? data.approximate_presence_count : undefined; + this.code = data.code; + this.expiresAt = data.expires_at ? Number.parseInt(data.expires_at) : undefined; + this.inviter = data.inviter ? new User(session, data.inviter) : undefined; + this.targetUser = data.target_user ? new User(session, data.target_user) : undefined; + this.targetApplication = data.target_application ? new Application(session, data.target_application) : undefined; + this.targetType = data.target_type; + if (data.channel) { + const guildId = data.guild && data.guild?.id ? data.guild.id : ""; + this.channel = new GuildChannel(session, data.channel, guildId); + } + if (data.guild_scheduled_event) { + this.guildScheduledEvent = { + id: data.guild_scheduled_event.id, + guildId: data.guild_scheduled_event.guild_id, + channelId: data.guild_scheduled_event.channel_id ? data.guild_scheduled_event.channel_id : undefined, + creatorId: data.guild_scheduled_event.creator_id ? data.guild_scheduled_event.creator_id : undefined, + name: data.guild_scheduled_event.name, + description: data.guild_scheduled_event.description ? data.guild_scheduled_event.description : undefined, + scheduledStartTime: data.guild_scheduled_event.scheduled_start_time, + scheduledEndTime: data.guild_scheduled_event.scheduled_end_time ? data.guild_scheduled_event.scheduled_end_time : undefined, + privacyLevel: data.guild_scheduled_event.privacy_level, + status: data.guild_scheduled_event.status, + entityType: data.guild_scheduled_event.entity_type, + entityId: data.guild ? data.guild.id : undefined, + entityMetadata: data.guild_scheduled_event.entity_metadata ? data.guild_scheduled_event.entity_metadata : undefined, + creator: data.guild_scheduled_event.creator ? new User(session, data.guild_scheduled_event.creator) : undefined, + userCount: data.guild_scheduled_event.user_count ? data.guild_scheduled_event.user_count : undefined, + image: data.guild_scheduled_event.image ? data.guild_scheduled_event.image : undefined + }; + } + if (data.stage_instance) { + const guildId1 = data.guild && data.guild?.id ? data.guild.id : ""; + this.stageInstance = { + members: data.stage_instance.members.map((m)=>new Member(session, m, guildId1)), + participantCount: data.stage_instance.participant_count, + speakerCount: data.stage_instance.speaker_count, + topic: data.stage_instance.topic + }; + } + } + session; + guild; + approximateMemberCount; + approximatePresenceCount; + code; + expiresAt; + inviter; + targetUser; + targetType; + channel; + stageInstance; + guildScheduledEvent; + targetApplication; + async delete() { + await Guild.prototype.deleteInvite.call(this.guild, this.code); + return this; + } +} +var PrivacyLevels; +(function(PrivacyLevels) { + PrivacyLevels[PrivacyLevels["Public"] = 1] = "Public"; + PrivacyLevels[PrivacyLevels["GuildOnly"] = 2] = "GuildOnly"; +})(PrivacyLevels || (PrivacyLevels = {})); +class StageInstance { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.channelId = data.channel_id; + this.guildId = data.guild_id; + this.topic = data.topic; + this.privacyLevel = data.privacy_level; + this.discoverableDisabled = data.discoverable_disabled; + this.guildScheduledEventId = data.guild_scheduled_event_id; + } + session; + id; + channelId; + guildId; + topic; + privacyLevel; + discoverableDisabled; + guildScheduledEventId; + async edit(options) { + const stageInstance = await this.session.rest.runMethod(this.session.rest, "PATCH", STAGE_INSTANCE(this.id), { + topic: options.topic, + privacy_level: options.privacyLevel + }); + return new StageInstance(this.session, stageInstance); + } + async delete() { + await this.session.rest.runMethod(this.session.rest, "DELETE", STAGE_INSTANCE(this.id)); + } +} +class ScheduledEvent { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.guildId = data.guild_id; + this.channelId = data.channel_id; + this.creatorId = data.creator_id ? data.creator_id : undefined; + this.name = data.name; + this.description = data.description; + this.scheduledStartTime = data.scheduled_start_time; + this.scheduledEndTime = data.scheduled_end_time; + this.privacyLevel = PrivacyLevels.GuildOnly; + this.status = data.status; + this.entityType = data.entity_type; + this.entityMetadata = data.entity_metadata ? data.entity_metadata : undefined; + this.creator = data.creator ? new User(session, data.creator) : undefined; + this.userCount = data.user_count; + this.image = data.image ? data.image : undefined; + } + session; + id; + guildId; + channelId; + creatorId; + name; + description; + scheduledStartTime; + scheduledEndTime; + privacyLevel; + status; + entityType; + entityMetadata; + creator; + userCount; + image; +} +var StatusTypes; +(function(StatusTypes) { + StatusTypes[StatusTypes["online"] = 0] = "online"; + StatusTypes[StatusTypes["dnd"] = 1] = "dnd"; + StatusTypes[StatusTypes["idle"] = 2] = "idle"; + StatusTypes[StatusTypes["invisible"] = 3] = "invisible"; + StatusTypes[StatusTypes["offline"] = 4] = "offline"; +})(StatusTypes || (StatusTypes = {})); +class Presence { + constructor(session, data){ + this.session = session; + this.user = new User(this.session, data.user); + this.guildId = data.guild_id; + this.status = StatusTypes[data.status]; + this.activities = data.activities.map((activity)=>Object.create({ + name: activity.name, + type: activity.type, + url: activity.url ? activity.url : undefined, + createdAt: activity.created_at, + timestamps: activity.timestamps, + applicationId: activity.application_id, + details: activity.details ? activity.details : undefined, + state: activity.state, + emoji: activity.emoji ? activity.emoji : undefined, + party: activity.party ? activity.party : undefined, + assets: activity.assets ? { + largeImage: activity.assets.large_image, + largeText: activity.assets.large_text, + smallImage: activity.assets.small_image, + smallText: activity.assets.small_text + } : null, + secrets: activity.secrets ? activity.secrets : undefined, + instance: !!activity.instance, + flags: activity.flags, + buttons: activity.buttons + })); + this.clientStatus = data.client_status; + } + session; + user; + guildId; + status; + activities; + clientStatus; +} +class Integration { + constructor(session, data){ + this.id = data.id; + this.session = session; + data.guild_id ? this.guildId = data.guild_id : null; + this.name = data.name; + this.type = data.type; + this.enabled = !!data.enabled; + this.syncing = !!data.syncing; + this.roleId = data.role_id; + this.enableEmoticons = !!data.enable_emoticons; + this.expireBehavior = data.expire_behavior; + this.expireGracePeriod = data.expire_grace_period; + this.syncedAt = data.synced_at; + this.subscriberCount = data.subscriber_count; + this.revoked = !!data.revoked; + this.user = data.user ? new User(session, data.user) : undefined; + this.account = { + id: data.account.id, + name: data.account.name + }; + if (data.application) { + this.application = { + id: data.application.id, + name: data.application.name, + icon: data.application.icon ? data.application.icon : undefined, + description: data.application.description, + bot: data.application.bot ? new User(session, data.application.bot) : undefined + }; + } + } + session; + id; + guildId; + name; + type; + enabled; + syncing; + roleId; + enableEmoticons; + expireBehavior; + expireGracePeriod; + syncedAt; + subscriberCount; + revoked; + user; + account; + application; +} +const READY = (session, shardId, payload)=>{ + session.applicationId = payload.application.id; + session.botId = payload.user.id; + session.emit("ready", { + ...payload, + user: new User(session, payload.user) + }, shardId); +}; +const MESSAGE_CREATE = (session, _shardId, message)=>{ + session.emit("messageCreate", new Message(session, message)); +}; +const MESSAGE_UPDATE = (session, _shardId, new_message)=>{ + if (!new_message.edited_timestamp) { + const message = { + session, + id: new_message.id, + guildId: new_message.guild_id, + channelId: new_message.channel_id + }; + Object.setPrototypeOf(message, Message.prototype); + session.emit("messageUpdate", message); + return; + } + session.emit("messageUpdate", new Message(session, new_message)); +}; +const MESSAGE_DELETE = (session, _shardId, { id , channel_id , guild_id })=>{ + session.emit("messageDelete", { + id, + channelId: channel_id, + guildId: guild_id + }); +}; +const GUILD_CREATE = (session, _shardId, guild)=>{ + session.emit("guildCreate", new Guild(session, guild)); +}; +const GUILD_DELETE = (session, _shardId, guild)=>{ + session.emit("guildDelete", { + id: guild.id, + unavailable: true + }); +}; +const GUILD_MEMBER_ADD = (session, _shardId, member)=>{ + session.emit("guildMemberAdd", new Member(session, member, member.guild_id)); +}; +const GUILD_MEMBER_UPDATE = (session, _shardId, member)=>{ + session.emit("guildMemberUpdate", new Member(session, member, member.guild_id)); +}; +const GUILD_MEMBER_REMOVE = (session, _shardId, member)=>{ + session.emit("guildMemberRemove", new User(session, member.user), member.guild_id); +}; +const GUILD_BAN_ADD = (session, _shardId, data)=>{ + session.emit("guildBanAdd", { + guildId: data.guild_id, + user: data.user + }); +}; +const GUILD_BAN_REMOVE = (session, _shardId, data)=>{ + session.emit("guildBanRemove", { + guildId: data.guild_id, + user: data.user + }); +}; +const GUILD_EMOJIS_UPDATE = (session, _shardId, data)=>{ + session.emit("guildEmojisUpdate", { + guildId: data.guild_id, + emojis: data.emojis + }); +}; +const GUILD_ROLE_CREATE = (session, _shardId, data)=>{ + session.emit("guildRoleCreate", { + guildId: data.guild_id, + role: data.role + }); +}; +const GUILD_ROLE_UPDATE = (session, _shardId, data)=>{ + session.emit("guildRoleUpdate", { + guildId: data.guild_id, + role: data.role + }); +}; +const GUILD_ROLE_DELETE = (session, _shardId, data)=>{ + session.emit("guildRoleDelete", { + guildId: data.guild_id, + roleId: data.role_id + }); +}; +const TYPING_START = (session, _shardId, payload)=>{ + session.emit("typingStart", { + channelId: payload.channel_id, + guildId: payload.guild_id ? payload.guild_id : undefined, + userId: payload.user_id, + timestamp: payload.timestamp, + member: payload.guild_id ? new Member(session, payload.member, payload.guild_id) : undefined + }); +}; +const INTERACTION_CREATE = (session, _shardId, interaction)=>{ + session.emit("interactionCreate", InteractionFactory.from(session, interaction)); +}; +const CHANNEL_CREATE = (session, _shardId, channel)=>{ + session.emit("channelCreate", ChannelFactory.from(session, channel)); +}; +const CHANNEL_UPDATE = (session, _shardId, channel)=>{ + session.emit("channelUpdate", ChannelFactory.from(session, channel)); +}; +const CHANNEL_DELETE = (session, _shardId, channel)=>{ + if (!channel.guild_id) return; + session.emit("channelDelete", new GuildChannel(session, channel, channel.guild_id)); +}; +const THREAD_CREATE = (session, _shardId, channel)=>{ + if (!channel.guild_id) return; + session.emit("threadCreate", new ThreadChannel(session, channel, channel.guild_id)); +}; +const THREAD_UPDATE = (session, _shardId, channel)=>{ + if (!channel.guild_id) return; + session.emit("threadUpdate", new ThreadChannel(session, channel, channel.guild_id)); +}; +const THREAD_DELETE = (session, _shardId, channel)=>{ + if (!channel.guild_id) return; + session.emit("threadDelete", new ThreadChannel(session, channel, channel.guild_id)); +}; +const THREAD_MEMBER_UPDATE = (session, _shardId, payload)=>{ + session.emit("threadMemberUpdate", { + guildId: payload.guild_id, + id: payload.id, + userId: payload.user_id, + joinedAt: payload.joined_at, + flags: payload.flags + }); +}; +const THREAD_MEMBERS_UPDATE = (session, _shardId, payload)=>{ + session.emit("threadMembersUpdate", { + memberCount: payload.member_count, + addedMembers: payload.added_members ? payload.added_members.map((tm)=>new ThreadMember(session, tm)) : undefined, + removedMemberIds: payload.removed_member_ids ? payload.removed_member_ids : undefined, + guildId: payload.guild_id, + id: payload.id + }); +}; +const THREAD_LIST_SYNC = (session, _shardId, payload)=>{ + session.emit("threadListSync", { + guildId: payload.guild_id, + channelIds: payload.channel_ids ?? [], + threads: payload.threads.map((channel)=>new ThreadChannel(session, channel, payload.guild_id)), + members: payload.members.map((member)=>new ThreadMember(session, member)) + }); +}; +const CHANNEL_PINS_UPDATE = (session, _shardId, payload)=>{ + session.emit("channelPinsUpdate", { + guildId: payload.guild_id, + channelId: payload.channel_id, + lastPinTimestamp: payload.last_pin_timestamp ? Date.parse(payload.last_pin_timestamp) : undefined + }); +}; +const USER_UPDATE = (session, _shardId, payload)=>{ + session.emit("userUpdate", new User(session, payload)); +}; +const PRESENCE_UPDATE = (session, _shardId, payload)=>{ + session.emit("presenceUpdate", new Presence(session, payload)); +}; +const WEBHOOKS_UPDATE = (session, _shardId, webhook)=>{ + session.emit("webhooksUpdate", { + guildId: webhook.guild_id, + channelId: webhook.channel_id + }); +}; +const INTEGRATION_CREATE = (session, _shardId, payload)=>{ + session.emit("integrationCreate", new Integration(session, payload)); +}; +const INTEGRATION_UPDATE = (session, _shardId, payload)=>{ + session.emit("integrationCreate", new Integration(session, payload)); +}; +const INTEGRATION_DELETE = (session, _shardId, payload)=>{ + session.emit("integrationDelete", { + id: payload.id, + guildId: payload.guild_id, + applicationId: payload.application_id + }); +}; +const AUTO_MODERATION_RULE_CREATE = (session, _shardId, payload)=>{ + session.emit("autoModerationRuleCreate", new AutoModerationRule(session, payload)); +}; +const AUTO_MODERATION_RULE_UPDATE = (session, _shardId, payload)=>{ + session.emit("autoModerationRuleUpdate", new AutoModerationRule(session, payload)); +}; +const AUTO_MODERATION_RULE_DELETE = (session, _shardId, payload)=>{ + session.emit("autoModerationRuleDelete", new AutoModerationRule(session, payload)); +}; +const AUTO_MODERATION_ACTION_EXECUTE = (session, _shardId, payload)=>{ + session.emit("autoModerationActionExecution", new AutoModerationExecution(session, payload)); +}; +const MESSAGE_REACTION_ADD = (session, _shardId, reaction)=>{ + session.emit("messageReactionAdd", NewMessageReactionAdd(session, reaction)); +}; +const MESSAGE_REACTION_REMOVE = (session, _shardId, reaction)=>{ + session.emit("messageReactionRemove", NewMessageReactionAdd(session, reaction)); +}; +const MESSAGE_REACTION_REMOVE_ALL = (session, _shardId, reaction)=>{ + session.emit("messageReactionRemoveAll", NewMessageReactionAdd(session, reaction)); +}; +const MESSAGE_REACTION_REMOVE_EMOJI = (session, _shardId, reaction)=>{ + session.emit("messageReactionRemoveEmoji", NewMessageReactionAdd(session, reaction)); +}; +const INVITE_CREATE = (session, _shardId, invite)=>{ + session.emit("inviteCreate", NewInviteCreate(session, invite)); +}; +const INVITE_DELETE = (session, _shardId, data)=>{ + session.emit("inviteDelete", { + channelId: data.channel_id, + guildId: data.guild_id, + code: data.code + }); +}; +const STAGE_INSTANCE_CREATE = (session, _shardId, payload)=>{ + session.emit("stageInstanceCreate", new StageInstance(session, payload)); +}; +const STAGE_INSTANCE_UPDATE = (session, _shardId, payload)=>{ + session.emit("stageInstanceUpdate", new StageInstance(session, payload)); +}; +const STAGE_INSTANCE_DELETE = (session, _shardId, payload)=>{ + session.emit("stageInstanceDelete", new StageInstance(session, payload)); +}; +const GUILD_SCHEDULED_EVENT_CREATE = (session, _shardId, payload)=>{ + session.emit("guildScheduledEventCreate", new ScheduledEvent(session, payload)); +}; +const GUILD_SCHEDULED_EVENT_UPDATE = (session, _shardId, payload)=>{ + session.emit("guildScheduledEventUpdate", new ScheduledEvent(session, payload)); +}; +const GUILD_SCHEDULED_EVENT_DELETE = (session, _shardId, payload)=>{ + session.emit("guildScheduledEventDelete", new ScheduledEvent(session, payload)); +}; +const GUILD_SCHEDULED_EVENT_USER_ADD = (session, _shardId, payload)=>{ + session.emit("guildScheduledEventUserAdd", { + scheduledEventId: payload.guild_scheduled_event_id, + userId: payload.user_id, + guildId: payload.guild_id + }); +}; +const GUILD_SCHEDULED_EVENT_USER_REMOVE = (session, _shardId, payload)=>{ + session.emit("guildScheduledEventUserRemove", { + scheduledEventId: payload.guild_scheduled_event_id, + userId: payload.user_id, + guildId: payload.guild_id + }); +}; +const raw = (session, shardId, data)=>{ + session.emit("raw", data, shardId); +}; +const mod = { + READY: READY, + MESSAGE_CREATE: MESSAGE_CREATE, + MESSAGE_UPDATE: MESSAGE_UPDATE, + MESSAGE_DELETE: MESSAGE_DELETE, + GUILD_CREATE: GUILD_CREATE, + GUILD_DELETE: GUILD_DELETE, + GUILD_MEMBER_ADD: GUILD_MEMBER_ADD, + GUILD_MEMBER_UPDATE: GUILD_MEMBER_UPDATE, + GUILD_MEMBER_REMOVE: GUILD_MEMBER_REMOVE, + GUILD_BAN_ADD: GUILD_BAN_ADD, + GUILD_BAN_REMOVE: GUILD_BAN_REMOVE, + GUILD_EMOJIS_UPDATE: GUILD_EMOJIS_UPDATE, + GUILD_ROLE_CREATE: GUILD_ROLE_CREATE, + GUILD_ROLE_UPDATE: GUILD_ROLE_UPDATE, + GUILD_ROLE_DELETE: GUILD_ROLE_DELETE, + TYPING_START: TYPING_START, + INTERACTION_CREATE: INTERACTION_CREATE, + CHANNEL_CREATE: CHANNEL_CREATE, + CHANNEL_UPDATE: CHANNEL_UPDATE, + CHANNEL_DELETE: CHANNEL_DELETE, + THREAD_CREATE: THREAD_CREATE, + THREAD_UPDATE: THREAD_UPDATE, + THREAD_DELETE: THREAD_DELETE, + THREAD_MEMBER_UPDATE: THREAD_MEMBER_UPDATE, + THREAD_MEMBERS_UPDATE: THREAD_MEMBERS_UPDATE, + THREAD_LIST_SYNC: THREAD_LIST_SYNC, + CHANNEL_PINS_UPDATE: CHANNEL_PINS_UPDATE, + USER_UPDATE: USER_UPDATE, + PRESENCE_UPDATE: PRESENCE_UPDATE, + WEBHOOKS_UPDATE: WEBHOOKS_UPDATE, + INTEGRATION_CREATE: INTEGRATION_CREATE, + INTEGRATION_UPDATE: INTEGRATION_UPDATE, + INTEGRATION_DELETE: INTEGRATION_DELETE, + AUTO_MODERATION_RULE_CREATE: AUTO_MODERATION_RULE_CREATE, + AUTO_MODERATION_RULE_UPDATE: AUTO_MODERATION_RULE_UPDATE, + AUTO_MODERATION_RULE_DELETE: AUTO_MODERATION_RULE_DELETE, + AUTO_MODERATION_ACTION_EXECUTE: AUTO_MODERATION_ACTION_EXECUTE, + MESSAGE_REACTION_ADD: MESSAGE_REACTION_ADD, + MESSAGE_REACTION_REMOVE: MESSAGE_REACTION_REMOVE, + MESSAGE_REACTION_REMOVE_ALL: MESSAGE_REACTION_REMOVE_ALL, + MESSAGE_REACTION_REMOVE_EMOJI: MESSAGE_REACTION_REMOVE_EMOJI, + INVITE_CREATE: INVITE_CREATE, + INVITE_DELETE: INVITE_DELETE, + STAGE_INSTANCE_CREATE: STAGE_INSTANCE_CREATE, + STAGE_INSTANCE_UPDATE: STAGE_INSTANCE_UPDATE, + STAGE_INSTANCE_DELETE: STAGE_INSTANCE_DELETE, + GUILD_SCHEDULED_EVENT_CREATE: GUILD_SCHEDULED_EVENT_CREATE, + GUILD_SCHEDULED_EVENT_UPDATE: GUILD_SCHEDULED_EVENT_UPDATE, + GUILD_SCHEDULED_EVENT_DELETE: GUILD_SCHEDULED_EVENT_DELETE, + GUILD_SCHEDULED_EVENT_USER_ADD: GUILD_SCHEDULED_EVENT_USER_ADD, + GUILD_SCHEDULED_EVENT_USER_REMOVE: GUILD_SCHEDULED_EVENT_USER_REMOVE, + raw: raw +}; +class Session extends EventEmitter { + options; + rest; + gateway; + #botId; + #applicationId; + set applicationId(id) { + this.#applicationId = id; + } + get applicationId() { + return this.#applicationId; + } + set botId(id) { + this.#botId = id; + } + get botId() { + return this.#botId; + } + constructor(options){ + super(); + this.options = options; + const defHandler = (shard, data)=>{ + mod.raw(this, shard.id, data); + if (!data.t || !data.d) { + return; + } + mod[data.t]?.(this, shard.id, data.d); + }; + this.rest = createRestManager({ + token: this.options.token, + debug: (text)=>{ + super.rawListeners("debug")?.forEach((fn)=>fn(text)); + }, + secretKey: this.options.rest?.secretKey ?? undefined + }); + this.gateway = createGatewayManager({ + gatewayBot: this.options.gateway?.data ?? {}, + gatewayConfig: { + token: this.options.token, + intents: this.options.intents + }, + handleDiscordPayload: this.options.rawHandler ?? defHandler + }); + this.#botId = getBotIdFromToken(options.token).toString(); + } + on(event, func) { + return super.on(event, func); + } + off(event, func) { + return super.off(event, func); + } + once(event, func) { + return super.once(event, func); + } + emit(event, ...params) { + return super.emit(event, ...params); + } + async editProfile(nick, avatarURL) { + const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL; + const user = await this.rest.runMethod(this.rest, "PATCH", USER(), { + username: nick, + avatar: avatar + }); + return new User(this, user); + } + editStatus(shardId, status) { + const shard = this.gateway.manager.shards.get(shardId); + if (!shard) { + throw new Error(`Unknown shard ${shardId}`); + } + shard.send({ + op: GatewayOpcodes.PresenceUpdate, + d: { + status: status.status, + since: null, + afk: false, + activities: status.activities.map((activity)=>{ + return { + name: activity.name, + type: activity.type, + url: activity.url, + created_at: activity.createdAt, + timestamps: activity.timestamps, + application_id: this.applicationId, + details: activity.details, + state: activity.state, + emoji: activity.emoji && { + name: activity.emoji.name, + id: activity.emoji.id, + animated: activity.emoji.animated + }, + party: activity.party, + assets: activity.assets && { + large_image: activity.assets.largeImage, + large_text: activity.assets.largeText, + small_image: activity.assets.smallImage, + small_text: activity.assets.smallText + }, + secrets: activity.secrets, + instance: activity.instance, + flags: activity.flags, + buttons: activity.buttons + }; + }) + } + }); + } + async fetchUser(id) { + const user = await this.rest.runMethod(this.rest, "GET", USER(id)); + if (!user.id) return; + return new User(this, user); + } + createApplicationCommand(options, guildId) { + return this.rest.runMethod(this.rest, "POST", guildId ? GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : APPLICATION_COMMANDS(this.applicationId), this.isContextApplicationCommand(options) ? { + name: options.name, + name_localizations: options.nameLocalizations, + type: options.type + } : { + name: options.name, + name_localizations: options.nameLocalizations, + description: options.description, + description_localizations: options.descriptionLocalizations, + type: options.type, + options: options.options, + default_member_permissions: options.defaultMemberPermissions ? new Permissions(options.defaultMemberPermissions).bitfield.toString() : undefined, + dm_permission: options.dmPermission + }); + } + deleteApplicationCommand(id, guildId) { + return this.rest.runMethod(this.rest, "DELETE", guildId ? GUILD_APPLICATION_COMMANDS(this.applicationId, guildId, id) : APPLICATION_COMMANDS(this.applicationId, id)); + } + updateApplicationCommandPermissions(guildId, id, bearerToken, options) { + return this.rest.runMethod(this.rest, "PUT", GUILD_APPLICATION_COMMANDS_PERMISSIONS(this.applicationId, guildId, id), { + permissions: options + }, { + headers: { + authorization: `Bearer ${bearerToken}` + } + }); + } + fetchApplicationCommand(id, options) { + return this.rest.runMethod(this.rest, "GET", options?.guildId ? GUILD_APPLICATION_COMMANDS_LOCALIZATIONS(this.applicationId, options.guildId, id, options?.withLocalizations) : APPLICATION_COMMANDS(this.applicationId, id)); + } + fetchApplicationCommandPermissions(guildId) { + return this.rest.runMethod(this.rest, "GET", GUILD_APPLICATION_COMMANDS_PERMISSIONS(this.applicationId, guildId)); + } + fetchApplicationCommandPermission(guildId, id) { + return this.rest.runMethod(this.rest, "GET", GUILD_APPLICATION_COMMANDS_PERMISSIONS(this.applicationId, guildId, id)); + } + upsertApplicationCommand(id, options, guildId) { + return this.rest.runMethod(this.rest, "PATCH", guildId ? GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : APPLICATION_COMMANDS(this.applicationId, id), this.isContextApplicationCommand(options) ? { + name: options.name, + type: options.type + } : { + name: options.name, + description: options.description, + type: options.type, + options: options.options + }); + } + upsertApplicationCommands(options, guildId) { + return this.rest.runMethod(this.rest, "PUT", guildId ? GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : APPLICATION_COMMANDS(this.applicationId), options.map((o)=>this.isContextApplicationCommand(o) ? { + name: o.name, + type: o.type + } : { + name: o.name, + description: o.description, + type: o.type, + options: o.options + })); + } + fetchCommands(guildId) { + return this.rest.runMethod(this.rest, "GET", guildId ? GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : APPLICATION_COMMANDS(this.applicationId)); + } + isContextApplicationCommand(cmd) { + return cmd.type === ApplicationCommandTypes.Message || cmd.type === ApplicationCommandTypes.User; + } + async start() { + const getGatewayBot = ()=>this.rest.runMethod(this.rest, "GET", GATEWAY_BOT()); + if (!Object.keys(this.options.gateway?.data ?? {}).length) { + const nonParsed = await getGatewayBot(); + this.gateway.gatewayBot = { + url: nonParsed.url, + shards: nonParsed.shards, + sessionStartLimit: { + total: nonParsed.session_start_limit.total, + remaining: nonParsed.session_start_limit.remaining, + resetAfter: nonParsed.session_start_limit.reset_after, + maxConcurrency: nonParsed.session_start_limit.max_concurrency + } + }; + this.gateway.lastShardId = this.gateway.gatewayBot.shards - 1; + this.gateway.manager.totalShards = this.gateway.gatewayBot.shards; + } + this.gateway.spawnShards(); + } +} +class Sticker { + constructor(session, data){ + this.session = session; + this.id = data.id; + this.packId = data.pack_id; + this.name = data.name; + this.description = data.description; + this.tags = data.tags.split(","); + this.type = data.type; + this.formatType = data.format_type; + this.available = !!data.available; + this.guildId = data.guild_id; + this.user = data.user ? new User(this.session, data.user) : undefined; + this.sortValue = data.sort_value; + } + session; + id; + packId; + name; + description; + tags; + type; + formatType; + available; + guildId; + user; + sortValue; + async fetchPremiumPack() { + const data = await this.session.rest.runMethod(this.session.rest, "GET", STICKER_PACKS()); + return { + id: data.id, + stickers: data.stickers.map((st)=>new Sticker(this.session, st)), + name: data.name, + skuId: data.sku_id, + coverStickerId: data.cover_sticker_id, + description: data.description, + bannerAssetId: data.banner_asset_id + }; + } +} +class ChoiceBuilder { + name; + value; + setName(name) { + this.name = name; + return this; + } + setValue(value) { + this.value = value; + return this; + } + toJSON() { + if (!this.name) throw new TypeError("Property 'name' is required"); + if (!this.value) throw new TypeError("Property 'value' is required"); + return { + name: this.name, + value: this.value + }; + } +} +class OptionBuilder { + required; + autocomplete; + type; + name; + description; + constructor(type, name, description){ + this.type = type; + this.name = name; + this.description = description; + } + setType(type) { + return this.type = type, this; + } + setName(name) { + return this.name = name, this; + } + setDescription(description) { + return this.description = description, this; + } + setRequired(required) { + return this.required = required, this; + } + toJSON() { + if (!this.type) throw new TypeError("Property 'type' is required"); + if (!this.name) throw new TypeError("Property 'name' is required"); + if (!this.description) { + throw new TypeError("Property 'description' is required"); + } + const applicationCommandOption = { + type: this.type, + name: this.name, + description: this.description, + required: this.required ? true : false + }; + return applicationCommandOption; + } +} +class OptionBuilderLimitedValues extends OptionBuilder { + choices; + minValue; + maxValue; + constructor(type, name, description){ + super(); + this.type = type; + this.name = name; + this.description = description; + } + setMinValue(n) { + return this.minValue = n, this; + } + setMaxValue(n) { + return this.maxValue = n, this; + } + addChoice(fn) { + const choice = fn(new ChoiceBuilder()); + this.choices ??= []; + this.choices.push(choice); + return this; + } + toJSON() { + return { + ...super.toJSON(), + choices: this.choices?.map((c)=>c.toJSON()) ?? [], + minValue: this.minValue, + maxValue: this.maxValue + }; + } +} +class OptionBuilderString extends OptionBuilder { + choices; + constructor(type, name, description){ + super(); + this.type = type; + this.name = name; + this.description = description; + } + addChoice(fn) { + const choice = fn(new ChoiceBuilder()); + this.choices ??= []; + this.choices.push(choice); + return this; + } + toJSON() { + return { + ...super.toJSON(), + choices: this.choices?.map((c)=>c.toJSON()) ?? [] + }; + } +} +class OptionBuilderChannel extends OptionBuilder { + channelTypes; + constructor(type, name, description){ + super(); + this.type = type; + this.name = name; + this.description = description; + } + addChannelTypes(...channels) { + this.channelTypes ??= []; + this.channelTypes.push(...channels); + return this; + } + toJSON() { + return { + ...super.toJSON(), + channelTypes: this.channelTypes ?? [] + }; + } +} +class OptionBased { + options; + addOption(fn, type) { + const option = fn(new OptionBuilder(type)); + this.options ??= []; + this.options.push(option); + return this; + } + addNestedOption(fn) { + const option = fn(new OptionBuilder(ApplicationCommandOptionTypes.SubCommand)); + this.options ??= []; + this.options.push(option); + return this; + } + addStringOption(fn) { + const option = fn(new OptionBuilderString(ApplicationCommandOptionTypes.String)); + this.options ??= []; + this.options.push(option); + return this; + } + addIntegerOption(fn) { + const option = fn(new OptionBuilderLimitedValues(ApplicationCommandOptionTypes.Integer)); + this.options ??= []; + this.options.push(option); + return this; + } + addNumberOption(fn) { + const option = fn(new OptionBuilderLimitedValues(ApplicationCommandOptionTypes.Number)); + this.options ??= []; + this.options.push(option); + return this; + } + addBooleanOption(fn) { + return this.addOption(fn, ApplicationCommandOptionTypes.Boolean); + } + addSubCommand(fn) { + const option = fn(new OptionBuilderNested(ApplicationCommandOptionTypes.SubCommand)); + this.options ??= []; + this.options.push(option); + return this; + } + addSubCommandGroup(fn) { + const option = fn(new OptionBuilderNested(ApplicationCommandOptionTypes.SubCommandGroup)); + this.options ??= []; + this.options.push(option); + return this; + } + addUserOption(fn) { + return this.addOption(fn, ApplicationCommandOptionTypes.User); + } + addChannelOption(fn) { + const option = fn(new OptionBuilderChannel(ApplicationCommandOptionTypes.Channel)); + this.options ??= []; + this.options.push(option); + return this; + } + addRoleOption(fn) { + return this.addOption(fn, ApplicationCommandOptionTypes.Role); + } + addMentionableOption(fn) { + return this.addOption(fn, ApplicationCommandOptionTypes.Mentionable); + } + static applyTo(klass, ignore = []) { + const methods = [ + "addOption", + "addNestedOption", + "addStringOption", + "addIntegerOption", + "addNumberOption", + "addBooleanOption", + "addSubCommand", + "addSubCommandGroup", + "addUserOption", + "addChannelOption", + "addRoleOption", + "addMentionableOption", + ]; + for (const method of methods){ + if (ignore.includes(method)) continue; + klass.prototype[method] = OptionBased.prototype[method]; + } + } +} +class OptionBuilderNested extends OptionBuilder { + constructor(type, name, description){ + super(); + this.type = type; + this.name = name; + this.description = description; + } + toJSON() { + if (!this.type) throw new TypeError("Property 'type' is required"); + if (!this.name) throw new TypeError("Property 'name' is required"); + if (!this.description) { + throw new TypeError("Property 'description' is required"); + } + return { + type: this.type, + name: this.name, + description: this.description, + options: this.options?.map((o)=>o.toJSON()) ?? [], + required: this.required ? true : false + }; + } +} +OptionBased.applyTo(OptionBuilderNested); +class ApplicationCommandBuilder { + constructor(type = ApplicationCommandTypes.ChatInput, name = "", description = "", defaultMemberPermissions, nameLocalizations, descriptionLocalizations, dmPermission = true){ + this.type = type; + this.name = name; + this.description = description; + this.defaultMemberPermissions = defaultMemberPermissions; + this.nameLocalizations = nameLocalizations; + this.descriptionLocalizations = descriptionLocalizations; + this.dmPermission = dmPermission; + } + type; + name; + description; + defaultMemberPermissions; + nameLocalizations; + descriptionLocalizations; + dmPermission; + setType(type) { + return this.type = type, this; + } + setName(name) { + return this.name = name, this; + } + setDescription(description) { + return this.description = description, this; + } + setDefaultMemberPermission(perm) { + return this.defaultMemberPermissions = perm, this; + } + setNameLocalizations(l) { + return this.nameLocalizations = l, this; + } + setDescriptionLocalizations(l) { + return this.descriptionLocalizations = l, this; + } + setDmPermission(perm) { + return this.dmPermission = perm, this; + } +} +class ChatInputApplicationCommandBuilder extends ApplicationCommandBuilder { + type = ApplicationCommandTypes.ChatInput; + toJSON() { + if (!this.type) throw new TypeError("Propety 'type' is required"); + if (!this.name) throw new TypeError("Propety 'name' is required"); + if (!this.description) { + throw new TypeError("Propety 'description' is required"); + } + return { + type: ApplicationCommandTypes.ChatInput, + name: this.name, + description: this.description, + options: this.options?.map((o)=>o.toJSON()) ?? [], + defaultMemberPermissions: this.defaultMemberPermissions, + nameLocalizations: this.nameLocalizations, + descriptionLocalizations: this.descriptionLocalizations, + dmPermission: this.dmPermission + }; + } +} +OptionBased.applyTo(ChatInputApplicationCommandBuilder); +class Collection extends Map { + constructor(session, entries){ + super(entries); + this.session = session; + } + session; + get(key) { + return super.get(key); + } + set(key, value) { + return super.set(key, value); + } + has(key) { + return super.has(key); + } + clear() { + return super.clear(); + } + random(amount) { + const arr = [ + ...this.values() + ]; + if (typeof amount === "undefined") return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length) return []; + if (amount && amount > arr.length) amount = arr.length; + return Array.from({ + length: Math.min(amount, arr.length) + }, ()=>arr.splice(Math.floor(Math.random() * arr.length), 1)[0]); + } + find(fn) { + for (const [key, value] of this.entries()){ + if (fn(value, key, this)) return value; + } + return undefined; + } + filter(fn) { + const result = new Collection(this.session); + for (const [key, value] of this.entries()){ + if (fn(value, key, this)) result.set(key, value); + } + return result; + } + forEach(fn) { + super.forEach((v, k)=>{ + fn(v, k, this); + }); + } + clone() { + return new Collection(this.session, this.entries()); + } + concat(structures) { + const conc = this.clone(); + for (const structure of structures){ + if (!structure || !(structure instanceof Collection)) { + continue; + } + for (const [key, value] of structure.entries()){ + conc.set(key, value); + } + } + return conc; + } + some(fn) { + for (const [key, value] of this.entries()){ + if (fn(value, key, this)) { + return true; + } + } + return false; + } + every(fn) { + for (const [key, value] of this.entries()){ + if (!fn(value, key, this)) { + return false; + } + } + return true; + } + first(amount) { + if (!amount || amount <= 1) { + return this.values().next().value; + } + const values = [ + ...this.values() + ]; + amount = Math.min(values.length, amount); + return values.slice(0, amount); + } + last(amount) { + const values = [ + ...this.values() + ]; + if (!amount || amount <= 1) { + return values[values.length - 1]; + } + amount = Math.min(values.length, amount); + return values.slice(-amount); + } + reverse() { + const entries = [ + ...this.entries() + ].reverse(); + this.clear(); + for (const [key, value] of entries)this.set(key, value); + return this; + } + map(fn) { + const result = []; + for (const [key, value] of this.entries()){ + result.push(fn(value, key, this)); + } + return result; + } + reduce(fn, initV) { + const entries = this.entries(); + const first = entries.next().value; + let result = initV; + if (result !== undefined) { + result = fn(result, first[1], first[0], this); + } else { + result = first; + } + for (const [key, value] of entries){ + result = fn(result, value, key, this); + } + return result; + } + get size() { + return super.size; + } + get empty() { + return this.size === 0; + } + updateFields(key, obj) { + const value = this.get(key); + if (!value) { + return; + } + for(const prop in obj){ + if (obj[prop]) { + value[prop] = obj[prop]; + } + } + return this.set(key, value); + } + getOr(key, or) { + return this.get(key) ?? or; + } + retrieve(key, fn) { + const value = this.get(key); + if (!value) { + return; + } + return fn(value); + } +} +function memberBootstrapper(cache, member, guildId) { + cache.guilds.retrieve(guildId, (guild)=>{ + guild.members.set(member.user.id, Object.assign(new Member(cache.session, member, guildId), { + userId: member.user.id, + get user () { + return cache.users.get(this.userId); + } + })); + }); +} +function userBootstrapper(cache, user) { + cache.users.set(user.id, new User(cache.session, user)); +} +function channelBootstrapper(cache, channel) { + if (!channel.guild_id) { + cache.dms.set(channel.id, Object.assign(new DMChannel(cache.session, channel), { + messages: new Collection(cache.session) + })); + return; + } + cache.guilds.retrieve(channel.guild_id, (guild)=>{ + if (textBasedChannels.includes(channel.type)) { + guild.channels.set(channel.id, Object.assign(ChannelFactory.fromGuildChannel(cache.session, channel), { + messages: new Collection(cache.session), + guildId: channel.guild_id, + get guild () { + return cache.guilds.get(this.guildId); + } + })); + } else { + guild.channels.set(channel.id, Object.assign(ChannelFactory.fromGuildChannel(cache.session, channel), { + guildId: channel.guild_id, + get guild () { + return cache.guilds.get(this.guildId); + } + })); + } + }); +} +function guildBootstrapper(cache, guild) { + const members = new Collection(cache.session, guild.members?.map((data)=>{ + const obj = Object.assign(new Member(cache.session, data, guild.id), { + userId: data.user.id, + get user () { + return cache.users.get(this.userId); + } + }); + return [ + data.user.id, + obj + ]; + })); + const channels = new Collection(cache.session, guild.channels?.map((data)=>{ + const obj = Object.assign(ChannelFactory.from(cache.session, data), { + messages: new Map() + }); + return [ + data.id, + obj + ]; + })); + cache.guilds.set(guild.id, Object.assign(new Guild(cache.session, guild), { + members, + channels + })); +} +function messageBootstrapper(cache, message, partial) { + if (message.member) { + const member = Object.assign(message.member, { + user: message.author + }); + memberBootstrapper(cache, member, message.guild_id); + } + if (cache.dms.has(message.channel_id)) { + cache.dms.retrieve(message.channel_id, (dm)=>{ + dm.messages[partial ? "updateFields" : "set"](message.id, Object.assign(new Message(cache.session, message), { + authorId: message.author.id, + get author () { + return cache.users.get(this.authorId); + } + })); + }); + } else { + cache.guilds.retrieve(message.guild_id, (guild)=>guild.channels.retrieve(message.channel_id, (dm)=>{ + dm.messages[partial ? "updateFields" : "set"](message.id, Object.assign(new Message(cache.session, message), { + authorId: message.author.id, + get author () { + return cache.users.get(this.authorId); + } + })); + })); + } +} +function reactionBootstrapper(cache, reaction, remove) { + cache.emojis.set(reaction.emoji.id ?? reaction.emoji.name, new Emoji(cache.session, reaction.emoji)); + function onAdd(message) { + const reactions = message.reactions.map((r)=>r.emoji.name); + const upsertData = { + count: 1, + emoji: reaction.emoji, + me: reaction.user_id === cache.session.botId + }; + if (reactions.length === 0) { + message.reactions = []; + } else if (!reactions.includes(reaction.emoji.name)) { + message.reactions.push(new MessageReaction(cache.session, upsertData)); + } else { + const current = message.reactions?.[reactions.indexOf(reaction.emoji.name)]; + if (current && message.reactions?.[message.reactions.indexOf(current)]) { + ++message.reactions[message.reactions.indexOf(current)].count; + } + } + } + function onRemove(message) { + const reactions = message.reactions.map((r)=>r.emoji.name); + if (reactions.indexOf(reaction.emoji.name) !== undefined) { + const current = message.reactions[reactions.indexOf(reaction.emoji.name)]; + if (current) { + if (current.count > 0) { + current.count--; + } + if (current.count === 0) { + message.reactions.splice(reactions?.indexOf(reaction.emoji.name), 1); + } + } + } + } + if (reaction.guild_id) { + cache.guilds.retrieve(reaction.guild_id, (guild)=>{ + guild.channels.retrieve(reaction.channel_id, (channel)=>{ + channel.messages.retrieve(reaction.message_id, (message)=>{ + if (remove) onRemove(message); + else onAdd(message); + }); + }); + }); + } else { + cache.dms.retrieve(reaction.channel_id, (channel)=>{ + channel.messages.retrieve(reaction.message_id, (message)=>{ + if (remove) onRemove(message); + else onAdd(message); + }); + }); + } +} +function reactionBootstrapperDeletions(cache, payload) { + if (payload.guild_id) { + cache.guilds.retrieve(payload.guild_id, (guild)=>{ + guild.channels.retrieve(payload.channel_id, (channel)=>{ + channel.messages.retrieve(payload.message_id, (message)=>{ + message.reactions = []; + }); + }); + }); + } else { + cache.dms.retrieve(payload.channel_id, (channel)=>{ + channel.messages.retrieve(payload.message_id, (message)=>{ + message.reactions = []; + }); + }); + } +} +const cache_sym = Symbol("@cache"); +function enableCache(session) { + const cache = { + guilds: new Collection(session), + users: new Collection(session), + dms: new Collection(session), + emojis: new Collection(session), + cache: cache_sym, + session + }; + session.on("raw", (data)=>{ + const raw = data.d; + if (!raw) return; + switch(data.t){ + case "MESSAGE_CREATE": + messageBootstrapper(cache, raw, false); + break; + case "MESSAGE_UPDATE": + messageBootstrapper(cache, raw, !raw.edited_timestamp); + break; + case "CHANNEL_CREATE": + channelBootstrapper(cache, raw); + break; + case "GUILD_MEMBER_ADD": + memberBootstrapper(cache, raw, raw.guild_id); + break; + case "GUILD_CREATE": + guildBootstrapper(cache, raw); + break; + case "GUILD_DELETE": + cache.guilds.delete(raw.id); + break; + case "MESSAGE_REACTION_ADD": + reactionBootstrapper(cache, raw, false); + break; + case "MESSAGE_REACTION_REMOVE": + reactionBootstrapper(cache, raw, false); + break; + case "MESSAGE_REACTION_REMOVE_ALL": + reactionBootstrapperDeletions(cache, raw); + break; + case "READY": + userBootstrapper(cache, raw.user); + break; + default: + session.emit("debug", `NOT CACHED: ${JSON.stringify(raw)}`); + } + }); + return cache; +} +export { cache_sym as cache_sym }; +export { enableCache as enableCache }; +export { enableCache as enableCache }; +export { Session as default }; diff --git a/build.ts b/build.ts index 8233dd9..e20803d 100644 --- a/build.ts +++ b/build.ts @@ -1,70 +1,70 @@ -import { build } from "https://deno.land/x/dnt@0.26.0/mod.ts"; +import { build } from 'https://deno.land/x/dnt@0.26.0/mod.ts'; -await Deno.remove("npm", { recursive: true }).catch((_) => {}); +await Deno.remove('npm', { recursive: true }).catch((_) => {}); await build({ compilerOptions: { - lib: ["webworker", "es2020"], + lib: ['webworker', 'es2020'], }, shims: { custom: [ { package: { - name: "ws", - version: "^8.4.0", + name: 'ws', + version: '^8.4.0', }, globalNames: [ { - name: "WebSocket", - exportName: "default", + name: 'WebSocket', + exportName: 'default', }, ], }, ], }, package: { - author: "Yuzuru", - name: "@oasisjs/biscuit", + author: 'Yuzuru', + name: '@oasisjs/biscuit', version: Deno.args[0], - description: " brand new bleeding edge non bloated Discord library", - license: "Apache License 2.0", + description: ' brand new bleeding edge non bloated Discord library', + license: 'Apache License 2.0', repository: { - type: "git", - url: "git+https://github.com/oasisjs/biscuit.git", + type: 'git', + url: 'git+https://github.com/oasisjs/biscuit.git', }, bugs: { - url: "https://github.com/oasisjs/biscuit/issues", + url: 'https://github.com/oasisjs/biscuit/issues', }, typesVersions: { - "*": { - "*": ["./types/mod.d.ts"], - "biscuit": ["./types/packages/biscuit/mod.d.ts"], - "discordeno": ["./types/packages/discordeno/mod.d.ts"], - "cache": ["./types/packages/cache/mod.d.ts"], + '*': { + '*': ['./types/mod.d.ts'], + 'biscuit': ['./types/packages/biscuit/mod.d.ts'], + 'discordeno': ['./types/packages/discordeno/mod.d.ts'], + 'cache': ['./types/packages/cache/mod.d.ts'], }, }, }, entryPoints: [ - "./mod.ts", + './mod.ts', { - name: "./biscuit", - path: "packages/biscuit/mod.ts", + name: './biscuit', + path: 'packages/biscuit/mod.ts', }, { - name: "./discordeno", - path: "packages/discordeno/mod.ts", + name: './discordeno', + path: 'packages/discordeno/mod.ts', }, { - name: "./cache", - path: "packages/cache/mod.ts", + name: './cache', + path: 'packages/cache/mod.ts', }, ], - outDir: "./npm", + outDir: './npm', declaration: true, typeCheck: false, test: false, }); // post build steps -Deno.copyFileSync("LICENSE", "npm/LICENSE"); -Deno.copyFileSync("README.md", "npm/README.md"); +Deno.copyFileSync('LICENSE', 'npm/LICENSE'); +Deno.copyFileSync('README.md', 'npm/README.md'); diff --git a/deno.json b/deno.json index d010978..2cf38f6 100644 --- a/deno.json +++ b/deno.json @@ -2,7 +2,8 @@ "fmt": { "options": { "indentWidth": 4, - "lineWidth": 120 + "lineWidth": 120, + "singleQuote": true } } } diff --git a/egg.json b/egg.json index d58888c..bb02ec5 100644 --- a/egg.json +++ b/egg.json @@ -4,7 +4,7 @@ "entry": "./mod.ts", "description": "A brand new bleeding edge non bloated Discord library", "homepage": "https://github.com/oasisjs/biscuit", - "version": "0.2.0", + "version": "0.2.1", "releaseType": "patch", "unstable": false, "unlisted": false, diff --git a/examples/components/mod.ts b/examples/components/mod.ts index a2f6ced..8092b32 100644 --- a/examples/components/mod.ts +++ b/examples/components/mod.ts @@ -1,4 +1,4 @@ -import "https://deno.land/std@0.146.0/dotenv/load.ts"; +import 'https://deno.land/std@0.146.0/dotenv/load.ts'; import { ActionRowBuilder, ButtonBuilder, @@ -6,26 +6,26 @@ import { GatewayIntents, InteractionResponseTypes, Session, -} from "https://deno.land/x/biscuit/mod.ts"; +} from 'https://deno.land/x/biscuit/mod.ts'; -const token = Deno.env.get("TOKEN") ?? Deno.args[0]; +const token = Deno.env.get('TOKEN') ?? Deno.args[0]; if (!token) { - throw new Error("Please provide a token"); + throw new Error('Please provide a token'); } const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Session({ token, intents }); -const PREFIX = ">"; -const components = new ButtonBuilder().setCustomId("ping").setLabel("Hello!").setStyle(ButtonStyles.Success); +const PREFIX = '>'; +const components = new ButtonBuilder().setCustomId('ping').setLabel('Hello!').setStyle(ButtonStyles.Success); const row = new ActionRowBuilder().addComponents(components).toJSON(); -session.on("ready", (payload) => { - console.log("Logged in as:", payload.user.username); +session.on('ready', (payload) => { + console.log('Logged in as:', payload.user.username); }); -session.on("messageCreate", (message) => { +session.on('messageCreate', (message) => { if (message.author?.bot || !message.content.startsWith(PREFIX)) { return; } @@ -33,21 +33,21 @@ session.on("messageCreate", (message) => { const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm); const name = args.shift()?.toLowerCase(); - if (name === "ping") { + if (name === 'ping') { message.reply({ components: [row] }); } }); // Follow interaction event -session.on("interactionCreate", (interaction) => { +session.on('interactionCreate', (interaction) => { if (!interaction.isComponent()) { return; } - if (interaction.customId === "ping") { + if (interaction.customId === 'ping') { interaction.respond({ type: InteractionResponseTypes.ChannelMessageWithSource, - data: { content: "pong!" }, + data: { content: 'pong!' }, }); } }); diff --git a/examples/hello-bun/index.js b/examples/hello-bun/index.js index 520ddc1..f0ab043 100644 --- a/examples/hello-bun/index.js +++ b/examples/hello-bun/index.js @@ -3,7 +3,7 @@ * this example should work on most systems, but if it doesn't just clone the library and import everything from mod.ts */ -const { GatewayIntents, Session } = require("../mod.ts"); +const { GatewayIntents, Session } = require('../mod.ts'); // if it didn't worked use: // import { GatewayIntents, Session } from "@oasisjs/biscuit"; @@ -12,20 +12,20 @@ const token = process.env.TOKEN; const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Session({ token, intents }); -session.on("ready", (payload) => { - console.log("Logged in as:", payload.user.username); +session.on('ready', (payload) => { + console.log('Logged in as:', payload.user.username); }); -session.on("messageCreate", async (message) => { +session.on('messageCreate', async (message) => { // GET - if (message.content.startsWith("whatever")) { + if (message.content.startsWith('whatever')) { const whatever = await message.fetch(); console.log(whatever); } // POST - if (message.content.startsWith("ping")) { - message.reply({ content: "pong!" }).catch((err) => console.error(err)); + if (message.content.startsWith('ping')) { + message.reply({ content: 'pong!' }).catch((err) => console.error(err)); } }); diff --git a/examples/hello-deno/mod.ts b/examples/hello-deno/mod.ts index a2a721e..45135c5 100644 --- a/examples/hello-deno/mod.ts +++ b/examples/hello-deno/mod.ts @@ -2,27 +2,27 @@ * Deno example */ -import "https://deno.land/std@0.146.0/dotenv/load.ts"; +import 'https://deno.land/std@0.146.0/dotenv/load.ts'; // Session to create a new bot (and intents) -import { GatewayIntents, Session } from "https://deno.land/x/biscuit/mod.ts"; +import { GatewayIntents, Session } from 'https://deno.land/x/biscuit/mod.ts'; -const token = Deno.env.get("TOKEN") ?? Deno.args[0]; +const token = Deno.env.get('TOKEN') ?? Deno.args[0]; if (!token) { - throw new Error("Please provide a token"); + throw new Error('Please provide a token'); } const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Session({ token, intents }); -session.on("ready", (payload) => { - console.log("Logged in as:", payload.user.username); +session.on('ready', (payload) => { + console.log('Logged in as:', payload.user.username); }); -const PREFIX = ">"; +const PREFIX = '>'; -session.on("messageCreate", (message) => { +session.on('messageCreate', (message) => { if (message.author?.bot || !message.content.startsWith(PREFIX)) { return; } @@ -30,8 +30,8 @@ session.on("messageCreate", (message) => { const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm); const name = args.shift()?.toLowerCase(); - if (name === "ping") { - message.reply({ content: "pong!" }); + if (name === 'ping') { + message.reply({ content: 'pong!' }); } }); diff --git a/examples/hello-node-mjs/index.mjs b/examples/hello-node-mjs/index.mjs index 6cce5af..d815615 100644 --- a/examples/hello-node-mjs/index.mjs +++ b/examples/hello-node-mjs/index.mjs @@ -4,31 +4,31 @@ // process for get the token /** @type {NodeJS.Process} process */ -import process from "node:process"; +import process from 'node:process'; // Session for create a new bot and intents -import { GatewayIntents, Session } from "@oasisjs/biscuit"; +import { GatewayIntents, Session } from '@oasisjs/biscuit'; // Discord bot token /** @type {string} token */ -const token = process.env.TOKEN || "YOUR_TOKEN_HERE"; +const token = process.env.TOKEN || 'YOUR_TOKEN_HERE'; -if (token === "") { - console.log(new Error("Please set the TOKEN environment variable")); +if (token === '') { + console.log(new Error('Please set the TOKEN environment variable')); } const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Session({ token, intents }); // Command prefix -const PREFIX = ">"; +const PREFIX = '>'; -session.on("ready", (data) => { - console.log("Ready! Let's start chatting!"); - console.log("Connected as: " + data.user.username); +session.on('ready', (data) => { + console.log('Ready! Let\'s start chatting!'); + console.log('Connected as: ' + data.user.username); }); -session.on("messageCreate", (message) => { +session.on('messageCreate', (message) => { if (message.author?.bot || !message.content.startsWith(PREFIX)) { return; } @@ -36,8 +36,8 @@ session.on("messageCreate", (message) => { const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm); const name = args.shift()?.toLowerCase(); - if (name === "ping") { - message.reply({ content: "pong!" }); + if (name === 'ping') { + message.reply({ content: 'pong!' }); } }); diff --git a/examples/hello-node/index.js b/examples/hello-node/index.js index d5ac79f..d68b3f6 100644 --- a/examples/hello-node/index.js +++ b/examples/hello-node/index.js @@ -4,31 +4,31 @@ // process for get the token /** @type {NodeJS.Process} process */ -const process = require("node:process"); +const process = require('node:process'); // Session for create a new bot and intents -const { Session, GatewayIntents } = require("@oasisjs/biscuit"); +const { Session, GatewayIntents } = require('@oasisjs/biscuit'); // Discord bot token /** @type {string} token */ -const token = process.env.TOKEN || "YOUR_TOKEN_HERE"; +const token = process.env.TOKEN || 'YOUR_TOKEN_HERE'; -if (token === "") { - return new Error("Please set the TOKEN environment variable"); +if (token === '') { + return new Error('Please set the TOKEN environment variable'); } const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Session({ token, intents }); // Command prefix -const PREFIX = ">"; +const PREFIX = '>'; -session.on("ready", (data) => { - console.log("Ready! Let's start chatting!"); - console.log("Connected as: " + data.user.username); +session.on('ready', (data) => { + console.log('Ready! Let\'s start chatting!'); + console.log('Connected as: ' + data.user.username); }); -session.on("messageCreate", (message) => { +session.on('messageCreate', (message) => { if (message.author?.bot || !message.content.startsWith(PREFIX)) { return; } @@ -36,8 +36,8 @@ session.on("messageCreate", (message) => { const args = message.content.substring(PREFIX.length).trim().split(/\s+/gm); const name = args.shift()?.toLowerCase(); - if (name === "ping") { - message.reply({ content: "pong!" }); + if (name === 'ping') { + message.reply({ content: 'pong!' }); } }); diff --git a/examples/slash-commands/mod.ts b/examples/slash-commands/mod.ts index 16a9f31..81e1fce 100644 --- a/examples/slash-commands/mod.ts +++ b/examples/slash-commands/mod.ts @@ -1,47 +1,47 @@ -import "https://deno.land/std@0.146.0/dotenv/load.ts"; +import 'https://deno.land/std@0.146.0/dotenv/load.ts'; import { CreateApplicationCommand, GatewayIntents, InteractionResponseTypes, Session, -} from "https://deno.land/x/biscuit/mod.ts"; +} from 'https://deno.land/x/biscuit/mod.ts'; -const token = Deno.env.get("TOKEN") ?? Deno.args[0]; +const token = Deno.env.get('TOKEN') ?? Deno.args[0]; if (!token) { - throw new Error("Please provide a token"); + throw new Error('Please provide a token'); } const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Session({ token, intents }); const command: CreateApplicationCommand = { - name: "ping", - description: "Replies with pong!", + name: 'ping', + description: 'Replies with pong!', }; -session.on("ready", async (payload) => { - console.log("Logged in as:", payload.user.username); - console.log("Creating the application commands..."); +session.on('ready', async (payload) => { + console.log('Logged in as:', payload.user.username); + console.log('Creating the application commands...'); // create command try { await session.createApplicationCommand(command); - console.log("Done!"); + console.log('Done!'); } catch (err) { console.error(err); } }); // Follow interaction event -session.on("interactionCreate", (interaction) => { +session.on('interactionCreate', (interaction) => { if (!interaction.isCommand()) { return; } - if (interaction.commandName === "ping") { + if (interaction.commandName === 'ping') { interaction.respond({ type: InteractionResponseTypes.ChannelMessageWithSource, - data: { content: "pong!" }, + data: { content: 'pong!' }, }); } }); diff --git a/hello.ts b/hello.ts index aa5aade..4a58a19 100644 --- a/hello.ts +++ b/hello.ts @@ -1,17 +1,17 @@ // Biscuit Discord library showcase -import Biscuit, { GatewayIntents } from "https://deno.land/x/biscuit/mod.ts"; +import Biscuit, { GatewayIntents } from 'https://deno.land/x/biscuit/mod.ts'; const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; const session = new Biscuit({ token: Deno.args[0], intents }); -session.on("ready", ({ user }) => { - console.log("Logged in as: %s!\nUse !ping to get a reply", user.username); +session.on('ready', ({ user }) => { + console.log('Logged in as: %s!\nUse !ping to get a reply', user.username); }); -session.on("messageCreate", (message) => { - if (message.content.startsWith("!ping")) { - message.reply({ content: "pong!" }); +session.on('messageCreate', (message) => { + if (message.content.startsWith('!ping')) { + message.reply({ content: 'pong!' }); } }); diff --git a/mod.ts b/mod.ts index bea564f..ff4bcf6 100644 --- a/mod.ts +++ b/mod.ts @@ -1,8 +1,8 @@ -import Session from "./packages/biscuit/mod.ts"; +import Session from './packages/biscuit/mod.ts'; export default Session; -export * from "./packages/biscuit/mod.ts"; -export * from "./packages/discordeno/mod.ts"; -export * from "./packages/cache/mod.ts"; -export { default as enableCache } from "./packages/cache/mod.ts"; +export * from './packages/biscuit/mod.ts'; +export * from './packages/discordeno/mod.ts'; +export * from './packages/cache/mod.ts'; +export { default as enableCache } from './packages/cache/mod.ts'; diff --git a/packages/biscuit/Actions.ts b/packages/biscuit/Actions.ts index 4b86767..ac61ddc 100644 --- a/packages/biscuit/Actions.ts +++ b/packages/biscuit/Actions.ts @@ -37,34 +37,34 @@ import type { DiscordTypingStart, DiscordUser, DiscordWebhookUpdate, -} from "../discordeno/mod.ts"; +} from '../discordeno/mod.ts'; -import type { Snowflake } from "./Snowflake.ts"; -import type { Session } from "./Session.ts"; -import type { Interaction } from "./structures/interactions/InteractionFactory.ts"; +import type { Snowflake } from './Snowflake.ts'; +import type { Session } from './Session.ts'; +import type { Interaction } from './structures/interactions/InteractionFactory.ts'; -import { AutoModerationRule } from "./structures/AutoModerationRule.ts"; -import { AutoModerationExecution } from "./structures/AutoModerationExecution.ts"; -import { type Channel, ChannelFactory, GuildChannel, ThreadChannel } from "./structures/channels.ts"; -import { type DiscordStageInstanceB, StageInstance } from "./structures/StageInstance.ts"; -import { ScheduledEvent } from "./structures/GuildScheduledEvent.ts"; -import { Presence } from "./structures/Presence.ts"; +import { AutoModerationRule } from './structures/AutoModerationRule.ts'; +import { AutoModerationExecution } from './structures/AutoModerationExecution.ts'; +import { type Channel, ChannelFactory, GuildChannel, ThreadChannel } from './structures/channels.ts'; +import { type DiscordStageInstanceB, StageInstance } from './structures/StageInstance.ts'; +import { ScheduledEvent } from './structures/GuildScheduledEvent.ts'; +import { Presence } from './structures/Presence.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.ts"; -import InteractionFactory from "./structures/interactions/InteractionFactory.ts"; -import { InviteCreate, NewInviteCreate } from "./structures/Invite.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.ts'; +import InteractionFactory from './structures/interactions/InteractionFactory.ts'; +import { InviteCreate, NewInviteCreate } from './structures/Invite.ts'; import { MessageReactionAdd, MessageReactionRemove, MessageReactionRemoveAll, MessageReactionRemoveEmoji, NewMessageReactionAdd, -} from "./structures/MessageReaction.ts"; +} from './structures/MessageReaction.ts'; export type RawHandler = (...args: [Session, number, T]) => void; export type Handler = (...args: T) => unknown; @@ -72,11 +72,11 @@ export type Handler = (...args: T) => export const READY: RawHandler = (session, shardId, payload) => { session.applicationId = payload.application.id; session.botId = payload.user.id; - session.emit("ready", { ...payload, user: new User(session, payload.user) }, shardId); + session.emit('ready', { ...payload, user: new User(session, payload.user) }, shardId); }; export const MESSAGE_CREATE: RawHandler = (session, _shardId, message) => { - session.emit("messageCreate", new Message(session, message)); + session.emit('messageCreate', new Message(session, message)); }; export const MESSAGE_UPDATE: RawHandler = (session, _shardId, new_message) => { @@ -95,63 +95,63 @@ export const MESSAGE_UPDATE: RawHandler = (session, _shardId, ne // we aknowledge people that their callback could be partial but giving them all functions of Message Object.setPrototypeOf(message, Message.prototype); - session.emit("messageUpdate", message); + session.emit('messageUpdate', message); return; } - session.emit("messageUpdate", new Message(session, new_message)); + session.emit('messageUpdate', new Message(session, new_message)); }; export const MESSAGE_DELETE: RawHandler = (session, _shardId, { id, channel_id, guild_id }) => { - session.emit("messageDelete", { id, channelId: channel_id, guildId: guild_id }); + session.emit('messageDelete', { id, channelId: channel_id, guildId: guild_id }); }; export const GUILD_CREATE: RawHandler = (session, _shardId, guild) => { - session.emit("guildCreate", new Guild(session, guild)); + session.emit('guildCreate', new Guild(session, guild)); }; export const GUILD_DELETE: RawHandler = (session, _shardId, guild) => { - session.emit("guildDelete", { id: guild.id, unavailable: true }); + session.emit('guildDelete', { id: guild.id, unavailable: true }); }; export const GUILD_MEMBER_ADD: RawHandler = (session, _shardId, member) => { - session.emit("guildMemberAdd", new Member(session, member, member.guild_id)); + session.emit('guildMemberAdd', new Member(session, member, member.guild_id)); }; export const GUILD_MEMBER_UPDATE: RawHandler = (session, _shardId, member) => { - session.emit("guildMemberUpdate", new Member(session, member, member.guild_id)); + session.emit('guildMemberUpdate', new Member(session, member, member.guild_id)); }; export const GUILD_MEMBER_REMOVE: RawHandler = (session, _shardId, member) => { - session.emit("guildMemberRemove", new User(session, member.user), member.guild_id); + session.emit('guildMemberRemove', new User(session, member.user), member.guild_id); }; export const GUILD_BAN_ADD: RawHandler = (session, _shardId, data) => { - session.emit("guildBanAdd", { guildId: data.guild_id, user: data.user }); + session.emit('guildBanAdd', { guildId: data.guild_id, user: data.user }); }; export const GUILD_BAN_REMOVE: RawHandler = (session, _shardId, data) => { - session.emit("guildBanRemove", { guildId: data.guild_id, user: data.user }); + session.emit('guildBanRemove', { guildId: data.guild_id, user: data.user }); }; export const GUILD_EMOJIS_UPDATE: RawHandler = (session, _shardId, data) => { - session.emit("guildEmojisUpdate", { guildId: data.guild_id, emojis: data.emojis }); + session.emit('guildEmojisUpdate', { guildId: data.guild_id, emojis: data.emojis }); }; export const GUILD_ROLE_CREATE: RawHandler = (session, _shardId, data) => { - session.emit("guildRoleCreate", { guildId: data.guild_id, role: data.role }); + session.emit('guildRoleCreate', { guildId: data.guild_id, role: data.role }); }; export const GUILD_ROLE_UPDATE: RawHandler = (session, _shardId, data) => { - session.emit("guildRoleUpdate", { guildId: data.guild_id, role: data.role }); + session.emit('guildRoleUpdate', { guildId: data.guild_id, role: data.role }); }; export const GUILD_ROLE_DELETE: RawHandler = (session, _shardId, data) => { - session.emit("guildRoleDelete", { guildId: data.guild_id, roleId: data.role_id }); + session.emit('guildRoleDelete', { guildId: data.guild_id, roleId: data.role_id }); }; export const TYPING_START: RawHandler = (session, _shardId, payload) => { - session.emit("typingStart", { + session.emit('typingStart', { channelId: payload.channel_id, guildId: payload.guild_id ? payload.guild_id : undefined, userId: payload.user_id, @@ -163,43 +163,43 @@ export const TYPING_START: RawHandler = (session, _shardId, }; export const INTERACTION_CREATE: RawHandler = (session, _shardId, interaction) => { - session.emit("interactionCreate", InteractionFactory.from(session, interaction)); + session.emit('interactionCreate', InteractionFactory.from(session, interaction)); }; export const CHANNEL_CREATE: RawHandler = (session, _shardId, channel) => { - session.emit("channelCreate", ChannelFactory.from(session, channel)); + session.emit('channelCreate', ChannelFactory.from(session, channel)); }; export const CHANNEL_UPDATE: RawHandler = (session, _shardId, channel) => { - session.emit("channelUpdate", ChannelFactory.from(session, channel)); + session.emit('channelUpdate', ChannelFactory.from(session, channel)); }; export const CHANNEL_DELETE: RawHandler = (session, _shardId, channel) => { if (!channel.guild_id) return; - session.emit("channelDelete", new GuildChannel(session, channel, channel.guild_id)); + session.emit('channelDelete', new GuildChannel(session, channel, channel.guild_id)); }; export const THREAD_CREATE: RawHandler = (session, _shardId, channel) => { if (!channel.guild_id) return; - session.emit("threadCreate", new ThreadChannel(session, channel, channel.guild_id)); + session.emit('threadCreate', new ThreadChannel(session, channel, channel.guild_id)); }; export const THREAD_UPDATE: RawHandler = (session, _shardId, channel) => { if (!channel.guild_id) return; - session.emit("threadUpdate", new ThreadChannel(session, channel, channel.guild_id)); + session.emit('threadUpdate', new ThreadChannel(session, channel, channel.guild_id)); }; export const THREAD_DELETE: RawHandler = (session, _shardId, channel) => { if (!channel.guild_id) return; - session.emit("threadDelete", new ThreadChannel(session, channel, channel.guild_id)); + session.emit('threadDelete', new ThreadChannel(session, channel, channel.guild_id)); }; export const THREAD_MEMBER_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("threadMemberUpdate", { + session.emit('threadMemberUpdate', { guildId: payload.guild_id, id: payload.id, userId: payload.user_id, @@ -209,7 +209,7 @@ export const THREAD_MEMBER_UPDATE: RawHandler = (sess }; export const THREAD_MEMBERS_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("threadMembersUpdate", { + session.emit('threadMembersUpdate', { memberCount: payload.member_count, addedMembers: payload.added_members ? payload.added_members.map((tm) => new ThreadMember(session, tm)) @@ -221,7 +221,7 @@ export const THREAD_MEMBERS_UPDATE: RawHandler = (se }; export const THREAD_LIST_SYNC: RawHandler = (session, _shardId, payload) => { - session.emit("threadListSync", { + session.emit('threadListSync', { guildId: payload.guild_id, channelIds: payload.channel_ids ?? [], threads: payload.threads.map((channel) => new ThreadChannel(session, channel, payload.guild_id)), @@ -230,7 +230,7 @@ export const THREAD_LIST_SYNC: RawHandler = (session, _sh }; export const CHANNEL_PINS_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("channelPinsUpdate", { + session.emit('channelPinsUpdate', { guildId: payload.guild_id, channelId: payload.channel_id, lastPinTimestamp: payload.last_pin_timestamp ? Date.parse(payload.last_pin_timestamp) : undefined, @@ -238,15 +238,15 @@ export const CHANNEL_PINS_UPDATE: RawHandler = (sessio }; export const USER_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("userUpdate", new User(session, payload)); + session.emit('userUpdate', new User(session, payload)); }; export const PRESENCE_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("presenceUpdate", new Presence(session, payload)); + session.emit('presenceUpdate', new Presence(session, payload)); }; export const WEBHOOKS_UPDATE: RawHandler = (session, _shardId, webhook) => { - session.emit("webhooksUpdate", { guildId: webhook.guild_id, channelId: webhook.channel_id }); + session.emit('webhooksUpdate', { guildId: webhook.guild_id, channelId: webhook.channel_id }); }; export const INTEGRATION_CREATE: RawHandler = ( @@ -254,7 +254,7 @@ export const INTEGRATION_CREATE: RawHandler { - session.emit("integrationCreate", new Integration(session, payload)); + session.emit('integrationCreate', new Integration(session, payload)); }; export const INTEGRATION_UPDATE: RawHandler = ( @@ -262,11 +262,11 @@ export const INTEGRATION_UPDATE: RawHandler { - session.emit("integrationCreate", new Integration(session, payload)); + session.emit('integrationCreate', new Integration(session, payload)); }; export const INTEGRATION_DELETE: RawHandler = (session, _shardId, payload) => { - session.emit("integrationDelete", { + session.emit('integrationDelete', { id: payload.id, guildId: payload.guild_id, applicationId: payload.application_id, @@ -274,15 +274,15 @@ export const INTEGRATION_DELETE: RawHandler = (session }; export const AUTO_MODERATION_RULE_CREATE: RawHandler = (session, _shardId, payload) => { - session.emit("autoModerationRuleCreate", new AutoModerationRule(session, payload)); + session.emit('autoModerationRuleCreate', new AutoModerationRule(session, payload)); }; export const AUTO_MODERATION_RULE_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("autoModerationRuleUpdate", new AutoModerationRule(session, payload)); + session.emit('autoModerationRuleUpdate', new AutoModerationRule(session, payload)); }; export const AUTO_MODERATION_RULE_DELETE: RawHandler = (session, _shardId, payload) => { - session.emit("autoModerationRuleDelete", new AutoModerationRule(session, payload)); + session.emit('autoModerationRuleDelete', new AutoModerationRule(session, payload)); }; export const AUTO_MODERATION_ACTION_EXECUTE: RawHandler = ( @@ -290,15 +290,15 @@ export const AUTO_MODERATION_ACTION_EXECUTE: RawHandler { - session.emit("autoModerationActionExecution", new AutoModerationExecution(session, payload)); + session.emit('autoModerationActionExecution', new AutoModerationExecution(session, payload)); }; export const MESSAGE_REACTION_ADD: RawHandler = (session, _shardId, reaction) => { - session.emit("messageReactionAdd", NewMessageReactionAdd(session, reaction)); + session.emit('messageReactionAdd', NewMessageReactionAdd(session, reaction)); }; export const MESSAGE_REACTION_REMOVE: RawHandler = (session, _shardId, reaction) => { - session.emit("messageReactionRemove", NewMessageReactionAdd(session, reaction)); + session.emit('messageReactionRemove', NewMessageReactionAdd(session, reaction)); }; export const MESSAGE_REACTION_REMOVE_ALL: RawHandler = ( @@ -306,7 +306,7 @@ export const MESSAGE_REACTION_REMOVE_ALL: RawHandler { - session.emit("messageReactionRemoveAll", NewMessageReactionAdd(session, reaction as DiscordMessageReactionAdd)); + session.emit('messageReactionRemoveAll', NewMessageReactionAdd(session, reaction as DiscordMessageReactionAdd)); }; export const MESSAGE_REACTION_REMOVE_EMOJI: RawHandler = ( @@ -314,39 +314,39 @@ export const MESSAGE_REACTION_REMOVE_EMOJI: RawHandler { - session.emit("messageReactionRemoveEmoji", NewMessageReactionAdd(session, reaction as DiscordMessageReactionAdd)); + session.emit('messageReactionRemoveEmoji', NewMessageReactionAdd(session, reaction as DiscordMessageReactionAdd)); }; export const INVITE_CREATE: RawHandler = (session, _shardId, invite) => { - session.emit("inviteCreate", NewInviteCreate(session, invite)); + session.emit('inviteCreate', NewInviteCreate(session, invite)); }; export const INVITE_DELETE: RawHandler = (session, _shardId, data) => { - session.emit("inviteDelete", { channelId: data.channel_id, guildId: data.guild_id, code: data.code }); + session.emit('inviteDelete', { channelId: data.channel_id, guildId: data.guild_id, code: data.code }); }; export const STAGE_INSTANCE_CREATE: RawHandler = (session, _shardId, payload) => { - session.emit("stageInstanceCreate", new StageInstance(session, payload)); + session.emit('stageInstanceCreate', new StageInstance(session, payload)); }; export const STAGE_INSTANCE_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("stageInstanceUpdate", new StageInstance(session, payload)); + session.emit('stageInstanceUpdate', new StageInstance(session, payload)); }; export const STAGE_INSTANCE_DELETE: RawHandler = (session, _shardId, payload) => { - session.emit("stageInstanceDelete", new StageInstance(session, payload)); + session.emit('stageInstanceDelete', new StageInstance(session, payload)); }; export const GUILD_SCHEDULED_EVENT_CREATE: RawHandler = (session, _shardId, payload) => { - session.emit("guildScheduledEventCreate", new ScheduledEvent(session, payload)); + session.emit('guildScheduledEventCreate', new ScheduledEvent(session, payload)); }; export const GUILD_SCHEDULED_EVENT_UPDATE: RawHandler = (session, _shardId, payload) => { - session.emit("guildScheduledEventUpdate", new ScheduledEvent(session, payload)); + session.emit('guildScheduledEventUpdate', new ScheduledEvent(session, payload)); }; export const GUILD_SCHEDULED_EVENT_DELETE: RawHandler = (session, _shardId, payload) => { - session.emit("guildScheduledEventDelete", new ScheduledEvent(session, payload)); + session.emit('guildScheduledEventDelete', new ScheduledEvent(session, payload)); }; export const GUILD_SCHEDULED_EVENT_USER_ADD: RawHandler = ( @@ -354,7 +354,7 @@ export const GUILD_SCHEDULED_EVENT_USER_ADD: RawHandler { - session.emit("guildScheduledEventUserAdd", { + session.emit('guildScheduledEventUserAdd', { scheduledEventId: payload.guild_scheduled_event_id, userId: payload.user_id, guildId: payload.guild_id, @@ -366,7 +366,7 @@ export const GUILD_SCHEDULED_EVENT_USER_REMOVE: RawHandler { - session.emit("guildScheduledEventUserRemove", { + session.emit('guildScheduledEventUserRemove', { scheduledEventId: payload.guild_scheduled_event_id, userId: payload.user_id, guildId: payload.guild_id, @@ -374,10 +374,10 @@ export const GUILD_SCHEDULED_EVENT_USER_REMOVE: RawHandler = (session, shardId, data) => { - session.emit("raw", data as { t: string; d: unknown }, shardId); + session.emit('raw', data as { t: string; d: unknown }, shardId); }; -export interface Ready extends Omit { +export interface Ready extends Omit { user: User; } diff --git a/packages/biscuit/Cdn.ts b/packages/biscuit/Cdn.ts index 7e24810..4292f18 100644 --- a/packages/biscuit/Cdn.ts +++ b/packages/biscuit/Cdn.ts @@ -1,12 +1,12 @@ -import type { Snowflake } from "./Snowflake.ts"; -import { baseEndpoints as Endpoints } from "../discordeno/mod.ts"; +import type { Snowflake } from './Snowflake.ts'; +import { baseEndpoints as Endpoints } from '../discordeno/mod.ts'; export function USER_AVATAR(userId: Snowflake, icon: string): string { return `${Endpoints.CDN_URL}/avatars/${userId}/${icon}`; } export function EMOJI_URL(id: Snowflake, animated = false): string { - return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`; + return `https://cdn.discordapp.com/emojis/${id}.${animated ? 'gif' : 'png'}`; } export function USER_DEFAULT_AVATAR( diff --git a/packages/biscuit/Routes.ts b/packages/biscuit/Routes.ts index 1ac377e..98c5aa6 100644 --- a/packages/biscuit/Routes.ts +++ b/packages/biscuit/Routes.ts @@ -1,15 +1,15 @@ -import type { Snowflake } from "./Snowflake.ts"; +import type { Snowflake } from './Snowflake.ts'; // cdn endpoints -export * from "./Cdn.ts"; +export * from './Cdn.ts'; export function USER(userId?: Snowflake): string { - if (!userId) return "/users/@me"; + if (!userId) return '/users/@me'; return `/users/${userId}`; } export function GATEWAY_BOT(): string { - return "/gateway/bot"; + return '/gateway/bot'; } export interface GetMessagesOptions { diff --git a/packages/biscuit/Session.ts b/packages/biscuit/Session.ts index 76f37c2..ea5343b 100644 --- a/packages/biscuit/Session.ts +++ b/packages/biscuit/Session.ts @@ -9,29 +9,29 @@ import type { GatewayBot, GatewayIntents, Localization, -} from "../discordeno/mod.ts"; +} from '../discordeno/mod.ts'; -import type { DiscordGatewayPayload, Shard } from "../discordeno/mod.ts"; -import type { Events } from "./Actions.ts"; -import type { PermissionResolvable } from "./structures/Permissions.ts"; -import type { Activities, StatusTypes } from "./structures/Presence.ts"; +import type { DiscordGatewayPayload, Shard } from '../discordeno/mod.ts'; +import type { Events } from './Actions.ts'; +import type { PermissionResolvable } from './structures/Permissions.ts'; +import type { Activities, StatusTypes } from './structures/Presence.ts'; -import { Permissions } from "./structures/Permissions.ts"; -import { Snowflake } from "./Snowflake.ts"; -import { EventEmitter } from "./util/EventEmmiter.ts"; +import { Permissions } from './structures/Permissions.ts'; +import { Snowflake } from './Snowflake.ts'; +import { EventEmitter } from './util/EventEmmiter.ts'; import { ApplicationCommandTypes, createGatewayManager, createRestManager, GatewayOpcodes, getBotIdFromToken, -} from "../discordeno/mod.ts"; +} from '../discordeno/mod.ts'; -import User from "./structures/User.ts"; -import { urlToBase64 } from "./util/urlToBase64.ts"; +import User from './structures/User.ts'; +import { urlToBase64 } from './util/urlToBase64.ts'; -import * as Routes from "./Routes.ts"; -import * as Actions from "./Actions.ts"; +import * as Routes from './Routes.ts'; +import * as Actions from './Actions.ts'; export type DiscordRawEventHandler = (shard: Shard, data: DiscordGatewayPayload) => unknown; @@ -54,7 +54,7 @@ export interface CreateApplicationCommand { /** * @link https://discord.com/developers/docs/interactions/application-commands#endpoints-json-params */ -export interface CreateContextApplicationCommand extends Omit { +export interface CreateContextApplicationCommand extends Omit { type: ApplicationCommandTypes.Message | ApplicationCommandTypes.User; } @@ -164,7 +164,7 @@ export class Session extends EventEmitter { token: this.options.token, debug: (text) => { // TODO: set this using the event emitter - super.rawListeners("debug")?.forEach((fn) => fn(text)); + super.rawListeners('debug')?.forEach((fn) => fn(text)); }, secretKey: this.options.rest?.secretKey ?? undefined, }); @@ -203,7 +203,7 @@ export class Session extends EventEmitter { async editProfile(nick?: string, avatarURL?: string | null): Promise { const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL; - const user = await this.rest.runMethod(this.rest, "PATCH", Routes.USER(), { + const user = await this.rest.runMethod(this.rest, 'PATCH', Routes.USER(), { username: nick, avatar: avatar, }); @@ -265,7 +265,7 @@ export class Session extends EventEmitter { } async fetchUser(id: Snowflake): Promise { - const user: DiscordUser = await this.rest.runMethod(this.rest, "GET", Routes.USER(id)); + const user: DiscordUser = await this.rest.runMethod(this.rest, 'GET', Routes.USER(id)); if (!user.id) return; @@ -278,7 +278,7 @@ export class Session extends EventEmitter { ): Promise { return this.rest.runMethod( this.rest, - "POST", + 'POST', guildId ? Routes.GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : Routes.APPLICATION_COMMANDS(this.applicationId), @@ -306,7 +306,7 @@ export class Session extends EventEmitter { deleteApplicationCommand(id: Snowflake, guildId?: Snowflake): Promise { return this.rest.runMethod( this.rest, - "DELETE", + 'DELETE', guildId ? Routes.GUILD_APPLICATION_COMMANDS(this.applicationId, guildId, id) : Routes.APPLICATION_COMMANDS(this.applicationId, id), @@ -321,7 +321,7 @@ export class Session extends EventEmitter { ): Promise { return this.rest.runMethod( this.rest, - "PUT", + 'PUT', Routes.GUILD_APPLICATION_COMMANDS_PERMISSIONS(this.applicationId, guildId, id), { permissions: options, @@ -335,7 +335,7 @@ export class Session extends EventEmitter { fetchApplicationCommand(id: Snowflake, options?: GetApplicationCommand): Promise { return this.rest.runMethod( this.rest, - "GET", + 'GET', options?.guildId ? Routes.GUILD_APPLICATION_COMMANDS_LOCALIZATIONS( this.applicationId, @@ -350,7 +350,7 @@ export class Session extends EventEmitter { fetchApplicationCommandPermissions(guildId: Snowflake): Promise { return this.rest.runMethod( this.rest, - "GET", + 'GET', Routes.GUILD_APPLICATION_COMMANDS_PERMISSIONS(this.applicationId, guildId), ); } @@ -361,7 +361,7 @@ export class Session extends EventEmitter { ): Promise { return this.rest.runMethod( this.rest, - "GET", + 'GET', Routes.GUILD_APPLICATION_COMMANDS_PERMISSIONS(this.applicationId, guildId, id), ); } @@ -373,7 +373,7 @@ export class Session extends EventEmitter { ): Promise { return this.rest.runMethod( this.rest, - "PATCH", + 'PATCH', guildId ? Routes.GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : Routes.APPLICATION_COMMANDS(this.applicationId, id), @@ -397,7 +397,7 @@ export class Session extends EventEmitter { ): Promise { return this.rest.runMethod( this.rest, - "PUT", + 'PUT', guildId ? Routes.GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : Routes.APPLICATION_COMMANDS(this.applicationId), @@ -420,7 +420,7 @@ export class Session extends EventEmitter { fetchCommands(guildId?: Snowflake): Promise { return this.rest.runMethod( this.rest, - "GET", + 'GET', guildId ? Routes.GUILD_APPLICATION_COMMANDS(this.applicationId, guildId) : Routes.APPLICATION_COMMANDS(this.applicationId), @@ -433,7 +433,7 @@ export class Session extends EventEmitter { } async start(): Promise { - const getGatewayBot = () => this.rest.runMethod(this.rest, "GET", Routes.GATEWAY_BOT()); + const getGatewayBot = () => this.rest.runMethod(this.rest, 'GET', Routes.GATEWAY_BOT()); // check if is empty if (!Object.keys(this.options.gateway?.data ?? {}).length) { diff --git a/packages/biscuit/Util.ts b/packages/biscuit/Util.ts index 484ab6f..bf83135 100644 --- a/packages/biscuit/Util.ts +++ b/packages/biscuit/Util.ts @@ -1,6 +1,6 @@ -import type { ButtonBuilder, InputTextBuilder, SelectMenuBuilder } from "./mod.ts"; -import type { Permissions } from "./structures/Permissions.ts"; -import type { Snowflake } from "./Snowflake.ts"; +import type { ButtonBuilder, InputTextBuilder, SelectMenuBuilder } from './mod.ts'; +import type { Permissions } from './structures/Permissions.ts'; +import type { Snowflake } from './Snowflake.ts'; /* * Represents a session's cache @@ -60,7 +60,7 @@ export interface PermissionsOverwrites { /** * @link https://discord.com/developers/docs/reference#image-formatting */ -export type ImageFormat = "jpg" | "jpeg" | "png" | "webp" | "gif" | "json"; +export type ImageFormat = 'jpg' | 'jpeg' | 'png' | 'webp' | 'gif' | 'json'; /** * @link https://discord.com/developers/docs/reference#image-formatting @@ -72,17 +72,17 @@ export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096; */ export class Util { static formatImageURL(url: string, size: ImageSize = 128, format?: ImageFormat) { - return `${url}.${format || (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`; + 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}`)); + return BigInt('0x' + (hash.startsWith('a_') ? `a${hash.substring(2)}` : `b${hash}`)); } static iconBigintToHash(icon: bigint) { const hash: string = icon.toString(16); - return hash.startsWith("a") ? `a_${hash.substring(1)}` : hash.substring(1); + return hash.startsWith('a') ? `a_${hash.substring(1)}` : hash.substring(1); } } diff --git a/packages/biscuit/mod.ts b/packages/biscuit/mod.ts index 190f223..26967bf 100644 --- a/packages/biscuit/mod.ts +++ b/packages/biscuit/mod.ts @@ -1,77 +1,77 @@ // structures -import { Session } from "./Session.ts"; +import { Session } from './Session.ts'; export default Session; -export * from "./structures/Application.ts"; -export * from "./structures/Attachment.ts"; -export * from "./structures/AutoModerationExecution.ts"; -export * from "./structures/AutoModerationRule.ts"; -export * from "./structures/Base.ts"; -export * from "./structures/Embed.ts"; -export * from "./structures/Emoji.ts"; -export * from "./structures/GuildEmoji.ts"; -export * from "./structures/GuildScheduledEvent.ts"; -export * from "./structures/Integration.ts"; -export * from "./structures/Invite.ts"; -export * from "./structures/Member.ts"; -export * from "./structures/Message.ts"; -export * from "./structures/MessageReaction.ts"; -export * from "./structures/Permissions.ts"; -export * from "./structures/Presence.ts"; -export * from "./structures/Role.ts"; -export * from "./structures/StageInstance.ts"; -export * from "./structures/Sticker.ts"; -export * from "./structures/ThreadMember.ts"; -export * from "./structures/User.ts"; -export * from "./structures/Webhook.ts"; -export * from "./structures/WelcomeChannel.ts"; -export * from "./structures/WelcomeScreen.ts"; +export * from './structures/Application.ts'; +export * from './structures/Attachment.ts'; +export * from './structures/AutoModerationExecution.ts'; +export * from './structures/AutoModerationRule.ts'; +export * from './structures/Base.ts'; +export * from './structures/Embed.ts'; +export * from './structures/Emoji.ts'; +export * from './structures/GuildEmoji.ts'; +export * from './structures/GuildScheduledEvent.ts'; +export * from './structures/Integration.ts'; +export * from './structures/Invite.ts'; +export * from './structures/Member.ts'; +export * from './structures/Message.ts'; +export * from './structures/MessageReaction.ts'; +export * from './structures/Permissions.ts'; +export * from './structures/Presence.ts'; +export * from './structures/Role.ts'; +export * from './structures/StageInstance.ts'; +export * from './structures/Sticker.ts'; +export * from './structures/ThreadMember.ts'; +export * from './structures/User.ts'; +export * from './structures/Webhook.ts'; +export * from './structures/WelcomeChannel.ts'; +export * from './structures/WelcomeScreen.ts'; // channels -export * from "./structures/channels.ts"; +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"; +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.ts"; +export * from './structures/guilds.ts'; // builders -export * from "./structures/builders/EmbedBuilder.ts"; -export * from "./structures/builders/components/InputTextComponentBuilder.ts"; -export * from "./structures/builders/components/MessageActionRow.ts"; -export * from "./structures/builders/components/MessageButton.ts"; -export * from "./structures/builders/components/MessageSelectMenu.ts"; -export * from "./structures/builders/components/SelectMenuOptionBuilder.ts"; -export * from "./structures/builders/slash/ApplicationCommand.ts"; -export * from "./structures/builders/slash/ApplicationCommandOption.ts"; +export * from './structures/builders/EmbedBuilder.ts'; +export * from './structures/builders/components/InputTextComponentBuilder.ts'; +export * from './structures/builders/components/MessageActionRow.ts'; +export * from './structures/builders/components/MessageButton.ts'; +export * from './structures/builders/components/MessageSelectMenu.ts'; +export * from './structures/builders/components/SelectMenuOptionBuilder.ts'; +export * from './structures/builders/slash/ApplicationCommand.ts'; +export * from './structures/builders/slash/ApplicationCommandOption.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"; +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'; // etc -export * from "./Snowflake.ts"; +export * from './Snowflake.ts'; // session -export * from "./Session.ts"; +export * from './Session.ts'; // util -export * from "./Util.ts"; -export * from "./util/urlToBase64.ts"; -export * from "./util/EventEmmiter.ts"; +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"; +export * as Routes from './Routes.ts'; +export * as Cdn from './Cdn.ts'; diff --git a/packages/biscuit/structures/Application.ts b/packages/biscuit/structures/Application.ts index 359a7aa..5ce0548 100644 --- a/packages/biscuit/structures/Application.ts +++ b/packages/biscuit/structures/Application.ts @@ -1,16 +1,16 @@ -import { Model } from "./Base.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; +import { Model } from './Base.ts'; +import type { Snowflake } from '../Snowflake.ts'; +import type { Session } from '../Session.ts'; import { DiscordApplication, DiscordInstallParams, DiscordTeam, DiscordUser, TeamMembershipStates, -} from "../../discordeno/mod.ts"; -import User from "./User.ts"; +} from '../../discordeno/mod.ts'; +import User from './User.ts'; -type SummaryDeprecated = ""; +type SummaryDeprecated = ''; export interface Team { /** a hash of the image of the team's icon */ @@ -28,11 +28,11 @@ export interface Team { export interface TeamMember { /** the user's membership state on the team */ membershipState: TeamMembershipStates; - permissions: "*"[]; + permissions: '*'[]; teamId: string; - user: Partial & Pick; + user: Partial & Pick; } // NewTeam create a new Team object for discord applications @@ -69,7 +69,7 @@ export class Application implements Model { this.termsOfServiceURL = data.terms_of_service_url; this.privacyPolicyURL = data.privacy_policy_url; this.owner = data.owner ? new User(session, data.owner as DiscordUser) : undefined; - this.summary = ""; + this.summary = ''; this.verifyKey = data.verify_key; this.team = data.team ? NewTeam(session, data.team) : undefined; this.guildId = data.guild_id; diff --git a/packages/biscuit/structures/Attachment.ts b/packages/biscuit/structures/Attachment.ts index cbad70a..a0f4a5a 100644 --- a/packages/biscuit/structures/Attachment.ts +++ b/packages/biscuit/structures/Attachment.ts @@ -1,7 +1,7 @@ -import type { Model } from "./Base.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; -import type { DiscordAttachment } from "../../discordeno/mod.ts"; +import type { Model } from './Base.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/packages/biscuit/structures/AutoModerationExecution.ts b/packages/biscuit/structures/AutoModerationExecution.ts index 6e2c7ab..845ae66 100644 --- a/packages/biscuit/structures/AutoModerationExecution.ts +++ b/packages/biscuit/structures/AutoModerationExecution.ts @@ -1,7 +1,7 @@ -import { AutoModerationTriggerTypes, DiscordAutoModerationActionExecution } from "../../discordeno/mod.ts"; -import type { Session } from "../Session.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import { AutoModerationAction } from "./AutoModerationRule.ts"; +import { AutoModerationTriggerTypes, DiscordAutoModerationActionExecution } from '../../discordeno/mod.ts'; +import type { Session } from '../Session.ts'; +import type { Snowflake } from '../Snowflake.ts'; +import { AutoModerationAction } from './AutoModerationRule.ts'; export class AutoModerationExecution { constructor(session: Session, data: DiscordAutoModerationActionExecution) { diff --git a/packages/biscuit/structures/AutoModerationRule.ts b/packages/biscuit/structures/AutoModerationRule.ts index a221d2a..3f15802 100644 --- a/packages/biscuit/structures/AutoModerationRule.ts +++ b/packages/biscuit/structures/AutoModerationRule.ts @@ -4,10 +4,10 @@ import { AutoModerationTriggerTypes, DiscordAutoModerationRule, DiscordAutoModerationRuleTriggerMetadataPresets, -} from "../../discordeno/mod.ts"; -import { Model } from "./Base.ts"; -import type { Session } from "../Session.ts"; -import type { Snowflake } from "../Snowflake.ts"; +} from '../../discordeno/mod.ts'; +import { Model } from './Base.ts'; +import type { Session } from '../Session.ts'; +import type { Snowflake } from '../Snowflake.ts'; export interface AutoModerationRuleTriggerMetadata { keywordFilter?: string[]; diff --git a/packages/biscuit/structures/Base.ts b/packages/biscuit/structures/Base.ts index efee6c5..fc21e7c 100644 --- a/packages/biscuit/structures/Base.ts +++ b/packages/biscuit/structures/Base.ts @@ -1,5 +1,5 @@ -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; +import type { Snowflake } from '../Snowflake.ts'; +import type { Session } from '../Session.ts'; /** * Represents a Discord data model diff --git a/packages/biscuit/structures/Embed.ts b/packages/biscuit/structures/Embed.ts index 2e0c867..96526c7 100644 --- a/packages/biscuit/structures/Embed.ts +++ b/packages/biscuit/structures/Embed.ts @@ -1,4 +1,4 @@ -import type { DiscordEmbed, EmbedTypes } from "../../discordeno/mod.ts"; +import type { DiscordEmbed, EmbedTypes } from '../../discordeno/mod.ts'; export interface Embed { title?: string; diff --git a/packages/biscuit/structures/Emoji.ts b/packages/biscuit/structures/Emoji.ts index 0d503b3..77b2406 100644 --- a/packages/biscuit/structures/Emoji.ts +++ b/packages/biscuit/structures/Emoji.ts @@ -1,6 +1,6 @@ -import type { Session } from "../Session.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { DiscordEmoji } from "../../discordeno/mod.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/packages/biscuit/structures/GuildEmoji.ts b/packages/biscuit/structures/GuildEmoji.ts index 15fb6af..f9b66ba 100644 --- a/packages/biscuit/structures/GuildEmoji.ts +++ b/packages/biscuit/structures/GuildEmoji.ts @@ -1,12 +1,12 @@ -import type { Model } from "./Base.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.ts"; -import Guild from "./guilds.ts"; -import Emoji from "./Emoji.ts"; -import User from "./User.ts"; -import * as Routes from "../Routes.ts"; +import type { Model } from './Base.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.ts'; +import Guild from './guilds.ts'; +import Emoji from './Emoji.ts'; +import User from './User.ts'; +import * as Routes from '../Routes.ts'; export class GuildEmoji extends Emoji implements Model { constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) { diff --git a/packages/biscuit/structures/GuildScheduledEvent.ts b/packages/biscuit/structures/GuildScheduledEvent.ts index d7f184a..5223a03 100644 --- a/packages/biscuit/structures/GuildScheduledEvent.ts +++ b/packages/biscuit/structures/GuildScheduledEvent.ts @@ -1,14 +1,14 @@ -import type { Model } from "./Base.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; -import { PrivacyLevels } from "./StageInstance.ts"; +import type { Model } from './Base.ts'; +import type { Snowflake } from '../Snowflake.ts'; +import type { Session } from '../Session.ts'; +import { PrivacyLevels } from './StageInstance.ts'; import type { DiscordScheduledEvent, DiscordScheduledEventEntityMetadata, ScheduledEventEntityType, ScheduledEventStatus, -} from "../../discordeno/mod.ts"; -import User from "./User.ts"; +} from '../../discordeno/mod.ts'; +import User from './User.ts'; export class ScheduledEvent implements Model { constructor(session: Session, data: DiscordScheduledEvent) { diff --git a/packages/biscuit/structures/Integration.ts b/packages/biscuit/structures/Integration.ts index f7bf481..183d008 100644 --- a/packages/biscuit/structures/Integration.ts +++ b/packages/biscuit/structures/Integration.ts @@ -1,8 +1,8 @@ -import type { Model } from "./Base.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"; +import type { Model } from './Base.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 { id: Snowflake; @@ -58,7 +58,7 @@ export class Integration implements Model { guildId?: Snowflake; name: string; - type: "twitch" | "youtube" | "discord"; + type: 'twitch' | 'youtube' | 'discord'; enabled?: boolean; syncing?: boolean; roleId?: string; diff --git a/packages/biscuit/structures/Invite.ts b/packages/biscuit/structures/Invite.ts index ce7824f..9715252 100644 --- a/packages/biscuit/structures/Invite.ts +++ b/packages/biscuit/structures/Invite.ts @@ -1,5 +1,5 @@ -import type { Session } from "../Session.ts"; -import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from '../Session.ts'; +import type { Snowflake } from '../Snowflake.ts'; import type { DiscordApplication, DiscordChannel, @@ -10,13 +10,13 @@ import type { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus, -} from "../../discordeno/mod.ts"; -import { TargetTypes } from "../../discordeno/mod.ts"; -import { GuildChannel } from "./channels.ts"; -import { Member } from "./Member.ts"; -import { Guild, InviteGuild } from "./guilds.ts"; -import User from "./User.ts"; -import Application from "./Application.ts"; +} from '../../discordeno/mod.ts'; +import { TargetTypes } from '../../discordeno/mod.ts'; +import { GuildChannel } from './channels.ts'; +import { Member } from './Member.ts'; +import { Guild, InviteGuild } from './guilds.ts'; +import User from './User.ts'; +import Application from './Application.ts'; export interface InviteStageInstance { /** The members speaking in the Stage */ @@ -101,7 +101,7 @@ export class Invite { this.targetType = data.target_type; if (data.channel) { - const guildId = (data.guild && data.guild?.id) ? data.guild.id : ""; + const guildId = (data.guild && data.guild?.id) ? data.guild.id : ''; this.channel = new GuildChannel(session, data.channel as DiscordChannel, guildId); } @@ -135,7 +135,7 @@ export class Invite { } if (data.stage_instance) { - const guildId = (data.guild && data.guild?.id) ? data.guild.id : ""; + const guildId = (data.guild && data.guild?.id) ? data.guild.id : ''; this.stageInstance = { members: data.stage_instance.members.map((m) => new Member(session, m as DiscordMemberWithUser, guildId) diff --git a/packages/biscuit/structures/Member.ts b/packages/biscuit/structures/Member.ts index 7cfe4e1..4329241 100644 --- a/packages/biscuit/structures/Member.ts +++ b/packages/biscuit/structures/Member.ts @@ -1,13 +1,13 @@ -import type { Model } from "./Base.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.ts"; -import { Guild } from "./guilds.ts"; -import Util from "../Util.ts"; -import User from "./User.ts"; -import * as Routes from "../Routes.ts"; +import type { Model } from './Base.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.ts'; +import { Guild } from './guilds.ts'; +import Util from '../Util.ts'; +import User from './User.ts'; +import * as Routes from '../Routes.ts'; /** * @link https://discord.com/developers/docs/resources/guild#guild-member-object diff --git a/packages/biscuit/structures/Message.ts b/packages/biscuit/structures/Message.ts index 1e40600..fbb071e 100644 --- a/packages/biscuit/structures/Message.ts +++ b/packages/biscuit/structures/Message.ts @@ -1,5 +1,5 @@ -import type { Model } from "./Base.ts"; -import type { Session } from "../Session.ts"; +import type { Model } from './Base.ts'; +import type { Session } from '../Session.ts'; import type { AllowedMentionsTypes, DiscordEmbed, @@ -9,24 +9,24 @@ import type { FileContent, MessageActivityTypes, MessageTypes, -} from "../../discordeno/mod.ts"; -import type { Channel } from "./channels.ts"; -import type { Component } from "./components/Component.ts"; -import type { GetReactions } from "../Routes.ts"; -import type { MessageInteraction } from "./interactions/InteractionFactory.ts"; -import { MessageFlags } from "../Util.ts"; -import { Snowflake } from "../Snowflake.ts"; -import { ChannelFactory, 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 Application, { NewTeam } from "./Application.ts"; -import InteractionFactory from "./interactions/InteractionFactory.ts"; -import * as Routes from "../Routes.ts"; -import { StickerItem } from "./Sticker.ts"; +} from '../../discordeno/mod.ts'; +import type { Channel } from './channels.ts'; +import type { Component } from './components/Component.ts'; +import type { GetReactions } from '../Routes.ts'; +import type { MessageInteraction } from './interactions/InteractionFactory.ts'; +import { MessageFlags } from '../Util.ts'; +import { Snowflake } from '../Snowflake.ts'; +import { ChannelFactory, 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 Application, { NewTeam } from './Application.ts'; +import InteractionFactory from './interactions/InteractionFactory.ts'; +import * as Routes from '../Routes.ts'; +import { StickerItem } from './Sticker.ts'; /** * @link https://discord.com/developers/docs/resources/channel#allowed-mentions-object @@ -137,7 +137,7 @@ export class Message implements Model { } // webhook handling - if (data.webhook_id && data.author.discriminator === "0000") { + if (data.webhook_id && data.author.discriminator === '0000') { this.webhook = { id: data.webhook_id!, username: data.author.username, @@ -322,7 +322,7 @@ export class Message implements Model { /** gets the url of the message that points to the message */ get url(): string { - return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`; + return `https://discord.com/channels/${this.guildId ?? '@me'}/${this.channelId}/${this.id}`; } /** @@ -339,7 +339,7 @@ export class Message implements Model { async pin(): Promise { await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.CHANNEL_PIN(this.channelId, this.id), ); } @@ -350,7 +350,7 @@ export class Message implements Model { async unpin(): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.CHANNEL_PIN(this.channelId, this.id), ); } @@ -359,7 +359,7 @@ export class Message implements Model { async edit(options: EditMessage): Promise { const message = await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.CHANNEL_MESSAGE(this.id, this.channelId), { content: options.content, @@ -394,7 +394,7 @@ export class Message implements Model { async delete({ reason }: { reason: string }): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.CHANNEL_MESSAGE(this.channelId, this.id), { reason }, ); @@ -406,7 +406,7 @@ export class Message implements Model { async reply(options: CreateMessage): Promise { const message = await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.CHANNEL_MESSAGES(this.channelId), { content: options.content, @@ -441,11 +441,11 @@ export class Message implements Model { /** adds a Reaction */ async addReaction(reaction: EmojiResolvable): Promise { - const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + const r = typeof reaction === 'string' ? reaction : `${reaction.name}:${reaction.id}`; await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.CHANNEL_MESSAGE_REACTION_ME(this.channelId, this.id, r), {}, ); @@ -453,11 +453,11 @@ export class Message implements Model { /** removes a reaction from someone */ async removeReaction(reaction: EmojiResolvable, options?: { userId: Snowflake }): Promise { - const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + const r = typeof reaction === 'string' ? reaction : `${reaction.name}:${reaction.id}`; await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', options?.userId ? Routes.CHANNEL_MESSAGE_REACTION_USER( this.channelId, @@ -474,11 +474,11 @@ export class Message implements Model { * not recommended since the cache handles reactions already */ async fetchReactions(reaction: EmojiResolvable, options?: GetReactions): Promise { - const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + const r = typeof reaction === 'string' ? reaction : `${reaction.name}:${reaction.id}`; const users = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.CHANNEL_MESSAGE_REACTION(this.channelId, this.id, encodeURIComponent(r), options), ); @@ -489,11 +489,11 @@ export class Message implements Model { * same as Message.removeReaction but removes using a unicode emoji */ async removeReactionEmoji(reaction: EmojiResolvable): Promise { - const r = typeof reaction === "string" ? reaction : `${reaction.name}:${reaction.id}`; + const r = typeof reaction === 'string' ? reaction : `${reaction.name}:${reaction.id}`; await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.CHANNEL_MESSAGE_REACTION(this.channelId, this.id, r), ); } @@ -502,7 +502,7 @@ export class Message implements Model { async nukeReactions(): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.CHANNEL_MESSAGE_REACTIONS(this.channelId, this.id), ); } @@ -511,7 +511,7 @@ export class Message implements Model { async crosspost(): Promise { const message = await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.CHANNEL_MESSAGE_CROSSPOST(this.channelId, this.id), ); @@ -522,7 +522,7 @@ export class Message implements Model { async fetch(): Promise<(Message | undefined)> { const message = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.CHANNEL_MESSAGE(this.channelId, this.id), ); diff --git a/packages/biscuit/structures/MessageReaction.ts b/packages/biscuit/structures/MessageReaction.ts index 809360e..38458a6 100644 --- a/packages/biscuit/structures/MessageReaction.ts +++ b/packages/biscuit/structures/MessageReaction.ts @@ -1,8 +1,8 @@ // deno-lint-ignore-file no-empty-interface -import type { Session } from "../Session.ts"; -import type { DiscordMemberWithUser, DiscordMessageReactionAdd, DiscordReaction } from "../../discordeno/mod.ts"; -import Emoji from "./Emoji.ts"; -import Member from "./Member.ts"; +import type { Session } from '../Session.ts'; +import type { DiscordMemberWithUser, DiscordMessageReactionAdd, DiscordReaction } from '../../discordeno/mod.ts'; +import Emoji from './Emoji.ts'; +import Member from './Member.ts'; export interface MessageReactionAdd { userId: string; @@ -13,13 +13,13 @@ export interface MessageReactionAdd { emoji: Partial; } -export interface MessageReactionRemove extends Omit {} +export interface MessageReactionRemove extends Omit {} -export interface MessageReactionRemoveAll extends Pick {} +export interface MessageReactionRemoveAll extends Pick {} export type MessageReactionRemoveEmoji = Pick< MessageReactionAdd, - "channelId" | "guildId" | "messageId" | "emoji" + 'channelId' | 'guildId' | 'messageId' | 'emoji' >; export function NewMessageReactionAdd(session: Session, data: DiscordMessageReactionAdd): MessageReactionAdd { @@ -29,7 +29,7 @@ export function NewMessageReactionAdd(session: Session, data: DiscordMessageReac messageId: data.message_id, guildId: data.guild_id, member: data.member - ? new Member(session, data.member as DiscordMemberWithUser, data.guild_id || "") + ? new Member(session, data.member as DiscordMemberWithUser, data.guild_id || '') : undefined, emoji: new Emoji(session, data.emoji), }; diff --git a/packages/biscuit/structures/Permissions.ts b/packages/biscuit/structures/Permissions.ts index dd254ea..be76069 100644 --- a/packages/biscuit/structures/Permissions.ts +++ b/packages/biscuit/structures/Permissions.ts @@ -1,4 +1,4 @@ -import { BitwisePermissionFlags } from "../../discordeno/mod.ts"; +import { BitwisePermissionFlags } from '../../discordeno/mod.ts'; export type PermissionString = keyof typeof BitwisePermissionFlags; export type PermissionResolvable = @@ -25,13 +25,13 @@ export class Permissions { static resolve(bit: PermissionResolvable): bigint { switch (typeof bit) { - case "bigint": + case 'bigint': return bit; - case "number": + case 'number': return BigInt(bit); - case "string": + case 'string': return BigInt(Permissions.Flags[bit]); - case "object": + case 'object': return Permissions.resolve( bit.map((p) => BigInt(Permissions.Flags[p])).reduce((acc, cur) => acc | cur, 0n), ); diff --git a/packages/biscuit/structures/Presence.ts b/packages/biscuit/structures/Presence.ts index 31dfea2..3909d78 100644 --- a/packages/biscuit/structures/Presence.ts +++ b/packages/biscuit/structures/Presence.ts @@ -4,11 +4,11 @@ import type { DiscordActivitySecrets, DiscordClientStatus, DiscordPresenceUpdate, -} from "../../discordeno/mod.ts"; -import type { Session } from "../Session.ts"; -import { User } from "./User.ts"; -import { Snowflake } from "../Snowflake.ts"; -import type { ComponentEmoji } from "../Util.ts"; +} from '../../discordeno/mod.ts'; +import type { Session } from '../Session.ts'; +import { User } from './User.ts'; +import { Snowflake } from '../Snowflake.ts'; +import type { ComponentEmoji } from '../Util.ts'; export interface ActivityAssets { largeImage?: string; diff --git a/packages/biscuit/structures/Role.ts b/packages/biscuit/structures/Role.ts index 65e5c13..00d57f8 100644 --- a/packages/biscuit/structures/Role.ts +++ b/packages/biscuit/structures/Role.ts @@ -1,10 +1,10 @@ -import type { Model } from "./Base.ts"; -import type { DiscordRole } from "../../discordeno/mod.ts"; -import type { Session } from "../Session.ts"; -import { Snowflake } from "../Snowflake.ts"; -import { Guild, type ModifyGuildRole } from "./guilds.ts"; -import Permissions from "./Permissions.ts"; -import Util from "../Util.ts"; +import type { Model } from './Base.ts'; +import type { DiscordRole } from '../../discordeno/mod.ts'; +import type { Session } from '../Session.ts'; +import { Snowflake } from '../Snowflake.ts'; +import { Guild, type ModifyGuildRole } from './guilds.ts'; +import Permissions from './Permissions.ts'; +import Util from '../Util.ts'; export class Role implements Model { constructor(session: Session, data: DiscordRole, guildId: Snowflake) { @@ -44,7 +44,7 @@ export class Role implements Model { } get hexColor(): string { - return `#${this.color.toString(16).padStart(6, "0")}`; + return `#${this.color.toString(16).padStart(6, '0')}`; } async delete(): Promise { @@ -67,7 +67,7 @@ export class Role implements Model { toString(): string { switch (this.id) { case this.guildId: - return "@everyone"; + return '@everyone'; default: return `<@&${this.id}>`; } diff --git a/packages/biscuit/structures/StageInstance.ts b/packages/biscuit/structures/StageInstance.ts index 2b58a04..0dbd52e 100644 --- a/packages/biscuit/structures/StageInstance.ts +++ b/packages/biscuit/structures/StageInstance.ts @@ -1,8 +1,8 @@ -import type { Model } from "./Base.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"; +import type { Model } from './Base.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'; export interface DiscordStageInstanceB extends DiscordAutoClosingStageInstance { privacy_level: PrivacyLevels; @@ -42,7 +42,7 @@ export class StageInstance implements Model { async edit(options: { topic?: string; privacyLevel?: PrivacyLevels }): Promise { const stageInstance = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', Routes.STAGE_INSTANCE(this.id), { topic: options.topic, @@ -54,7 +54,7 @@ export class StageInstance implements Model { } async delete(): Promise { - await this.session.rest.runMethod(this.session.rest, "DELETE", Routes.STAGE_INSTANCE(this.id)); + await this.session.rest.runMethod(this.session.rest, 'DELETE', Routes.STAGE_INSTANCE(this.id)); } } diff --git a/packages/biscuit/structures/Sticker.ts b/packages/biscuit/structures/Sticker.ts index 5e92128..0587a67 100644 --- a/packages/biscuit/structures/Sticker.ts +++ b/packages/biscuit/structures/Sticker.ts @@ -1,9 +1,9 @@ -import type { DiscordSticker, DiscordStickerPack, StickerFormatTypes, StickerTypes } from "../../discordeno/mod.ts"; -import type { Model } from "./Base.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; -import { User } from "./User.ts"; -import * as Routes from "../Routes.ts"; +import type { DiscordSticker, DiscordStickerPack, StickerFormatTypes, StickerTypes } from '../../discordeno/mod.ts'; +import type { Model } from './Base.ts'; +import type { Snowflake } from '../Snowflake.ts'; +import type { Session } from '../Session.ts'; +import { User } from './User.ts'; +import * as Routes from '../Routes.ts'; export interface StickerItem { id: Snowflake; @@ -28,7 +28,7 @@ export class Sticker implements Model { this.packId = data.pack_id; this.name = data.name; this.description = data.description; - this.tags = data.tags.split(","); + this.tags = data.tags.split(','); this.type = data.type; this.formatType = data.format_type; this.available = !!data.available; @@ -52,7 +52,7 @@ export class Sticker implements Model { async fetchPremiumPack(): Promise { const data = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.STICKER_PACKS(), ); return { diff --git a/packages/biscuit/structures/ThreadMember.ts b/packages/biscuit/structures/ThreadMember.ts index 20bcddc..7e8af7d 100644 --- a/packages/biscuit/structures/ThreadMember.ts +++ b/packages/biscuit/structures/ThreadMember.ts @@ -1,8 +1,8 @@ -import type { Model } from "./Base.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"; +import type { Model } from './Base.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 @@ -28,7 +28,7 @@ export class ThreadMember implements Model { async quitThread(memberId: Snowflake = this.session.botId): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.THREAD_USER(this.id, memberId), ); } @@ -36,7 +36,7 @@ export class ThreadMember implements Model { async fetchMember(memberId: Snowflake = this.session.botId): Promise { const member = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.THREAD_USER(this.id, memberId), ); diff --git a/packages/biscuit/structures/User.ts b/packages/biscuit/structures/User.ts index d0b7de9..090d491 100644 --- a/packages/biscuit/structures/User.ts +++ b/packages/biscuit/structures/User.ts @@ -1,10 +1,10 @@ -import type { Model } from "./Base.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; -import type { DiscordUser, PremiumTypes, UserFlags } from "../../discordeno/mod.ts"; -import type { ImageFormat, ImageSize } from "../Util.ts"; -import Util from "../Util.ts"; -import * as Routes from "../Routes.ts"; +import type { Model } from './Base.ts'; +import type { Snowflake } from '../Snowflake.ts'; +import type { Session } from '../Session.ts'; +import type { DiscordUser, PremiumTypes, UserFlags } from '../../discordeno/mod.ts'; +import type { ImageFormat, ImageSize } from '../Util.ts'; +import Util from '../Util.ts'; +import * as Routes from '../Routes.ts'; /** * @link https://discord.com/developers/docs/resources/user#user-object diff --git a/packages/biscuit/structures/Webhook.ts b/packages/biscuit/structures/Webhook.ts index 1d38dd1..a56d651 100644 --- a/packages/biscuit/structures/Webhook.ts +++ b/packages/biscuit/structures/Webhook.ts @@ -1,6 +1,6 @@ -import type { Model } from "./Base.ts"; -import type { Session } from "../Session.ts"; -import type { Snowflake } from "../Snowflake.ts"; +import type { Model } from './Base.ts'; +import type { Session } from '../Session.ts'; +import type { Snowflake } from '../Snowflake.ts'; import type { DiscordEmbed, DiscordMessage, @@ -8,14 +8,14 @@ import type { DiscordWebhook, FileContent, WebhookTypes, -} from "../../discordeno/mod.ts"; -import type { WebhookOptions } from "../Routes.ts"; -import type { Attachment } from "./Attachment.ts"; -import type { AllowedMentions, CreateMessage } from "./Message.ts"; -import Util from "../Util.ts"; -import User from "./User.ts"; -import Message from "./Message.ts"; -import * as Routes from "../Routes.ts"; +} from '../../discordeno/mod.ts'; +import type { WebhookOptions } from '../Routes.ts'; +import type { Attachment } from './Attachment.ts'; +import type { AllowedMentions, CreateMessage } from './Message.ts'; +import Util from '../Util.ts'; +import User from './User.ts'; +import Message from './Message.ts'; +import * as Routes from '../Routes.ts'; /** * @link https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params @@ -88,9 +88,9 @@ export class Webhook implements Model { wait: options?.wait, threadId: options?.threadId, }), - method: "POST", + method: 'POST', payload: this.session.rest.createRequestBody(this.session.rest, { - method: "POST", + method: 'POST', body: { ...data, }, @@ -103,7 +103,7 @@ export class Webhook implements Model { async fetch(): Promise { const message = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.WEBHOOK_TOKEN(this.id, this.token), ); @@ -117,7 +117,7 @@ export class Webhook implements Model { const message = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.WEBHOOK_MESSAGE(this.id, this.token, messageId, options), ); @@ -126,12 +126,12 @@ export class Webhook implements Model { async deleteMessage(messageId: Snowflake, options?: { threadId?: Snowflake }): Promise { if (!this.token) { - throw new Error("No token found"); + throw new Error('No token found'); } await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.WEBHOOK_MESSAGE(this.id, this.token, messageId, options), ); } @@ -141,12 +141,12 @@ export class Webhook implements Model { options?: EditWebhookMessage & { threadId?: Snowflake }, ): Promise { if (!this.token) { - throw new Error("No token found"); + throw new Error('No token found'); } const message = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', messageId ? Routes.WEBHOOK_MESSAGE(this.id, this.token, messageId) : Routes.WEBHOOK_MESSAGE_ORIGINAL(this.id, this.token), diff --git a/packages/biscuit/structures/WelcomeChannel.ts b/packages/biscuit/structures/WelcomeChannel.ts index d8ae04d..ef604f6 100644 --- a/packages/biscuit/structures/WelcomeChannel.ts +++ b/packages/biscuit/structures/WelcomeChannel.ts @@ -1,8 +1,8 @@ -import type { Model } from "./Base.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"; +import type { Model } from './Base.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'; /** * Not a channel diff --git a/packages/biscuit/structures/WelcomeScreen.ts b/packages/biscuit/structures/WelcomeScreen.ts index 6aca4fc..01c9250 100644 --- a/packages/biscuit/structures/WelcomeScreen.ts +++ b/packages/biscuit/structures/WelcomeScreen.ts @@ -1,6 +1,6 @@ -import type { Session } from "../Session.ts"; -import type { DiscordWelcomeScreen } from "../../discordeno/mod.ts"; -import WelcomeChannel from "./WelcomeChannel.ts"; +import type { Session } from '../Session.ts'; +import type { DiscordWelcomeScreen } from '../../discordeno/mod.ts'; +import WelcomeChannel from './WelcomeChannel.ts'; /** * @link https://discord.com/developers/docs/resources/guild#welcome-screen-object diff --git a/packages/biscuit/structures/builders/EmbedBuilder.ts b/packages/biscuit/structures/builders/EmbedBuilder.ts index 661ea2b..d95455f 100644 --- a/packages/biscuit/structures/builders/EmbedBuilder.ts +++ b/packages/biscuit/structures/builders/EmbedBuilder.ts @@ -1,4 +1,4 @@ -import type { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from "../../../discordeno/mod.ts"; +import type { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from '../../../discordeno/mod.ts'; export interface EmbedFooter { text: string; diff --git a/packages/biscuit/structures/builders/components/InputTextComponentBuilder.ts b/packages/biscuit/structures/builders/components/InputTextComponentBuilder.ts index 9e94b10..0daa5b0 100644 --- a/packages/biscuit/structures/builders/components/InputTextComponentBuilder.ts +++ b/packages/biscuit/structures/builders/components/InputTextComponentBuilder.ts @@ -1,4 +1,4 @@ -import type { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from "../../../../discordeno/mod.ts"; +import type { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from '../../../../discordeno/mod.ts'; export class InputTextBuilder { constructor() { diff --git a/packages/biscuit/structures/builders/components/MessageActionRow.ts b/packages/biscuit/structures/builders/components/MessageActionRow.ts index 796d53d..3217988 100644 --- a/packages/biscuit/structures/builders/components/MessageActionRow.ts +++ b/packages/biscuit/structures/builders/components/MessageActionRow.ts @@ -1,5 +1,5 @@ -import type { DiscordActionRow, MessageComponentTypes } from "../../../../discordeno/mod.ts"; -import type { ComponentBuilder } from "../../../Util.ts"; +import type { DiscordActionRow, MessageComponentTypes } from '../../../../discordeno/mod.ts'; +import type { ComponentBuilder } from '../../../Util.ts'; export class ActionRowBuilder { constructor() { @@ -26,7 +26,7 @@ export class ActionRowBuilder { toJSON(): DiscordActionRow { return { type: this.type, - components: this.components.map((c) => c.toJSON()) as DiscordActionRow["components"], + components: this.components.map((c) => c.toJSON()) as DiscordActionRow['components'], }; } } diff --git a/packages/biscuit/structures/builders/components/MessageButton.ts b/packages/biscuit/structures/builders/components/MessageButton.ts index 6f1c64f..3721f69 100644 --- a/packages/biscuit/structures/builders/components/MessageButton.ts +++ b/packages/biscuit/structures/builders/components/MessageButton.ts @@ -1,5 +1,5 @@ -import { type ButtonStyles, type DiscordButtonComponent, MessageComponentTypes } from "../../../../discordeno/mod.ts"; -import type { ComponentEmoji } from "../../../Util.ts"; +import { type ButtonStyles, type DiscordButtonComponent, MessageComponentTypes } from '../../../../discordeno/mod.ts'; +import type { ComponentEmoji } from '../../../Util.ts'; export class ButtonBuilder { constructor() { diff --git a/packages/biscuit/structures/builders/components/MessageSelectMenu.ts b/packages/biscuit/structures/builders/components/MessageSelectMenu.ts index a612ff5..f932cd5 100644 --- a/packages/biscuit/structures/builders/components/MessageSelectMenu.ts +++ b/packages/biscuit/structures/builders/components/MessageSelectMenu.ts @@ -1,5 +1,5 @@ -import { type DiscordSelectMenuComponent, MessageComponentTypes } from "../../../../discordeno/mod.ts"; -import type { 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/packages/biscuit/structures/builders/components/SelectMenuOptionBuilder.ts b/packages/biscuit/structures/builders/components/SelectMenuOptionBuilder.ts index 4a5d1c9..561c98b 100644 --- a/packages/biscuit/structures/builders/components/SelectMenuOptionBuilder.ts +++ b/packages/biscuit/structures/builders/components/SelectMenuOptionBuilder.ts @@ -1,5 +1,5 @@ -import type { DiscordSelectOption } from "../../../../discordeno/mod.ts"; -import type { ComponentEmoji } from "../../../Util.ts"; +import type { DiscordSelectOption } from '../../../../discordeno/mod.ts'; +import type { ComponentEmoji } from '../../../Util.ts'; export class SelectMenuOptionBuilder { constructor() { diff --git a/packages/biscuit/structures/builders/slash/ApplicationCommand.ts b/packages/biscuit/structures/builders/slash/ApplicationCommand.ts index 18bac82..204d1e8 100644 --- a/packages/biscuit/structures/builders/slash/ApplicationCommand.ts +++ b/packages/biscuit/structures/builders/slash/ApplicationCommand.ts @@ -1,13 +1,13 @@ -import type { Localization, PermissionStrings } from "../../../../discordeno/mod.ts"; -import { ApplicationCommandTypes } from "../../../../discordeno/mod.ts"; -import { OptionBased } from "./ApplicationCommandOption.ts"; -import { CreateApplicationCommand } from "../../../Session.ts"; +import type { Localization, PermissionStrings } from '../../../../discordeno/mod.ts'; +import { ApplicationCommandTypes } from '../../../../discordeno/mod.ts'; +import { OptionBased } from './ApplicationCommandOption.ts'; +import { CreateApplicationCommand } from '../../../Session.ts'; export abstract class ApplicationCommandBuilder implements CreateApplicationCommand { constructor( type: ApplicationCommandTypes = ApplicationCommandTypes.ChatInput, - name: string = "", - description: string = "", + name: string = '', + description: string = '', defaultMemberPermissions?: PermissionStrings[], nameLocalizations?: Localization, descriptionLocalizations?: Localization, @@ -74,7 +74,7 @@ export class MessageApplicationCommandBuilder { } toJSON(): { name: string; type: ApplicationCommandTypes.Message } { - if (!this.name) throw new TypeError("Propety 'name' is required"); + if (!this.name) throw new TypeError('Propety \'name\' is required'); return { type: ApplicationCommandTypes.Message, @@ -87,10 +87,10 @@ export class ChatInputApplicationCommandBuilder extends ApplicationCommandBuilde type: ApplicationCommandTypes.ChatInput = ApplicationCommandTypes.ChatInput; toJSON(): CreateApplicationCommand { - if (!this.type) throw new TypeError("Propety 'type' is required"); - if (!this.name) throw new TypeError("Propety 'name' is required"); + if (!this.type) throw new TypeError('Propety \'type\' is required'); + if (!this.name) throw new TypeError('Propety \'name\' is required'); if (!this.description) { - throw new TypeError("Propety 'description' is required"); + throw new TypeError('Propety \'description\' is required'); } return { diff --git a/packages/biscuit/structures/builders/slash/ApplicationCommandOption.ts b/packages/biscuit/structures/builders/slash/ApplicationCommandOption.ts index 4aa3286..24864b7 100644 --- a/packages/biscuit/structures/builders/slash/ApplicationCommandOption.ts +++ b/packages/biscuit/structures/builders/slash/ApplicationCommandOption.ts @@ -1,5 +1,5 @@ -import { ApplicationCommandOptionTypes, type ChannelTypes, type Localization } from "../../../../discordeno/mod.ts"; -import { ApplicationCommandOptionChoice } from "../../interactions/BaseInteraction.ts"; +import { ApplicationCommandOptionTypes, type ChannelTypes, type Localization } from '../../../../discordeno/mod.ts'; +import { ApplicationCommandOptionChoice } from '../../interactions/BaseInteraction.ts'; export class ChoiceBuilder { name?: string; @@ -16,8 +16,8 @@ export class ChoiceBuilder { } toJSON(): ApplicationCommandOptionChoice { - if (!this.name) throw new TypeError("Property 'name' is required"); - if (!this.value) throw new TypeError("Property 'value' is required"); + if (!this.name) throw new TypeError('Property \'name\' is required'); + if (!this.value) throw new TypeError('Property \'value\' is required'); return { name: this.name, @@ -56,10 +56,10 @@ export class OptionBuilder { } toJSON(): ApplicationCommandOption { - if (!this.type) throw new TypeError("Property 'type' is required"); - if (!this.name) throw new TypeError("Property 'name' is required"); + if (!this.type) throw new TypeError('Property \'type\' is required'); + if (!this.name) throw new TypeError('Property \'name\' is required'); if (!this.description) { - throw new TypeError("Property 'description' is required"); + throw new TypeError('Property \'description\' is required'); } const applicationCommandOption: ApplicationCommandOption = { @@ -261,18 +261,18 @@ export class OptionBased { // deno-lint-ignore ban-types static applyTo(klass: Function, ignore: Array = []): void { const methods: Array = [ - "addOption", - "addNestedOption", - "addStringOption", - "addIntegerOption", - "addNumberOption", - "addBooleanOption", - "addSubCommand", - "addSubCommandGroup", - "addUserOption", - "addChannelOption", - "addRoleOption", - "addMentionableOption", + 'addOption', + 'addNestedOption', + 'addStringOption', + 'addIntegerOption', + 'addNumberOption', + 'addBooleanOption', + 'addSubCommand', + 'addSubCommandGroup', + 'addUserOption', + 'addChannelOption', + 'addRoleOption', + 'addMentionableOption', ]; for (const method of methods) { @@ -296,10 +296,10 @@ export class OptionBuilderNested extends OptionBuilder { } override toJSON(): ApplicationCommandOption { - if (!this.type) throw new TypeError("Property 'type' is required"); - if (!this.name) throw new TypeError("Property 'name' is required"); + if (!this.type) throw new TypeError('Property \'type\' is required'); + if (!this.name) throw new TypeError('Property \'name\' is required'); if (!this.description) { - throw new TypeError("Property 'description' is required"); + throw new TypeError('Property \'description\' is required'); } return { diff --git a/packages/biscuit/structures/channels.ts b/packages/biscuit/structures/channels.ts index 1bfc048..aaa1dd3 100644 --- a/packages/biscuit/structures/channels.ts +++ b/packages/biscuit/structures/channels.ts @@ -1,8 +1,8 @@ /** Types */ -import type { Model } from "./Base.ts"; -import type { Snowflake } from "../Snowflake.ts"; -import type { Session } from "../Session.ts"; -import type { PermissionsOverwrites } from "../Util.ts"; +import type { Model } from './Base.ts'; +import type { Snowflake } from '../Snowflake.ts'; +import type { Session } from '../Session.ts'; +import type { PermissionsOverwrites } from '../Util.ts'; /** External from vendor */ import { @@ -17,19 +17,19 @@ import { GatewayOpcodes, TargetTypes, VideoQualityModes, -} from "../../discordeno/mod.ts"; +} from '../../discordeno/mod.ts'; /** Functions and others */ -import { calculateShardId } from "../../discordeno/gateway/calculateShardId.ts"; -import { urlToBase64 } from "../util/urlToBase64.ts"; +import { calculateShardId } from '../../discordeno/gateway/calculateShardId.ts'; +import { urlToBase64 } from '../util/urlToBase64.ts'; /** Classes and routes */ -import * as Routes from "../Routes.ts"; -import Message, { CreateMessage, EditMessage, EmojiResolvable } from "./Message.ts"; -import Invite from "./Invite.ts"; -import Webhook from "./Webhook.ts"; -import User from "./User.ts"; -import ThreadMember from "./ThreadMember.ts"; +import * as Routes from '../Routes.ts'; +import Message, { CreateMessage, EditMessage, EmojiResolvable } from './Message.ts'; +import Invite from './Invite.ts'; +import Webhook from './Webhook.ts'; +import User from './User.ts'; +import ThreadMember from './ThreadMember.ts'; export abstract class BaseChannel implements Model { constructor(session: Session, data: DiscordChannel) { @@ -147,19 +147,19 @@ export class TextChannel { // deno-lint-ignore ban-types static applyTo(klass: Function, ignore: Array = []): void { const methods: Array = [ - "fetchPins", - "createInvite", - "fetchMessages", - "sendTyping", - "pinMessage", - "unpinMessage", - "addReaction", - "removeReaction", - "nukeReactions", - "fetchPins", - "sendMessage", - "editMessage", - "createWebhook", + 'fetchPins', + 'createInvite', + 'fetchMessages', + 'sendTyping', + 'pinMessage', + 'unpinMessage', + 'addReaction', + 'removeReaction', + 'nukeReactions', + 'fetchPins', + 'sendMessage', + 'editMessage', + 'createWebhook', ]; for (const method of methods) { @@ -172,7 +172,7 @@ export class TextChannel { async fetchPins(): Promise { const messages = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.CHANNEL_PINS(this.id), ); return messages[0] ? messages.map((x: DiscordMessage) => new Message(this.session, x)) : []; @@ -181,7 +181,7 @@ export class TextChannel { async createInvite(options?: DiscordInviteOptions): Promise { const invite = await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.CHANNEL_INVITES(this.id), options ? { @@ -200,10 +200,10 @@ export class TextChannel { } async fetchMessages(options?: Routes.GetMessagesOptions): Promise { - if (options?.limit! > 100) throw Error("Values must be between 0-100"); + if (options?.limit! > 100) throw Error('Values must be between 0-100'); const messages = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.CHANNEL_MESSAGES(this.id, options), ); return messages[0] ? messages.map((x) => new Message(this.session, x)) : []; @@ -212,7 +212,7 @@ export class TextChannel { async sendTyping(): Promise { await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.CHANNEL_TYPING(this.id), ); } @@ -280,7 +280,7 @@ export class TextChannel { async createWebhook(options: CreateWebhook): Promise { const webhook = await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.CHANNEL_WEBHOOKS(this.id), { name: options.name, @@ -379,7 +379,7 @@ export class GuildChannel extends BaseChannel implements Model { async fetchInvites(): Promise { const invites = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.CHANNEL_INVITES(this.id), ); @@ -394,22 +394,22 @@ export class GuildChannel extends BaseChannel implements Model { ): Promise { const channel = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', Routes.CHANNEL(this.id), { name: options.name, - type: "type" in options ? options.type : undefined, + 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, + 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 + 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, }, @@ -418,25 +418,25 @@ export class GuildChannel extends BaseChannel implements Model { } async getArchivedThreads( - options: Routes.ListArchivedThreads & { type: "public" | "private" | "privateJoinedThreads" }, + options: Routes.ListArchivedThreads & { type: 'public' | 'private' | 'privateJoinedThreads' }, ): Promise { let func: (channelId: Snowflake, options: Routes.ListArchivedThreads) => string; switch (options.type) { - case "public": + case 'public': func = Routes.THREAD_ARCHIVED_PUBLIC; break; - case "private": + case 'private': func = Routes.THREAD_START_PRIVATE; break; - case "privateJoinedThreads": + case 'privateJoinedThreads': func = Routes.THREAD_ARCHIVED_PRIVATE_JOINED; break; } const { threads, members, has_more } = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', func(this.id, options), ); @@ -454,8 +454,8 @@ export class GuildChannel extends BaseChannel implements Model { async createThread(options: ThreadCreateOptions): Promise { const thread = await this.session.rest.runMethod( this.session.rest, - "POST", - "messageId" in options + 'POST', + 'messageId' in options ? Routes.THREAD_START_PUBLIC(this.id, options.messageId) : Routes.THREAD_START_PRIVATE(this.id), { @@ -541,7 +541,7 @@ export class DMChannel extends BaseChannel implements Model { async close(): Promise { const channel = await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.CHANNEL(this.id), ); @@ -549,7 +549,7 @@ export class DMChannel extends BaseChannel implements Model { } } -export interface DMChannel extends Omit, Omit {} +export interface DMChannel extends Omit, Omit {} TextChannel.applyTo(DMChannel); @@ -632,7 +632,7 @@ export class ThreadChannel extends GuildChannel implements Model { async joinThread(): Promise { await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.THREAD_ME(this.id), ); } @@ -640,7 +640,7 @@ export class ThreadChannel extends GuildChannel implements Model { async addToThread(guildMemberId: Snowflake): Promise { await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.THREAD_USER(this.id, guildMemberId), ); } @@ -648,7 +648,7 @@ export class ThreadChannel extends GuildChannel implements Model { async leaveToThread(guildMemberId: Snowflake): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.THREAD_USER(this.id, guildMemberId), ); } @@ -664,7 +664,7 @@ export class ThreadChannel extends GuildChannel implements Model { async fetchMembers(): Promise { const members = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.THREAD_MEMBERS(this.id), ); @@ -672,7 +672,7 @@ export class ThreadChannel extends GuildChannel implements Model { } } -export interface ThreadChannel extends Omit, Omit {} +export interface ThreadChannel extends Omit, Omit {} TextChannel.applyTo(ThreadChannel); @@ -730,7 +730,7 @@ export class ChannelFactory { case ChannelTypes.GuildStageVoice: return new StageChannel(session, channel, channel.guild_id!); default: - throw new Error("Channel was not implemented"); + throw new Error('Channel was not implemented'); } } @@ -753,7 +753,7 @@ export class ChannelFactory { if (textBasedChannels.includes(channel.type)) { return new TextChannel(session, channel); } - throw new Error("Channel was not implemented"); + throw new Error('Channel was not implemented'); } } } diff --git a/packages/biscuit/structures/components/ActionRowComponent.ts b/packages/biscuit/structures/components/ActionRowComponent.ts index d6e5d46..faf76a3 100644 --- a/packages/biscuit/structures/components/ActionRowComponent.ts +++ b/packages/biscuit/structures/components/ActionRowComponent.ts @@ -1,12 +1,12 @@ -import type { Session } from "../../Session.ts"; -import type { DiscordComponent, DiscordInputTextComponent } from "../../../discordeno/mod.ts"; -import type { ActionRowComponent, Component } from "./Component.ts"; -import { ButtonStyles, MessageComponentTypes } from "../../../discordeno/mod.ts"; -import BaseComponent from "./Component.ts"; -import Button from "./ButtonComponent.ts"; -import LinkButton from "./LinkButtonComponent.ts"; -import SelectMenu from "./SelectMenuComponent.ts"; -import InputText from "./TextInputComponent.ts"; +import type { Session } from '../../Session.ts'; +import type { DiscordComponent, DiscordInputTextComponent } from '../../../discordeno/mod.ts'; +import type { ActionRowComponent, Component } from './Component.ts'; +import { ButtonStyles, MessageComponentTypes } from '../../../discordeno/mod.ts'; +import BaseComponent from './Component.ts'; +import Button from './ButtonComponent.ts'; +import LinkButton from './LinkButtonComponent.ts'; +import SelectMenu from './SelectMenuComponent.ts'; +import InputText from './TextInputComponent.ts'; export class ActionRow extends BaseComponent implements ActionRowComponent { constructor(session: Session, data: DiscordComponent) { @@ -26,7 +26,7 @@ export class ActionRow extends BaseComponent implements ActionRowComponent { case MessageComponentTypes.InputText: return new InputText(session, component as DiscordInputTextComponent); case MessageComponentTypes.ActionRow: - throw new Error("Cannot have an action row inside an action row"); + throw new Error('Cannot have an action row inside an action row'); } }); } diff --git a/packages/biscuit/structures/components/ButtonComponent.ts b/packages/biscuit/structures/components/ButtonComponent.ts index c690d33..0ec9c80 100644 --- a/packages/biscuit/structures/components/ButtonComponent.ts +++ b/packages/biscuit/structures/components/ButtonComponent.ts @@ -1,9 +1,9 @@ -import type { Session } from "../../Session.ts"; -import type { ButtonStyles, DiscordComponent } from "../../../discordeno/mod.ts"; -import type { ButtonComponent } from "./Component.ts"; -import { MessageComponentTypes } from "../../../discordeno/mod.ts"; -import BaseComponent from "./Component.ts"; -import Emoji from "../Emoji.ts"; +import type { Session } from '../../Session.ts'; +import type { ButtonStyles, DiscordComponent } from '../../../discordeno/mod.ts'; +import type { ButtonComponent } from './Component.ts'; +import { MessageComponentTypes } from '../../../discordeno/mod.ts'; +import BaseComponent from './Component.ts'; +import Emoji from '../Emoji.ts'; export class Button extends BaseComponent implements ButtonComponent { constructor(session: Session, data: DiscordComponent) { diff --git a/packages/biscuit/structures/components/Component.ts b/packages/biscuit/structures/components/Component.ts index 89d7b63..66b199c 100644 --- a/packages/biscuit/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 "../../../discordeno/mod.ts"; +import type Emoji from '../Emoji.ts'; +import { ButtonStyles, MessageComponentTypes, TextStyles } from '../../../discordeno/mod.ts'; export class BaseComponent { constructor(type: MessageComponentTypes) { diff --git a/packages/biscuit/structures/components/ComponentFactory.ts b/packages/biscuit/structures/components/ComponentFactory.ts index 6d1f570..7de784d 100644 --- a/packages/biscuit/structures/components/ComponentFactory.ts +++ b/packages/biscuit/structures/components/ComponentFactory.ts @@ -1,12 +1,12 @@ -import type { Session } from "../../Session.ts"; -import type { DiscordComponent, DiscordInputTextComponent } from "../../../discordeno/mod.ts"; -import type { Component } from "./Component.ts"; -import { ButtonStyles, MessageComponentTypes } from "../../../discordeno/mod.ts"; -import ActionRow from "./ActionRowComponent.ts"; -import Button from "./ButtonComponent.ts"; -import LinkButton from "./ButtonComponent.ts"; -import SelectMenu from "./SelectMenuComponent.ts"; -import TextInput from "./TextInputComponent.ts"; +import type { Session } from '../../Session.ts'; +import type { DiscordComponent, DiscordInputTextComponent } from '../../../discordeno/mod.ts'; +import type { Component } from './Component.ts'; +import { ButtonStyles, MessageComponentTypes } from '../../../discordeno/mod.ts'; +import ActionRow from './ActionRowComponent.ts'; +import Button from './ButtonComponent.ts'; +import LinkButton from './ButtonComponent.ts'; +import SelectMenu from './SelectMenuComponent.ts'; +import TextInput from './TextInputComponent.ts'; export class ComponentFactory { /** diff --git a/packages/biscuit/structures/components/LinkButtonComponent.ts b/packages/biscuit/structures/components/LinkButtonComponent.ts index d6375e9..11907d0 100644 --- a/packages/biscuit/structures/components/LinkButtonComponent.ts +++ b/packages/biscuit/structures/components/LinkButtonComponent.ts @@ -1,9 +1,9 @@ -import type { Session } from "../../Session.ts"; -import type { ButtonStyles, DiscordComponent } from "../../../discordeno/mod.ts"; -import type { LinkButtonComponent } from "./Component.ts"; -import { MessageComponentTypes } from "../../../discordeno/mod.ts"; -import BaseComponent from "./Component.ts"; -import Emoji from "../Emoji.ts"; +import type { Session } from '../../Session.ts'; +import type { ButtonStyles, DiscordComponent } from '../../../discordeno/mod.ts'; +import type { LinkButtonComponent } from './Component.ts'; +import { MessageComponentTypes } from '../../../discordeno/mod.ts'; +import BaseComponent from './Component.ts'; +import Emoji from '../Emoji.ts'; export class LinkButton extends BaseComponent implements LinkButtonComponent { constructor(session: Session, data: DiscordComponent) { diff --git a/packages/biscuit/structures/components/SelectMenuComponent.ts b/packages/biscuit/structures/components/SelectMenuComponent.ts index 25bb6d8..505bef2 100644 --- a/packages/biscuit/structures/components/SelectMenuComponent.ts +++ b/packages/biscuit/structures/components/SelectMenuComponent.ts @@ -1,9 +1,9 @@ -import type { Session } from "../../Session.ts"; -import type { DiscordComponent } from "../../../discordeno/mod.ts"; -import type { SelectMenuComponent, SelectMenuOption } from "./Component.ts"; -import { MessageComponentTypes } from "../../../discordeno/mod.ts"; -import BaseComponent from "./Component.ts"; -import Emoji from "../Emoji.ts"; +import type { Session } from '../../Session.ts'; +import type { DiscordComponent } from '../../../discordeno/mod.ts'; +import type { SelectMenuComponent, SelectMenuOption } from './Component.ts'; +import { MessageComponentTypes } from '../../../discordeno/mod.ts'; +import BaseComponent from './Component.ts'; +import Emoji from '../Emoji.ts'; export class SelectMenu extends BaseComponent implements SelectMenuComponent { constructor(session: Session, data: DiscordComponent) { diff --git a/packages/biscuit/structures/components/TextInputComponent.ts b/packages/biscuit/structures/components/TextInputComponent.ts index 3567f30..6b9bdb6 100644 --- a/packages/biscuit/structures/components/TextInputComponent.ts +++ b/packages/biscuit/structures/components/TextInputComponent.ts @@ -1,8 +1,8 @@ -import type { Session } from "../../Session.ts"; -import type { DiscordInputTextComponent } from "../../../discordeno/mod.ts"; -import type { TextInputComponent } from "./Component.ts"; -import { MessageComponentTypes, TextStyles } from "../../../discordeno/mod.ts"; -import BaseComponent from "./Component.ts"; +import type { Session } from '../../Session.ts'; +import type { DiscordInputTextComponent } from '../../../discordeno/mod.ts'; +import type { TextInputComponent } from './Component.ts'; +import { MessageComponentTypes, TextStyles } from '../../../discordeno/mod.ts'; +import BaseComponent from './Component.ts'; export class TextInput extends BaseComponent implements TextInputComponent { constructor(session: Session, data: DiscordInputTextComponent) { diff --git a/packages/biscuit/structures/guilds.ts b/packages/biscuit/structures/guilds.ts index 97f3162..da61a24 100644 --- a/packages/biscuit/structures/guilds.ts +++ b/packages/biscuit/structures/guilds.ts @@ -1,5 +1,5 @@ -import type { Model } from "./Base.ts"; -import type { Session } from "../Session.ts"; +import type { Model } from './Base.ts'; +import type { Session } from '../Session.ts'; import type { ChannelTypes, DefaultMessageNotificationLevels, @@ -16,20 +16,20 @@ import type { SystemChannelFlags, VerificationLevels, VideoQualityModes, -} from "../../discordeno/mod.ts"; -import type { ImageFormat, ImageSize } from "../Util.ts"; -import { GuildFeatures, PremiumTiers } from "../../discordeno/mod.ts"; -import { Snowflake } from "../Snowflake.ts"; -import Util from "../Util.ts"; -import * as Routes from "../Routes.ts"; -import WelcomeScreen from "./WelcomeScreen.ts"; -import { GuildChannel, ReturnThreadsArchive, ThreadChannel } from "./channels.ts"; -import ThreadMember from "./ThreadMember.ts"; -import Member from "./Member.ts"; -import Role from "./Role.ts"; -import GuildEmoji from "./GuildEmoji.ts"; -import { urlToBase64 } from "../util/urlToBase64.ts"; -import Invite from "./Invite.ts"; +} from '../../discordeno/mod.ts'; +import type { ImageFormat, ImageSize } from '../Util.ts'; +import { GuildFeatures, PremiumTiers } from '../../discordeno/mod.ts'; +import { Snowflake } from '../Snowflake.ts'; +import Util from '../Util.ts'; +import * as Routes from '../Routes.ts'; +import WelcomeScreen from './WelcomeScreen.ts'; +import { GuildChannel, ReturnThreadsArchive, ThreadChannel } from './channels.ts'; +import ThreadMember from './ThreadMember.ts'; +import Member from './Member.ts'; +import Role from './Role.ts'; +import GuildEmoji from './GuildEmoji.ts'; +import { urlToBase64 } from '../util/urlToBase64.ts'; +import Invite from './Invite.ts'; /** BaseGuild */ /** @@ -242,7 +242,7 @@ export interface GuildCreateOptionsChannel { userLimit?: number; rtcRegion?: string | null; videoQualityMode?: VideoQualityModes; - permissionOverwrites?: MakeRequired, "id">[]; + permissionOverwrites?: MakeRequired, 'id'>[]; rateLimitPerUser?: number; } @@ -391,7 +391,7 @@ export class Guild extends BaseGuild implements Model { async editBotNickname(options: { nick: string | null; reason?: string }): Promise<(string | undefined)> { const result = await this.session.rest.runMethod<{ nick?: string } | undefined>( this.session.rest, - "PATCH", + 'PATCH', Routes.USER_NICK(this.id), options, ); @@ -400,13 +400,13 @@ export class Guild extends BaseGuild implements Model { } async createEmoji(options: CreateGuildEmoji): Promise { - if (options.image && !options.image.startsWith("data:image/")) { + if (options.image && !options.image.startsWith('data:image/')) { options.image = await urlToBase64(options.image); } const emoji = await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.GUILD_EMOJIS(this.id), options, ); @@ -417,7 +417,7 @@ export class Guild extends BaseGuild implements Model { async deleteEmoji(id: Snowflake, { reason }: { reason?: string } = {}): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.GUILD_EMOJI(this.id, id), { reason }, ); @@ -426,7 +426,7 @@ export class Guild extends BaseGuild implements Model { async editEmoji(id: Snowflake, options: ModifyGuildEmoji): Promise { const emoji = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', Routes.GUILD_EMOJI(this.id, id), options, ); @@ -438,7 +438,7 @@ export class Guild extends BaseGuild implements Model { let icon: string | undefined; if (options.iconHash) { - if (typeof options.iconHash === "string") { + if (typeof options.iconHash === 'string') { icon = options.iconHash; } else { icon = Util.iconBigintToHash(options.iconHash); @@ -447,7 +447,7 @@ export class Guild extends BaseGuild implements Model { const role = await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.GUILD_ROLES(this.id), { name: options.name, @@ -463,13 +463,13 @@ export class Guild extends BaseGuild implements Model { } async deleteRole(roleId: Snowflake): Promise { - await this.session.rest.runMethod(this.session.rest, "DELETE", Routes.GUILD_ROLE(this.id, roleId)); + await this.session.rest.runMethod(this.session.rest, 'DELETE', Routes.GUILD_ROLE(this.id, roleId)); } async editRole(roleId: Snowflake, options: ModifyGuildRole): Promise { const role = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', Routes.GUILD_ROLE(this.id, roleId), { name: options.name, @@ -485,7 +485,7 @@ export class Guild extends BaseGuild implements Model { async addRole(memberId: Snowflake, roleId: Snowflake, { reason }: { reason?: string } = {}): Promise { await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.GUILD_MEMBER_ROLE(this.id, memberId, roleId), { reason }, ); @@ -494,7 +494,7 @@ export class Guild extends BaseGuild implements Model { async removeRole(memberId: Snowflake, roleId: Snowflake, { reason }: { reason?: string } = {}): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.GUILD_MEMBER_ROLE(this.id, memberId, roleId), { reason }, ); @@ -506,7 +506,7 @@ export class Guild extends BaseGuild implements Model { async moveRoles(options: ModifyRolePositions[]): Promise { const roles = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', Routes.GUILD_ROLES(this.id), options, ); @@ -517,7 +517,7 @@ export class Guild extends BaseGuild implements Model { async deleteInvite(inviteCode: string): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.INVITE(inviteCode), {}, ); @@ -526,7 +526,7 @@ export class Guild extends BaseGuild implements Model { async fetchInvite(inviteCode: string, options: Routes.GetInvite): Promise { const inviteMetadata = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.INVITE(inviteCode, options), ); @@ -536,7 +536,7 @@ export class Guild extends BaseGuild implements Model { async fetchInvites(): Promise { const invites = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.GUILD_INVITES(this.id), ); @@ -549,7 +549,7 @@ export class Guild extends BaseGuild implements Model { async banMember(memberId: Snowflake, options: CreateGuildBan): Promise { await this.session.rest.runMethod( this.session.rest, - "PUT", + 'PUT', Routes.GUILD_BAN(this.id, memberId), options ? { @@ -566,7 +566,7 @@ export class Guild extends BaseGuild implements Model { async kickMember(memberId: Snowflake, { reason }: { reason?: string }): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.GUILD_MEMBER(this.id, memberId), { reason }, ); @@ -578,7 +578,7 @@ export class Guild extends BaseGuild implements Model { async unbanMember(memberId: Snowflake): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.GUILD_BAN(this.id, memberId), ); } @@ -586,7 +586,7 @@ export class Guild extends BaseGuild implements Model { async editMember(memberId: Snowflake, options: ModifyGuildMember): Promise { const member = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', Routes.GUILD_MEMBER(this.id, memberId), { nick: options.nick, @@ -606,7 +606,7 @@ export class Guild extends BaseGuild implements Model { async pruneMembers(options: BeginGuildPrune): Promise { const result = await this.session.rest.runMethod<{ pruned: number }>( this.session.rest, - "POST", + 'POST', Routes.GUILD_PRUNE(this.id), { days: options.days, @@ -621,17 +621,17 @@ export class Guild extends BaseGuild implements Model { async getPruneCount(): Promise { const result = await this.session.rest.runMethod<{ pruned: number }>( this.session.rest, - "GET", + 'GET', Routes.GUILD_PRUNE(this.id), ); return result.pruned; } - async getActiveThreads(): Promise> { + async getActiveThreads(): Promise> { const { threads, members } = await this.session.rest.runMethod( this.session.rest, - "GET", + 'GET', Routes.THREAD_ACTIVE(this.id), ); @@ -651,7 +651,7 @@ export class Guild extends BaseGuild implements Model { async delete(): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.GUILDS(this.id), ); } @@ -662,7 +662,7 @@ export class Guild extends BaseGuild implements Model { async leave(): Promise { await this.session.rest.runMethod( this.session.rest, - "DELETE", + 'DELETE', Routes.USER_GUILDS(this.id), ); } @@ -673,7 +673,7 @@ export class Guild extends BaseGuild implements Model { * precondition: Bot should be in less than 10 servers */ static async create(session: Session, options: GuildCreateOptions): Promise { - const guild = await session.rest.runMethod(session.rest, "POST", Routes.GUILDS(), { + const guild = await session.rest.runMethod(session.rest, 'POST', Routes.GUILDS(), { name: options.name, afk_channel_id: options.afkChannelId, afk_timeout: options.afkTimeout, @@ -681,7 +681,7 @@ export class Guild extends BaseGuild implements Model { explicit_content_filter: options.explicitContentFilter, system_channel_flags: options.systemChannelFlags, verification_level: options.verificationLevel, - icon: "iconURL" in options + icon: 'iconURL' in options ? options.iconURL && urlToBase64(options.iconURL) : options.iconHash && Util.iconBigintToHash(options.iconHash), channels: options.channels?.map((channel) => ({ @@ -736,7 +736,7 @@ export class Guild extends BaseGuild implements Model { * Edits a guild and returns its data */ async edit(options: GuildEditOptions): Promise { - const guild = await this.session.rest.runMethod(this.session.rest, "PATCH", Routes.GUILDS(), { + const guild = await this.session.rest.runMethod(this.session.rest, 'PATCH', Routes.GUILDS(), { name: options.name, afk_channel_id: options.afkChannelId, afk_timeout: options.afkTimeout, @@ -744,17 +744,17 @@ export class Guild extends BaseGuild implements Model { explicit_content_filter: options.explicitContentFilter, system_channel_flags: options.systemChannelFlags, verification_level: options.verificationLevel, - icon: "iconURL" in options + icon: 'iconURL' in options ? options.iconURL && urlToBase64(options.iconURL) : options.iconHash && Util.iconBigintToHash(options.iconHash), // extra props - splash: "splashURL" in options + splash: 'splashURL' in options ? options.splashURL && urlToBase64(options.splashURL) : options.iconHash && Util.iconBigintToHash(options.iconHash), - banner: "bannerURL" in options + banner: 'bannerURL' in options ? options.bannerURL && urlToBase64(options.bannerURL) : options.bannerHash && Util.iconBigintToHash(options.bannerHash), - discovery_splash: "discoverySplashURL" in options + discovery_splash: 'discoverySplashURL' in options ? options.discoverySplashURL && urlToBase64(options.discoverySplashURL) : options.discoverySplashHash && Util.iconBigintToHash(options.discoverySplashHash), owner_id: options.ownerId, diff --git a/packages/biscuit/structures/interactions/AutoCompleteInteraction.ts b/packages/biscuit/structures/interactions/AutoCompleteInteraction.ts index 2e42647..74a9993 100644 --- a/packages/biscuit/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 "../../Snowflake.ts"; -import type { Session } from "../../Session.ts"; -import type { ApplicationCommandTypes, DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts"; -import type { ApplicationCommandOptionChoice } from "./BaseInteraction.ts"; -import { InteractionResponseTypes } from "../../../discordeno/mod.ts"; -import BaseInteraction from "./BaseInteraction.ts"; -import * as Routes from "../../Routes.ts"; +import type { Model } from '../Base.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 './BaseInteraction.ts'; +import { InteractionResponseTypes } from '../../../discordeno/mod.ts'; +import BaseInteraction from './BaseInteraction.ts'; +import * as Routes from '../../Routes.ts'; export class AutoCompleteInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { @@ -26,7 +26,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model { async respondWithChoices(choices: ApplicationCommandOptionChoice[]): Promise { await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.INTERACTION_ID_TOKEN(this.id, this.token), { data: { choices }, diff --git a/packages/biscuit/structures/interactions/BaseInteraction.ts b/packages/biscuit/structures/interactions/BaseInteraction.ts index 3cba34c..579c9fc 100644 --- a/packages/biscuit/structures/interactions/BaseInteraction.ts +++ b/packages/biscuit/structures/interactions/BaseInteraction.ts @@ -1,22 +1,22 @@ -import type { Model } from "../Base.ts"; -import type { Session } from "../../Session.ts"; -import type { DiscordInteraction, DiscordMessage, DiscordMessageComponents } from "../../../discordeno/mod.ts"; -import type CommandInteraction from "./CommandInteraction.ts"; -import type PingInteraction from "./PingInteraction.ts"; -import type ComponentInteraction from "./ComponentInteraction.ts"; -import type ModalSubmitInteraction from "./ModalSubmitInteraction.ts"; -import type AutoCompleteInteraction from "./AutoCompleteInteraction.ts"; -import type { CreateMessage } from "../Message.ts"; -import type { MessageFlags } from "../../Util.ts"; -import type { EditWebhookMessage } from "../Webhook.ts"; -import { InteractionResponseTypes, InteractionTypes } from "../../../discordeno/mod.ts"; -import { Snowflake } from "../../Snowflake.ts"; -import User from "../User.ts"; -import Member from "../Member.ts"; -import Message from "../Message.ts"; -import Permsisions from "../Permissions.ts"; -import Webhook from "../Webhook.ts"; -import * as Routes from "../../Routes.ts"; +import type { Model } from '../Base.ts'; +import type { Session } from '../../Session.ts'; +import type { DiscordInteraction, DiscordMessage, DiscordMessageComponents } from '../../../discordeno/mod.ts'; +import type CommandInteraction from './CommandInteraction.ts'; +import type PingInteraction from './PingInteraction.ts'; +import type ComponentInteraction from './ComponentInteraction.ts'; +import type ModalSubmitInteraction from './ModalSubmitInteraction.ts'; +import type AutoCompleteInteraction from './AutoCompleteInteraction.ts'; +import type { CreateMessage } from '../Message.ts'; +import type { MessageFlags } from '../../Util.ts'; +import type { EditWebhookMessage } from '../Webhook.ts'; +import { InteractionResponseTypes, InteractionTypes } from '../../../discordeno/mod.ts'; +import { Snowflake } from '../../Snowflake.ts'; +import User from '../User.ts'; +import Member from '../Member.ts'; +import Message from '../Message.ts'; +import Permsisions from '../Permissions.ts'; +import Webhook from '../Webhook.ts'; +import * as Routes from '../../Routes.ts'; /** * @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response @@ -30,7 +30,7 @@ export interface InteractionResponse { * @link https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ export interface InteractionApplicationCommandCallbackData - extends Pick { + extends Pick { customId?: string; title?: string; components?: DiscordMessageComponents; @@ -124,7 +124,7 @@ export abstract class BaseInteraction implements Model { async editReply(options: EditWebhookMessage & { messageId?: Snowflake }): Promise { const message = await this.session.rest.runMethod( this.session.rest, - "PATCH", + 'PATCH', options.messageId ? Routes.WEBHOOK_MESSAGE(this.id, this.token, options.messageId) : Routes.WEBHOOK_MESSAGE_ORIGINAL(this.id, this.token), @@ -217,8 +217,8 @@ export abstract class BaseInteraction implements Model { async respond( resp: InteractionResponse | { with: InteractionApplicationCommandCallbackData }, ): Promise { - const options = "with" in resp ? resp.with : resp.data; - const type = "type" in resp ? resp.type : InteractionResponseTypes.ChannelMessageWithSource; + const options = 'with' in resp ? resp.with : resp.data; + const type = 'type' in resp ? resp.type : InteractionResponseTypes.ChannelMessageWithSource; const data = { content: options?.content, @@ -235,11 +235,11 @@ export abstract class BaseInteraction implements Model { if (!this.responded) { await this.session.rest.sendRequest(this.session.rest, { url: Routes.INTERACTION_ID_TOKEN(this.id, this.token), - method: "POST", + method: 'POST', payload: this.session.rest.createRequestBody(this.session.rest, { - method: "POST", + method: 'POST', body: { type, data, file: options?.files }, - headers: { "Authorization": "" }, + headers: { 'Authorization': '' }, }), }); diff --git a/packages/biscuit/structures/interactions/CommandInteraction.ts b/packages/biscuit/structures/interactions/CommandInteraction.ts index d570fa5..b6609ca 100644 --- a/packages/biscuit/structures/interactions/CommandInteraction.ts +++ b/packages/biscuit/structures/interactions/CommandInteraction.ts @@ -1,19 +1,19 @@ -import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../Snowflake.ts"; -import type { Session } from "../../Session.ts"; +import type { Model } from '../Base.ts'; +import type { Snowflake } from '../../Snowflake.ts'; +import type { Session } from '../../Session.ts'; import type { ApplicationCommandTypes, DiscordInteraction, DiscordMemberWithUser, InteractionTypes, -} from "../../../discordeno/mod.ts"; -import BaseInteraction from "./BaseInteraction.ts"; -import CommandInteractionOptionResolver from "./CommandInteractionOptionResolver.ts"; -import Attachment from "../Attachment.ts"; -import User from "../User.ts"; -import Member from "../Member.ts"; -import Message from "../Message.ts"; -import Role from "../Role.ts"; +} from '../../../discordeno/mod.ts'; +import BaseInteraction from './BaseInteraction.ts'; +import CommandInteractionOptionResolver from './CommandInteractionOptionResolver.ts'; +import Attachment from '../Attachment.ts'; +import User from '../User.ts'; +import Member from '../Member.ts'; +import Message from '../Message.ts'; +import Role from '../Role.ts'; export class CommandInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { diff --git a/packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts b/packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts index ef96bc8..ed8cdc2 100644 --- a/packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts +++ b/packages/biscuit/structures/interactions/CommandInteractionOptionResolver.ts @@ -1,5 +1,5 @@ -import type { DiscordInteractionDataOption, DiscordInteractionDataResolved } from "../../../discordeno/mod.ts"; -import { ApplicationCommandOptionTypes } from "../../../discordeno/mod.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 }; @@ -37,7 +37,7 @@ export function transformOasisInteractionDataOption(o: DiscordInteractionDataOpt return output; } -export interface CommandInteractionOption extends Omit { +export interface CommandInteractionOption extends Omit { Attachment?: string; Boolean?: boolean; User?: bigint; @@ -96,8 +96,8 @@ export class CommandInteractionOptionResolver { // pass } - if (required === true && properties.every((prop) => typeof option[prop] === "undefined")) { - throw new TypeError(`Properties ${properties.join(", ")} are missing in option ${name}`); + if (required === true && properties.every((prop) => typeof option[prop] === 'undefined')) { + throw new TypeError(`Properties ${properties.join(', ')} are missing in option ${name}`); } return option; @@ -107,12 +107,12 @@ export class CommandInteractionOptionResolver { get(name: string | number, required: boolean): CommandInteractionOption | undefined; get(name: string | number, required?: boolean) { const option: CommandInteractionOption | undefined = this.hoistedOptions.find((o) => - typeof name === "number" ? o.name === name.toString() : o.name === name + typeof name === 'number' ? o.name === name.toString() : o.name === name ); if (!option) { if (required && name in this.hoistedOptions.map((o) => o.name)) { - throw new TypeError("Option marked as required was undefined"); + throw new TypeError('Option marked as required was undefined'); } return; @@ -128,7 +128,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.String, - ["Otherwise"], + ['Otherwise'], required, ); @@ -142,7 +142,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.Number, - ["Otherwise"], + ['Otherwise'], required, ); @@ -156,7 +156,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.Integer, - ["Otherwise"], + ['Otherwise'], required, ); @@ -170,7 +170,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.Boolean, - ["Otherwise"], + ['Otherwise'], required, ); @@ -182,7 +182,7 @@ export class CommandInteractionOptionResolver { getUser(name: string | number, required?: boolean): bigint | undefined; getUser(name: string | number, required = false) { const option: CommandInteractionOption | void = this.getTypedOption(name, ApplicationCommandOptionTypes.User, [ - "Otherwise", + 'Otherwise', ], required); return option?.Otherwise ?? undefined; @@ -195,7 +195,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.Channel, - ["Otherwise"], + ['Otherwise'], required, ); @@ -209,7 +209,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.Mentionable, - ["Otherwise"], + ['Otherwise'], required, ); @@ -221,7 +221,7 @@ export class CommandInteractionOptionResolver { getRole(name: string | number, required?: boolean): bigint | undefined; getRole(name: string | number, required = false) { const option: CommandInteractionOption | void = this.getTypedOption(name, ApplicationCommandOptionTypes.Role, [ - "Otherwise", + 'Otherwise', ], required); return option?.Otherwise ?? undefined; @@ -234,7 +234,7 @@ export class CommandInteractionOptionResolver { const option: CommandInteractionOption | void = this.getTypedOption( name, ApplicationCommandOptionTypes.Attachment, - ["Otherwise"], + ['Otherwise'], required, ); @@ -246,7 +246,7 @@ export class CommandInteractionOptionResolver { const focusedOption: CommandInteractionOption | void = this.hoistedOptions.find((option) => option.focused); if (!focusedOption) { - throw new TypeError("No option found"); + throw new TypeError('No option found'); } return full ? focusedOption : focusedOption.Otherwise; @@ -254,7 +254,7 @@ export class CommandInteractionOptionResolver { getSubCommand(required = true): (string | CommandInteractionOption[] | undefined)[] { if (required && !this.#subcommand) { - throw new TypeError("Option marked as required was undefined"); + throw new TypeError('Option marked as required was undefined'); } return [this.#subcommand, this.hoistedOptions]; @@ -262,7 +262,7 @@ export class CommandInteractionOptionResolver { getSubCommandGroup(required = false): (string | CommandInteractionOption[] | undefined)[] { if (required && !this.#group) { - throw new TypeError("Option marked as required was undefined"); + throw new TypeError('Option marked as required was undefined'); } return [this.#group, this.hoistedOptions]; diff --git a/packages/biscuit/structures/interactions/ComponentInteraction.ts b/packages/biscuit/structures/interactions/ComponentInteraction.ts index 86cd953..2c8e7cf 100644 --- a/packages/biscuit/structures/interactions/ComponentInteraction.ts +++ b/packages/biscuit/structures/interactions/ComponentInteraction.ts @@ -1,10 +1,10 @@ -import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../Snowflake.ts"; -import type { Session } from "../../Session.ts"; -import type { DiscordInteraction, InteractionTypes } from "../../../discordeno/mod.ts"; -import { InteractionResponseTypes, MessageComponentTypes } from "../../../discordeno/mod.ts"; -import BaseInteraction from "./BaseInteraction.ts"; -import Message from "../Message.ts"; +import type { Model } from '../Base.ts'; +import type { Snowflake } from '../../Snowflake.ts'; +import type { Session } from '../../Session.ts'; +import type { DiscordInteraction, InteractionTypes } from '../../../discordeno/mod.ts'; +import { InteractionResponseTypes, MessageComponentTypes } from '../../../discordeno/mod.ts'; +import BaseInteraction from './BaseInteraction.ts'; +import Message from '../Message.ts'; export class ComponentInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { diff --git a/packages/biscuit/structures/interactions/InteractionFactory.ts b/packages/biscuit/structures/interactions/InteractionFactory.ts index 75d5232..1548ade 100644 --- a/packages/biscuit/structures/interactions/InteractionFactory.ts +++ b/packages/biscuit/structures/interactions/InteractionFactory.ts @@ -1,14 +1,14 @@ -import type { Session } from "../../Session.ts"; -import type { Snowflake } from "../../Snowflake.ts"; -import type { DiscordInteraction, DiscordMessageInteraction } from "../../../discordeno/mod.ts"; -import { InteractionTypes } from "../../../discordeno/mod.ts"; -import User from "../User.ts"; -import Member from "../Member.ts"; -import CommandInteraction from "./CommandInteraction.ts"; -import ComponentInteraction from "./ComponentInteraction.ts"; -import PingInteraction from "./PingInteraction.ts"; -import AutoCompleteInteraction from "./AutoCompleteInteraction.ts"; -import ModalSubmitInteraction from "./ModalSubmitInteraction.ts"; +import type { Session } from '../../Session.ts'; +import type { Snowflake } from '../../Snowflake.ts'; +import type { DiscordInteraction, DiscordMessageInteraction } from '../../../discordeno/mod.ts'; +import { InteractionTypes } from '../../../discordeno/mod.ts'; +import User from '../User.ts'; +import Member from '../Member.ts'; +import CommandInteraction from './CommandInteraction.ts'; +import ComponentInteraction from './ComponentInteraction.ts'; +import PingInteraction from './PingInteraction.ts'; +import AutoCompleteInteraction from './AutoCompleteInteraction.ts'; +import ModalSubmitInteraction from './ModalSubmitInteraction.ts'; /** * @link https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object-message-interaction-structure diff --git a/packages/biscuit/structures/interactions/ModalSubmitInteraction.ts b/packages/biscuit/structures/interactions/ModalSubmitInteraction.ts index fa7fa88..98a667a 100644 --- a/packages/biscuit/structures/interactions/ModalSubmitInteraction.ts +++ b/packages/biscuit/structures/interactions/ModalSubmitInteraction.ts @@ -1,14 +1,14 @@ -import type { Model } from "../Base.ts"; -import type { Snowflake } from "../../Snowflake.ts"; -import type { Session } from "../../Session.ts"; +import type { Model } from '../Base.ts'; +import type { Snowflake } from '../../Snowflake.ts'; +import type { Session } from '../../Session.ts'; import type { DiscordInteraction, DiscordMessageComponents, InteractionTypes, MessageComponentTypes, -} from "../../../discordeno/mod.ts"; -import BaseInteraction from "./BaseInteraction.ts"; -import Message from "../Message.ts"; +} from '../../../discordeno/mod.ts'; +import BaseInteraction from './BaseInteraction.ts'; +import Message from '../Message.ts'; export class ModalSubmitInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { diff --git a/packages/biscuit/structures/interactions/PingInteraction.ts b/packages/biscuit/structures/interactions/PingInteraction.ts index 4909a05..fff9fad 100644 --- a/packages/biscuit/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 "../../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 "../../Routes.ts"; +import type { Model } from '../Base.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 '../../Routes.ts'; export class PingInteraction extends BaseInteraction implements Model { constructor(session: Session, data: DiscordInteraction) { @@ -25,7 +25,7 @@ export class PingInteraction extends BaseInteraction implements Model { async pong(): Promise { await this.session.rest.runMethod( this.session.rest, - "POST", + 'POST', Routes.INTERACTION_ID_TOKEN(this.id, this.token), { type: InteractionResponseTypes.Pong, diff --git a/packages/biscuit/util/urlToBase64.ts b/packages/biscuit/util/urlToBase64.ts index 991ade2..e0d08a9 100644 --- a/packages/biscuit/util/urlToBase64.ts +++ b/packages/biscuit/util/urlToBase64.ts @@ -2,7 +2,7 @@ export async function urlToBase64(url: string): Promise { const buffer = await fetch(url).then((res) => res.arrayBuffer()); const imageStr = encode(buffer); - const type = url.substring(url.lastIndexOf(".") + 1); + const type = url.substring(url.lastIndexOf('.') + 1); return `data:image/${type};base64,${imageStr}`; } @@ -38,12 +38,12 @@ const base64abc: string[] = [ * @param data */ export function encode(data: ArrayBuffer | string): string { - const uint8: Uint8Array = typeof data === "string" + const uint8: Uint8Array = typeof data === 'string' ? new TextEncoder().encode(data) : data instanceof Uint8Array ? data : new Uint8Array(data); - let result = "", + let result = '', i; const l: number = uint8.length; for (i = 2; i < l; i += 3) { @@ -56,14 +56,14 @@ export function encode(data: ArrayBuffer | string): string { // 1 octet yet to write result += base64abc[uint8[i - 2] >> 2]; result += base64abc[(uint8[i - 2] & 0x03) << 4]; - result += "=="; + result += '=='; } if (i === l) { // 2 octets yet to write result += base64abc[uint8[i - 2] >> 2]; result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; result += base64abc[(uint8[i - 1] & 0x0f) << 2]; - result += "="; + result += '='; } return result; } diff --git a/packages/cache/Collection.ts b/packages/cache/Collection.ts index 85d4f5d..72e26a4 100644 --- a/packages/cache/Collection.ts +++ b/packages/cache/Collection.ts @@ -1,4 +1,4 @@ -import type { Session, Snowflake } from "./deps.ts"; +import type { Session, Snowflake } from './deps.ts'; export class Collection extends Map { constructor(session: Session, entries?: Iterable) { @@ -28,7 +28,7 @@ export class Collection extends Map { random(amount: number): V[]; random(amount?: number): V | V[] | undefined { const arr = [...this.values()]; - if (typeof amount === "undefined") return arr[Math.floor(Math.random() * arr.length)]; + if (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)]; if (!arr.length) return []; if (amount && amount > arr.length) amount = arr.length; return Array.from( diff --git a/packages/cache/channels.ts b/packages/cache/channels.ts index 042119e..6973027 100644 --- a/packages/cache/channels.ts +++ b/packages/cache/channels.ts @@ -1,18 +1,18 @@ -import type { ChannelInGuild, ChannelTypes, ChannelWithMessagesInGuild, DiscordChannel, Snowflake } from "./deps.ts"; -import type { CachedMessage } from "./messages.ts"; -import type { CachedGuild } from "./guilds.ts"; -import type { SessionCache } from "./mod.ts"; -import { Collection } from "./Collection.ts"; -import { ChannelFactory, DMChannel, textBasedChannels } from "./deps.ts"; +import type { ChannelInGuild, ChannelTypes, ChannelWithMessagesInGuild, DiscordChannel, Snowflake } from './deps.ts'; +import type { CachedMessage } from './messages.ts'; +import type { CachedGuild } from './guilds.ts'; +import type { SessionCache } from './mod.ts'; +import { Collection } from './Collection.ts'; +import { ChannelFactory, DMChannel, textBasedChannels } from './deps.ts'; -export interface CachedGuildChannel extends Omit { +export interface CachedGuildChannel extends Omit { type: ChannelTypes; messages: Collection; guild: CachedGuild; guildId: Snowflake; } -export interface CachedGuildChannel extends Omit { +export interface CachedGuildChannel extends Omit { type: ChannelTypes; guild: CachedGuild; guildId: Snowflake; diff --git a/packages/cache/deps.ts b/packages/cache/deps.ts index dc3c536..896499f 100644 --- a/packages/cache/deps.ts +++ b/packages/cache/deps.ts @@ -1,2 +1,2 @@ -export * from "../biscuit/mod.ts"; -export * from "../discordeno/mod.ts"; +export * from '../biscuit/mod.ts'; +export * from '../discordeno/mod.ts'; diff --git a/packages/cache/guilds.ts b/packages/cache/guilds.ts index 693d220..5fa232d 100644 --- a/packages/cache/guilds.ts +++ b/packages/cache/guilds.ts @@ -1,12 +1,12 @@ -import type { DiscordGuild, DiscordMemberWithUser } from "./deps.ts"; -import type { SessionCache } from "./mod.ts"; -import type { CachedMember } from "./members.ts"; -import type { CachedUser } from "./users.ts"; -import type { CachedGuildChannel } from "./channels.ts"; -import { ChannelFactory, Guild, Member } from "./deps.ts"; -import { Collection } from "./Collection.ts"; +import type { DiscordGuild, DiscordMemberWithUser } from './deps.ts'; +import type { SessionCache } from './mod.ts'; +import type { CachedMember } from './members.ts'; +import type { CachedUser } from './users.ts'; +import type { CachedGuildChannel } from './channels.ts'; +import { ChannelFactory, Guild, Member } from './deps.ts'; +import { Collection } from './Collection.ts'; -export interface CachedGuild extends Omit { +export interface CachedGuild extends Omit { channels: Collection; members: Collection; } diff --git a/packages/cache/members.ts b/packages/cache/members.ts index 944aed2..7d342b2 100644 --- a/packages/cache/members.ts +++ b/packages/cache/members.ts @@ -1,9 +1,9 @@ -import type { DiscordMemberWithUser, Snowflake } from "./deps.ts"; -import type { SessionCache } from "./mod.ts"; -import type { CachedUser } from "./users.ts"; -import { Member } from "./deps.ts"; +import type { DiscordMemberWithUser, Snowflake } from './deps.ts'; +import type { SessionCache } from './mod.ts'; +import type { CachedUser } from './users.ts'; +import { Member } from './deps.ts'; -export interface CachedMember extends Omit { +export interface CachedMember extends Omit { userId: Snowflake; user?: CachedUser; } diff --git a/packages/cache/messages.ts b/packages/cache/messages.ts index 3588fc7..d85fad2 100644 --- a/packages/cache/messages.ts +++ b/packages/cache/messages.ts @@ -6,13 +6,13 @@ import type { DiscordMessageReactionRemove, DiscordMessageReactionRemoveAll, Snowflake, -} from "./deps.ts"; -import type { CachedUser } from "./users.ts"; -import type { SessionCache } from "./mod.ts"; -import { Emoji, GuildEmoji, Message, MessageReaction } from "./deps.ts"; -import { memberBootstrapper } from "./members.ts"; +} from './deps.ts'; +import type { CachedUser } from './users.ts'; +import type { SessionCache } from './mod.ts'; +import { Emoji, GuildEmoji, Message, MessageReaction } from './deps.ts'; +import { memberBootstrapper } from './members.ts'; -export interface CachedMessage extends Omit { +export interface CachedMessage extends Omit { authorId: Snowflake; author?: CachedUser; } @@ -27,7 +27,7 @@ export function messageBootstrapper(cache: SessionCache, message: DiscordMessage if (cache.dms.has(message.channel_id)) { // is dm cache.dms.retrieve(message.channel_id, (dm) => { - dm.messages[partial ? "updateFields" : "set"]( + dm.messages[partial ? 'updateFields' : 'set']( message.id, Object.assign( new Message(cache.session, message), @@ -44,7 +44,7 @@ export function messageBootstrapper(cache: SessionCache, message: DiscordMessage // is not dm cache.guilds.retrieve(message.guild_id!, (guild) => guild.channels.retrieve(message.channel_id, (dm) => { - dm.messages[partial ? "updateFields" : "set"]( + dm.messages[partial ? 'updateFields' : 'set']( message.id, Object.assign( new Message(cache.session, message), diff --git a/packages/cache/mod.ts b/packages/cache/mod.ts index 3d7de38..84bf29a 100644 --- a/packages/cache/mod.ts +++ b/packages/cache/mod.ts @@ -1,15 +1,15 @@ -import type { Emoji, Session, SymCache } from "./deps.ts"; -import type { CachedGuild } from "./guilds.ts"; -import type { CachedUser } from "./users.ts"; -import type { CachedDMChannel } from "./channels.ts"; -import { Collection } from "./Collection.ts"; -import { memberBootstrapper } from "./members.ts"; -import { userBootstrapper } from "./users.ts"; -import { channelBootstrapper } from "./channels.ts"; -import { guildBootstrapper } from "./guilds.ts"; -import { messageBootstrapper, reactionBootstrapper, reactionBootstrapperDeletions } from "./messages.ts"; +import type { Emoji, Session, SymCache } from './deps.ts'; +import type { CachedGuild } from './guilds.ts'; +import type { CachedUser } from './users.ts'; +import type { CachedDMChannel } from './channels.ts'; +import { Collection } from './Collection.ts'; +import { memberBootstrapper } from './members.ts'; +import { userBootstrapper } from './users.ts'; +import { channelBootstrapper } from './channels.ts'; +import { guildBootstrapper } from './guilds.ts'; +import { messageBootstrapper, reactionBootstrapper, reactionBootstrapperDeletions } from './messages.ts'; -export const cache_sym = Symbol("@cache"); +export const cache_sym = Symbol('@cache'); export interface SessionCache extends SymCache { guilds: Collection; @@ -29,7 +29,7 @@ export function enableCache(session: Session): SessionCache { session, }; - session.on("raw", (data) => { + session.on('raw', (data) => { // deno-lint-ignore no-explicit-any const raw = data.d as any; @@ -38,38 +38,38 @@ export function enableCache(session: Session): SessionCache { switch (data.t) { // TODO: add more events // for now users have to use the bootstrappers that are not implemented yet - case "MESSAGE_CREATE": + case 'MESSAGE_CREATE': messageBootstrapper(cache, raw, false); break; - case "MESSAGE_UPDATE": + case 'MESSAGE_UPDATE': messageBootstrapper(cache, raw, !raw.edited_timestamp); break; - case "CHANNEL_CREATE": + case 'CHANNEL_CREATE': channelBootstrapper(cache, raw); break; - case "GUILD_MEMBER_ADD": + case 'GUILD_MEMBER_ADD': memberBootstrapper(cache, raw, raw.guild_id); break; - case "GUILD_CREATE": + case 'GUILD_CREATE': guildBootstrapper(cache, raw); break; - case "GUILD_DELETE": + case 'GUILD_DELETE': cache.guilds.delete(raw.id); break; - case "MESSAGE_REACTION_ADD": + case 'MESSAGE_REACTION_ADD': reactionBootstrapper(cache, raw, false); break; - case "MESSAGE_REACTION_REMOVE": + case 'MESSAGE_REACTION_REMOVE': reactionBootstrapper(cache, raw, false); break; - case "MESSAGE_REACTION_REMOVE_ALL": + case 'MESSAGE_REACTION_REMOVE_ALL': reactionBootstrapperDeletions(cache, raw); break; - case "READY": + case 'READY': userBootstrapper(cache, raw.user); break; default: - session.emit("debug", `NOT CACHED: ${JSON.stringify(raw)}`); + session.emit('debug', `NOT CACHED: ${JSON.stringify(raw)}`); } }); diff --git a/packages/cache/users.ts b/packages/cache/users.ts index d453474..75b97f0 100644 --- a/packages/cache/users.ts +++ b/packages/cache/users.ts @@ -1,6 +1,6 @@ -import type { DiscordUser } from "./deps.ts"; -import type { SessionCache } from "./mod.ts"; -import { User } from "./deps.ts"; +import type { DiscordUser } from './deps.ts'; +import type { SessionCache } from './mod.ts'; +import { User } from './deps.ts'; export type CachedUser = User; diff --git a/packages/discordeno/gateway/calculateShardId.ts b/packages/discordeno/gateway/calculateShardId.ts index a3db346..e5faa23 100644 --- a/packages/discordeno/gateway/calculateShardId.ts +++ b/packages/discordeno/gateway/calculateShardId.ts @@ -1,4 +1,4 @@ -import { GatewayManager } from "./manager/gatewayManager.ts"; +import { GatewayManager } from './manager/gatewayManager.ts'; export function calculateShardId(gateway: GatewayManager, guildId: bigint) { if (gateway.manager.totalShards === 1) return 0; diff --git a/packages/discordeno/gateway/manager/calculateTotalShards.ts b/packages/discordeno/gateway/manager/calculateTotalShards.ts index afac127..c4ac468 100644 --- a/packages/discordeno/gateway/manager/calculateTotalShards.ts +++ b/packages/discordeno/gateway/manager/calculateTotalShards.ts @@ -1,4 +1,4 @@ -import { GatewayManager } from "./gatewayManager.ts"; +import { GatewayManager } from './gatewayManager.ts'; /** Handler used to determine max number of shards to use based upon the max concurrency. */ export function calculateTotalShards(gateway: GatewayManager): number { diff --git a/packages/discordeno/gateway/manager/calculateWorkerId.ts b/packages/discordeno/gateway/manager/calculateWorkerId.ts index 0e76fc3..ed36ff4 100644 --- a/packages/discordeno/gateway/manager/calculateWorkerId.ts +++ b/packages/discordeno/gateway/manager/calculateWorkerId.ts @@ -1,4 +1,4 @@ -import { GatewayManager } from "./gatewayManager.ts"; +import { GatewayManager } from './gatewayManager.ts'; export function calculateWorkerId(manager: GatewayManager, shardId: number) { // Ignore decimal numbers. diff --git a/packages/discordeno/gateway/manager/gatewayManager.ts b/packages/discordeno/gateway/manager/gatewayManager.ts index 98a1eb7..48b75c2 100644 --- a/packages/discordeno/gateway/manager/gatewayManager.ts +++ b/packages/discordeno/gateway/manager/gatewayManager.ts @@ -1,10 +1,10 @@ -import { DiscordGatewayPayload } from "../../types/discord.ts"; -import { GatewayBot, PickPartial } from "../../types/shared.ts"; -import { LeakyBucket } from "../../util/bucket.ts"; -import { CreateShard, createShard } from "../shard/createShard.ts"; -import { Shard, ShardGatewayConfig } from "../shard/types.ts"; -import { calculateTotalShards } from "./calculateTotalShards.ts"; -import { calculateWorkerId } from "./calculateWorkerId.ts"; +import { DiscordGatewayPayload } from '../../types/discord.ts'; +import { GatewayBot, PickPartial } from '../../types/shared.ts'; +import { LeakyBucket } from '../../util/bucket.ts'; +import { CreateShard, createShard } from '../shard/createShard.ts'; +import { Shard, ShardGatewayConfig } from '../shard/types.ts'; +import { calculateTotalShards } from './calculateTotalShards.ts'; +import { calculateWorkerId } from './calculateWorkerId.ts'; // import { // markNewGuildShardId, // resharder, @@ -12,11 +12,11 @@ import { calculateWorkerId } from "./calculateWorkerId.ts"; // resharderIsPending, // reshardingEditGuildShardIds, // } from "./resharder.ts"; -import { spawnShards } from "./spawnShards.ts"; -import { prepareBuckets } from "./prepareBuckets.ts"; -import { tellWorkerToIdentify } from "./tellWorkerToIdentify.ts"; -import { createShardManager, ShardManager } from "./shardManager.ts"; -import { stop } from "./stop.ts"; +import { spawnShards } from './spawnShards.ts'; +import { prepareBuckets } from './prepareBuckets.ts'; +import { tellWorkerToIdentify } from './tellWorkerToIdentify.ts'; +import { createShardManager, ShardManager } from './shardManager.ts'; +import { stop } from './stop.ts'; export type GatewayManager = ReturnType; @@ -27,7 +27,7 @@ export type GatewayManager = ReturnType; * bots. */ export function createGatewayManager( - options: PickPartial, + options: PickPartial, ) { const prepareBucketsOverwritten = options.prepareBuckets ?? prepareBuckets; const spawnShardsOverwritten = options.spawnShards ?? spawnShards; @@ -222,10 +222,10 @@ export interface CreateGatewayManager { /** Important data which is used by the manager to connect shards to the gateway. */ gatewayBot: GatewayBot; - gatewayConfig: PickPartial; + gatewayConfig: PickPartial; /** Options which are used to create a new shard. */ - createShardOptions?: Omit; + createShardOptions?: Omit; /** Stored as bucketId: { workers: [workerId, [ShardIds]], createNextShard: boolean } */ buckets: Map< @@ -276,19 +276,19 @@ export interface CreateGatewayManager { } export type GatewayDebugEvents = - | "GW ERROR" - | "GW CLOSED" - | "GW CLOSED_RECONNECT" - | "GW RAW" - | "GW RECONNECT" - | "GW INVALID_SESSION" - | "GW RESUMED" - | "GW RESUMING" - | "GW IDENTIFYING" - | "GW RAW_SEND" - | "GW MAX REQUESTS" - | "GW DEBUG" - | "GW HEARTBEATING" - | "GW HEARTBEATING_STARTED" - | "GW HEARTBEATING_DETAILS" - | "GW HEARTBEATING_CLOSED"; + | 'GW ERROR' + | 'GW CLOSED' + | 'GW CLOSED_RECONNECT' + | 'GW RAW' + | 'GW RECONNECT' + | 'GW INVALID_SESSION' + | 'GW RESUMED' + | 'GW RESUMING' + | 'GW IDENTIFYING' + | 'GW RAW_SEND' + | 'GW MAX REQUESTS' + | 'GW DEBUG' + | 'GW HEARTBEATING' + | 'GW HEARTBEATING_STARTED' + | 'GW HEARTBEATING_DETAILS' + | 'GW HEARTBEATING_CLOSED'; diff --git a/packages/discordeno/gateway/manager/mod.ts b/packages/discordeno/gateway/manager/mod.ts index f3c0567..c0ee0d9 100644 --- a/packages/discordeno/gateway/manager/mod.ts +++ b/packages/discordeno/gateway/manager/mod.ts @@ -1,8 +1,8 @@ -export * from "./calculateTotalShards.ts"; -export * from "./calculateWorkerId.ts"; -export * from "./gatewayManager.ts"; -export * from "./prepareBuckets.ts"; -export * from "./shardManager.ts"; -export * from "./spawnShards.ts"; -export * from "./stop.ts"; -export * from "./tellWorkerToIdentify.ts"; +export * from './calculateTotalShards.ts'; +export * from './calculateWorkerId.ts'; +export * from './gatewayManager.ts'; +export * from './prepareBuckets.ts'; +export * from './shardManager.ts'; +export * from './spawnShards.ts'; +export * from './stop.ts'; +export * from './tellWorkerToIdentify.ts'; diff --git a/packages/discordeno/gateway/manager/prepareBuckets.ts b/packages/discordeno/gateway/manager/prepareBuckets.ts index d813fa9..5e13f1a 100644 --- a/packages/discordeno/gateway/manager/prepareBuckets.ts +++ b/packages/discordeno/gateway/manager/prepareBuckets.ts @@ -1,5 +1,5 @@ -import { createLeakyBucket } from "../../util/bucket.ts"; -import { GatewayManager } from "./gatewayManager.ts"; +import { createLeakyBucket } from '../../util/bucket.ts'; +import { GatewayManager } from './gatewayManager.ts'; export function prepareBuckets(gateway: GatewayManager) { for (let i = 0; i < gateway.gatewayBot.sessionStartLimit.maxConcurrency; ++i) { diff --git a/packages/discordeno/gateway/manager/resharder.ts b/packages/discordeno/gateway/manager/resharder.ts index d0e4d7f..2c67b0b 100644 --- a/packages/discordeno/gateway/manager/resharder.ts +++ b/packages/discordeno/gateway/manager/resharder.ts @@ -1,5 +1,5 @@ -import { GatewayBot } from "../../types/shared.ts"; -import { createGatewayManager, GatewayManager } from "./gatewayManager.ts"; +import { GatewayBot } from '../../types/shared.ts'; +import { createGatewayManager, GatewayManager } from './gatewayManager.ts'; export type Resharder = ReturnType; @@ -118,7 +118,7 @@ export interface ActivateResharderOptions { /** Handler that by default will check to see if resharding should occur. Can be overridden if you have multiple servers and you want to communicate through redis pubsub or whatever you prefer. */ export function activate(resharder: Resharder): void { if (resharder.intervalId !== undefined) { - throw new Error("[RESHARDER] Cannot activate the resharder more than one time."); + throw new Error('[RESHARDER] Cannot activate the resharder more than one time.'); } resharder.intervalId = setInterval(async () => { @@ -173,7 +173,7 @@ export async function reshard(resharder: Resharder, gatewayBot: GatewayBot) { gateway.handleDiscordPayload = oldHandler; oldGateway.handleDiscordPayload = function (og, data, shardId) { // ALLOW EXCEPTION FOR CHUNKING TO PREVENT REQUESTS FREEZING - if (data.t !== "GUILD_MEMBERS_CHUNK") return; + if (data.t !== 'GUILD_MEMBERS_CHUNK') return; oldHandler(og, data, shardId); }; @@ -181,7 +181,7 @@ export async function reshard(resharder: Resharder, gatewayBot: GatewayBot) { clearInterval(timer); await gateway.resharding.editGuildShardIds(); await gateway.resharding.closeOldShards(oldGateway); - gateway.debug("GW DEBUG", "[Resharding] Complete."); + gateway.debug('GW DEBUG', '[Resharding] Complete.'); resolve(gateway); }, 30000); }) as Promise; @@ -291,7 +291,7 @@ export async function resharderCloseOldShards(oldGateway: GatewayManager) { return oldGateway.closeWS( shard.ws, 3066, - "Shard has been resharded. Closing shard since it has no queue.", + 'Shard has been resharded. Closing shard since it has no queue.', ); } @@ -300,7 +300,7 @@ export async function resharderCloseOldShards(oldGateway: GatewayManager) { oldGateway.closeWS( shard.ws, 3066, - "Shard has been resharded. Delayed closing shard since it had a queue.", + 'Shard has been resharded. Delayed closing shard since it had a queue.', ); }, 300000); }); diff --git a/packages/discordeno/gateway/manager/shardManager.ts b/packages/discordeno/gateway/manager/shardManager.ts index e621530..79cbb34 100644 --- a/packages/discordeno/gateway/manager/shardManager.ts +++ b/packages/discordeno/gateway/manager/shardManager.ts @@ -1,7 +1,7 @@ -import { DiscordGatewayPayload } from "../../types/discord.ts"; -import { PickPartial } from "../../types/shared.ts"; -import { CreateShard, createShard } from "../shard/createShard.ts"; -import { Shard, ShardGatewayConfig } from "../shard/types.ts"; +import { DiscordGatewayPayload } from '../../types/discord.ts'; +import { PickPartial } from '../../types/shared.ts'; +import { CreateShard, createShard } from '../shard/createShard.ts'; +import { Shard, ShardGatewayConfig } from '../shard/types.ts'; // TODO: debug @@ -100,9 +100,9 @@ export interface CreateShardManager { // PROPERTIES // ---------- /** Options which are used to create a new Shard. */ - createShardOptions?: Omit; + createShardOptions?: Omit; /** Gateway configuration which is used when creating a Shard. */ - gatewayConfig: PickPartial; + gatewayConfig: PickPartial; /** Ids of the Shards which should be managed. */ shardIds: number[]; /** Total amount of Shard used by the bot. */ diff --git a/packages/discordeno/gateway/manager/spawnShards.ts b/packages/discordeno/gateway/manager/spawnShards.ts index 5bd9df1..b897284 100644 --- a/packages/discordeno/gateway/manager/spawnShards.ts +++ b/packages/discordeno/gateway/manager/spawnShards.ts @@ -1,8 +1,8 @@ -import { GatewayIntents } from "../../types/shared.ts"; -import { createLeakyBucket } from "../../util/bucket.ts"; -import { createShard } from "../shard/createShard.ts"; -import { Shard } from "../shard/types.ts"; -import { createGatewayManager, GatewayManager } from "./gatewayManager.ts"; +import { GatewayIntents } from '../../types/shared.ts'; +import { createLeakyBucket } from '../../util/bucket.ts'; +import { createShard } from '../shard/createShard.ts'; +import { Shard } from '../shard/types.ts'; +import { createGatewayManager, GatewayManager } from './gatewayManager.ts'; /** Begin spawning shards. */ export function spawnShards(gateway: GatewayManager) { diff --git a/packages/discordeno/gateway/manager/stop.ts b/packages/discordeno/gateway/manager/stop.ts index 753fb6c..0c4feca 100644 --- a/packages/discordeno/gateway/manager/stop.ts +++ b/packages/discordeno/gateway/manager/stop.ts @@ -1,5 +1,5 @@ -import { delay } from "../../util/delay.ts"; -import { GatewayManager } from "./gatewayManager.ts"; +import { delay } from '../../util/delay.ts'; +import { GatewayManager } from './gatewayManager.ts'; export async function stop(gateway: GatewayManager, code: number, reason: string) { gateway.manager.shards.forEach((shard) => shard.close(code, reason)); diff --git a/packages/discordeno/gateway/manager/tellWorkerToIdentify.ts b/packages/discordeno/gateway/manager/tellWorkerToIdentify.ts index 5913752..38955cf 100644 --- a/packages/discordeno/gateway/manager/tellWorkerToIdentify.ts +++ b/packages/discordeno/gateway/manager/tellWorkerToIdentify.ts @@ -1,6 +1,6 @@ -import { GatewayIntents } from "../../types/shared.ts"; -import { createShard } from "../shard/createShard.ts"; -import { GatewayManager } from "./gatewayManager.ts"; +import { GatewayIntents } from '../../types/shared.ts'; +import { createShard } from '../shard/createShard.ts'; +import { GatewayManager } from './gatewayManager.ts'; /** Allows users to hook in and change to communicate to different workers across different servers or anything they like. For example using redis pubsub to talk to other servers. */ export async function tellWorkerToIdentify( diff --git a/packages/discordeno/gateway/mod.ts b/packages/discordeno/gateway/mod.ts index 9315ff3..11a6246 100644 --- a/packages/discordeno/gateway/mod.ts +++ b/packages/discordeno/gateway/mod.ts @@ -1,2 +1,2 @@ -export * from "./manager/mod.ts"; -export * from "./shard/mod.ts"; +export * from './manager/mod.ts'; +export * from './shard/mod.ts'; diff --git a/packages/discordeno/gateway/shard/calculateSafeRequests.ts b/packages/discordeno/gateway/shard/calculateSafeRequests.ts index 12695b5..69e5d3e 100644 --- a/packages/discordeno/gateway/shard/calculateSafeRequests.ts +++ b/packages/discordeno/gateway/shard/calculateSafeRequests.ts @@ -1,4 +1,4 @@ -import { Shard } from "./types.ts"; +import { Shard } from './types.ts'; export function calculateSafeRequests(shard: Shard) { // * 2 adds extra safety layer for discords OP 1 requests that we need to respond to diff --git a/packages/discordeno/gateway/shard/close.ts b/packages/discordeno/gateway/shard/close.ts index 9dfefa6..e2ff2f9 100644 --- a/packages/discordeno/gateway/shard/close.ts +++ b/packages/discordeno/gateway/shard/close.ts @@ -1,4 +1,4 @@ -import { Shard } from "./types.ts"; +import { Shard } from './types.ts'; export function close(shard: Shard, code: number, reason: string): void { if (shard.socket?.readyState !== WebSocket.OPEN) return; diff --git a/packages/discordeno/gateway/shard/connect.ts b/packages/discordeno/gateway/shard/connect.ts index 3386b2c..b1bceda 100644 --- a/packages/discordeno/gateway/shard/connect.ts +++ b/packages/discordeno/gateway/shard/connect.ts @@ -1,4 +1,4 @@ -import { Shard, ShardState } from "./types.ts"; +import { Shard, ShardState } from './types.ts'; // TODO: Remove code marked WSL GATEWAY PATCH once a bug in bun is fixed: // `https://github.com/Jarred-Sumner/bun/issues/521` diff --git a/packages/discordeno/gateway/shard/createShard.ts b/packages/discordeno/gateway/shard/createShard.ts index d17e220..48e1f2b 100644 --- a/packages/discordeno/gateway/shard/createShard.ts +++ b/packages/discordeno/gateway/shard/createShard.ts @@ -1,5 +1,5 @@ -import { identify } from "./identify.ts"; -import { handleMessage } from "./handleMessage.ts"; +import { identify } from './identify.ts'; +import { handleMessage } from './handleMessage.ts'; import { DEFAULT_HEARTBEAT_INTERVAL, GATEWAY_RATE_LIMIT_RESET_INTERVAL, @@ -11,21 +11,21 @@ import { ShardSocketCloseCodes, ShardSocketRequest, ShardState, -} from "./types.ts"; -import { startHeartbeating } from "./startHeartbeating.ts"; -import { stopHeartbeating } from "./stopHeartbeating.ts"; -import { resume } from "./resume.ts"; -import { createLeakyBucket, LeakyBucket } from "../../util/bucket.ts"; -import { calculateSafeRequests } from "./calculateSafeRequests.ts"; -import { send } from "./send.ts"; -import { handleClose } from "./handleClose.ts"; -import { connect } from "./connect.ts"; -import { close } from "./close.ts"; -import { shutdown } from "./shutdown.ts"; -import { isOpen } from "./isOpen.ts"; -import { DiscordGatewayPayload, DiscordStatusUpdate } from "../../types/discord.ts"; -import { GatewayIntents, PickPartial } from "../../types/shared.ts"; -import { API_VERSION } from "../../util/constants.ts"; +} from './types.ts'; +import { startHeartbeating } from './startHeartbeating.ts'; +import { stopHeartbeating } from './stopHeartbeating.ts'; +import { resume } from './resume.ts'; +import { createLeakyBucket, LeakyBucket } from '../../util/bucket.ts'; +import { calculateSafeRequests } from './calculateSafeRequests.ts'; +import { send } from './send.ts'; +import { handleClose } from './handleClose.ts'; +import { connect } from './connect.ts'; +import { close } from './close.ts'; +import { shutdown } from './shutdown.ts'; +import { isOpen } from './isOpen.ts'; +import { DiscordGatewayPayload, DiscordStatusUpdate } from '../../types/discord.ts'; +import { GatewayIntents, PickPartial } from '../../types/shared.ts'; +import { API_VERSION } from '../../util/constants.ts'; // TODO: debug // TODO: function overwrite @@ -59,12 +59,12 @@ export function createShard( compress: options.gatewayConfig.compress ?? false, intents: options.gatewayConfig.intents ?? 0, properties: { - os: options.gatewayConfig?.properties?.os ?? "linux", - browser: options.gatewayConfig?.properties?.browser ?? "Discordeno", - device: options.gatewayConfig?.properties?.device ?? "Discordeno", + os: options.gatewayConfig?.properties?.os ?? 'linux', + browser: options.gatewayConfig?.properties?.browser ?? 'Discordeno', + device: options.gatewayConfig?.properties?.device ?? 'Discordeno', }, token: options.gatewayConfig.token, - url: options.gatewayConfig.url ?? "wss://gateway.discord.gg", + url: options.gatewayConfig.url ?? 'wss://gateway.discord.gg', version: options.gatewayConfig.version ?? API_VERSION, } as ShardGatewayConfig, /** This contains all the heartbeat information */ @@ -201,7 +201,7 @@ export function createShard( * This is used to resolve internal waiting states. * Mapped by SelectedEvents => ResolveFunction */ - resolves: new Map<"READY" | "RESUMED" | "INVALID_SESSION", (payload: DiscordGatewayPayload) => void>(), + resolves: new Map<'READY' | 'RESUMED' | 'INVALID_SESSION', (payload: DiscordGatewayPayload) => void>(), /** @private Internal shard function. * Only use this function if you know what you are doing. @@ -228,7 +228,7 @@ export interface CreateShard { id: number; /** Gateway configuration for the shard. */ - gatewayConfig: PickPartial; + gatewayConfig: PickPartial; /** The total amount of shards which are used to communicate with Discord. */ totalShards: number; @@ -329,5 +329,5 @@ export interface CreateShard { /** This is used to resolve internal waiting states. * Mapped by SelectedEvents => ResolveFunction */ - resolves?: Shard["resolves"]; + resolves?: Shard['resolves']; } diff --git a/packages/discordeno/gateway/shard/deps.ts b/packages/discordeno/gateway/shard/deps.ts index e2cb039..48f6d60 100644 --- a/packages/discordeno/gateway/shard/deps.ts +++ b/packages/discordeno/gateway/shard/deps.ts @@ -1 +1 @@ -export { inflate as decompressWith } from "../../zlib.js"; +export { inflate as decompressWith } from '../../zlib.js'; diff --git a/packages/discordeno/gateway/shard/handleClose.ts b/packages/discordeno/gateway/shard/handleClose.ts index 02683e9..318d8be 100644 --- a/packages/discordeno/gateway/shard/handleClose.ts +++ b/packages/discordeno/gateway/shard/handleClose.ts @@ -1,5 +1,5 @@ -import { GatewayCloseEventCodes } from "../../types/shared.ts"; -import { Shard, ShardSocketCloseCodes, ShardState } from "./types.ts"; +import { GatewayCloseEventCodes } from '../../types/shared.ts'; +import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts'; export async function handleClose(shard: Shard, close: CloseEvent): Promise { // gateway.debug("GW CLOSED", { shardId, payload: event }); @@ -47,7 +47,7 @@ export async function handleClose(shard: Shard, close: CloseEvent): Promise): } // Safeguard incase decompression failed to make a string. - if (typeof message !== "string") return; + if (typeof message !== 'string') return; const messageData = JSON.parse(message) as DiscordGatewayPayload; // gateway.debug("GW RAW", { shardId, payload: messageData }); @@ -96,8 +96,8 @@ export async function handleMessage(shard: Shard, message_: MessageEvent): // Reference: https://discord.com/developers/docs/topics/gateway#resuming await delay(Math.floor((Math.random() * 4 + 1) * 1000)); - shard.resolves.get("INVALID_SESSION")?.(messageData); - shard.resolves.delete("INVALID_SESSION"); + shard.resolves.get('INVALID_SESSION')?.(messageData); + shard.resolves.delete('INVALID_SESSION'); // When resumable is false we need to re-identify if (!resumable) { @@ -113,7 +113,7 @@ export async function handleMessage(shard: Shard, message_: MessageEvent): } } - if (messageData.t === "RESUMED") { + if (messageData.t === 'RESUMED') { // gateway.debug("GW RESUMED", { shardId }); shard.state = ShardState.Connected; @@ -122,10 +122,10 @@ export async function handleMessage(shard: Shard, message_: MessageEvent): // Continue the requests which have been queued since the shard went offline. shard.offlineSendQueue.map((resolve) => resolve()); - shard.resolves.get("RESUMED")?.(messageData); - shard.resolves.delete("RESUMED"); + shard.resolves.get('RESUMED')?.(messageData); + shard.resolves.delete('RESUMED'); } // Important for future resumes. - else if (messageData.t === "READY") { + else if (messageData.t === 'READY') { const payload = messageData.d as DiscordReady; shard.sessionId = payload.session_id; @@ -135,8 +135,8 @@ export async function handleMessage(shard: Shard, message_: MessageEvent): // Important when this is a re-identify shard.offlineSendQueue.map((resolve) => resolve()); - shard.resolves.get("READY")?.(messageData); - shard.resolves.delete("READY"); + shard.resolves.get('READY')?.(messageData); + shard.resolves.delete('READY'); } // Update the sequence number if it is present diff --git a/packages/discordeno/gateway/shard/identify.ts b/packages/discordeno/gateway/shard/identify.ts index b11bac5..c494e2d 100644 --- a/packages/discordeno/gateway/shard/identify.ts +++ b/packages/discordeno/gateway/shard/identify.ts @@ -1,12 +1,12 @@ -import { GatewayOpcodes } from "../../types/shared.ts"; -import { Shard, ShardSocketCloseCodes, ShardState } from "./types.ts"; +import { GatewayOpcodes } from '../../types/shared.ts'; +import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts'; export async function identify(shard: Shard): Promise { // A new identify has been requested even though there is already a connection open. // Therefore we need to close the old connection and heartbeating before creating a new one. if (shard.state === ShardState.Connected) { // console.log("CLOSING EXISTING SHARD: #" + shard.id); - shard.close(ShardSocketCloseCodes.ReIdentifying, "Re-identifying closure of old connection."); + shard.close(ShardSocketCloseCodes.ReIdentifying, 'Re-identifying closure of old connection.'); } shard.state = ShardState.Identifying; @@ -35,15 +35,15 @@ export async function identify(shard: Shard): Promise { }, true); return new Promise((resolve) => { - shard.resolves.set("READY", () => { + shard.resolves.set('READY', () => { shard.events.identified?.(shard); resolve(); }); // When identifying too fast, // Discord sends an invalid session payload. // This can safely be ignored though and the shard starts a new identify action. - shard.resolves.set("INVALID_SESSION", () => { - shard.resolves.delete("READY"); + shard.resolves.set('INVALID_SESSION', () => { + shard.resolves.delete('READY'); resolve(); }); }); diff --git a/packages/discordeno/gateway/shard/isOpen.ts b/packages/discordeno/gateway/shard/isOpen.ts index 7708262..8c40ee5 100644 --- a/packages/discordeno/gateway/shard/isOpen.ts +++ b/packages/discordeno/gateway/shard/isOpen.ts @@ -1,4 +1,4 @@ -import { Shard } from "./types.ts"; +import { Shard } from './types.ts'; export function isOpen(shard: Shard): boolean { return shard.socket?.readyState === WebSocket.OPEN; diff --git a/packages/discordeno/gateway/shard/mod.ts b/packages/discordeno/gateway/shard/mod.ts index 753770e..d72483b 100644 --- a/packages/discordeno/gateway/shard/mod.ts +++ b/packages/discordeno/gateway/shard/mod.ts @@ -1,14 +1,14 @@ -export * from "./calculateSafeRequests.ts"; -export * from "./close.ts"; -export * from "./connect.ts"; -export * from "./createShard.ts"; -export * from "./handleClose.ts"; -export * from "./handleMessage.ts"; -export * from "./identify.ts"; -export * from "./isOpen.ts"; -export * from "./resume.ts"; -export * from "./send.ts"; -export * from "./shutdown.ts"; -export * from "./startHeartbeating.ts"; -export * from "./stopHeartbeating.ts"; -export * from "./types.ts"; +export * from './calculateSafeRequests.ts'; +export * from './close.ts'; +export * from './connect.ts'; +export * from './createShard.ts'; +export * from './handleClose.ts'; +export * from './handleMessage.ts'; +export * from './identify.ts'; +export * from './isOpen.ts'; +export * from './resume.ts'; +export * from './send.ts'; +export * from './shutdown.ts'; +export * from './startHeartbeating.ts'; +export * from './stopHeartbeating.ts'; +export * from './types.ts'; diff --git a/packages/discordeno/gateway/shard/resume.ts b/packages/discordeno/gateway/shard/resume.ts index 1d46839..769fe77 100644 --- a/packages/discordeno/gateway/shard/resume.ts +++ b/packages/discordeno/gateway/shard/resume.ts @@ -1,5 +1,5 @@ -import { GatewayOpcodes } from "../../types/shared.ts"; -import { Shard, ShardSocketCloseCodes, ShardState } from "./types.ts"; +import { GatewayOpcodes } from '../../types/shared.ts'; +import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts'; export async function resume(shard: Shard): Promise { // gateway.debug("GW RESUMING", { shardId }); @@ -8,7 +8,7 @@ export async function resume(shard: Shard): Promise { if (shard.isOpen()) { shard.close( ShardSocketCloseCodes.ResumeClosingOldConnection, - "Reconnecting the shard, closing old connection.", + 'Reconnecting the shard, closing old connection.', ); } @@ -39,12 +39,12 @@ export async function resume(shard: Shard): Promise { }, true); return new Promise((resolve) => { - shard.resolves.set("RESUMED", () => resolve()); + shard.resolves.set('RESUMED', () => resolve()); // If it is attempted to resume with an invalid session id, // Discord sends an invalid session payload // Not erroring here since it is easy that this happens, also it would be not catchable - shard.resolves.set("INVALID_SESSION", () => { - shard.resolves.delete("RESUMED"); + shard.resolves.set('INVALID_SESSION', () => { + shard.resolves.delete('RESUMED'); resolve(); }); }); diff --git a/packages/discordeno/gateway/shard/send.ts b/packages/discordeno/gateway/shard/send.ts index 2cbaa4b..582f4fd 100644 --- a/packages/discordeno/gateway/shard/send.ts +++ b/packages/discordeno/gateway/shard/send.ts @@ -1,4 +1,4 @@ -import { Shard, ShardSocketRequest } from "./types.ts"; +import { Shard, ShardSocketRequest } from './types.ts'; async function checkOffline(shard: Shard, highPriority: boolean): Promise { if (!shard.isOpen()) { diff --git a/packages/discordeno/gateway/shard/shutdown.ts b/packages/discordeno/gateway/shard/shutdown.ts index c329c93..13cb39f 100644 --- a/packages/discordeno/gateway/shard/shutdown.ts +++ b/packages/discordeno/gateway/shard/shutdown.ts @@ -1,6 +1,6 @@ -import { Shard, ShardSocketCloseCodes, ShardState } from "./types.ts"; +import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts'; export async function shutdown(shard: Shard): Promise { - shard.close(ShardSocketCloseCodes.Shutdown, "Shard shutting down."); + shard.close(ShardSocketCloseCodes.Shutdown, 'Shard shutting down.'); shard.state = ShardState.Offline; } diff --git a/packages/discordeno/gateway/shard/startHeartbeating.ts b/packages/discordeno/gateway/shard/startHeartbeating.ts index dd01302..df799ab 100644 --- a/packages/discordeno/gateway/shard/startHeartbeating.ts +++ b/packages/discordeno/gateway/shard/startHeartbeating.ts @@ -1,5 +1,5 @@ -import { GatewayOpcodes } from "../../types/shared.ts"; -import { Shard, ShardSocketCloseCodes, ShardState } from "./types.ts"; +import { GatewayOpcodes } from '../../types/shared.ts'; +import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts'; export function startHeartbeating(shard: Shard, interval: number) { // gateway.debug("GW HEARTBEATING_STARTED", { shardId, interval }); @@ -40,7 +40,7 @@ export function startHeartbeating(shard: Shard, interval: number) { if (!shard.heart.acknowledged) { shard.close( ShardSocketCloseCodes.ZombiedConnection, - "Zombied connection, did not receive an heartbeat ACK in time.", + 'Zombied connection, did not receive an heartbeat ACK in time.', ); return await shard.identify(); diff --git a/packages/discordeno/gateway/shard/stopHeartbeating.ts b/packages/discordeno/gateway/shard/stopHeartbeating.ts index b2e7de8..cb0914c 100644 --- a/packages/discordeno/gateway/shard/stopHeartbeating.ts +++ b/packages/discordeno/gateway/shard/stopHeartbeating.ts @@ -1,4 +1,4 @@ -import { Shard } from "./types.ts"; +import { Shard } from './types.ts'; export function stopHeartbeating(shard: Shard): void { // Clear the regular heartbeat interval. diff --git a/packages/discordeno/gateway/shard/types.ts b/packages/discordeno/gateway/shard/types.ts index d84cac0..39dc892 100644 --- a/packages/discordeno/gateway/shard/types.ts +++ b/packages/discordeno/gateway/shard/types.ts @@ -1,6 +1,6 @@ -import { DiscordGatewayPayload } from "../../types/discord.ts"; -import { GatewayOpcodes } from "../../types/shared.ts"; -import { createShard } from "./createShard.ts"; +import { DiscordGatewayPayload } from '../../types/discord.ts'; +import { GatewayOpcodes } from '../../types/shared.ts'; +import { createShard } from './createShard.ts'; // TODO: think whether we also need an identifiedShard function diff --git a/packages/discordeno/mod.ts b/packages/discordeno/mod.ts index b96e207..50e1a07 100644 --- a/packages/discordeno/mod.ts +++ b/packages/discordeno/mod.ts @@ -1,5 +1,5 @@ -export * from "./gateway/mod.ts"; -export * from "./rest/mod.ts"; -export * from "./types/mod.ts"; -export * from "./util/constants.ts"; -export * from "./util/token.ts"; +export * from './gateway/mod.ts'; +export * from './rest/mod.ts'; +export * from './types/mod.ts'; +export * from './util/constants.ts'; +export * from './util/token.ts'; diff --git a/packages/discordeno/rest/checkRateLimits.ts b/packages/discordeno/rest/checkRateLimits.ts index 77514ec..81a42a1 100644 --- a/packages/discordeno/rest/checkRateLimits.ts +++ b/packages/discordeno/rest/checkRateLimits.ts @@ -1,9 +1,9 @@ -import { RestManager } from "./restManager.ts"; +import { RestManager } from './restManager.ts'; /** Check the rate limits for a url or a bucket. */ export function checkRateLimits(rest: RestManager, url: string) { const ratelimited = rest.rateLimitedPaths.get(url); - const global = rest.rateLimitedPaths.get("global"); + const global = rest.rateLimitedPaths.get('global'); const now = Date.now(); if (ratelimited && now < ratelimited.resetTimestamp) { diff --git a/packages/discordeno/rest/cleanupQueues.ts b/packages/discordeno/rest/cleanupQueues.ts index 3ea9d53..95343b7 100644 --- a/packages/discordeno/rest/cleanupQueues.ts +++ b/packages/discordeno/rest/cleanupQueues.ts @@ -1,4 +1,4 @@ -import { RestManager } from "./restManager.ts"; +import { RestManager } from './restManager.ts'; /** Cleans up the queues by checking if there is nothing left and removing it. */ export function cleanupQueues(rest: RestManager) { diff --git a/packages/discordeno/rest/convertRestError.ts b/packages/discordeno/rest/convertRestError.ts index eb7cd08..37ffd43 100644 --- a/packages/discordeno/rest/convertRestError.ts +++ b/packages/discordeno/rest/convertRestError.ts @@ -1,4 +1,4 @@ -import { RestRequestRejection } from "./rest.ts"; +import { RestRequestRejection } from './rest.ts'; export function convertRestError(errorStack: Error, data: RestRequestRejection): Error { errorStack.message = `[${data.status}] ${data.error}\n${data.body}`; diff --git a/packages/discordeno/rest/createRequestBody.ts b/packages/discordeno/rest/createRequestBody.ts index 3e43e82..8ed52e5 100644 --- a/packages/discordeno/rest/createRequestBody.ts +++ b/packages/discordeno/rest/createRequestBody.ts @@ -1,16 +1,16 @@ -import { RestManager } from "./restManager.ts"; -import { FileContent } from "../types/shared.ts"; -import { USER_AGENT } from "../util/constants.ts"; -import { RequestMethod, RestPayload, RestRequest } from "./rest.ts"; +import { RestManager } from './restManager.ts'; +import { FileContent } from '../types/shared.ts'; +import { USER_AGENT } from '../util/constants.ts'; +import { RequestMethod, RestPayload, RestRequest } from './rest.ts'; /** Creates the request body and headers that are necessary to send a request. Will handle different types of methods and everything necessary for discord. */ // export function createRequestBody(rest: RestManager, queuedRequest: { request: RestRequest; payload: RestPayload }) { export function createRequestBody(rest: RestManager, options: CreateRequestBodyOptions) { const headers: Record = { - "user-agent": USER_AGENT, + 'user-agent': USER_AGENT, }; - if (!options.unauthorized) headers["authorization"] = `Bot ${rest.token}`; + if (!options.unauthorized) headers['authorization'] = `Bot ${rest.token}`; // SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED if (options.headers) { @@ -20,13 +20,13 @@ export function createRequestBody(rest: RestManager, options: CreateRequestBodyO } // GET METHODS SHOULD NOT HAVE A BODY - if (options.method === "GET") { + if (options.method === 'GET') { options.body = undefined; } // IF A REASON IS PROVIDED ENCODE IT IN HEADERS if (options.body?.reason) { - headers["X-Audit-Log-Reason"] = encodeURIComponent(options.body.reason as string); + headers['X-Audit-Log-Reason'] = encodeURIComponent(options.body.reason as string); options.body.reason = undefined; } @@ -46,10 +46,10 @@ export function createRequestBody(rest: RestManager, options: CreateRequestBodyO ); } - form.append("payload_json", JSON.stringify({ ...options.body, file: undefined })); + form.append('payload_json', JSON.stringify({ ...options.body, file: undefined })); options.body.file = form; - } else if (options.body && !["GET", "DELETE"].includes(options.method)) { - headers["Content-Type"] = "application/json"; + } else if (options.body && !['GET', 'DELETE'].includes(options.method)) { + headers['Content-Type'] = 'application/json'; } return { diff --git a/packages/discordeno/rest/mod.ts b/packages/discordeno/rest/mod.ts index 5713808..6729976 100644 --- a/packages/discordeno/rest/mod.ts +++ b/packages/discordeno/rest/mod.ts @@ -1,14 +1,14 @@ -export * from "./checkRateLimits.ts"; -export * from "./cleanupQueues.ts"; -export * from "./createRequestBody.ts"; -export * from "./processGlobalQueue.ts"; -export * from "./processQueue.ts"; -export * from "./processRateLimitedPaths.ts"; -export * from "./processRequest.ts"; -export * from "./processRequestHeaders.ts"; -export * from "./rest.ts"; -export * from "./restManager.ts"; -export * from "./runMethod.ts"; -export * from "./simplifyUrl.ts"; -export * from "./convertRestError.ts"; -export * from "./sendRequest.ts"; +export * from './checkRateLimits.ts'; +export * from './cleanupQueues.ts'; +export * from './createRequestBody.ts'; +export * from './processGlobalQueue.ts'; +export * from './processQueue.ts'; +export * from './processRateLimitedPaths.ts'; +export * from './processRequest.ts'; +export * from './processRequestHeaders.ts'; +export * from './rest.ts'; +export * from './restManager.ts'; +export * from './runMethod.ts'; +export * from './simplifyUrl.ts'; +export * from './convertRestError.ts'; +export * from './sendRequest.ts'; diff --git a/packages/discordeno/rest/processGlobalQueue.ts b/packages/discordeno/rest/processGlobalQueue.ts index 4d7932a..f0c794b 100644 --- a/packages/discordeno/rest/processGlobalQueue.ts +++ b/packages/discordeno/rest/processGlobalQueue.ts @@ -1,5 +1,5 @@ -import { RestManager } from "./restManager.ts"; -import { HTTPResponseCodes } from "../types/shared.ts"; +import { RestManager } from './restManager.ts'; +import { HTTPResponseCodes } from '../types/shared.ts'; export async function processGlobalQueue(rest: RestManager) { // IF QUEUE IS EMPTY EXIT diff --git a/packages/discordeno/rest/processQueue.ts b/packages/discordeno/rest/processQueue.ts index 0ac08b7..a3456b8 100644 --- a/packages/discordeno/rest/processQueue.ts +++ b/packages/discordeno/rest/processQueue.ts @@ -1,4 +1,4 @@ -import { RestManager } from "./restManager.ts"; +import { RestManager } from './restManager.ts'; /** Processes the queue by looping over each path separately until the queues are empty. */ export function processQueue(rest: RestManager, id: string) { diff --git a/packages/discordeno/rest/processRateLimitedPaths.ts b/packages/discordeno/rest/processRateLimitedPaths.ts index eae47cb..aff717c 100644 --- a/packages/discordeno/rest/processRateLimitedPaths.ts +++ b/packages/discordeno/rest/processRateLimitedPaths.ts @@ -1,4 +1,4 @@ -import { RestManager } from "./restManager.ts"; +import { RestManager } from './restManager.ts'; /** This will create a infinite loop running in 1 seconds using tail recursion to keep rate limits clean. When a rate limit resets, this will remove it so the queue can proceed. */ export function processRateLimitedPaths(rest: RestManager) { @@ -12,7 +12,7 @@ export function processRateLimitedPaths(rest: RestManager) { // RATE LIMIT IS OVER, DELETE THE RATE LIMITER rest.rateLimitedPaths.delete(key); // IF IT WAS GLOBAL ALSO MARK THE GLOBAL VALUE AS FALSE - if (key === "global") rest.globallyRateLimited = false; + if (key === 'global') rest.globallyRateLimited = false; } // ALL PATHS ARE CLEARED CAN CANCEL OUT! diff --git a/packages/discordeno/rest/processRequest.ts b/packages/discordeno/rest/processRequest.ts index 5a72b1d..781d50b 100644 --- a/packages/discordeno/rest/processRequest.ts +++ b/packages/discordeno/rest/processRequest.ts @@ -1,17 +1,17 @@ -import { RestManager } from "./restManager.ts"; -import { BASE_URL } from "../util/constants.ts"; -import { RestPayload, RestRequest } from "./rest.ts"; +import { RestManager } from './restManager.ts'; +import { BASE_URL } from '../util/constants.ts'; +import { RestPayload, RestRequest } from './rest.ts'; /** Processes a request and assigns it to a queue or creates a queue if none exists for it. */ export function processRequest(rest: RestManager, request: RestRequest, payload: RestPayload) { - const route = request.url.substring(request.url.indexOf("api/")); - const parts = route.split("/"); + const route = request.url.substring(request.url.indexOf('api/')); + const parts = route.split('/'); // REMOVE THE API parts.shift(); // REMOVES THE VERSION NUMBER - if (parts[0]?.startsWith("v")) parts.shift(); + if (parts[0]?.startsWith('v')) parts.shift(); // SET THE NEW REQUEST URL - request.url = `${BASE_URL}/v${rest.version}/${parts.join("/")}`; + request.url = `${BASE_URL}/v${rest.version}/${parts.join('/')}`; // REMOVE THE MAJOR PARAM parts.shift(); diff --git a/packages/discordeno/rest/processRequestHeaders.ts b/packages/discordeno/rest/processRequestHeaders.ts index 2385792..c40ffe9 100644 --- a/packages/discordeno/rest/processRequestHeaders.ts +++ b/packages/discordeno/rest/processRequestHeaders.ts @@ -1,19 +1,19 @@ -import { RestManager } from "./restManager.ts"; +import { RestManager } from './restManager.ts'; /** Processes the rate limit headers and determines if it needs to be rate limited and returns the bucket id if available */ export function processRequestHeaders(rest: RestManager, url: string, headers: Headers) { let rateLimited = false; // GET ALL NECESSARY HEADERS - const remaining = headers.get("x-ratelimit-remaining"); - const retryAfter = headers.get("x-ratelimit-reset-after"); + const remaining = headers.get('x-ratelimit-remaining'); + const retryAfter = headers.get('x-ratelimit-reset-after'); const reset = Date.now() + Number(retryAfter) * 1000; - const global = headers.get("x-ratelimit-global"); + const global = headers.get('x-ratelimit-global'); // undefined override null needed for typings - const bucketId = headers.get("x-ratelimit-bucket") || undefined; + const bucketId = headers.get('x-ratelimit-bucket') || undefined; // IF THERE IS NO REMAINING RATE LIMIT, MARK IT AS RATE LIMITED - if (remaining === "0") { + if (remaining === '0') { rateLimited = true; // SAVE THE URL AS LIMITED, IMPORTANT FOR NEW REQUESTS BY USER WITHOUT BUCKET @@ -35,21 +35,21 @@ export function processRequestHeaders(rest: RestManager, url: string, headers: H // IF THERE IS NO REMAINING GLOBAL LIMIT, MARK IT RATE LIMITED GLOBALLY if (global) { - const retryAfter = headers.get("retry-after"); + const retryAfter = headers.get('retry-after'); const globalReset = Date.now() + Number(retryAfter) * 1000; rest.debug(`[REST = Globally Rate Limited] URL: ${url} | Global Rest: ${globalReset}`); rest.globallyRateLimited = true; rateLimited = true; - rest.rateLimitedPaths.set("global", { - url: "global", + rest.rateLimitedPaths.set('global', { + url: 'global', resetTimestamp: globalReset, bucketId, }); if (bucketId) { rest.rateLimitedPaths.set(bucketId, { - url: "global", + url: 'global', resetTimestamp: globalReset, bucketId, }); diff --git a/packages/discordeno/rest/rest.ts b/packages/discordeno/rest/rest.ts index c794dc0..7eee9d0 100644 --- a/packages/discordeno/rest/rest.ts +++ b/packages/discordeno/rest/rest.ts @@ -28,4 +28,4 @@ export interface RestRateLimitedPath { bucketId?: string; } -export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; +export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; diff --git a/packages/discordeno/rest/restManager.ts b/packages/discordeno/rest/restManager.ts index 0f8a93b..30c09fa 100644 --- a/packages/discordeno/rest/restManager.ts +++ b/packages/discordeno/rest/restManager.ts @@ -1,19 +1,19 @@ -import { checkRateLimits } from "./checkRateLimits.ts"; -import { cleanupQueues } from "./cleanupQueues.ts"; -import { createRequestBody } from "./createRequestBody.ts"; -import { processGlobalQueue } from "./processGlobalQueue.ts"; -import { processQueue } from "./processQueue.ts"; -import { processRateLimitedPaths } from "./processRateLimitedPaths.ts"; -import { processRequest } from "./processRequest.ts"; -import { processRequestHeaders } from "./processRequestHeaders.ts"; -import { convertRestError } from "./convertRestError.ts"; -import { RestPayload, RestRateLimitedPath, RestRequest } from "./rest.ts"; -import { runMethod } from "./runMethod.ts"; -import { simplifyUrl } from "./simplifyUrl.ts"; -import { baseEndpoints } from "../util/constants.ts"; -import { API_VERSION } from "../util/constants.ts"; -import { removeTokenPrefix } from "../util/token.ts"; -import { sendRequest } from "./sendRequest.ts"; +import { checkRateLimits } from './checkRateLimits.ts'; +import { cleanupQueues } from './cleanupQueues.ts'; +import { createRequestBody } from './createRequestBody.ts'; +import { processGlobalQueue } from './processGlobalQueue.ts'; +import { processQueue } from './processQueue.ts'; +import { processRateLimitedPaths } from './processRateLimitedPaths.ts'; +import { processRequest } from './processRequest.ts'; +import { processRequestHeaders } from './processRequestHeaders.ts'; +import { convertRestError } from './convertRestError.ts'; +import { RestPayload, RestRateLimitedPath, RestRequest } from './rest.ts'; +import { runMethod } from './runMethod.ts'; +import { simplifyUrl } from './simplifyUrl.ts'; +import { baseEndpoints } from '../util/constants.ts'; +import { API_VERSION } from '../util/constants.ts'; +import { removeTokenPrefix } from '../util/token.ts'; +import { sendRequest } from './sendRequest.ts'; export function createRestManager(options: CreateRestManagerOptions) { const version = options.version || API_VERSION; @@ -39,8 +39,8 @@ export function createRestManager(options: CreateRestManagerOptions) { version, token: removeTokenPrefix(options.token), maxRetryCount: options.maxRetryCount || 10, - secretKey: options.secretKey || "discordeno_best_lib_ever", - customUrl: options.customUrl || "", + secretKey: options.secretKey || 'discordeno_best_lib_ever', + customUrl: options.customUrl || '', pathQueues: new Map< string, { diff --git a/packages/discordeno/rest/runMethod.ts b/packages/discordeno/rest/runMethod.ts index 9a714a7..c3a7512 100644 --- a/packages/discordeno/rest/runMethod.ts +++ b/packages/discordeno/rest/runMethod.ts @@ -1,6 +1,6 @@ -import { RestManager } from "./restManager.ts"; -import { API_VERSION, BASE_URL, baseEndpoints } from "../util/constants.ts"; -import { RequestMethod, RestRequestRejection, RestRequestResponse } from "./rest.ts"; +import { RestManager } from './restManager.ts'; +import { API_VERSION, BASE_URL, baseEndpoints } from '../util/constants.ts'; +import { RequestMethod, RestRequestRejection, RestRequestResponse } from './rest.ts'; export async function runMethod( rest: RestManager, @@ -23,18 +23,18 @@ export async function runMethod( }`, ); - const errorStack = new Error("Location:"); + const errorStack = new Error('Location:'); // @ts-ignore Breaks deno deploy. Luca said add ts-ignore until it's fixed Error.captureStackTrace?.(errorStack); // For proxies we don't need to do any of the legwork so we just forward the request - if (!baseEndpoints.BASE_URL.startsWith(BASE_URL) && route[0] === "/") { + if (!baseEndpoints.BASE_URL.startsWith(BASE_URL) && route[0] === '/') { const result = await fetch(`${baseEndpoints.BASE_URL}${route}`, { body: body ? JSON.stringify(body) : undefined, headers: { Authorization: rest.secretKey, - "Content-Type": "application/json", + 'Content-Type': 'application/json', }, method, }).catch((error) => { @@ -59,14 +59,14 @@ export async function runMethod( rest.processRequest( rest, { - url: route[0] === "/" ? `${BASE_URL}/v${API_VERSION}${route}` : route, + url: route[0] === '/' ? `${BASE_URL}/v${API_VERSION}${route}` : route, method, reject: (data: RestRequestRejection) => { const restError = rest.convertRestError(errorStack, data); reject(restError); }, respond: (data: RestRequestResponse) => - resolve(data.status !== 204 ? JSON.parse(data.body ?? "{}") : (undefined as unknown as T)), + resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : (undefined as unknown as T)), }, { bucketId: options?.bucketId, diff --git a/packages/discordeno/rest/runProxyMethod.ts b/packages/discordeno/rest/runProxyMethod.ts index 8ab4035..bcdf06d 100644 --- a/packages/discordeno/rest/runProxyMethod.ts +++ b/packages/discordeno/rest/runProxyMethod.ts @@ -1,13 +1,13 @@ -import { RestManager } from "./restManager.ts"; -import { RestRequestRejection, RestRequestResponse } from "./rest.ts"; +import { RestManager } from './restManager.ts'; +import { RestRequestRejection, RestRequestResponse } from './rest.ts'; -export type ProxyMethodResponse = Omit & { body?: T }; +export type ProxyMethodResponse = Omit & { body?: T }; // Left out proxy request, because it's not needed here // this file could also be moved to a plugin. export async function runProxyMethod( rest: RestManager, - method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH", + method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', url: string, body?: unknown, retryCount = 0, @@ -30,11 +30,11 @@ export async function runProxyMethod( method, reject: (data: RestRequestRejection) => { const { body: b, ...r } = data; - reject({ body: data.status !== 204 ? JSON.parse(b ?? "{}") : (undefined as unknown as T), ...r }); + reject({ body: data.status !== 204 ? JSON.parse(b ?? '{}') : (undefined as unknown as T), ...r }); }, respond: (data: RestRequestResponse) => { const { body: b, ...r } = data; - resolve({ body: data.status !== 204 ? JSON.parse(b ?? "{}") : (undefined as unknown as T), ...r }); + resolve({ body: data.status !== 204 ? JSON.parse(b ?? '{}') : (undefined as unknown as T), ...r }); }, }, { diff --git a/packages/discordeno/rest/sendRequest.ts b/packages/discordeno/rest/sendRequest.ts index 5481827..26c7ece 100644 --- a/packages/discordeno/rest/sendRequest.ts +++ b/packages/discordeno/rest/sendRequest.ts @@ -1,7 +1,7 @@ -import { HTTPResponseCodes } from "../types/shared.ts"; -import { BASE_URL } from "../util/constants.ts"; -import { RequestMethod } from "./rest.ts"; -import { RestManager } from "./restManager.ts"; +import { HTTPResponseCodes } from '../types/shared.ts'; +import { BASE_URL } from '../util/constants.ts'; +import { RequestMethod } from './rest.ts'; +import { RestManager } from './restManager.ts'; export interface RestSendRequestOptions { url: string; @@ -50,31 +50,31 @@ export async function sendRequest(rest: RestManager, options: RestSendRequest `[REST - httpError] Payload: ${JSON.stringify(options)} | Response: ${JSON.stringify(response)}`, ); - let error = "REQUEST_UNKNOWN_ERROR"; + let error = 'REQUEST_UNKNOWN_ERROR'; switch (response.status) { case HTTPResponseCodes.BadRequest: - error = "The options was improperly formatted, or the server couldn't understand it."; + error = 'The options was improperly formatted, or the server couldn\'t understand it.'; break; case HTTPResponseCodes.Unauthorized: - error = "The Authorization header was missing or invalid."; + error = 'The Authorization header was missing or invalid.'; break; case HTTPResponseCodes.Forbidden: - error = "The Authorization token you passed did not have permission to the resource."; + error = 'The Authorization token you passed did not have permission to the resource.'; break; case HTTPResponseCodes.NotFound: - error = "The resource at the location specified doesn't exist."; + error = 'The resource at the location specified doesn\'t exist.'; break; case HTTPResponseCodes.MethodNotAllowed: - error = "The HTTP method used is not valid for the location specified."; + error = 'The HTTP method used is not valid for the location specified.'; break; case HTTPResponseCodes.GatewayUnavailable: - error = "There was not a gateway available to process your options. Wait a bit and retry."; + error = 'There was not a gateway available to process your options. Wait a bit and retry.'; break; } if ( rest.invalidRequestErrorStatuses.includes(response.status) && - !(response.status === 429 && response.headers.get("X-RateLimit-Scope")) + !(response.status === 429 && response.headers.get('X-RateLimit-Scope')) ) { // INCREMENT CURRENT INVALID REQUESTS ++rest.invalidRequests; @@ -112,7 +112,7 @@ export async function sendRequest(rest: RestManager, options: RestSendRequest options.reject?.({ ok: false, status: response.status, - error: "The options was rate limited and it maxed out the retries limit.", + error: 'The options was rate limited and it maxed out the retries limit.', }); // @ts-ignore Code should never reach here @@ -149,10 +149,10 @@ export async function sendRequest(rest: RestManager, options: RestSendRequest options.reject?.({ ok: false, status: 599, - error: "Internal Proxy Error", + error: 'Internal Proxy Error', }); - throw new Error("Something went wrong in sendRequest", { + throw new Error('Something went wrong in sendRequest', { cause: error, }); } diff --git a/packages/discordeno/rest/simplifyUrl.ts b/packages/discordeno/rest/simplifyUrl.ts index ae7c174..288faed 100644 --- a/packages/discordeno/rest/simplifyUrl.ts +++ b/packages/discordeno/rest/simplifyUrl.ts @@ -7,17 +7,17 @@ export function simplifyUrl(url: string, method: string) { let route = url .replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, function (match, p) { - return ["channels", "guilds"].includes(p) ? match : `/${p}/skillzPrefersID`; + return ['channels', 'guilds'].includes(p) ? match : `/${p}/skillzPrefersID`; }) - .replace(/\/reactions\/[^/]+/g, "/reactions/skillzPrefersID"); + .replace(/\/reactions\/[^/]+/g, '/reactions/skillzPrefersID'); // GENERAL /reactions and /reactions/emoji/@me share the buckets - if (route.includes("/reactions")) { - route = route.substring(0, route.indexOf("/reactions") + "/reactions".length); + if (route.includes('/reactions')) { + route = route.substring(0, route.indexOf('/reactions') + '/reactions'.length); } // Delete Message endpoint has its own rate limit - if (method === "DELETE" && route.endsWith("/messages/skillzPrefersID")) { + if (method === 'DELETE' && route.endsWith('/messages/skillzPrefersID')) { route = method + route; } diff --git a/packages/discordeno/types/discord.ts b/packages/discordeno/types/discord.ts index f75b9fa..62d65bd 100644 --- a/packages/discordeno/types/discord.ts +++ b/packages/discordeno/types/discord.ts @@ -41,7 +41,7 @@ import { VideoQualityModes, VisibilityTypes, WebhookTypes, -} from "./shared.ts"; +} from './shared.ts'; /** https://discord.com/developers/docs/resources/user#user-object */ export interface DiscordUser { @@ -108,7 +108,7 @@ export interface DiscordIntegration { /** Integration name */ name: string; /** Integration type (twitch, youtube or discord) */ - type: "twitch" | "youtube" | "discord"; + type: 'twitch' | 'youtube' | 'discord'; /** Is this integration enabled */ enabled?: boolean; /** Is this integration syncing */ @@ -287,12 +287,12 @@ export interface DiscordTeamMember { /** The user's membership state on the team */ membership_state: TeamMembershipStates; /** Will always be `["*"]` */ - permissions: "*"[]; + permissions: '*'[]; /** The id of the parent team of which they are a member */ team_id: string; /** The avatar, discriminator, id, and username of the user */ - user: Partial & Pick; + user: Partial & Pick; } /** https://discord.com/developers/docs/topics/gateway#webhooks-update-webhook-update-event-fields */ @@ -586,7 +586,7 @@ export interface DiscordGuild { /** When this guild was joined at */ joined_at?: string; /** States of members currently in voice channels; lacks the guild_id key */ - voice_states?: Omit[]; + voice_states?: Omit[]; /** Users in the guild */ members?: DiscordMember[]; /** Channels in the guild */ @@ -759,7 +759,7 @@ export interface DiscordChannel { /** https://discord.com/developers/docs/topics/gateway#presence-update */ export interface DiscordPresenceUpdate { /** Either "idle", "dnd", "online", or "offline" */ - status: "idle" | "dnd" | "online" | "offline"; + status: 'idle' | 'dnd' | 'online' | 'offline'; /** The user presence is being updated for */ user: DiscordUser; /** id of the guild */ @@ -774,7 +774,7 @@ export interface DiscordStatusUpdate { /** User's current activities */ activities: DiscordActivity[]; /** Either "idle", "dnd", "online", or "offline" */ - status: "idle" | "dnd" | "online" | "offline"; + status: 'idle' | 'dnd' | 'online' | 'offline'; } /** https://discord.com/developers/docs/resources/guild#welcome-screen-object-welcome-screen-structure */ @@ -1030,7 +1030,7 @@ export interface DiscordMessage { /** if the message is an Interaction or application-owned webhook, this is the id of the application */ application_id?: string; /** Data showing the source of a crossposted channel follow add, pin or reply message */ - message_reference?: Omit; + message_reference?: Omit; /** Message flags combined as a bitfield */ flags?: number; /** @@ -1046,7 +1046,7 @@ export interface DiscordMessage { /** Sent if the message is a response to an Interaction */ interaction?: DiscordMessageInteraction; /** The thread that was started from this message, includes thread member object */ - thread?: Omit & { member: DiscordThreadMember }; + thread?: Omit & { member: DiscordThreadMember }; /** The components related to this message */ components?: DiscordMessageComponents; /** Sent if the message contains stickers */ @@ -1327,11 +1327,11 @@ export interface DiscordInteractionData { /** The Ids and User objects */ users?: Record; /** The Ids and partial Member objects */ - members?: Record>; + members?: Record>; /** The Ids and Role objects */ roles?: Record; /** The Ids and partial Channel objects */ - channels?: Record>; + channels?: Record>; /** The ids and attachment objects */ attachments: Record; }; @@ -1362,11 +1362,11 @@ export interface DiscordInteractionDataResolved { /** The Ids and User objects */ users?: Record; /** The Ids and partial Member objects */ - members?: Record>; + members?: Record>; /** The Ids and Role objects */ roles?: Record; /** The Ids and partial Channel objects */ - channels?: Record>; + channels?: Record>; /** The Ids and attachments objects */ attachments?: Record; } @@ -1541,93 +1541,93 @@ export type DiscordAuditLogChange = new_value: string; old_value: string; key: - | "name" - | "description" - | "discovery_splash_hash" - | "banner_hash" - | "preferred_locale" - | "rules_channel_id" - | "public_updates_channel_id" - | "icon_hash" - | "image_hash" - | "splash_hash" - | "owner_id" - | "region" - | "afk_channel_id" - | "vanity_url_code" - | "widget_channel_id" - | "system_channel_id" - | "topic" - | "application_id" - | "permissions" - | "allow" - | "deny" - | "code" - | "channel_id" - | "inviter_id" - | "nick" - | "avatar_hash" - | "id" - | "location" - | "command_id"; + | 'name' + | 'description' + | 'discovery_splash_hash' + | 'banner_hash' + | 'preferred_locale' + | 'rules_channel_id' + | 'public_updates_channel_id' + | 'icon_hash' + | 'image_hash' + | 'splash_hash' + | 'owner_id' + | 'region' + | 'afk_channel_id' + | 'vanity_url_code' + | 'widget_channel_id' + | 'system_channel_id' + | 'topic' + | 'application_id' + | 'permissions' + | 'allow' + | 'deny' + | 'code' + | 'channel_id' + | 'inviter_id' + | 'nick' + | 'avatar_hash' + | 'id' + | 'location' + | 'command_id'; } | { new_value: number; old_value: number; key: - | "afk_timeout" - | "mfa_level" - | "verification_level" - | "explicit_content_filter" - | "default_message_notifications" - | "prune_delete_days" - | "position" - | "bitrate" - | "rate_limit_per_user" - | "color" - | "max_uses" - | "uses" - | "max_age" - | "expire_behavior" - | "expire_grace_period" - | "user_limit" - | "privacy_level" - | "auto_archive_duration" - | "default_auto_archive_duration" - | "entity_type" - | "status" - | "communication_disabled_until"; + | 'afk_timeout' + | 'mfa_level' + | 'verification_level' + | 'explicit_content_filter' + | 'default_message_notifications' + | 'prune_delete_days' + | 'position' + | 'bitrate' + | 'rate_limit_per_user' + | 'color' + | 'max_uses' + | 'uses' + | 'max_age' + | 'expire_behavior' + | 'expire_grace_period' + | 'user_limit' + | 'privacy_level' + | 'auto_archive_duration' + | 'default_auto_archive_duration' + | 'entity_type' + | 'status' + | 'communication_disabled_until'; } | { new_value: Partial[]; old_value?: Partial[]; - key: "$add" | "$remove"; + key: '$add' | '$remove'; } | { new_value: boolean; old_value: boolean; key: - | "widget_enabled" - | "nsfw" - | "hoist" - | "mentionable" - | "temporary" - | "deaf" - | "mute" - | "enable_emoticons" - | "archived" - | "locked" - | "invitable"; + | 'widget_enabled' + | 'nsfw' + | 'hoist' + | 'mentionable' + | 'temporary' + | 'deaf' + | 'mute' + | 'enable_emoticons' + | 'archived' + | 'locked' + | 'invitable'; } | { new_value: DiscordOverwrite[]; old_value: DiscordOverwrite[]; - key: "permission_overwrites"; + key: 'permission_overwrites'; } | { new_value: string | number; old_value: string | number; - key: "type"; + key: 'type'; }; /** https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ @@ -2088,7 +2088,7 @@ export interface DiscordGuildBanAddRemove { } /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */ -export interface DiscordMessageReactionRemove extends Omit {} +export interface DiscordMessageReactionRemove extends Omit {} /** https://discord.com/developers/docs/topics/gateway#message-reaction-add */ export interface DiscordMessageReactionAdd { @@ -2163,11 +2163,11 @@ export interface DiscordReady { /** The shard information associated with this session, if sent when identifying */ shard?: [number, number]; /** Contains id and flags */ - application: Partial & Pick; + application: Partial & Pick; } /** https://discord.com/developers/docs/resources/guild#unavailable-guild-object */ -export interface DiscordUnavailableGuild extends Pick {} +export interface DiscordUnavailableGuild extends Pick {} /** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */ export interface DiscordMessageDeleteBulk { @@ -2204,28 +2204,28 @@ export interface DiscordTemplate { & Omit< PickPartial< DiscordGuild, - | "name" - | "description" - | "verification_level" - | "default_message_notifications" - | "explicit_content_filter" - | "preferred_locale" - | "afk_timeout" - | "channels" - | "afk_channel_id" - | "system_channel_id" - | "system_channel_flags" + | 'name' + | 'description' + | 'verification_level' + | 'default_message_notifications' + | 'explicit_content_filter' + | 'preferred_locale' + | 'afk_timeout' + | 'channels' + | 'afk_channel_id' + | 'system_channel_id' + | 'system_channel_flags' >, - "roles" + 'roles' > & { roles: ( & Omit< PickPartial< DiscordRole, - "name" | "color" | "hoist" | "mentionable" | "permissions" | "icon" | "unicode_emoji" + 'name' | 'color' | 'hoist' | 'mentionable' | 'permissions' | 'icon' | 'unicode_emoji' >, - "id" + 'id' > & { id: number } )[]; @@ -2337,7 +2337,7 @@ export interface DiscordGuildMemberUpdate { /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */ export interface DiscordMessageReactionRemoveAll - extends Pick {} + extends Pick {} // TODO: add docs link export interface DiscordValidateDiscoverySearchTerm { @@ -2365,7 +2365,7 @@ export interface DiscordScheduledEventUserAdd { /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji */ export type DiscordMessageReactionRemoveEmoji = Pick< DiscordMessageReactionAdd, - "channel_id" | "guild_id" | "message_id" | "emoji" + 'channel_id' | 'guild_id' | 'message_id' | 'emoji' >; /** https://discord.com/developers/docs/topics/gateway#guild-member-remove */ diff --git a/packages/discordeno/types/mod.ts b/packages/discordeno/types/mod.ts index 1ef8f1d..c59b7fb 100644 --- a/packages/discordeno/types/mod.ts +++ b/packages/discordeno/types/mod.ts @@ -1,2 +1,2 @@ -export * from "./discord.ts"; -export * from "./shared.ts"; +export * from './discord.ts'; +export * from './shared.ts'; diff --git a/packages/discordeno/types/shared.ts b/packages/discordeno/types/shared.ts index b3c189a..f3a1b1b 100644 --- a/packages/discordeno/types/shared.ts +++ b/packages/discordeno/types/shared.ts @@ -105,11 +105,11 @@ export enum ButtonStyles { /** https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mention-types */ export enum AllowedMentionsTypes { /** Controls role mentions */ - RoleMentions = "roles", + RoleMentions = 'roles', /** Controls user mentions */ - UserMentions = "users", + UserMentions = 'users', /** Controls @everyone and @here mentions */ - EveryoneMentions = "everyone", + EveryoneMentions = 'everyone', } /** https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types */ @@ -123,7 +123,7 @@ export enum WebhookTypes { } /** https://discord.com/developers/docs/resources/channel#embed-object-embed-types */ -export type EmbedTypes = "rich" | "image" | "video" | "gifv" | "article" | "link"; +export type EmbedTypes = 'rich' | 'image' | 'video' | 'gifv' | 'article' | 'link'; /** https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level */ export enum DefaultMessageNotificationLevels { @@ -172,49 +172,49 @@ export interface BaseRole { /** https://discord.com/developers/docs/resources/guild#guild-object-guild-features */ export enum GuildFeatures { /** Guild has access to set an invite splash background */ - InviteSplash = "INVITE_SPLASH", + InviteSplash = 'INVITE_SPLASH', /** Guild has access to set 384 kbps bitrate in voice (previously VIP voice servers) */ - VipRegions = "VIP_REGIONS", + VipRegions = 'VIP_REGIONS', /** Guild has access to set a vanity URL */ - VanityUrl = "VANITY_URL", + VanityUrl = 'VANITY_URL', /** Guild is verified */ - Verified = "VERIFIED", + Verified = 'VERIFIED', /** Guild is partnered */ - Partnered = "PARTNERED", + Partnered = 'PARTNERED', /** Guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates */ - Community = "COMMUNITY", + Community = 'COMMUNITY', /** Guild has access to use commerce features (i.e. create store channels) */ - Commerce = "COMMERCE", + Commerce = 'COMMERCE', /** Guild has access to create news channels */ - News = "NEWS", + News = 'NEWS', /** Guild is able to be discovered in the directory */ - Discoverable = "DISCOVERABLE", + Discoverable = 'DISCOVERABLE', /** guild cannot be discoverable */ - DiscoverableDisabled = "DISCOVERABLE_DISABLED", + DiscoverableDisabled = 'DISCOVERABLE_DISABLED', /** Guild is able to be featured in the directory */ - Feature = "FEATURABLE", + Feature = 'FEATURABLE', /** Guild has access to set an animated guild icon */ - AnimatedIcon = "ANIMATED_ICON", + AnimatedIcon = 'ANIMATED_ICON', /** Guild has access to set a guild banner image */ - Banner = "BANNER", + Banner = 'BANNER', /** Guild has enabled the welcome screen */ - WelcomeScreenEnabled = "WELCOME_SCREEN_ENABLED", + WelcomeScreenEnabled = 'WELCOME_SCREEN_ENABLED', /** Guild has enabled [Membership Screening](https://discord.com/developers/docs/resources/guild#membership-screening-object) */ - MemberVerificationGateEnabled = "MEMBER_VERIFICATION_GATE_ENABLED", + MemberVerificationGateEnabled = 'MEMBER_VERIFICATION_GATE_ENABLED', /** Guild can be previewed before joining via Membership Screening or the directory */ - PreviewEnabled = "PREVIEW_ENABLED", + PreviewEnabled = 'PREVIEW_ENABLED', /** Guild has enabled ticketed events */ - TicketedEventsEnabled = "TICKETED_EVENTS_ENABLED", + TicketedEventsEnabled = 'TICKETED_EVENTS_ENABLED', /** Guild has enabled monetization */ - MonetizationEnabled = "MONETIZATION_ENABLED", + MonetizationEnabled = 'MONETIZATION_ENABLED', /** Guild has increased custom sticker slots */ - MoreStickers = "MORE_STICKERS", + MoreStickers = 'MORE_STICKERS', /** Guild has access to create private threads */ - PrivateThreads = "PRIVATE_THREADS", + PrivateThreads = 'PRIVATE_THREADS', /** Guild is able to set role icons */ - RoleIcons = "ROLE_ICONS", + RoleIcons = 'ROLE_ICONS', /** Guild has set up auto moderation rules */ - AutoModeration = "AUTO_MODERATION", + AutoModeration = 'AUTO_MODERATION', } /** https://discord.com/developers/docs/resources/guild#guild-object-mfa-level */ @@ -834,65 +834,65 @@ export enum GatewayOpcodes { } export type GatewayDispatchEventNames = - | "READY" - | "CHANNEL_CREATE" - | "CHANNEL_DELETE" - | "CHANNEL_PINS_UPDATE" - | "CHANNEL_UPDATE" - | "GUILD_BAN_ADD" - | "GUILD_BAN_REMOVE" - | "GUILD_CREATE" - | "GUILD_DELETE" - | "GUILD_EMOJIS_UPDATE" - | "GUILD_INTEGRATIONS_UPDATE" - | "GUILD_MEMBER_ADD" - | "GUILD_MEMBER_REMOVE" - | "GUILD_MEMBER_UPDATE" - | "GUILD_MEMBERS_CHUNK" - | "GUILD_ROLE_CREATE" - | "GUILD_ROLE_DELETE" - | "GUILD_ROLE_UPDATE" - | "GUILD_UPDATE" - | "GUILD_SCHEDULED_EVENT_CREATE" - | "GUILD_SCHEDULED_EVENT_DELETE" - | "GUILD_SCHEDULED_EVENT_UPDATE" - | "GUILD_SCHEDULED_EVENT_USER_ADD" - | "GUILD_SCHEDULED_EVENT_USER_REMOVE" - | "INTERACTION_CREATE" - | "INVITE_CREATE" - | "INVITE_DELETE" - | "MESSAGE_CREATE" - | "MESSAGE_DELETE_BULK" - | "MESSAGE_DELETE" - | "MESSAGE_REACTION_ADD" - | "MESSAGE_REACTION_REMOVE_ALL" - | "MESSAGE_REACTION_REMOVE_EMOJI" - | "MESSAGE_REACTION_REMOVE" - | "MESSAGE_UPDATE" - | "PRESENCE_UPDATE" - | "TYPING_START" - | "USER_UPDATE" - | "VOICE_SERVER_UPDATE" - | "VOICE_STATE_UPDATE" - | "WEBHOOKS_UPDATE" - | "INTEGRATION_CREATE" - | "INTEGRATION_UPDATE" - | "INTEGRATION_DELETE" - | "STAGE_INSTANCE_CREATE" - | "STAGE_INSTANCE_UPDATE" - | "STAGE_INSTANCE_DELETE" - | "THREAD_CREATE" - | "THREAD_UPDATE" - | "THREAD_DELETE" - | "THREAD_LIST_SYNC" - | "THREAD_MEMBERS_UPDATE"; + | 'READY' + | 'CHANNEL_CREATE' + | 'CHANNEL_DELETE' + | 'CHANNEL_PINS_UPDATE' + | 'CHANNEL_UPDATE' + | 'GUILD_BAN_ADD' + | 'GUILD_BAN_REMOVE' + | 'GUILD_CREATE' + | 'GUILD_DELETE' + | 'GUILD_EMOJIS_UPDATE' + | 'GUILD_INTEGRATIONS_UPDATE' + | 'GUILD_MEMBER_ADD' + | 'GUILD_MEMBER_REMOVE' + | 'GUILD_MEMBER_UPDATE' + | 'GUILD_MEMBERS_CHUNK' + | 'GUILD_ROLE_CREATE' + | 'GUILD_ROLE_DELETE' + | 'GUILD_ROLE_UPDATE' + | 'GUILD_UPDATE' + | 'GUILD_SCHEDULED_EVENT_CREATE' + | 'GUILD_SCHEDULED_EVENT_DELETE' + | 'GUILD_SCHEDULED_EVENT_UPDATE' + | 'GUILD_SCHEDULED_EVENT_USER_ADD' + | 'GUILD_SCHEDULED_EVENT_USER_REMOVE' + | 'INTERACTION_CREATE' + | 'INVITE_CREATE' + | 'INVITE_DELETE' + | 'MESSAGE_CREATE' + | 'MESSAGE_DELETE_BULK' + | 'MESSAGE_DELETE' + | 'MESSAGE_REACTION_ADD' + | 'MESSAGE_REACTION_REMOVE_ALL' + | 'MESSAGE_REACTION_REMOVE_EMOJI' + | 'MESSAGE_REACTION_REMOVE' + | 'MESSAGE_UPDATE' + | 'PRESENCE_UPDATE' + | 'TYPING_START' + | 'USER_UPDATE' + | 'VOICE_SERVER_UPDATE' + | 'VOICE_STATE_UPDATE' + | 'WEBHOOKS_UPDATE' + | 'INTEGRATION_CREATE' + | 'INTEGRATION_UPDATE' + | 'INTEGRATION_DELETE' + | 'STAGE_INSTANCE_CREATE' + | 'STAGE_INSTANCE_UPDATE' + | 'STAGE_INSTANCE_DELETE' + | 'THREAD_CREATE' + | 'THREAD_UPDATE' + | 'THREAD_DELETE' + | 'THREAD_LIST_SYNC' + | 'THREAD_MEMBERS_UPDATE'; export type GatewayEventNames = | GatewayDispatchEventNames - | "READY" - | "RESUMED" + | 'READY' + | 'RESUMED' // THIS IS A CUSTOM DD EVENT NOT A DISCORD EVENT - | "GUILD_LOADED_DD"; + | 'GUILD_LOADED_DD'; /** https://discord.com/developers/docs/topics/gateway#list-of-intents */ export enum GatewayIntents { @@ -1044,159 +1044,159 @@ export enum InteractionResponseTypes { export enum Errors { // Bot Role errors - BOTS_HIGHEST_ROLE_TOO_LOW = "BOTS_HIGHEST_ROLE_TOO_LOW", + BOTS_HIGHEST_ROLE_TOO_LOW = 'BOTS_HIGHEST_ROLE_TOO_LOW', // Channel Errors - CHANNEL_NOT_FOUND = "CHANNEL_NOT_FOUND", - CHANNEL_NOT_IN_GUILD = "CHANNEL_NOT_IN_GUILD", - CHANNEL_NOT_TEXT_BASED = "CHANNEL_NOT_TEXT_BASED", - CHANNEL_NOT_STAGE_VOICE = "CHANNEL_NOT_STAGE_VOICE", - MESSAGE_MAX_LENGTH = "MESSAGE_MAX_LENGTH", - RULES_CHANNEL_CANNOT_BE_DELETED = "RULES_CHANNEL_CANNOT_BE_DELETED", - UPDATES_CHANNEL_CANNOT_BE_DELETED = "UPDATES_CHANNEL_CANNOT_BE_DELETED", - INVALID_TOPIC_LENGTH = "INVALID_TOPIC_LENGTH", + CHANNEL_NOT_FOUND = 'CHANNEL_NOT_FOUND', + CHANNEL_NOT_IN_GUILD = 'CHANNEL_NOT_IN_GUILD', + CHANNEL_NOT_TEXT_BASED = 'CHANNEL_NOT_TEXT_BASED', + CHANNEL_NOT_STAGE_VOICE = 'CHANNEL_NOT_STAGE_VOICE', + MESSAGE_MAX_LENGTH = 'MESSAGE_MAX_LENGTH', + RULES_CHANNEL_CANNOT_BE_DELETED = 'RULES_CHANNEL_CANNOT_BE_DELETED', + UPDATES_CHANNEL_CANNOT_BE_DELETED = 'UPDATES_CHANNEL_CANNOT_BE_DELETED', + INVALID_TOPIC_LENGTH = 'INVALID_TOPIC_LENGTH', // Guild Errors - GUILD_NOT_DISCOVERABLE = "GUILD_NOT_DISCOVERABLE", - GUILD_WIDGET_NOT_ENABLED = "GUILD_WIDGET_NOT_ENABLED", - GUILD_NOT_FOUND = "GUILD_NOT_FOUND", - MEMBER_NOT_FOUND = "MEMBER_NOT_FOUND", - MEMBER_NOT_IN_VOICE_CHANNEL = "MEMBER_NOT_IN_VOICE_CHANNEL", - MEMBER_SEARCH_LIMIT_TOO_HIGH = "MEMBER_SEARCH_LIMIT_TOO_HIGH", - MEMBER_SEARCH_LIMIT_TOO_LOW = "MEMBER_SEARCH_LIMIT_TOO_LOW", - PRUNE_MAX_DAYS = "PRUNE_MAX_DAYS", - ROLE_NOT_FOUND = "ROLE_NOT_FOUND", + GUILD_NOT_DISCOVERABLE = 'GUILD_NOT_DISCOVERABLE', + GUILD_WIDGET_NOT_ENABLED = 'GUILD_WIDGET_NOT_ENABLED', + GUILD_NOT_FOUND = 'GUILD_NOT_FOUND', + MEMBER_NOT_FOUND = 'MEMBER_NOT_FOUND', + MEMBER_NOT_IN_VOICE_CHANNEL = 'MEMBER_NOT_IN_VOICE_CHANNEL', + MEMBER_SEARCH_LIMIT_TOO_HIGH = 'MEMBER_SEARCH_LIMIT_TOO_HIGH', + MEMBER_SEARCH_LIMIT_TOO_LOW = 'MEMBER_SEARCH_LIMIT_TOO_LOW', + PRUNE_MAX_DAYS = 'PRUNE_MAX_DAYS', + ROLE_NOT_FOUND = 'ROLE_NOT_FOUND', // Thread errors - INVALID_THREAD_PARENT_CHANNEL_TYPE = "INVALID_THREAD_PARENT_CHANNEL_TYPE", - GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS = "GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS", - NOT_A_THREAD_CHANNEL = "NOT_A_THREAD_CHANNEL", - MISSING_MANAGE_THREADS_AND_NOT_MEMBER = "MISSING_MANAGE_THREADS_AND_NOT_MEMBER", - CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD = "CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD", + INVALID_THREAD_PARENT_CHANNEL_TYPE = 'INVALID_THREAD_PARENT_CHANNEL_TYPE', + GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS = 'GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS', + NOT_A_THREAD_CHANNEL = 'NOT_A_THREAD_CHANNEL', + MISSING_MANAGE_THREADS_AND_NOT_MEMBER = 'MISSING_MANAGE_THREADS_AND_NOT_MEMBER', + CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD = 'CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD', HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS = - "HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS", + 'HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS', // Message Get Errors - INVALID_GET_MESSAGES_LIMIT = "INVALID_GET_MESSAGES_LIMIT", + INVALID_GET_MESSAGES_LIMIT = 'INVALID_GET_MESSAGES_LIMIT', // Message Delete Errors - DELETE_MESSAGES_MIN = "DELETE_MESSAGES_MIN", - PRUNE_MIN_DAYS = "PRUNE_MIN_DAYS", + DELETE_MESSAGES_MIN = 'DELETE_MESSAGES_MIN', + PRUNE_MIN_DAYS = 'PRUNE_MIN_DAYS', // Interaction Errors - INVALID_SLASH_DESCRIPTION = "INVALID_SLASH_DESCRIPTION", - INVALID_SLASH_NAME = "INVALID_SLASH_NAME", - INVALID_SLASH_OPTIONS = "INVALID_SLASH_OPTIONS", - INVALID_SLASH_OPTIONS_CHOICES = "INVALID_SLASH_OPTIONS_CHOICES", - TOO_MANY_SLASH_OPTIONS = "TOO_MANY_SLASH_OPTIONS", - INVALID_SLASH_OPTION_CHOICE_NAME = "INVALID_SLASH_OPTION_CHOICE_NAME", - INVALID_SLASH_OPTIONS_CHOICE_VALUE_TYPE = "INVALID_SLASH_OPTIONS_CHOICE_VALUE_TYPE", - TOO_MANY_SLASH_OPTION_CHOICES = "TOO_MANY_SLASH_OPTION_CHOICES", - ONLY_STRING_OR_INTEGER_OPTIONS_CAN_HAVE_CHOICES = "ONLY_STRING_OR_INTEGER_OPTIONS_CAN_HAVE_CHOICES", - INVALID_SLASH_OPTION_NAME = "INVALID_SLASH_OPTION_NAME", - INVALID_SLASH_OPTION_DESCRIPTION = "INVALID_SLASH_OPTION_DESCRIPTION", - INVALID_CONTEXT_MENU_COMMAND_NAME = "INVALID_CONTEXT_MENU_COMMAND_NAME", - INVALID_CONTEXT_MENU_COMMAND_DESCRIPTION = "INVALID_CONTEXT_MENU_COMMAND_DESCRIPTION", + INVALID_SLASH_DESCRIPTION = 'INVALID_SLASH_DESCRIPTION', + INVALID_SLASH_NAME = 'INVALID_SLASH_NAME', + INVALID_SLASH_OPTIONS = 'INVALID_SLASH_OPTIONS', + INVALID_SLASH_OPTIONS_CHOICES = 'INVALID_SLASH_OPTIONS_CHOICES', + TOO_MANY_SLASH_OPTIONS = 'TOO_MANY_SLASH_OPTIONS', + INVALID_SLASH_OPTION_CHOICE_NAME = 'INVALID_SLASH_OPTION_CHOICE_NAME', + INVALID_SLASH_OPTIONS_CHOICE_VALUE_TYPE = 'INVALID_SLASH_OPTIONS_CHOICE_VALUE_TYPE', + TOO_MANY_SLASH_OPTION_CHOICES = 'TOO_MANY_SLASH_OPTION_CHOICES', + ONLY_STRING_OR_INTEGER_OPTIONS_CAN_HAVE_CHOICES = 'ONLY_STRING_OR_INTEGER_OPTIONS_CAN_HAVE_CHOICES', + INVALID_SLASH_OPTION_NAME = 'INVALID_SLASH_OPTION_NAME', + INVALID_SLASH_OPTION_DESCRIPTION = 'INVALID_SLASH_OPTION_DESCRIPTION', + INVALID_CONTEXT_MENU_COMMAND_NAME = 'INVALID_CONTEXT_MENU_COMMAND_NAME', + INVALID_CONTEXT_MENU_COMMAND_DESCRIPTION = 'INVALID_CONTEXT_MENU_COMMAND_DESCRIPTION', // Webhook Errors - INVALID_WEBHOOK_NAME = "INVALID_WEBHOOK_NAME", - INVALID_WEBHOOK_OPTIONS = "INVALID_WEBHOOK_OPTIONS", + INVALID_WEBHOOK_NAME = 'INVALID_WEBHOOK_NAME', + INVALID_WEBHOOK_OPTIONS = 'INVALID_WEBHOOK_OPTIONS', // Permission Errors - MISSING_ADD_REACTIONS = "MISSING_ADD_REACTIONS", - MISSING_ADMINISTRATOR = "MISSING_ADMINISTRATOR", - MISSING_ATTACH_FILES = "MISSING_ATTACH_FILES", - MISSING_BAN_MEMBERS = "MISSING_BAN_MEMBERS", - MISSING_CHANGE_NICKNAME = "MISSING_CHANGE_NICKNAME", - MISSING_CONNECT = "MISSING_CONNECT", - MISSING_CREATE_INSTANT_INVITE = "MISSING_CREATE_INSTANT_INVITE", - MISSING_DEAFEN_MEMBERS = "MISSING_DEAFEN_MEMBERS", - MISSING_EMBED_LINKS = "MISSING_EMBED_LINKS", - MISSING_INTENT_GUILD_MEMBERS = "MISSING_INTENT_GUILD_MEMBERS", - MISSING_KICK_MEMBERS = "MISSING_KICK_MEMBERS", - MISSING_MANAGE_CHANNELS = "MISSING_MANAGE_CHANNELS", - MISSING_MANAGE_EMOJIS = "MISSING_MANAGE_EMOJIS", - MISSING_MANAGE_GUILD = "MISSING_MANAGE_GUILD", - MISSING_MANAGE_MESSAGES = "MISSING_MANAGE_MESSAGES", - MISSING_MANAGE_NICKNAMES = "MISSING_MANAGE_NICKNAMES", - MISSING_MANAGE_ROLES = "MISSING_MANAGE_ROLES", - MISSING_MANAGE_WEBHOOKS = "MISSING_MANAGE_WEBHOOKS", - MISSING_MENTION_EVERYONE = "MISSING_MENTION_EVERYONE", - MISSING_MOVE_MEMBERS = "MISSING_MOVE_MEMBERS", - MISSING_MUTE_MEMBERS = "MISSING_MUTE_MEMBERS", - MISSING_PRIORITY_SPEAKER = "MISSING_PRIORITY_SPEAKER", - MISSING_READ_MESSAGE_HISTORY = "MISSING_READ_MESSAGE_HISTORY", - MISSING_SEND_MESSAGES = "MISSING_SEND_MESSAGES", - MISSING_SEND_TTS_MESSAGES = "MISSING_SEND_TTS_MESSAGES", - MISSING_SPEAK = "MISSING_SPEAK", - MISSING_STREAM = "MISSING_STREAM", - MISSING_USE_VAD = "MISSING_USE_VAD", - MISSING_USE_EXTERNAL_EMOJIS = "MISSING_USE_EXTERNAL_EMOJIS", - MISSING_VIEW_AUDIT_LOG = "MISSING_VIEW_AUDIT_LOG", - MISSING_VIEW_CHANNEL = "MISSING_VIEW_CHANNEL", - MISSING_VIEW_GUILD_INSIGHTS = "MISSING_VIEW_GUILD_INSIGHTS", + MISSING_ADD_REACTIONS = 'MISSING_ADD_REACTIONS', + MISSING_ADMINISTRATOR = 'MISSING_ADMINISTRATOR', + MISSING_ATTACH_FILES = 'MISSING_ATTACH_FILES', + MISSING_BAN_MEMBERS = 'MISSING_BAN_MEMBERS', + MISSING_CHANGE_NICKNAME = 'MISSING_CHANGE_NICKNAME', + MISSING_CONNECT = 'MISSING_CONNECT', + MISSING_CREATE_INSTANT_INVITE = 'MISSING_CREATE_INSTANT_INVITE', + MISSING_DEAFEN_MEMBERS = 'MISSING_DEAFEN_MEMBERS', + MISSING_EMBED_LINKS = 'MISSING_EMBED_LINKS', + MISSING_INTENT_GUILD_MEMBERS = 'MISSING_INTENT_GUILD_MEMBERS', + MISSING_KICK_MEMBERS = 'MISSING_KICK_MEMBERS', + MISSING_MANAGE_CHANNELS = 'MISSING_MANAGE_CHANNELS', + MISSING_MANAGE_EMOJIS = 'MISSING_MANAGE_EMOJIS', + MISSING_MANAGE_GUILD = 'MISSING_MANAGE_GUILD', + MISSING_MANAGE_MESSAGES = 'MISSING_MANAGE_MESSAGES', + MISSING_MANAGE_NICKNAMES = 'MISSING_MANAGE_NICKNAMES', + MISSING_MANAGE_ROLES = 'MISSING_MANAGE_ROLES', + MISSING_MANAGE_WEBHOOKS = 'MISSING_MANAGE_WEBHOOKS', + MISSING_MENTION_EVERYONE = 'MISSING_MENTION_EVERYONE', + MISSING_MOVE_MEMBERS = 'MISSING_MOVE_MEMBERS', + MISSING_MUTE_MEMBERS = 'MISSING_MUTE_MEMBERS', + MISSING_PRIORITY_SPEAKER = 'MISSING_PRIORITY_SPEAKER', + MISSING_READ_MESSAGE_HISTORY = 'MISSING_READ_MESSAGE_HISTORY', + MISSING_SEND_MESSAGES = 'MISSING_SEND_MESSAGES', + MISSING_SEND_TTS_MESSAGES = 'MISSING_SEND_TTS_MESSAGES', + MISSING_SPEAK = 'MISSING_SPEAK', + MISSING_STREAM = 'MISSING_STREAM', + MISSING_USE_VAD = 'MISSING_USE_VAD', + MISSING_USE_EXTERNAL_EMOJIS = 'MISSING_USE_EXTERNAL_EMOJIS', + MISSING_VIEW_AUDIT_LOG = 'MISSING_VIEW_AUDIT_LOG', + MISSING_VIEW_CHANNEL = 'MISSING_VIEW_CHANNEL', + MISSING_VIEW_GUILD_INSIGHTS = 'MISSING_VIEW_GUILD_INSIGHTS', // User Errors - NICKNAMES_MAX_LENGTH = "NICKNAMES_MAX_LENGTH", - USERNAME_INVALID_CHARACTER = "USERNAME_INVALID_CHARACTER", - USERNAME_INVALID_USERNAME = "USERNAME_INVALID_USERNAME", - USERNAME_MAX_LENGTH = "USERNAME_MAX_LENGTH", - USERNAME_MIN_LENGTH = "USERNAME_MIN_LENGTH", - NONCE_TOO_LONG = "NONCE_TOO_LONG", - INVITE_MAX_AGE_INVALID = "INVITE_MAX_AGE_INVALID", - INVITE_MAX_USES_INVALID = "INVITE_MAX_USES_INVALID", + NICKNAMES_MAX_LENGTH = 'NICKNAMES_MAX_LENGTH', + USERNAME_INVALID_CHARACTER = 'USERNAME_INVALID_CHARACTER', + USERNAME_INVALID_USERNAME = 'USERNAME_INVALID_USERNAME', + USERNAME_MAX_LENGTH = 'USERNAME_MAX_LENGTH', + USERNAME_MIN_LENGTH = 'USERNAME_MIN_LENGTH', + NONCE_TOO_LONG = 'NONCE_TOO_LONG', + INVITE_MAX_AGE_INVALID = 'INVITE_MAX_AGE_INVALID', + INVITE_MAX_USES_INVALID = 'INVITE_MAX_USES_INVALID', // API Errors - RATE_LIMIT_RETRY_MAXED = "RATE_LIMIT_RETRY_MAXED", - REQUEST_CLIENT_ERROR = "REQUEST_CLIENT_ERROR", - REQUEST_SERVER_ERROR = "REQUEST_SERVER_ERROR", - REQUEST_UNKNOWN_ERROR = "REQUEST_UNKNOWN_ERROR", + RATE_LIMIT_RETRY_MAXED = 'RATE_LIMIT_RETRY_MAXED', + REQUEST_CLIENT_ERROR = 'REQUEST_CLIENT_ERROR', + REQUEST_SERVER_ERROR = 'REQUEST_SERVER_ERROR', + REQUEST_UNKNOWN_ERROR = 'REQUEST_UNKNOWN_ERROR', // Component Errors - TOO_MANY_COMPONENTS = "TOO_MANY_COMPONENTS", - TOO_MANY_ACTION_ROWS = "TOO_MANY_ACTION_ROWS", - LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID = "LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID", - COMPONENT_LABEL_TOO_BIG = "COMPONENT_LABEL_TOO_BIG", - COMPONENT_CUSTOM_ID_TOO_BIG = "COMPONENT_CUSTOM_ID_TOO_BIG", - BUTTON_REQUIRES_CUSTOM_ID = "BUTTON_REQUIRES_CUSTOM_ID", - COMPONENT_SELECT_MUST_BE_ALONE = "COMPONENT_SELECT_MUST_BE_ALONE", - COMPONENT_PLACEHOLDER_TOO_BIG = "COMPONENT_PLACEHOLDER_TOO_BIG", - COMPONENT_SELECT_MIN_VALUE_TOO_LOW = "COMPONENT_SELECT_MIN_VALUE_TOO_LOW", - COMPONENT_SELECT_MIN_VALUE_TOO_MANY = "COMPONENT_SELECT_MIN_VALUE_TOO_MANY", - COMPONENT_SELECT_MAX_VALUE_TOO_LOW = "COMPONENT_SELECT_MAX_VALUE_TOO_LOW", - COMPONENT_SELECT_MAX_VALUE_TOO_MANY = "COMPONENT_SELECT_MAX_VALUE_TOO_MANY", - COMPONENT_SELECT_OPTIONS_TOO_LOW = "COMPONENT_SELECT_OPTIONS_TOO_LOW", - COMPONENT_SELECT_OPTIONS_TOO_MANY = "COMPONENT_SELECT_OPTIONS_TOO_MANY", - SELECT_OPTION_LABEL_TOO_BIG = "SELECT_OPTION_LABEL_TOO_BIG", - SELECT_OPTION_VALUE_TOO_BIG = "SELECT_OPTION_VALUE_TOO_BIG", - SELECT_OPTION_TOO_MANY_DEFAULTS = "SELECT_OPTION_TOO_MANY_DEFAULTS", - COMPONENT_SELECT_MIN_HIGHER_THAN_MAX = "COMPONENT_SELECT_MIN_HIGHER_THAN_MAX", - CANNOT_ADD_USER_TO_ARCHIVED_THREADS = "CANNOT_ADD_USER_TO_ARCHIVED_THREADS", - CANNOT_LEAVE_ARCHIVED_THREAD = "CANNOT_LEAVE_ARCHIVED_THREAD", - CANNOT_REMOVE_FROM_ARCHIVED_THREAD = "CANNOT_REMOVE_FROM_ARCHIVED_THREAD", - YOU_CAN_NOT_DM_THE_BOT_ITSELF = "YOU_CAN_NOT_DM_THE_BOT_ITSELF", + TOO_MANY_COMPONENTS = 'TOO_MANY_COMPONENTS', + TOO_MANY_ACTION_ROWS = 'TOO_MANY_ACTION_ROWS', + LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID = 'LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID', + COMPONENT_LABEL_TOO_BIG = 'COMPONENT_LABEL_TOO_BIG', + COMPONENT_CUSTOM_ID_TOO_BIG = 'COMPONENT_CUSTOM_ID_TOO_BIG', + BUTTON_REQUIRES_CUSTOM_ID = 'BUTTON_REQUIRES_CUSTOM_ID', + COMPONENT_SELECT_MUST_BE_ALONE = 'COMPONENT_SELECT_MUST_BE_ALONE', + COMPONENT_PLACEHOLDER_TOO_BIG = 'COMPONENT_PLACEHOLDER_TOO_BIG', + COMPONENT_SELECT_MIN_VALUE_TOO_LOW = 'COMPONENT_SELECT_MIN_VALUE_TOO_LOW', + COMPONENT_SELECT_MIN_VALUE_TOO_MANY = 'COMPONENT_SELECT_MIN_VALUE_TOO_MANY', + COMPONENT_SELECT_MAX_VALUE_TOO_LOW = 'COMPONENT_SELECT_MAX_VALUE_TOO_LOW', + COMPONENT_SELECT_MAX_VALUE_TOO_MANY = 'COMPONENT_SELECT_MAX_VALUE_TOO_MANY', + COMPONENT_SELECT_OPTIONS_TOO_LOW = 'COMPONENT_SELECT_OPTIONS_TOO_LOW', + COMPONENT_SELECT_OPTIONS_TOO_MANY = 'COMPONENT_SELECT_OPTIONS_TOO_MANY', + SELECT_OPTION_LABEL_TOO_BIG = 'SELECT_OPTION_LABEL_TOO_BIG', + SELECT_OPTION_VALUE_TOO_BIG = 'SELECT_OPTION_VALUE_TOO_BIG', + SELECT_OPTION_TOO_MANY_DEFAULTS = 'SELECT_OPTION_TOO_MANY_DEFAULTS', + COMPONENT_SELECT_MIN_HIGHER_THAN_MAX = 'COMPONENT_SELECT_MIN_HIGHER_THAN_MAX', + CANNOT_ADD_USER_TO_ARCHIVED_THREADS = 'CANNOT_ADD_USER_TO_ARCHIVED_THREADS', + CANNOT_LEAVE_ARCHIVED_THREAD = 'CANNOT_LEAVE_ARCHIVED_THREAD', + CANNOT_REMOVE_FROM_ARCHIVED_THREAD = 'CANNOT_REMOVE_FROM_ARCHIVED_THREAD', + YOU_CAN_NOT_DM_THE_BOT_ITSELF = 'YOU_CAN_NOT_DM_THE_BOT_ITSELF', } export enum Locales { - Danish = "da", - German = "de", - EnglishUk = "en-GB", - EnglishUs = "en-US", - Spanish = "es-ES", - French = "fr", - Croatian = "hr", - Italian = "it", - Lithuanian = "lt", - Hungarian = "hu", - Dutch = "nl", - Norwegian = "no", - Polish = "pl", - PortugueseBrazilian = "pt-BR", - RomanianRomania = "ro", - Finnish = "fi", - Swedish = "sv-SE", - Vietnamese = "vi", - Turkish = "tr", - Czech = "cs", - Greek = "el", - Bulgarian = "bg", - Russian = "ru", - Ukrainian = "uk", - Hindi = "hi", - Thai = "th", - ChineseChina = "zh-CN", - Japanese = "ja", - ChineseTaiwan = "zh-TW", - Korean = "ko", + Danish = 'da', + German = 'de', + EnglishUk = 'en-GB', + EnglishUs = 'en-US', + Spanish = 'es-ES', + French = 'fr', + Croatian = 'hr', + Italian = 'it', + Lithuanian = 'lt', + Hungarian = 'hu', + Dutch = 'nl', + Norwegian = 'no', + Polish = 'pl', + PortugueseBrazilian = 'pt-BR', + RomanianRomania = 'ro', + Finnish = 'fi', + Swedish = 'sv-SE', + Vietnamese = 'vi', + Turkish = 'tr', + Czech = 'cs', + Greek = 'el', + Bulgarian = 'bg', + Russian = 'ru', + Ukrainian = 'uk', + Hindi = 'hi', + Thai = 'th', + ChineseChina = 'zh-CN', + Japanese = 'ja', + ChineseTaiwan = 'zh-TW', + Korean = 'ko', } export type Localization = Partial>; diff --git a/packages/discordeno/util/bucket.ts b/packages/discordeno/util/bucket.ts index 00eb60b..1c0af57 100644 --- a/packages/discordeno/util/bucket.ts +++ b/packages/discordeno/util/bucket.ts @@ -1,5 +1,5 @@ -import { PickPartial } from "../types/shared.ts"; -import { delay } from "./delay.ts"; +import { PickPartial } from '../types/shared.ts'; +import { delay } from './delay.ts'; /** A Leaky Bucket. * Useful for rate limiting purposes. @@ -67,9 +67,9 @@ export function createLeakyBucket( & Omit< PickPartial< LeakyBucket, - "max" | "refillInterval" | "refillAmount" + 'max' | 'refillInterval' | 'refillAmount' >, - "tokens" + 'tokens' > & { /** Current tokens in the bucket. diff --git a/packages/discordeno/util/constants.ts b/packages/discordeno/util/constants.ts index 6516158..0c21ba5 100644 --- a/packages/discordeno/util/constants.ts +++ b/packages/discordeno/util/constants.ts @@ -1,18 +1,18 @@ /** https://discord.com/developers/docs/reference#api-reference-base-url */ -export const BASE_URL = "https://discord.com/api"; +export const BASE_URL = 'https://discord.com/api'; /** https://discord.com/developers/docs/reference#api-versioning-api-versions */ export const API_VERSION = 10; // TODO: update this version /** https://github.com/discordeno/discordeno/releases */ -export const DISCORDENO_VERSION = "13.0.0-rc45"; +export const DISCORDENO_VERSION = '13.0.0-rc45'; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`; /** https://discord.com/developers/docs/reference#image-formatting-image-base-url */ -export const IMAGE_BASE_URL = "https://cdn.discordapp.com"; +export const IMAGE_BASE_URL = 'https://cdn.discordapp.com'; // This can be modified by big brain bots and use a proxy export const baseEndpoints = { diff --git a/packages/discordeno/util/mod.ts b/packages/discordeno/util/mod.ts index 89115b0..2f6d895 100644 --- a/packages/discordeno/util/mod.ts +++ b/packages/discordeno/util/mod.ts @@ -1,5 +1,5 @@ -export * from "./bucket.ts"; -export * from "./collection.ts"; -export * from "./constants.ts"; -export * from "./delay.ts"; -export * from "./token.ts"; +export * from './bucket.ts'; +export * from './collection.ts'; +export * from './constants.ts'; +export * from './delay.ts'; +export * from './token.ts'; diff --git a/packages/discordeno/util/token.ts b/packages/discordeno/util/token.ts index 5b758fc..b3ae8ea 100644 --- a/packages/discordeno/util/token.ts +++ b/packages/discordeno/util/token.ts @@ -1,14 +1,14 @@ /** Removes the Bot before the token. */ -export function removeTokenPrefix(token?: string, type: "GATEWAY" | "REST" = "REST"): string { +export function removeTokenPrefix(token?: string, type: 'GATEWAY' | 'REST' = 'REST'): string { // If no token is provided, throw an error if (!token) throw new Error(`The ${type} was not given a token. Please provide a token and try again.`); // If the token does not have a prefix just return token - if (!token.startsWith("Bot ")) return token; + if (!token.startsWith('Bot ')) return token; // Remove the prefix and return only the token. - return token.substring(token.indexOf(" ") + 1); + return token.substring(token.indexOf(' ') + 1); } /** Get the bot id from the bot token. WARNING: Discord staff has mentioned this may not be stable forever. Use at your own risk. However, note for over 5 years this has never broken. */ export function getBotIdFromToken(token: string) { - return BigInt(atob(token.split(".")[0])); + return BigInt(atob(token.split('.')[0])); } diff --git a/scripts.ts b/scripts.ts index eed003e..baf1d9f 100644 --- a/scripts.ts +++ b/scripts.ts @@ -1,6 +1,6 @@ export default { scripts: { - fmt: "deno fmt", - check: "deno check mod.ts", + fmt: 'deno fmt', + check: 'deno check mod.ts', }, };