diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 93d09cbf3..1c34aa3c9 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,7 +1,11 @@ -## Description +**Please describe the changes this PR makes and why it should be merged:** - +**Status** -## Issues +- [ ] Code changes have been tested against the Discord API, or there are no code changes - +**Semantic versioning classification:** + +- [ ] This PR changes the library's interface (methods or parameters added) + - [ ] This PR includes breaking changes (methods removed or renamed, parameters moved or removed) +- [ ] This PR **only** includes non-code changes, like changes to documentation, README, etc. diff --git a/.vscode/settings.json b/.vscode/settings.json index 41b6452d6..f5003566b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,6 @@ }, "editor.codeActionsOnSave": { "source.organizeImports": true - } + }, + "editor.defaultFormatter": "denoland.vscode-deno" } diff --git a/README.md b/README.md index d7c3ed0c0..662026ec3 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ # Discordeno -Discord API library wrapper in Deno +> Discord API library wrapper in Deno -[Discord Server](https://discord.gg/J4NqJ72) +[![Discord](https://img.shields.io/discord/223909216866402304?color=7289da&logo=discord&logoColor=white)](https://discord.gg/J4NqJ72) +![Testing/Linting](https://github.com/Skillz4Killz/Discordeno/workflows/Testing/Linting/badge.svg) +[![nest.land](https://nest.land/badge-large.svg)](https://nest.land/package/Discordeno) [Website](https://discordeno.netlify.app) -[![nest badge](https://nest.land/badge-large.svg)](https://nest.land/package/Discordeno) -![Testing](https://github.com/Skillz4Killz/Discordeno/workflows/Testing/Linting/badge.svg) - ## Beginner Developers Don't worry a lot of developers start out coding their first projects as a Discord bot(I did 😉) and it is not so easy. With Discordeno, I tried to build it in a way that solved all the headaches I had when first starting out coding bots. If you are a beginner developer, please use a boilerplate: The official one is at: [GitHub](https://github.com/Skillz4Killz/Discordeno-bot-template) but there will be more listed on the website. It is a beautiful website indeed! Check it out! @@ -43,12 +42,15 @@ Don't worry a lot of developers start out coding their first projects as a Disco - Supports nested folders to keep cleaner translation files **Hot Reloadable** - - Easily update your code without having to restart the bot everytime. + +- Easily update your code without having to restart the bot everytime. **Step By Step Guide** - - There is a step by step walkthrough to learn how to create Discord bots with Discordeno on our website! + +- There is a step by step walkthrough to learn how to create Discord bots with Discordeno on our website! ## Advanced Developers + The instructions below are meant for advanced developers! Starting with Discordeno is very simple, you can start from scratch without any boilerplates/frameworks: Add this snippet of code into a new TypeScript file: @@ -60,18 +62,18 @@ import { Intents } from "https://x.nest.land/Discordeno@9.0.1/src/types/options. import config from "./config.ts"; StartBot({ - token: config.token, - intents: [Intents.GUILD_MESSAGES, Intents.GUILDS], - eventHandlers: { - ready: () => { - console.log(`Logged!`); - }, - messageCreate: (message) => { - if (message.content === "!ping") { - sendMessage(message.channelID, "Pong"); - } - } - } + token: config.token, + intents: [Intents.GUILD_MESSAGES, Intents.GUILDS], + eventHandlers: { + ready: () => { + console.log(`Logged!`); + }, + messageCreate: (message) => { + if (message.content === "!ping") { + sendMessage(message.channelID, "Pong"); + } + }, + }, }); ``` diff --git a/docs/config.js b/docs/config.js index 91a97ad51..ad1b28355 100644 --- a/docs/config.js +++ b/docs/config.js @@ -66,7 +66,7 @@ const config = { title: "Discordeno", description: "Easy Deno module for Discord API interactions..", ogImage: "https://i.imgur.com/7O5E6hI.png", - docsLocation: "https://github.com/Skillz4Killz/Discordeno", + docsLocation: "https://github.com/Skillz4Killz/Discordeno/tree/master/docs/content", favicon: "", }, pwa: { diff --git a/mod.ts b/mod.ts index a7a5b58b5..07db84e82 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,5 @@ import createClient from "./src/module/client.ts"; -export * from "./src/controllers/mod.ts"; export * from "./src/controllers/bans.ts"; export * from "./src/controllers/cache.ts"; export * from "./src/controllers/channels.ts"; @@ -8,26 +7,23 @@ export * from "./src/controllers/guilds.ts"; export * from "./src/controllers/members.ts"; export * from "./src/controllers/messages.ts"; export * from "./src/controllers/misc.ts"; +export * from "./src/controllers/mod.ts"; export * from "./src/controllers/reactions.ts"; export * from "./src/controllers/roles.ts"; - -export * from "./src/module/client.ts"; -export * from "./src/module/requestManager.ts"; -export * from "./src/module/shardingManager.ts"; - -export * from "./src/structures/mod.ts"; -export * from "./src/structures/channel.ts"; -export * from "./src/structures/guild.ts"; -export * from "./src/structures/member.ts"; -export * from "./src/structures/message.ts"; -export * from "./src/structures/role.ts"; - export * from "./src/handlers/channel.ts"; export * from "./src/handlers/guild.ts"; export * from "./src/handlers/member.ts"; export * from "./src/handlers/message.ts"; export * from "./src/handlers/webhook.ts"; - +export * from "./src/module/client.ts"; +export * from "./src/module/requestManager.ts"; +export * from "./src/module/shardingManager.ts"; +export * from "./src/structures/channel.ts"; +export * from "./src/structures/guild.ts"; +export * from "./src/structures/member.ts"; +export * from "./src/structures/message.ts"; +export * from "./src/structures/mod.ts"; +export * from "./src/structures/role.ts"; export * from "./src/types/activity.ts"; export * from "./src/types/cdn.ts"; export * from "./src/types/channel.ts"; @@ -41,7 +37,6 @@ export * from "./src/types/options.ts"; export * from "./src/types/permission.ts"; export * from "./src/types/presence.ts"; export * from "./src/types/role.ts"; - export * from "./src/utils/cache.ts"; export * from "./src/utils/cdn.ts"; export * from "./src/utils/collection.ts"; diff --git a/src/controllers/bans.ts b/src/controllers/bans.ts index 2c84ad051..dbd4cf10c 100644 --- a/src/controllers/bans.ts +++ b/src/controllers/bans.ts @@ -1,7 +1,6 @@ +import { eventHandlers } from "../module/client.ts"; import type { DiscordPayload } from "../types/discord.ts"; import type { GuildBanPayload } from "../types/guild.ts"; - -import { eventHandlers } from "../module/client.ts"; import { cacheHandlers } from "./cache.ts"; export async function handleInternalGuildBanAdd(data: DiscordPayload) { diff --git a/src/controllers/cache.ts b/src/controllers/cache.ts index 6e336faac..676d45534 100644 --- a/src/controllers/cache.ts +++ b/src/controllers/cache.ts @@ -2,9 +2,8 @@ import type { Channel } from "../structures/channel.ts"; import type { Guild } from "../structures/guild.ts"; import type { Message } from "../structures/message.ts"; import type { PresenceUpdatePayload } from "../types/discord.ts"; -import type { Collection } from "../utils/collection.ts"; - import { cache } from "../utils/cache.ts"; +import type { Collection } from "../utils/collection.ts"; export type TableName = | "guilds" diff --git a/src/controllers/channels.ts b/src/controllers/channels.ts index bdd2cede3..36d78c576 100644 --- a/src/controllers/channels.ts +++ b/src/controllers/channels.ts @@ -1,9 +1,8 @@ -import type { ChannelCreatePayload } from "../types/channel.ts"; -import type { DiscordPayload } from "../types/discord.ts"; - -import { ChannelTypes } from "../types/channel.ts"; -import { structures } from "../structures/mod.ts"; import { eventHandlers } from "../module/client.ts"; +import { structures } from "../structures/mod.ts"; +import type { ChannelCreatePayload } from "../types/channel.ts"; +import { ChannelTypes } from "../types/channel.ts"; +import type { DiscordPayload } from "../types/discord.ts"; import { cacheHandlers } from "./cache.ts"; export async function handleInternalChannelCreate(data: DiscordPayload) { diff --git a/src/controllers/guilds.ts b/src/controllers/guilds.ts index 824a62359..ef4d4c271 100644 --- a/src/controllers/guilds.ts +++ b/src/controllers/guilds.ts @@ -1,15 +1,14 @@ +import { eventHandlers } from "../module/client.ts"; +import { structures } from "../structures/mod.ts"; import type { DiscordPayload } from "../types/discord.ts"; -import type { GuildUpdateChange } from "../types/options.ts"; import type { CreateGuildPayload, GuildDeletePayload, GuildEmojisUpdatePayload, UpdateGuildPayload, } from "../types/guild.ts"; - +import type { GuildUpdateChange } from "../types/options.ts"; import { cache } from "../utils/cache.ts"; -import { structures } from "../structures/mod.ts"; -import { eventHandlers } from "../module/client.ts"; import { cacheHandlers } from "./cache.ts"; export async function handleInternalGuildCreate( diff --git a/src/controllers/members.ts b/src/controllers/members.ts index 099d1d11c..6d413f90f 100644 --- a/src/controllers/members.ts +++ b/src/controllers/members.ts @@ -1,3 +1,5 @@ +import { eventHandlers } from "../module/client.ts"; +import { structures } from "../structures/mod.ts"; import type { DiscordPayload } from "../types/discord.ts"; import type { GuildBanPayload, @@ -5,9 +7,6 @@ import type { GuildMemberChunkPayload, GuildMemberUpdatePayload, } from "../types/guild.ts"; - -import { eventHandlers } from "../module/client.ts"; -import { structures } from "../structures/mod.ts"; import { cache } from "../utils/cache.ts"; import { cacheHandlers } from "./cache.ts"; diff --git a/src/controllers/misc.ts b/src/controllers/misc.ts index 153dcfb4e..3cd7bc813 100644 --- a/src/controllers/misc.ts +++ b/src/controllers/misc.ts @@ -1,4 +1,7 @@ -import type { UserPayload } from "../types/guild.ts"; +import { delay } from "../../deps.ts"; +import { eventHandlers, setBotID } from "../module/client.ts"; +import { allowNextShard } from "../module/shardingManager.ts"; +import { structures } from "../structures/mod.ts"; import type { DiscordPayload, PresenceUpdatePayload, @@ -7,11 +10,7 @@ import type { VoiceStateUpdatePayload, WebhookUpdatePayload, } from "../types/discord.ts"; - -import { allowNextShard } from "../module/shardingManager.ts"; -import { delay } from "../../deps.ts"; -import { eventHandlers, setBotID } from "../module/client.ts"; -import { structures } from "../structures/mod.ts"; +import type { UserPayload } from "../types/guild.ts"; import { cache } from "../utils/cache.ts"; import { cacheHandlers } from "./cache.ts"; diff --git a/src/controllers/reactions.ts b/src/controllers/reactions.ts index e65d93f69..670a7126d 100644 --- a/src/controllers/reactions.ts +++ b/src/controllers/reactions.ts @@ -1,12 +1,11 @@ +import { botID, eventHandlers } from "../module/client.ts"; +import { structures } from "../structures/mod.ts"; import type { DiscordPayload } from "../types/discord.ts"; import type { BaseMessageReactionPayload, MessageReactionPayload, MessageReactionRemoveEmojiPayload, } from "../types/message.ts"; - -import { botID, eventHandlers } from "../module/client.ts"; -import { structures } from "../structures/mod.ts"; import { cacheHandlers } from "./cache.ts"; export async function handleInternalMessageReactionAdd(data: DiscordPayload) { diff --git a/src/controllers/roles.ts b/src/controllers/roles.ts index 6ac8527ac..9f889d23b 100644 --- a/src/controllers/roles.ts +++ b/src/controllers/roles.ts @@ -1,11 +1,10 @@ +import { eventHandlers } from "../module/client.ts"; +import { structures } from "../structures/mod.ts"; import type { DiscordPayload } from "../types/discord.ts"; import type { GuildRoleDeletePayload, GuildRolePayload, } from "../types/guild.ts"; - -import { eventHandlers } from "../module/client.ts"; -import { structures } from "../structures/mod.ts"; import { cacheHandlers } from "./cache.ts"; export async function handleInternalGuildRoleCreate(data: DiscordPayload) { diff --git a/src/handlers/channel.ts b/src/handlers/channel.ts index 2986b7480..881521ea0 100644 --- a/src/handlers/channel.ts +++ b/src/handlers/channel.ts @@ -1,22 +1,21 @@ -import type { MessageCreateOptions } from "../types/message.ts"; -import type { - GetMessagesAfter, - GetMessagesBefore, - GetMessagesAround, - GetMessages, - MessageContent, - CreateInviteOptions, - ChannelEditOptions, - FollowedChannelPayload, -} from "../types/channel.ts"; -import type { RawOverwrite } from "../types/guild.ts"; - import { endpoints } from "../constants/discord.ts"; import { RequestManager } from "../module/requestManager.ts"; +import { structures } from "../structures/mod.ts"; +import type { + ChannelEditOptions, + CreateInviteOptions, + FollowedChannelPayload, + GetMessages, + GetMessagesAfter, + GetMessagesAround, + GetMessagesBefore, + MessageContent, +} from "../types/channel.ts"; import { Errors } from "../types/errors.ts"; +import type { RawOverwrite } from "../types/guild.ts"; +import type { MessageCreateOptions } from "../types/message.ts"; import { Permissions } from "../types/permission.ts"; import { botHasChannelPermissions } from "../utils/permissions.ts"; -import { structures } from "../structures/mod.ts"; /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ export function channelOverwriteHasPermission( diff --git a/src/handlers/guild.ts b/src/handlers/guild.ts index 5bf2a967d..741f7b2f0 100644 --- a/src/handlers/guild.ts +++ b/src/handlers/guild.ts @@ -1,43 +1,49 @@ +import { endpoints } from "../constants/discord.ts"; +import { cacheHandlers } from "../controllers/cache.ts"; +import { identifyPayload } from "../module/client.ts"; +import { RequestManager } from "../module/requestManager.ts"; +import { requestAllMembers } from "../module/shardingManager.ts"; import type { Guild } from "../structures/guild.ts"; +import type { Member } from "../structures/member.ts"; +import { structures } from "../structures/mod.ts"; +import type { ImageFormats, ImageSize } from "../types/cdn.ts"; import { ChannelCreatePayload, ChannelTypes, } from "../types/channel.ts"; -import type { ImageFormats, ImageSize } from "../types/cdn.ts"; +import { Errors } from "../types/errors.ts"; import type { + BannedUser, + BanOptions, + + ChannelCreateOptions, CreateEmojisOptions, - PositionSwap, - EditEmojisOptions, + CreateRoleOptions, + + CreateServerOptions, + EditEmojisOptions, + + EditIntegrationOptions, FetchMembersOptions, GetAuditLogsOptions, - EditIntegrationOptions, - BanOptions, + GuildEditOptions, + PositionSwap, + PruneOptions, PrunePayload, - ChannelCreateOptions, - BannedUser, - UserPayload, - CreateServerOptions, -} from "../types/guild.ts"; -import type { RoleData } from "../types/role.ts"; -import type { MemberCreatePayload } from "../types/member.ts"; -import type { Member } from "../structures/member.ts"; -import { Collection } from "../utils/collection.ts"; -import { urlToBase64 } from "../utils/utils.ts"; + UserPayload, +} from "../types/guild.ts"; +import type { MemberCreatePayload } from "../types/member.ts"; import { Intents } from "../types/options.ts"; -import { identifyPayload } from "../module/client.ts"; -import { requestAllMembers } from "../module/shardingManager.ts"; -import { botHasPermission, calculateBits } from "../utils/permissions.ts"; -import { RequestManager } from "../module/requestManager.ts"; -import { endpoints } from "../constants/discord.ts"; -import { Errors } from "../types/errors.ts"; import { Permissions } from "../types/permission.ts"; -import { structures } from "../structures/mod.ts"; -import { cacheHandlers } from "../controllers/cache.ts"; +import type { RoleData } from "../types/role.ts"; import { formatImageURL } from "../utils/cdn.ts"; +import { Collection } from "../utils/collection.ts"; +import { botHasPermission, calculateBits } from "../utils/permissions.ts"; +import { urlToBase64 } from "../utils/utils.ts"; /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ export function createServer(options: CreateServerOptions) { diff --git a/src/handlers/member.ts b/src/handlers/member.ts index 245e0fc49..9d31cf4af 100644 --- a/src/handlers/member.ts +++ b/src/handlers/member.ts @@ -1,25 +1,24 @@ -import type { Member } from "../structures/member.ts"; -import type { ImageSize, ImageFormats } from "../types/cdn.ts"; -import type { - MessageContent, - DMChannelCreatePayload, -} from "../types/channel.ts"; -import type { EditMemberOptions } from "../types/member.ts"; - -import { sendMessage } from "./channel.ts"; -import { structures } from "../structures/mod.ts"; -import { cacheHandlers } from "../controllers/cache.ts"; -import { formatImageURL } from "../utils/cdn.ts"; import { endpoints } from "../constants/discord.ts"; +import { cacheHandlers } from "../controllers/cache.ts"; import { botID } from "../module/client.ts"; -import { Permissions } from "../types/permission.ts"; -import { Errors } from "../types/errors.ts"; import { RequestManager } from "../module/requestManager.ts"; +import type { Member } from "../structures/member.ts"; +import { structures } from "../structures/mod.ts"; +import type { ImageFormats, ImageSize } from "../types/cdn.ts"; +import type { + DMChannelCreatePayload, + MessageContent, +} from "../types/channel.ts"; +import { Errors } from "../types/errors.ts"; +import type { EditMemberOptions } from "../types/member.ts"; +import { Permissions } from "../types/permission.ts"; +import { formatImageURL } from "../utils/cdn.ts"; import { - highestRole, - higherRolePosition, botHasPermission, + higherRolePosition, + highestRole, } from "../utils/permissions.ts"; +import { sendMessage } from "./channel.ts"; /** The users custom avatar or the default avatar if you don't have a member object. */ export function rawAvatarURL( diff --git a/src/handlers/message.ts b/src/handlers/message.ts index ac00ce422..3b99c5b32 100644 --- a/src/handlers/message.ts +++ b/src/handlers/message.ts @@ -1,16 +1,15 @@ -import type { Message } from "../structures/message.ts"; -import type { MessageContent } from "../types/channel.ts"; -import type { UserPayload } from "../types/guild.ts"; -import type { MessageCreateOptions } from "../types/message.ts"; - import { delay } from "../../deps.ts"; -import { structures } from "../structures/mod.ts"; +import { endpoints } from "../constants/discord.ts"; import { cacheHandlers } from "../controllers/cache.ts"; import { botID } from "../module/client.ts"; -import { Permissions } from "../types/permission.ts"; -import { Errors } from "../types/errors.ts"; import { RequestManager } from "../module/requestManager.ts"; -import { endpoints } from "../constants/discord.ts"; +import type { Message } from "../structures/message.ts"; +import { structures } from "../structures/mod.ts"; +import type { MessageContent } from "../types/channel.ts"; +import { Errors } from "../types/errors.ts"; +import type { UserPayload } from "../types/guild.ts"; +import type { MessageCreateOptions } from "../types/message.ts"; +import { Permissions } from "../types/permission.ts"; import { botHasChannelPermissions } from "../utils/permissions.ts"; /** Delete a message with the channel id and message id only. */ diff --git a/src/handlers/webhook.ts b/src/handlers/webhook.ts index 2b139307e..e4b37509a 100644 --- a/src/handlers/webhook.ts +++ b/src/handlers/webhook.ts @@ -1,17 +1,16 @@ +import { endpoints } from "../constants/discord.ts"; +import { RequestManager } from "../module/requestManager.ts"; +import { structures } from "../structures/mod.ts"; +import { Errors } from "../types/errors.ts"; +import type { MessageCreateOptions } from "../types/message.ts"; +import { Permissions } from "../types/permission.ts"; import type { + ExecuteWebhookOptions, WebhookCreateOptions, WebhookPayload, - ExecuteWebhookOptions, } from "../types/webhook.ts"; -import type { MessageCreateOptions } from "../types/message.ts"; - import { botHasChannelPermissions } from "../utils/permissions.ts"; -import { Permissions } from "../types/permission.ts"; -import { Errors } from "../types/errors.ts"; -import { RequestManager } from "../module/requestManager.ts"; -import { endpoints } from "../constants/discord.ts"; import { urlToBase64 } from "../utils/utils.ts"; -import { structures } from "../structures/mod.ts"; /** Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations: * diff --git a/src/module/basicShard.ts b/src/module/basicShard.ts index b55ed4edd..6d92e3115 100644 --- a/src/module/basicShard.ts +++ b/src/module/basicShard.ts @@ -1,24 +1,27 @@ -import type { DiscordBotGatewayData, ReadyPayload } from "../types/discord.ts"; -import type { IdentifyPayload } from "./client.ts"; import { connectWebSocket, + delay, + inflate, isWebSocketCloseEvent, isWebSocketPingEvent, isWebSocketPongEvent, WebSocket, } from "../../deps.ts"; -import type { DiscordHeartbeatPayload } from "../types/discord.ts"; -import type { FetchMembersOptions } from "../types/guild.ts"; -import type { BotStatusRequest } from "../utils/utils.ts"; -import { handleDiscordPayload } from "./shardingManager.ts"; +import type { + DiscordBotGatewayData, + DiscordHeartbeatPayload, + ReadyPayload, +} from "../types/discord.ts"; import { GatewayOpcode } from "../types/discord.ts"; -import { - eventHandlers, - botGatewayData, -} from "./client.ts"; -import { delay } from "../../deps.ts"; -import { inflate } from "../../deps.ts"; +import type { FetchMembersOptions } from "../types/guild.ts"; import { Collection } from "../utils/collection.ts"; +import type { BotStatusRequest } from "../utils/utils.ts"; +import type { IdentifyPayload } from "./client.ts"; +import { + botGatewayData, + eventHandlers, +} from "./client.ts"; +import { handleDiscordPayload } from "./shardingManager.ts"; export const basicShards = new Collection(); const heartbeating = new Set(); diff --git a/src/module/client.ts b/src/module/client.ts index 1c150d988..53dbcf843 100644 --- a/src/module/client.ts +++ b/src/module/client.ts @@ -1,9 +1,8 @@ -import type { ClientOptions, EventHandlers } from "../types/options.ts"; -import type { DiscordBotGatewayData } from "../types/discord.ts"; - -import { spawnShards } from "./shardingManager.ts"; import { endpoints } from "../constants/discord.ts"; +import type { DiscordBotGatewayData } from "../types/discord.ts"; +import type { ClientOptions, EventHandlers } from "../types/options.ts"; import { RequestManager } from "./requestManager.ts"; +import { spawnShards } from "./shardingManager.ts"; export let authorization = ""; export let botID = ""; diff --git a/src/module/requestManager.ts b/src/module/requestManager.ts index e0a04b02c..8d37a14fb 100644 --- a/src/module/requestManager.ts +++ b/src/module/requestManager.ts @@ -1,10 +1,9 @@ -import { HttpResponseCode } from "../types/discord.ts"; -import { authorization, eventHandlers } from "./client.ts"; -import { baseEndpoints } from "../constants/discord.ts"; -import type { RequestMethods } from "../types/fetch.ts"; - -import { Errors } from "../types/errors.ts"; import { delay } from "../../deps.ts"; +import { baseEndpoints } from "../constants/discord.ts"; +import { HttpResponseCode } from "../types/discord.ts"; +import { Errors } from "../types/errors.ts"; +import type { RequestMethods } from "../types/fetch.ts"; +import { authorization, eventHandlers } from "./client.ts"; const pathQueues: { [key: string]: QueuedRequest[] } = {}; const ratelimitedPaths = new Map(); diff --git a/src/module/shard.ts b/src/module/shard.ts index b9f24a6e1..c2e864487 100644 --- a/src/module/shard.ts +++ b/src/module/shard.ts @@ -1,19 +1,14 @@ import type { WebSocket } from "../../deps.ts"; +import { connectWebSocket, delay, isWebSocketCloseEvent } from "../../deps.ts"; import type { DiscordBotGatewayData, DiscordHeartbeatPayload, ReadyPayload, } from "../types/discord.ts"; +import { GatewayOpcode } from "../types/discord.ts"; import type { FetchMembersOptions } from "../types/guild.ts"; import type { DebugArg } from "../types/options.ts"; -import { GatewayOpcode } from "../types/discord.ts"; -import { delay } from "../../deps.ts"; -import { - connectWebSocket, - isWebSocketCloseEvent, -} from "../../deps.ts"; - let shardSocket: WebSocket; /** The session id is needed for RESUME functionality when discord disconnects randomly. */ diff --git a/src/module/shardingManager.ts b/src/module/shardingManager.ts index b1eba89c2..48c3ffb08 100644 --- a/src/module/shardingManager.ts +++ b/src/module/shardingManager.ts @@ -1,26 +1,26 @@ -import type { IdentifyPayload } from "./client.ts"; +import { delay } from "../../deps.ts"; +import { controllers } from "../controllers/mod.ts"; import type { Guild } from "../structures/guild.ts"; -import type { FetchMembersOptions } from "../types/guild.ts"; import type { DiscordBotGatewayData, DiscordPayload, } from "../types/discord.ts"; -import type { BotStatusRequest } from "../utils/utils.ts"; - -import { controllers } from "../controllers/mod.ts"; +import { GatewayOpcode } from "../types/discord.ts"; +import type { FetchMembersOptions } from "../types/guild.ts"; import { cache } from "../utils/cache.ts"; +import type { BotStatusRequest } from "../utils/utils.ts"; import { + botGatewayStatusRequest, createBasicShard, requestGuildMembers, - botGatewayStatusRequest, } from "./basicShard.ts"; +import type { IdentifyPayload } from "./client.ts"; import { - eventHandlers, botGatewayData, + eventHandlers, + identifyPayload, } from "./client.ts"; -import { GatewayOpcode } from "../types/discord.ts"; -import { delay } from "../../deps.ts"; let shardCounter = 0; let basicSharding = false; diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 31dd876c3..64e77ef9b 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -1,7 +1,6 @@ +import { cacheHandlers } from "../controllers/cache.ts"; import type { ChannelCreatePayload } from "../types/channel.ts"; import type { Unpromise } from "../types/misc.ts"; - -import { cacheHandlers } from "../controllers/cache.ts"; import { calculatePermissions } from "../utils/permissions.ts"; export async function createChannel( diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 74a7c7a2e..70f391c7f 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -1,9 +1,8 @@ import type { CreateGuildPayload } from "../types/guild.ts"; -import type { Member } from "./member.ts"; import type { Unpromise } from "../types/misc.ts"; - -import { structures } from "./mod.ts"; import { Collection } from "../utils/collection.ts"; +import type { Member } from "./member.ts"; +import { structures } from "./mod.ts"; export async function createGuild(data: CreateGuildPayload, shardID: number) { const { diff --git a/src/types/channel.ts b/src/types/channel.ts index e7b7c1401..f4892bad2 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -1,4 +1,4 @@ -import type { RawOverwrite, Overwrite } from "./guild.ts"; +import type { Overwrite, RawOverwrite } from "./guild.ts"; import type { Embed } from "./message.ts"; export interface ChannelEditOptions { diff --git a/src/types/discord.ts b/src/types/discord.ts index 9154cc4d1..161c15b59 100644 --- a/src/types/discord.ts +++ b/src/types/discord.ts @@ -1,7 +1,7 @@ -import type { Activity } from "./message.ts"; -import type { ClientStatusPayload } from "./presence.ts"; import type { PartialUser, UserPayload } from "./guild.ts"; import type { MemberCreatePayload } from "./member.ts"; +import type { Activity } from "./message.ts"; +import type { ClientStatusPayload } from "./presence.ts"; export interface DiscordPayload { /** OP code for the payload */ diff --git a/src/types/guild.ts b/src/types/guild.ts index bc98453f8..8e35d70d2 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -1,10 +1,10 @@ +import type { ChannelCreatePayload, ChannelTypes } from "./channel.ts"; import type { Emoji, StatusType } from "./discord.ts"; -import type { Permission } from "./permission.ts"; -import type { RoleData } from "./role.ts"; import type { MemberCreatePayload } from "./member.ts"; import type { Activity } from "./message.ts"; +import type { Permission } from "./permission.ts"; import type { ClientStatusPayload } from "./presence.ts"; -import type { ChannelCreatePayload, ChannelTypes } from "./channel.ts"; +import type { RoleData } from "./role.ts"; export interface GuildRolePayload { /** The id of the guild */ diff --git a/src/types/message.ts b/src/types/message.ts index 66b082e5d..8bb2fdd18 100644 --- a/src/types/message.ts +++ b/src/types/message.ts @@ -1,7 +1,7 @@ -import type { UserPayload } from "./guild.ts"; -import type { MemberCreatePayload } from "./member.ts"; import type { Channel } from "../structures/channel.ts"; import type { ChannelType } from "./channel.ts"; +import type { UserPayload } from "./guild.ts"; +import type { MemberCreatePayload } from "./member.ts"; export interface MentionedUser extends UserPayload { member: MemberCreatePayload; diff --git a/src/types/options.ts b/src/types/options.ts index 410780aaf..1ad67dc6c 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -1,26 +1,30 @@ -import type { - Properties, - Emoji, - DiscordPayload, - PresenceUpdatePayload, - TypingStartPayload, - VoiceStateUpdatePayload, -} from "./discord.ts"; -import type { Role } from "../structures/role.ts"; -import type { Message } from "../structures/message.ts"; -import type { - PartialMessage, - ReactionPayload, - BaseMessageReactionPayload, - MessageReactionRemoveEmojiPayload, - Embed, - Attachment, - MessageReactionUncachedPayload, -} from "./message.ts"; import type { Channel } from "../structures/channel.ts"; import type { Guild } from "../structures/guild.ts"; import type { Member } from "../structures/member.ts"; +import type { Message } from "../structures/message.ts"; +import type { Role } from "../structures/role.ts"; +import type { + DiscordPayload, + Emoji, + + PresenceUpdatePayload, + Properties, + + TypingStartPayload, + VoiceStateUpdatePayload, +} from "./discord.ts"; import type { UserPayload } from "./guild.ts"; +import type { + Attachment, + BaseMessageReactionPayload, + + Embed, + MessageReactionRemoveEmojiPayload, + + MessageReactionUncachedPayload, + PartialMessage, + ReactionPayload, +} from "./message.ts"; export interface Fulfilled_Client_Options { token: string; diff --git a/src/utils/cache.ts b/src/utils/cache.ts index 7042b504e..3bb3c8d26 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -1,8 +1,8 @@ -import { Collection } from "./collection.ts"; -import type { Message } from "../structures/message.ts"; -import type { Guild } from "../structures/guild.ts"; import type { Channel } from "../structures/channel.ts"; +import type { Guild } from "../structures/guild.ts"; +import type { Message } from "../structures/message.ts"; import type { PresenceUpdatePayload } from "../types/discord.ts"; +import { Collection } from "./collection.ts"; export interface CacheData { isReady: boolean; diff --git a/src/utils/cdn.ts b/src/utils/cdn.ts index ca4e2b22a..b4748e219 100644 --- a/src/utils/cdn.ts +++ b/src/utils/cdn.ts @@ -1,4 +1,4 @@ -import type { ImageSize, ImageFormats } from "../types/cdn.ts"; +import type { ImageFormats, ImageSize } from "../types/cdn.ts"; export const formatImageURL = ( url: string, diff --git a/src/utils/permissions.ts b/src/utils/permissions.ts index daa7fe27d..37e9fac90 100644 --- a/src/utils/permissions.ts +++ b/src/utils/permissions.ts @@ -1,10 +1,9 @@ -import type { Permission } from "../types/permission.ts"; -import type { Role } from "../structures/role.ts"; -import type { Guild } from "../structures/guild.ts"; - -import { Permissions } from "../types/permission.ts"; -import { botID } from "../module/client.ts"; import { cacheHandlers } from "../controllers/cache.ts"; +import { botID } from "../module/client.ts"; +import type { Guild } from "../structures/guild.ts"; +import type { Role } from "../structures/role.ts"; +import type { Permission } from "../types/permission.ts"; +import { Permissions } from "../types/permission.ts"; /** Checks if the member has this permission. If the member is an owner or has admin perms it will always be true. */ export async function memberIDHasPermission( diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 194701611..78591d522 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,8 +1,7 @@ -import type { StatusType } from "../types/discord.ts"; - -import { ActivityType } from "../types/activity.ts"; -import { sendGatewayCommand } from "../module/shardingManager.ts"; import { encode } from "../../deps.ts"; +import { sendGatewayCommand } from "../module/shardingManager.ts"; +import { ActivityType } from "../types/activity.ts"; +import type { StatusType } from "../types/discord.ts"; export const sleep = (timeout: number) => { return new Promise((resolve) => setTimeout(resolve, timeout));