diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f454d4eed..14095425e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -30,7 +30,6 @@ "extensions": [ "denoland.vscode-deno", "pkief.material-icon-theme", - "coenraads.bracket-pair-colorizer", "equinusocio.vsc-material-theme", "tabnine.tabnine-vscode" ], diff --git a/bot.ts b/bot.ts index 9cb2a99f5..6c2d65738 100644 --- a/bot.ts +++ b/bot.ts @@ -1,16 +1,13 @@ import { createRestManager, CreateRestManagerOptions } from "./rest/mod.ts"; -import { GatewayIntents } from "./types/gateway/gatewayIntents.ts"; -import { GetGatewayBot } from "./types/gateway/getGatewayBot.ts"; import { bigintToSnowflake, snowflakeToBigint } from "./util/bigint.ts"; import { Collection } from "./util/collection.ts"; import { - DiscordenoChannel, - DiscordenoGuild, - DiscordenoMember, - DiscordenoMessage, - DiscordenoRole, - DiscordenoUser, - DiscordenoVoiceState, + Channel, + Guild, + Member, + Message, + Role, + ScheduledEvent, transformChannel, transformGuild, transformMember, @@ -18,6 +15,8 @@ import { transformRole, transformUser, transformVoiceState, + User, + VoiceState, } from "./transformers/mod.ts"; import { baseEndpoints, @@ -29,25 +28,21 @@ import { SLASH_COMMANDS_NAME_REGEX, USER_AGENT, } from "./util/constants.ts"; -import { Errors } from "./types/discordeno/errors.ts"; -import { DiscordGatewayPayload, GatewayDispatchEventNames, GatewayPayload } from "./types/gateway/gatewayPayload.ts"; import { createGatewayManager, GatewayManager } from "./gateway/mod.ts"; import { validateLength } from "./util/validateLength.ts"; import { delay, formatImageURL, hasProperty } from "./util/utils.ts"; import { iconBigintToHash, iconHashToBigInt } from "./util/hash.ts"; import { calculateShardId } from "./util/calculateShardId.ts"; import * as handlers from "./handlers/mod.ts"; -import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts"; -import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts"; -import { Emoji } from "./types/emojis/emoji.ts"; +import { Interaction, transformInteraction } from "./transformers/interaction.ts"; +import { Integration, transformIntegration } from "./transformers/integration.ts"; import { transformApplication } from "./transformers/application.ts"; import { transformTeam } from "./transformers/team.ts"; -import { DiscordenoInvite, transformInvite } from "./transformers/invite.ts"; +import { Invite, transformInvite } from "./transformers/invite.ts"; import * as helpers from "./helpers/mod.ts"; -import { DiscordenoEmoji, transformEmoji } from "./transformers/emoji.ts"; +import { Emoji, transformEmoji } from "./transformers/emoji.ts"; import { transformActivity } from "./transformers/activity.ts"; -import { DiscordenoPresence, transformPresence } from "./transformers/presence.ts"; -import { DiscordReady } from "./types/gateway/ready.ts"; +import { PresenceUpdate, transformPresence } from "./transformers/presence.ts"; import { urlToBase64 } from "./util/urlToBase64.ts"; import { transformAttachment } from "./transformers/attachment.ts"; import { transformEmbed } from "./transformers/embed.ts"; @@ -57,8 +52,7 @@ import { transformAuditlogEntry } from "./transformers/auditlogEntry.ts"; import { transformApplicationCommandPermission } from "./transformers/applicationCommandPermission.ts"; import { calculateBits, calculatePermissions } from "./util/permissions.ts"; import { transformScheduledEvent } from "./transformers/scheduledEvent.ts"; -import { DiscordenoScheduledEvent } from "./transformers/scheduledEvent.ts"; -import { DiscordenoThreadMember, transformThreadMember } from "./transformers/threadMember.ts"; +import { ThreadMember, transformThreadMember } from "./transformers/threadMember.ts"; import { transformApplicationCommandOption } from "./transformers/applicationCommandOption.ts"; import { transformApplicationCommand } from "./transformers/applicationCommand.ts"; import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts"; @@ -66,7 +60,9 @@ import { transformVoiceRegion } from "./transformers/voiceRegion.ts"; import { transformWidget } from "./transformers/widget.ts"; import { transformStageInstance } from "./transformers/stageInstance.ts"; import { transformSticker } from "./transformers/sticker.ts"; -import { transformGatewayBot } from "./transformers/gatewayBot.ts"; +import { GetGatewayBot, transformGatewayBot } from "./transformers/gatewayBot.ts"; +import { DiscordEmoji, DiscordGatewayPayload, DiscordReady } from "./types/discord.ts"; +import { Errors, GatewayDispatchEventNames, GatewayIntents } from "./types/shared.ts"; export function createBot(options: CreateBotOptions): Bot { const bot = { @@ -160,7 +156,6 @@ export function createEventHandlers( voiceServerUpdate: events.voiceServerUpdate ?? ignore, voiceStateUpdate: events.voiceStateUpdate ?? ignore, channelCreate: events.channelCreate ?? ignore, - voiceChannelLeave: events.voiceChannelLeave ?? ignore, channelDelete: events.channelDelete ?? ignore, channelPinsUpdate: events.channelPinsUpdate ?? ignore, channelUpdate: events.channelUpdate ?? ignore, @@ -297,8 +292,8 @@ export function createHelpers( ...createBaseHelpers(customHelpers || {}), }) ) { - // @ts-ignore - TODO: make the types better converted[name as keyof FinalHelpers] = ( + // @ts-ignore - TODO: make the types better ...args: RemoveFirstFromTuple> ) => // @ts-ignore - TODO: make the types better @@ -394,21 +389,21 @@ export type RestManager = ReturnType; export interface EventHandlers { debug: (text: string, ...args: any[]) => unknown; - threadCreate: (bot: Bot, thread: DiscordenoChannel) => unknown; - threadDelete: (bot: Bot, thread: DiscordenoChannel) => unknown; + threadCreate: (bot: Bot, thread: Channel) => unknown; + threadDelete: (bot: Bot, thread: Channel) => unknown; threadMembersUpdate: ( bot: Bot, payload: { id: bigint; guildId: bigint; - addedMembers?: DiscordenoThreadMember[]; + addedMembers?: ThreadMember[]; removedMemberIds?: bigint[]; }, ) => unknown; - threadUpdate: (bot: Bot, thread: DiscordenoChannel) => unknown; - scheduledEventCreate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown; - scheduledEventUpdate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown; - scheduledEventDelete: (bot: Bot, event: DiscordenoScheduledEvent) => unknown; + threadUpdate: (bot: Bot, thread: Channel) => unknown; + scheduledEventCreate: (bot: Bot, event: ScheduledEvent) => unknown; + scheduledEventUpdate: (bot: Bot, event: ScheduledEvent) => unknown; + scheduledEventDelete: (bot: Bot, event: ScheduledEvent) => unknown; /** Sent when a user has subscribed to a guild scheduled event. EXPERIMENTAL! */ scheduledEventUserAdd: ( bot: Bot, @@ -432,7 +427,7 @@ export interface EventHandlers { payload: { shardId: number; v: number; - user: DiscordenoUser; + user: User; guilds: bigint[]; sessionId: string; shard?: number[]; @@ -440,14 +435,14 @@ export interface EventHandlers { }, rawPayload: DiscordReady, ) => any; - interactionCreate: (bot: Bot, interaction: DiscordenoInteraction) => any; - integrationCreate: (bot: Bot, integration: DiscordenoIntegration) => any; + interactionCreate: (bot: Bot, interaction: Interaction) => any; + integrationCreate: (bot: Bot, integration: Integration) => any; integrationDelete: ( bot: Bot, payload: { id: bigint; guildId: bigint; applicationId?: bigint }, ) => any; integrationUpdate: (bot: Bot, payload: { guildId: bigint }) => any; - inviteCreate: (bot: Bot, invite: DiscordenoInvite) => any; + inviteCreate: (bot: Bot, invite: Invite) => any; inviteDelete: ( bot: Bot, payload: { @@ -458,25 +453,25 @@ export interface EventHandlers { ) => any; guildMemberAdd: ( bot: Bot, - member: DiscordenoMember, - user: DiscordenoUser, + member: Member, + user: User, ) => any; - guildMemberRemove: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any; + guildMemberRemove: (bot: Bot, user: User, guildId: bigint) => any; guildMemberUpdate: ( bot: Bot, - member: DiscordenoMember, - user: DiscordenoUser, + member: Member, + user: User, ) => any; - messageCreate: (bot: Bot, message: DiscordenoMessage) => any; + messageCreate: (bot: Bot, message: Message) => any; messageDelete: ( bot: Bot, payload: { id: bigint; channelId: bigint; guildId?: bigint }, - message?: DiscordenoMessage, + message?: Message, ) => any; messageUpdate: ( bot: Bot, - message: DiscordenoMessage, - oldMessage?: DiscordenoMessage, + message: Message, + oldMessage?: Message, ) => any; reactionAdd: ( bot: Bot, @@ -485,8 +480,8 @@ export interface EventHandlers { channelId: bigint; messageId: bigint; guildId?: bigint; - member?: DiscordenoMember; - emoji: DiscordenoEmoji; + member?: Member; + emoji: Emoji; }, ) => any; reactionRemove: ( @@ -496,7 +491,7 @@ export interface EventHandlers { channelId: bigint; messageId: bigint; guildId?: bigint; - emoji: DiscordenoEmoji; + emoji: Emoji; }, ) => any; reactionRemoveEmoji: ( @@ -505,7 +500,7 @@ export interface EventHandlers { channelId: bigint; messageId: bigint; guildId?: bigint; - emoji: DiscordenoEmoji; + emoji: Emoji; }, ) => any; reactionRemoveAll: ( @@ -518,8 +513,8 @@ export interface EventHandlers { ) => any; presenceUpdate: ( bot: Bot, - presence: DiscordenoPresence, - oldPresence?: DiscordenoPresence, + presence: PresenceUpdate, + oldPresence?: PresenceUpdate, ) => any; voiceServerUpdate: ( bot: Bot, @@ -527,41 +522,20 @@ export interface EventHandlers { ) => any; voiceStateUpdate: ( bot: Bot, - voiceState: { - guildId?: bigint; - channelId?: bigint; - userId: bigint; - member?: DiscordenoMember; - user?: DiscordenoUser; - sessionId: string; - deaf: boolean; - mute: boolean; - selfDeaf: boolean; - selfMute: boolean; - selfStream?: boolean; - selfVideo: boolean; - suppress: boolean; - requestToSpeakTimestamp?: number; - }, + voiceState: VoiceState, ) => any; - channelCreate: (bot: Bot, channel: DiscordenoChannel) => any; + channelCreate: (bot: Bot, channel: Channel) => any; dispatchRequirements: ( bot: Bot, - data: GatewayPayload, + data: DiscordGatewayPayload, shardId: number, ) => any; - voiceChannelLeave: ( - bot: Bot, - voiceState: DiscordenoVoiceState, - guild: DiscordenoGuild, - channel?: DiscordenoChannel, - ) => any; - channelDelete: (bot: Bot, channel: DiscordenoChannel) => any; + channelDelete: (bot: Bot, channel: Channel) => any; channelPinsUpdate: ( bot: Bot, data: { guildId?: bigint; channelId: bigint; lastPinTimestamp?: number }, ) => any; - channelUpdate: (bot: Bot, channel: DiscordenoChannel) => any; + channelUpdate: (bot: Bot, channel: Channel) => any; stageInstanceCreate: ( bot: Bot, data: { @@ -589,29 +563,28 @@ export interface EventHandlers { topic: string; }, ) => any; - // TODO: THREADS guildEmojisUpdate: ( bot: Bot, payload: { guildId: bigint; - emojis: Collection; + emojis: Collection; }, ) => any; - guildBanAdd: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any; - guildBanRemove: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any; - guildLoaded: (bot: Bot, guild: DiscordenoGuild) => any; - guildCreate: (bot: Bot, guild: DiscordenoGuild) => any; + guildBanAdd: (bot: Bot, user: User, guildId: bigint) => any; + guildBanRemove: (bot: Bot, user: User, guildId: bigint) => any; + guildLoaded: (bot: Bot, guild: Guild) => any; + guildCreate: (bot: Bot, guild: Guild) => any; guildDelete: (bot: Bot, id: bigint, shardId: number) => any; - guildUpdate: (bot: Bot, guild: DiscordenoGuild) => any; - raw: (bot: Bot, data: GatewayPayload, shardId: number) => any; - roleCreate: (bot: Bot, role: DiscordenoRole) => any; + guildUpdate: (bot: Bot, guild: Guild) => any; + raw: (bot: Bot, data: DiscordGatewayPayload, shardId: number) => any; + roleCreate: (bot: Bot, role: Role) => any; roleDelete: (bot: Bot, payload: { guildId: bigint; roleId: bigint }) => any; - roleUpdate: (bot: Bot, role: DiscordenoRole) => any; + roleUpdate: (bot: Bot, role: Role) => any; webhooksUpdate: ( bot: Bot, payload: { channelId: bigint; guildId: bigint }, ) => any; - botUpdate: (bot: Bot, user: DiscordenoUser) => any; + botUpdate: (bot: Bot, user: User) => any; typingStart: ( bot: Bot, payload: { @@ -619,7 +592,7 @@ export interface EventHandlers { channelId: bigint; userId: bigint; timestamp: number; - member: DiscordenoMember | undefined; + member: Member | undefined; }, ) => any; } @@ -702,7 +675,7 @@ export function createBotGatewayHandlers( options: Partial, ): Record< GatewayDispatchEventNames | "GUILD_LOADED_DD", - (bot: Bot, data: GatewayPayload, shardId: number) => any + (bot: Bot, data: DiscordGatewayPayload, shardId: number) => any > { return { // misc @@ -713,12 +686,12 @@ export function createBotGatewayHandlers( CHANNEL_PINS_UPDATE: options.CHANNEL_PINS_UPDATE ?? handlers.handleChannelPinsUpdate, CHANNEL_UPDATE: options.CHANNEL_UPDATE ?? handlers.handleChannelUpdate, - // THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate, - // THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate, - // THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete, - // THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync, - // THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handlers.handleThreadMemberUpdate, - // THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate, + THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate, + THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate, + THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete, + THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync, + THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handlers.handleThreadMemberUpdate, + THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate, STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ?? handlers.handleStageInstanceCreate, STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ?? diff --git a/gateway/createShard.ts b/gateway/createShard.ts index 145f6e55c..a72e7ef21 100644 --- a/gateway/createShard.ts +++ b/gateway/createShard.ts @@ -1,4 +1,4 @@ -import { GatewayCloseEventCodes } from "../types/codes/gatewayCloseEventCodes.ts"; +import { GatewayCloseEventCodes } from "../types/shared.ts"; import { GatewayManager } from "./gateway_manager.ts"; export function createShard(gateway: GatewayManager, shardId: number) { diff --git a/gateway/gateway_manager.ts b/gateway/gateway_manager.ts index d96002f49..ba7f65b50 100644 --- a/gateway/gateway_manager.ts +++ b/gateway/gateway_manager.ts @@ -20,9 +20,9 @@ import { prepareBuckets, spawnShards } from "./spawnShards.ts"; import { stopGateway } from "./stopGateway.ts"; import { tellWorkerToIdentify } from "./tellWorkerToIdentify.ts"; import { DiscordenoShard } from "./shard.ts"; -import { GatewayIntents } from "../types/gateway/gatewayIntents.ts"; -import { StatusUpdate } from "../types/gateway/statusUpdate.ts"; -import { GatewayPayload } from "../types/gateway/gatewayPayload.ts"; +import { GatewayIntents } from "../types/shared.ts"; +import { StatusUpdate } from "../helpers/misc/editBotStatus.ts"; +import { DiscordGatewayPayload } from "../types/discord.ts"; /** Create a new Gateway Manager. * @@ -188,7 +188,7 @@ export interface GatewayManager { /** Begins heartbeating of the shard to keep it alive. */ heartbeat: typeof heartbeat; /** Sends the discord payload to another server. */ - handleDiscordPayload: (gateway: GatewayManager, data: GatewayPayload, shardId: number) => any; + handleDiscordPayload: (gateway: GatewayManager, data: DiscordGatewayPayload, shardId: number) => any; /** Tell the worker to begin identifying this shard */ tellWorkerToIdentify: typeof tellWorkerToIdentify; /** Handle the different logs. Used for debugging. */ diff --git a/gateway/handleOnMessage.ts b/gateway/handleOnMessage.ts index 08930adc2..553d54ec5 100644 --- a/gateway/handleOnMessage.ts +++ b/gateway/handleOnMessage.ts @@ -1,15 +1,16 @@ import { GatewayManager } from "./gateway_manager.ts"; -import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts"; -import type { DiscordGatewayPayload } from "../types/gateway/gatewayPayload.ts"; -import type { DiscordHello } from "../types/gateway/hello.ts"; -import type { DiscordReady } from "../types/gateway/ready.ts"; -import { Guild } from "../types/guilds/guild.ts"; -import { UnavailableGuild } from "../types/guilds/unavailableGuild.ts"; -import { Message } from "../types/messages/mod.ts"; -import { SnakeCasedPropertiesDeep } from "../types/util.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { delay } from "../util/utils.ts"; import { decompressWith } from "./deps.ts"; +import { + DiscordGatewayPayload, + DiscordGuild, + DiscordHello, + DiscordMessage, + DiscordReady, + DiscordUnavailableGuild, +} from "../types/discord.ts"; +import { GatewayOpcodes } from "../types/shared.ts"; /** Handler for handling every message event from websocket. */ // deno-lint-ignore no-explicit-any @@ -125,7 +126,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha // MUST HANDLE GUILD_CREATE EVENTS AS THEY ARE EXPENSIVE WITHOUT GATEWAY CACHE if (messageData.t === "GUILD_CREATE") { - const id = snowflakeToBigint((messageData.d as SnakeCasedPropertiesDeep).id); + const id = snowflakeToBigint((messageData.d as DiscordGuild).id); // SHARD RESUMED MOST LIKELY, THEY EMIT GUILD CREATES. OR GUILD BECAME AVAILABLE AGAIN if (gateway.cache.guildIds.has(id)) return; @@ -142,7 +143,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha // MESSAGE_UPDATE CAN SPAM FOR NO REASON USE THIS TO IGNORE if (messageData.t === "MESSAGE_UPDATE") { - const payload = messageData.d as SnakeCasedPropertiesDeep; + const payload = messageData.d as DiscordMessage; const id = snowflakeToBigint(payload.id); const content = payload.content || ""; @@ -161,7 +162,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha // MUST HANDLE GUILD_DELETE EVENTS FOR UNAVAILABLE if (messageData.t === "GUILD_DELETE") { - if ((messageData.d as UnavailableGuild).unavailable) return; + if ((messageData.d as DiscordUnavailableGuild).unavailable) return; } // IF NO TYPE THEN THIS SHOULD NOT BE SENT FORWARD diff --git a/gateway/heartbeat.ts b/gateway/heartbeat.ts index 8d7f7576d..e8b58d0ad 100644 --- a/gateway/heartbeat.ts +++ b/gateway/heartbeat.ts @@ -1,4 +1,4 @@ -import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts"; +import { GatewayOpcodes } from "../types/shared.ts"; import { delay } from "../util/utils.ts"; import { GatewayManager } from "./gateway_manager.ts"; diff --git a/gateway/identify.ts b/gateway/identify.ts index 58ac03a16..6b59bffd5 100644 --- a/gateway/identify.ts +++ b/gateway/identify.ts @@ -1,4 +1,4 @@ -import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts"; +import { GatewayOpcodes } from "../types/shared.ts"; import { GatewayManager } from "./gateway_manager.ts"; export function identify(gateway: GatewayManager, shardId: number, maxShards: number) { diff --git a/gateway/mod.ts b/gateway/mod.ts index f48e31e32..d41ed7e6c 100644 --- a/gateway/mod.ts +++ b/gateway/mod.ts @@ -8,7 +8,6 @@ export * from "./resharder.ts"; export * from "./resume.ts"; export * from "./spawnShards.ts"; export * from "./sendShardMessage.ts"; -export * from "./startGatewayOptions.ts"; export * from "./tellWorkerToIdentify.ts"; export * from "./shard.ts"; export * from "./gateway_manager.ts"; diff --git a/gateway/resharder.ts b/gateway/resharder.ts index 319480e5a..fdf43ae35 100644 --- a/gateway/resharder.ts +++ b/gateway/resharder.ts @@ -1,6 +1,5 @@ -import { transformGatewayBot } from "../transformers/gatewayBot.ts"; -import { GetGatewayBot } from "../types/gateway/getGatewayBot.ts"; -import { DiscordReady } from "../types/gateway/ready.ts"; +import { GetGatewayBot, transformGatewayBot } from "../transformers/gatewayBot.ts"; +import { DiscordReady } from "../types/discord.ts"; import { createGatewayManager, GatewayManager } from "./gateway_manager.ts"; /** The handler to automatically reshard when necessary. */ diff --git a/gateway/resume.ts b/gateway/resume.ts index 72fedd2d6..4328e21cb 100644 --- a/gateway/resume.ts +++ b/gateway/resume.ts @@ -1,4 +1,4 @@ -import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts"; +import { GatewayOpcodes } from "../types/shared.ts"; import { GatewayManager } from "./gateway_manager.ts"; export function resume(gateway: GatewayManager, shardId: number) { diff --git a/gateway/shard.ts b/gateway/shard.ts index 20480293d..e1d2f2388 100644 --- a/gateway/shard.ts +++ b/gateway/shard.ts @@ -1,4 +1,4 @@ -import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts"; +import { GatewayOpcodes } from "../types/shared.ts"; export interface DiscordenoShard { /** The shard id number. */ diff --git a/gateway/startGatewayOptions.ts b/gateway/startGatewayOptions.ts deleted file mode 100644 index e8078bc1c..000000000 --- a/gateway/startGatewayOptions.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { GatewayIntents } from "../types/gateway/gatewayIntents.ts"; - -export interface StartGatewayOptions { - /** The bot token. */ - token: string; - /** Whether or not to use compression for gateway payloads. */ - compress?: boolean; - /** The intents you would like to enable. */ - intents: (GatewayIntents | keyof typeof GatewayIntents)[]; - /** The max amount of shards used for identifying. This can be useful for zero-downtime updates or resharding. */ - maxShards?: number; - /** The first shard Id for this group of shards. */ - firstShardId: number; - /** The last shard Id for this group. If none is provided, it will default to loading all shards. */ - lastShardId?: number; - /** The url to forward all payloads to. */ - url: string; - /** The amount of shards per worker. By default this is 25. Use this to spread the load from shards to different CPU cores. */ - shardsPerWorker?: number; - /** The maximum amount of workers available. By default this is 4. Another way to think of worker is how many CPU cores does your server/machine have. */ - maxWorkers?: number; - /** Whether or not you want to allow automated sharding. By default this is true. */ - reshard?: boolean; - /** The authorization key that the bot http server will expect. */ - secretKey: string; -} diff --git a/handlers/channels/CHANNEL_CREATE.ts b/handlers/channels/CHANNEL_CREATE.ts index f3ba05270..f7a8c690f 100644 --- a/handlers/channels/CHANNEL_CREATE.ts +++ b/handlers/channels/CHANNEL_CREATE.ts @@ -1,11 +1,8 @@ -import type { Channel } from "../../types/channels/channel.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; - import type { Bot } from "../../bot.ts"; +import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload) { - const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep }); + const channel = bot.transformers.channel(bot, { channel: payload.d as DiscordChannel }); bot.events.channelCreate(bot, channel); } diff --git a/handlers/channels/CHANNEL_DELETE.ts b/handlers/channels/CHANNEL_DELETE.ts index 18c3b07bb..fb6c7be9b 100644 --- a/handlers/channels/CHANNEL_DELETE.ts +++ b/handlers/channels/CHANNEL_DELETE.ts @@ -1,10 +1,8 @@ -import type { Channel } from "../../types/channels/channel.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; import type { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordChannel; if (!payload.guild_id) return; bot.events.channelDelete( diff --git a/handlers/channels/CHANNEL_PINS_UPDATE.ts b/handlers/channels/CHANNEL_PINS_UPDATE.ts index 4b100b88e..7361a44e5 100644 --- a/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { ChannelPinsUpdate } from "../../types/channels/channelPinsUpdate.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordChannelPinsUpdate, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordChannelPinsUpdate; bot.events.channelPinsUpdate(bot, { guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined, diff --git a/handlers/channels/CHANNEL_UPDATE.ts b/handlers/channels/CHANNEL_UPDATE.ts index f5af206a1..6933f0b7a 100644 --- a/handlers/channels/CHANNEL_UPDATE.ts +++ b/handlers/channels/CHANNEL_UPDATE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { Channel } from "../../types/channels/channel.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordChannel; const channel = bot.transformers.channel(bot, { channel: payload }); bot.events.channelUpdate(bot, channel); diff --git a/handlers/channels/STAGE_INSTANCE_CREATE.ts b/handlers/channels/STAGE_INSTANCE_CREATE.ts index 3ccb08a04..e2c2ac58a 100644 --- a/handlers/channels/STAGE_INSTANCE_CREATE.ts +++ b/handlers/channels/STAGE_INSTANCE_CREATE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { StageInstance } from "../../types/channels/stageInstance.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts"; export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordStageInstance; bot.events.stageInstanceCreate(bot, { id: bot.transformers.snowflake(payload.id), diff --git a/handlers/channels/STAGE_INSTANCE_DELETE.ts b/handlers/channels/STAGE_INSTANCE_DELETE.ts index a02a0194d..b98f27008 100644 --- a/handlers/channels/STAGE_INSTANCE_DELETE.ts +++ b/handlers/channels/STAGE_INSTANCE_DELETE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { StageInstance } from "../../types/channels/stageInstance.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts"; export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordStageInstance; bot.events.stageInstanceDelete(bot, { id: bot.transformers.snowflake(payload.id), diff --git a/handlers/channels/STAGE_INSTANCE_UPDATE.ts b/handlers/channels/STAGE_INSTANCE_UPDATE.ts index 383e77aa0..0685127fc 100644 --- a/handlers/channels/STAGE_INSTANCE_UPDATE.ts +++ b/handlers/channels/STAGE_INSTANCE_UPDATE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { StageInstance } from "../../types/channels/stageInstance.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts"; export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordStageInstance; bot.events.stageInstanceUpdate(bot, { id: bot.transformers.snowflake(payload.id), diff --git a/handlers/channels/THREAD_CREATE.ts b/handlers/channels/THREAD_CREATE.ts index 7c2938133..a13d1247b 100644 --- a/handlers/channels/THREAD_CREATE.ts +++ b/handlers/channels/THREAD_CREATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import { Channel } from "../../types/channels/channel.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordChannel; bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload })); } diff --git a/handlers/channels/THREAD_DELETE.ts b/handlers/channels/THREAD_DELETE.ts index d9e685038..9b9755752 100644 --- a/handlers/channels/THREAD_DELETE.ts +++ b/handlers/channels/THREAD_DELETE.ts @@ -1,9 +1,7 @@ import { Bot } from "../../bot.ts"; -import { Channel } from "../../types/channels/channel.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordChannel; bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload })); } diff --git a/handlers/channels/THREAD_LIST_SYNC.ts b/handlers/channels/THREAD_LIST_SYNC.ts index 1317c8cd7..b476e1385 100644 --- a/handlers/channels/THREAD_LIST_SYNC.ts +++ b/handlers/channels/THREAD_LIST_SYNC.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import { ThreadListSync } from "../../types/channels/threads/threadListSync.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordThreadListSync } from "../../types/discord.ts"; export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordThreadListSync; const guildId = bot.transformers.snowflake(payload.guild_id); return { diff --git a/handlers/channels/THREAD_MEMBERS_UPDATE.ts b/handlers/channels/THREAD_MEMBERS_UPDATE.ts index 762d3609d..be40fe07d 100644 --- a/handlers/channels/THREAD_MEMBERS_UPDATE.ts +++ b/handlers/channels/THREAD_MEMBERS_UPDATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import { ThreadMembersUpdate } from "../../types/channels/threads/threadMembersUpdate.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordThreadMembersUpdate } from "../../types/discord.ts"; export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordThreadMembersUpdate; bot.events.threadMembersUpdate(bot, { id: bot.transformers.snowflake(payload.id), guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/handlers/channels/THREAD_MEMBER_UPDATE.ts b/handlers/channels/THREAD_MEMBER_UPDATE.ts index b506b9ce4..d0087cdb7 100644 --- a/handlers/channels/THREAD_MEMBER_UPDATE.ts +++ b/handlers/channels/THREAD_MEMBER_UPDATE.ts @@ -1,5 +1,5 @@ import { Bot } from "../../bot.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; +import { DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) { // This event is documented for completeness, but unlikely to be used by most bots diff --git a/handlers/channels/THREAD_UPDATE.ts b/handlers/channels/THREAD_UPDATE.ts index 0c2f37fa2..ec839a350 100644 --- a/handlers/channels/THREAD_UPDATE.ts +++ b/handlers/channels/THREAD_UPDATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import { Channel } from "../../types/channels/channel.ts"; -import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts"; export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordChannel; bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload })); } diff --git a/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index bd9db7c6a..ba7712750 100644 --- a/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -1,11 +1,9 @@ import type { Bot } from "../../bot.ts"; -import type { GuildEmojisUpdate } from "../../types/emojis/guildEmojisUpdate.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildEmojisUpdate } from "../../types/discord.ts"; import { Collection } from "../../util/collection.ts"; export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildEmojisUpdate; bot.events.guildEmojisUpdate(bot, { guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/handlers/guilds/GUILD_BAN_ADD.ts b/handlers/guilds/GUILD_BAN_ADD.ts index 67206ff40..889cd2133 100644 --- a/handlers/guilds/GUILD_BAN_ADD.ts +++ b/handlers/guilds/GUILD_BAN_ADD.ts @@ -1,9 +1,7 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildBanAddRemove } from "../../types/guilds/guildBanAddRemove.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../types/discord.ts"; export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildBanAddRemove; bot.events.guildBanAdd(bot, bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id)); } diff --git a/handlers/guilds/GUILD_BAN_REMOVE.ts b/handlers/guilds/GUILD_BAN_REMOVE.ts index fac4e1544..993df1c8b 100644 --- a/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildBanAddRemove } from "../../types/guilds/guildBanAddRemove.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../types/discord.ts"; export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildBanAddRemove; await bot.events.guildBanRemove( bot, diff --git a/handlers/guilds/GUILD_CREATE.ts b/handlers/guilds/GUILD_CREATE.ts index cda31cabe..52d4764e5 100644 --- a/handlers/guilds/GUILD_CREATE.ts +++ b/handlers/guilds/GUILD_CREATE.ts @@ -1,9 +1,7 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { Guild } from "../../types/guilds/guild.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts"; export function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuild; bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId })); } diff --git a/handlers/guilds/GUILD_DELETE.ts b/handlers/guilds/GUILD_DELETE.ts index fee609421..80bddd0e0 100644 --- a/handlers/guilds/GUILD_DELETE.ts +++ b/handlers/guilds/GUILD_DELETE.ts @@ -1,9 +1,7 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { UnavailableGuild } from "../../types/guilds/unavailableGuild.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordUnavailableGuild } from "../../types/discord.ts"; export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordUnavailableGuild; bot.events.guildDelete(bot, bot.transformers.snowflake(payload.id), shardId); } diff --git a/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 013c6456f..ae05e67ca 100644 --- a/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildIntegrationsUpdate } from "../../types/integrations/guildIntegrationsUpdate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildIntegrationsUpdate } from "../../types/discord.ts"; export async function handleGuildIntegrationsUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildIntegrationsUpdate; bot.events.integrationUpdate(bot, { guildId: bot.transformers.snowflake(payload.guild_id) }); } diff --git a/handlers/guilds/GUILD_LOADED_DD.ts b/handlers/guilds/GUILD_LOADED_DD.ts index ca988fb99..7ae89e5d2 100644 --- a/handlers/guilds/GUILD_LOADED_DD.ts +++ b/handlers/guilds/GUILD_LOADED_DD.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { Guild } from "../../types/guilds/guild.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts"; export function handleGuildLoaded(bot: Bot, data: DiscordGatewayPayload, shardId: number) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuild; const guild = bot.transformers.guild(bot, { guild: payload, shardId }); bot.events.guildLoaded(bot, guild); diff --git a/handlers/guilds/GUILD_UPDATE.ts b/handlers/guilds/GUILD_UPDATE.ts index 52ab69f23..9f457be70 100644 --- a/handlers/guilds/GUILD_UPDATE.ts +++ b/handlers/guilds/GUILD_UPDATE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { Guild } from "../../types/guilds/guild.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts"; export async function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuild; bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId })); } diff --git a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts index f6dd9699b..91841b958 100644 --- a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts +++ b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts @@ -1,9 +1,7 @@ -import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts"; import type { Bot } from "../../../bot.ts"; -import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../../types/util.ts"; +import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts"; export function handleGuildScheduledEventCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordScheduledEvent; bot.events.scheduledEventCreate(bot, bot.transformers.scheduledEvent(bot, payload)); } diff --git a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts index 321ebd721..704df9697 100644 --- a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts +++ b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts @@ -1,9 +1,7 @@ -import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts"; import type { Bot } from "../../../bot.ts"; -import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../../types/util.ts"; +import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts"; export function handleGuildScheduledEventDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordScheduledEvent; bot.events.scheduledEventDelete(bot, bot.transformers.scheduledEvent(bot, payload)); } diff --git a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts index cf11bae1d..a08f89f94 100644 --- a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts +++ b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts @@ -1,9 +1,7 @@ -import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts"; import type { Bot } from "../../../bot.ts"; -import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../../types/util.ts"; +import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts"; export function handleGuildScheduledEventUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordScheduledEvent; bot.events.scheduledEventUpdate(bot, bot.transformers.scheduledEvent(bot, payload)); } diff --git a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts index 06cf75d76..144fd672a 100644 --- a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts +++ b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../../bot.ts"; -import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts"; -import { ScheduledEventUserAdd } from "../../../types/guilds/scheduledEvents.ts"; -import { SnakeCasedPropertiesDeep } from "../../../types/util.ts"; +import { DiscordGatewayPayload, DiscordScheduledEventUserAdd } from "../../../types/discord.ts"; export function handleGuildScheduledEventUserAdd(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordScheduledEventUserAdd; return bot.events.scheduledEventUserAdd(bot, { guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id), diff --git a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts index 5b4b1cf1b..7a53e9b26 100644 --- a/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +++ b/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts @@ -1,10 +1,8 @@ import type { Bot } from "../../../bot.ts"; -import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts"; -import { ScheduledEventUserRemove } from "../../../types/guilds/scheduledEvents.ts"; -import { SnakeCasedPropertiesDeep } from "../../../types/util.ts"; +import { DiscordGatewayPayload, DiscordScheduledEventUserRemove } from "../../../types/discord.ts"; export function handleGuildScheduledEventUserRemove(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordScheduledEventUserRemove; return bot.events.scheduledEventUserRemove(bot, { guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id), diff --git a/handlers/integrations/INTEGRATION_CREATE.ts b/handlers/integrations/INTEGRATION_CREATE.ts index ef3586d56..87a10ab58 100644 --- a/handlers/integrations/INTEGRATION_CREATE.ts +++ b/handlers/integrations/INTEGRATION_CREATE.ts @@ -1,11 +1,9 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { IntegrationCreateUpdate } from "../../types/integrations/integrationCreateUpdate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../types/discord.ts"; export function handleIntegrationCreate(bot: Bot, data: DiscordGatewayPayload) { bot.events.integrationCreate( bot, - bot.transformers.integration(bot, data.d as SnakeCasedPropertiesDeep), + bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate), ); } diff --git a/handlers/integrations/INTEGRATION_DELETE.ts b/handlers/integrations/INTEGRATION_DELETE.ts index fc8ef77eb..a9f19e1b1 100644 --- a/handlers/integrations/INTEGRATION_DELETE.ts +++ b/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { IntegrationDelete } from "../../types/integrations/integrationDelete.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordIntegrationDelete } from "../../types/discord.ts"; export function handleIntegrationDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordIntegrationDelete; bot.events.integrationDelete(bot, { id: bot.transformers.snowflake(payload.id), diff --git a/handlers/integrations/INTEGRATION_UPDATE.ts b/handlers/integrations/INTEGRATION_UPDATE.ts index 965268841..40cc920f3 100644 --- a/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/handlers/integrations/INTEGRATION_UPDATE.ts @@ -1,11 +1,9 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { IntegrationCreateUpdate } from "../../types/integrations/integrationCreateUpdate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../types/discord.ts"; export function handleIntegrationUpdate(bot: Bot, data: DiscordGatewayPayload) { bot.events.integrationUpdate( bot, - bot.transformers.integration(bot, data.d as SnakeCasedPropertiesDeep), + bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate), ); } diff --git a/handlers/interactions/INTERACTION_CREATE.ts b/handlers/interactions/INTERACTION_CREATE.ts index b89769abb..9c9d4cfb2 100644 --- a/handlers/interactions/INTERACTION_CREATE.ts +++ b/handlers/interactions/INTERACTION_CREATE.ts @@ -1,9 +1,7 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { Interaction } from "../../types/interactions/interaction.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordInteraction } from "../../types/discord.ts"; export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload) { - bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as SnakeCasedPropertiesDeep).id)); - bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as SnakeCasedPropertiesDeep)); + bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as DiscordInteraction).id)); + bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as DiscordInteraction)); } diff --git a/handlers/invites/INVITE_CREATE.ts b/handlers/invites/INVITE_CREATE.ts index 9fcd2d3fa..624a694ec 100644 --- a/handlers/invites/INVITE_CREATE.ts +++ b/handlers/invites/INVITE_CREATE.ts @@ -1,8 +1,6 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { InviteCreate } from "../../types/invites/inviteCreate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordInviteCreate } from "../../types/discord.ts"; export function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload) { - bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as SnakeCasedPropertiesDeep)); + bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as DiscordInviteCreate)); } diff --git a/handlers/invites/INVITE_DELETE.ts b/handlers/invites/INVITE_DELETE.ts index 2fadb7e86..db4e54d44 100644 --- a/handlers/invites/INVITE_DELETE.ts +++ b/handlers/invites/INVITE_DELETE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { InviteDelete } from "../../types/invites/inviteDelete.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordInviteDelete } from "../../types/discord.ts"; export function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordInviteDelete; bot.events.inviteDelete(bot, { /** The channel of the invite */ diff --git a/handlers/members/GUILD_MEMBERS_CHUNK.ts b/handlers/members/GUILD_MEMBERS_CHUNK.ts index 7d3bad401..4e0fba27a 100644 --- a/handlers/members/GUILD_MEMBERS_CHUNK.ts +++ b/handlers/members/GUILD_MEMBERS_CHUNK.ts @@ -1,11 +1,9 @@ import { Bot } from "../../bot.ts"; import { statusTypes } from "../../transformers/presence.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildMembersChunk } from "../../types/members/guildMembersChunk.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildMembersChunk } from "../../types/discord.ts"; export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildMembersChunk; const guildId = bot.transformers.snowflake(payload.guild_id); diff --git a/handlers/members/GUILD_MEMBER_ADD.ts b/handlers/members/GUILD_MEMBER_ADD.ts index 7ef44c978..0c87836a0 100644 --- a/handlers/members/GUILD_MEMBER_ADD.ts +++ b/handlers/members/GUILD_MEMBER_ADD.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildMemberAdd } from "../../types/members/guildMemberAdd.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildMemberAdd } from "../../types/discord.ts"; export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildMemberAdd; const guildId = bot.transformers.snowflake(payload.guild_id); const user = bot.transformers.user(bot, payload.user); const member = bot.transformers.member(bot, payload, guildId, user.id); diff --git a/handlers/members/GUILD_MEMBER_REMOVE.ts b/handlers/members/GUILD_MEMBER_REMOVE.ts index 9d1eab357..383a32be4 100644 --- a/handlers/members/GUILD_MEMBER_REMOVE.ts +++ b/handlers/members/GUILD_MEMBER_REMOVE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildMemberRemove } from "../../types/members/guildMemberRemove.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildMemberRemove } from "../../types/discord.ts"; export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildMemberRemove; const guildId = bot.transformers.snowflake(payload.guild_id); const user = bot.transformers.user(bot, payload.user); diff --git a/handlers/members/GUILD_MEMBER_UPDATE.ts b/handlers/members/GUILD_MEMBER_UPDATE.ts index 671272973..ba413141b 100644 --- a/handlers/members/GUILD_MEMBER_UPDATE.ts +++ b/handlers/members/GUILD_MEMBER_UPDATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildMemberUpdate } from "../../types/members/guildMemberUpdate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildMemberUpdate } from "../../types/discord.ts"; export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildMemberUpdate; const user = bot.transformers.user(bot, payload.user); bot.events.guildMemberUpdate( diff --git a/handlers/messages/MESSAGE_CREATE.ts b/handlers/messages/MESSAGE_CREATE.ts index 1dbf3dba6..012bd4104 100644 --- a/handlers/messages/MESSAGE_CREATE.ts +++ b/handlers/messages/MESSAGE_CREATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { Message } from "../../types/messages/message.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessage } from "../../types/discord.ts"; export async function handleMessageCreate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessage; bot.events.messageCreate(bot, bot.transformers.message(bot, payload)); } diff --git a/handlers/messages/MESSAGE_DELETE.ts b/handlers/messages/MESSAGE_DELETE.ts index 21172c115..a20f6c5e2 100644 --- a/handlers/messages/MESSAGE_DELETE.ts +++ b/handlers/messages/MESSAGE_DELETE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { MessageDelete } from "../../types/messages/messageDelete.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessageDelete } from "../../types/discord.ts"; export async function handleMessageDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessageDelete; bot.events.messageDelete(bot, { id: bot.transformers.snowflake(payload.id), diff --git a/handlers/messages/MESSAGE_DELETE_BULK.ts b/handlers/messages/MESSAGE_DELETE_BULK.ts index 5c450a801..ca449a03e 100644 --- a/handlers/messages/MESSAGE_DELETE_BULK.ts +++ b/handlers/messages/MESSAGE_DELETE_BULK.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { MessageDeleteBulk } from "../../types/messages/messageDeleteBulk.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessageDeleteBulk } from "../../types/discord.ts"; export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessageDeleteBulk; return { ids: payload.ids.map((id) => bot.transformers.snowflake(id)), diff --git a/handlers/messages/MESSAGE_REACTION_ADD.ts b/handlers/messages/MESSAGE_REACTION_ADD.ts index 71c04e253..ff4f3bef8 100644 --- a/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { MessageReactionAdd } from "../../types/messages/messageReactionAdd.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessageReactionAdd } from "../../types/discord.ts"; export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessageReactionAdd; const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined; const userId = bot.transformers.snowflake(payload.user_id); diff --git a/handlers/messages/MESSAGE_REACTION_REMOVE.ts b/handlers/messages/MESSAGE_REACTION_REMOVE.ts index 69b8b0fc1..b33341863 100644 --- a/handlers/messages/MESSAGE_REACTION_REMOVE.ts +++ b/handlers/messages/MESSAGE_REACTION_REMOVE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { MessageReactionRemove } from "../../types/messages/messageReactionRemove.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessageReactionRemove } from "../../types/discord.ts"; export async function handleMessageReactionRemove(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessageReactionRemove; bot.events.reactionRemove(bot, { userId: bot.transformers.snowflake(payload.user_id), diff --git a/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts b/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts index 417001433..f2a384925 100644 --- a/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts +++ b/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { MessageReactionRemoveAll } from "../../types/messages/messageReactionRemoveAll.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessageReactionRemoveAll } from "../../types/discord.ts"; export async function handleMessageReactionRemoveAll(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessageReactionRemoveAll; bot.events.reactionRemoveAll(bot, { channelId: bot.transformers.snowflake(payload.channel_id), diff --git a/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts b/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts index 342f23bfa..3f102a110 100644 --- a/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts +++ b/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { MessageReactionRemoveEmoji } from "../../types/messages/messageReactionRemoveEmoji.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessageReactionRemoveEmoji } from "../../types/discord.ts"; export async function handleMessageReactionRemoveEmoji(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessageReactionRemoveEmoji; bot.events.reactionRemoveEmoji(bot, { channelId: bot.transformers.snowflake(payload.channel_id), diff --git a/handlers/messages/MESSAGE_UPDATE.ts b/handlers/messages/MESSAGE_UPDATE.ts index 1f368cd9e..d26b8ed54 100644 --- a/handlers/messages/MESSAGE_UPDATE.ts +++ b/handlers/messages/MESSAGE_UPDATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { Message } from "../../types/messages/message.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordMessage } from "../../types/discord.ts"; export async function handleMessageUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordMessage; if (!payload.edited_timestamp) return; bot.events.messageUpdate(bot, bot.transformers.message(bot, payload)); diff --git a/handlers/misc/PRESENCE_UPDATE.ts b/handlers/misc/PRESENCE_UPDATE.ts index 248e05a90..2071f8da1 100644 --- a/handlers/misc/PRESENCE_UPDATE.ts +++ b/handlers/misc/PRESENCE_UPDATE.ts @@ -1,9 +1,6 @@ import { Bot } from "../../bot.ts"; -import type { PresenceUpdate } from "../../types/activity/presenceUpdate.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordPresenceUpdate } from "../../types/discord.ts"; export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; - bot.events.presenceUpdate(bot, bot.transformers.presence(bot, payload)); + bot.events.presenceUpdate(bot, bot.transformers.presence(bot, data.d as DiscordPresenceUpdate)); } diff --git a/handlers/misc/READY.ts b/handlers/misc/READY.ts index fd7952e2f..b438bff9d 100644 --- a/handlers/misc/READY.ts +++ b/handlers/misc/READY.ts @@ -1,6 +1,5 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { DiscordReady } from "../../types/gateway/ready.ts"; +import { DiscordGatewayPayload, DiscordReady } from "../../types/discord.ts"; export function handleReady(bot: Bot, data: DiscordGatewayPayload, shardId: number) { const payload = data.d as DiscordReady; diff --git a/handlers/misc/TYPING_START.ts b/handlers/misc/TYPING_START.ts index aa7f522ca..6bb6e06fd 100644 --- a/handlers/misc/TYPING_START.ts +++ b/handlers/misc/TYPING_START.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { TypingStart } from "../../types/misc/typingStart.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordTypingStart } from "../../types/discord.ts"; export function handleTypingStart(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordTypingStart; const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined; const userId = bot.transformers.snowflake(payload.user_id); diff --git a/handlers/misc/USER_UPDATE.ts b/handlers/misc/USER_UPDATE.ts index afb5cf58d..c02f2bdf8 100644 --- a/handlers/misc/USER_UPDATE.ts +++ b/handlers/misc/USER_UPDATE.ts @@ -1,9 +1,7 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { User } from "../../types/users/user.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordUser } from "../../types/discord.ts"; export async function handleUserUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordUser; bot.events.botUpdate(bot, bot.transformers.user(bot, payload)); } diff --git a/handlers/roles/GUILD_ROLE_CREATE.ts b/handlers/roles/GUILD_ROLE_CREATE.ts index 69616913e..d1fc1e9d4 100644 --- a/handlers/roles/GUILD_ROLE_CREATE.ts +++ b/handlers/roles/GUILD_ROLE_CREATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildRoleCreate } from "../../types/guilds/guildRoleCreate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildRoleCreate } from "../../types/discord.ts"; export async function handleGuildRoleCreate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildRoleCreate; bot.events.roleCreate( bot, bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) }), diff --git a/handlers/roles/GUILD_ROLE_DELETE.ts b/handlers/roles/GUILD_ROLE_DELETE.ts index bde34292f..e0e13fa22 100644 --- a/handlers/roles/GUILD_ROLE_DELETE.ts +++ b/handlers/roles/GUILD_ROLE_DELETE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildRoleDelete } from "../../types/guilds/guildRoleDelete.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildRoleDelete } from "../../types/discord.ts"; export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildRoleDelete; bot.events.roleDelete(bot, { roleId: bot.transformers.snowflake(payload.role_id), guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/handlers/roles/GUILD_ROLE_UPDATE.ts b/handlers/roles/GUILD_ROLE_UPDATE.ts index 350e9bcfc..7d4ce211d 100644 --- a/handlers/roles/GUILD_ROLE_UPDATE.ts +++ b/handlers/roles/GUILD_ROLE_UPDATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { GuildRoleUpdate } from "../../types/guilds/guildRoleUpdate.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordGuildRoleUpdate } from "../../types/discord.ts"; export async function handleGuildRoleUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordGuildRoleUpdate; bot.events.roleUpdate( bot, diff --git a/handlers/voice/VOICE_SERVER_UPDATE.ts b/handlers/voice/VOICE_SERVER_UPDATE.ts index b706eae57..73b5dd250 100644 --- a/handlers/voice/VOICE_SERVER_UPDATE.ts +++ b/handlers/voice/VOICE_SERVER_UPDATE.ts @@ -1,10 +1,8 @@ import { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { VoiceServerUpdate } from "../../types/voice/voiceServerUpdate.ts"; +import { DiscordGatewayPayload, DiscordVoiceServerUpdate } from "../../types/discord.ts"; export async function handleVoiceServerUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordVoiceServerUpdate; bot.events.voiceServerUpdate(bot, { token: payload.token, diff --git a/handlers/voice/VOICE_STATE_UPDATE.ts b/handlers/voice/VOICE_STATE_UPDATE.ts index f447589e8..9c3767812 100644 --- a/handlers/voice/VOICE_STATE_UPDATE.ts +++ b/handlers/voice/VOICE_STATE_UPDATE.ts @@ -1,31 +1,11 @@ -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { VoiceState } from "../../types/voice/voiceState.ts"; import { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordVoiceState } from "../../types/discord.ts"; export async function handleVoiceStateUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordVoiceState; if (!payload.guild_id) return; const guildId = bot.transformers.snowflake(payload.guild_id); - const userId = bot.transformers.snowflake(payload.user_id); - bot.events.voiceStateUpdate(bot, { - guildId, - userId, - channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined, - member: payload.member ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined, - user: payload.member ? bot.transformers.user(bot, payload.member.user) : undefined, - sessionId: payload.session_id, - deaf: payload.deaf, - mute: payload.mute, - selfDeaf: payload.self_deaf, - selfMute: payload.self_mute, - selfStream: payload.self_stream, - selfVideo: payload.self_video, - suppress: payload.suppress, - requestToSpeakTimestamp: payload.request_to_speak_timestamp - ? Date.parse(payload.request_to_speak_timestamp) - : undefined, - }); + bot.events.voiceStateUpdate(bot, bot.transformers.voiceState(bot, { voiceState: payload, guildId })); } diff --git a/handlers/webhooks/WEBHOOKS_UPDATE.ts b/handlers/webhooks/WEBHOOKS_UPDATE.ts index 266ca8357..3271649e8 100644 --- a/handlers/webhooks/WEBHOOKS_UPDATE.ts +++ b/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,10 +1,8 @@ -import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import type { WebhookUpdate } from "../../types/webhooks/webhooksUpdate.ts"; import { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordGatewayPayload, DiscordWebhookUpdate } from "../../types/discord.ts"; export function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload) { - const payload = data.d as SnakeCasedPropertiesDeep; + const payload = data.d as DiscordWebhookUpdate; bot.events.webhooksUpdate(bot, { channelId: bot.transformers.snowflake(payload.channel_id), guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/helpers/channels/createChannel.ts b/helpers/channels/createChannel.ts index 5992c30ff..22c5d6cf3 100644 --- a/helpers/channels/createChannel.ts +++ b/helpers/channels/createChannel.ts @@ -1,14 +1,14 @@ -import type { Channel } from "../../types/channels/channel.ts"; -import { ChannelTypes } from "../../types/channels/channelTypes.ts"; -import type { CreateGuildChannel } from "../../types/guilds/createGuildChannel.ts"; import type { Bot } from "../../bot.ts"; +import { ChannelTypes } from "../../types/shared.ts"; +import { DiscordChannel } from "../../types/discord.ts"; +import { OverwriteReadable } from "./editChannelOverwrite.ts"; /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel, reason?: string) { // BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000 if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000; - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.GUILD_CHANNELS(guildId), @@ -36,3 +36,26 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG return bot.transformers.channel(bot, { channel: result, guildId }); } + +export interface CreateGuildChannel { + /** Channel name (1-100 characters) */ + name: string; + /** The type of channel */ + type?: ChannelTypes; + /** Channel topic (0-1024 characters) */ + topic?: string; + /** The bitrate (in bits) of the voice channel (voice only) */ + bitrate?: number; + /** The user limit of the voice channel (voice only) */ + userLimit?: number; + /** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */ + rateLimitPerUser?: number; + /** Sorting position of the channel */ + position?: number; + /** The channel's permission overwrites */ + permissionOverwrites?: OverwriteReadable[]; + /** Id of the parent category for a channel */ + parentId?: bigint; + /** Whether the channel is nsfw */ + nsfw?: boolean; +} diff --git a/helpers/channels/createStageInstance.ts b/helpers/channels/createStageInstance.ts index 4ab876775..0c630ce07 100644 --- a/helpers/channels/createStageInstance.ts +++ b/helpers/channels/createStageInstance.ts @@ -1,12 +1,17 @@ -import type { StageInstance } from "../../types/channels/stageInstance.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordStageInstance } from "../../types/discord.ts"; /** Creates a new Stage instance associated to a Stage channel. Requires the user to be a moderator of the Stage channel. */ export async function createStageInstance(bot: Bot, channelId: bigint, topic: string) { - const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, { - channel_id: channelId.toString(), - topic, - }); + const result = await bot.rest.runMethod( + bot.rest, + "post", + bot.constants.endpoints.STAGE_INSTANCES, + { + channel_id: channelId.toString(), + topic, + }, + ); return bot.transformers.stageInstance(bot, result); } diff --git a/helpers/channels/deleteChannel.ts b/helpers/channels/deleteChannel.ts index da0aa943d..3d66439b5 100644 --- a/helpers/channels/deleteChannel.ts +++ b/helpers/channels/deleteChannel.ts @@ -1,9 +1,9 @@ import type { Bot } from "../../bot.ts"; -import { Channel } from "../../types/channels/channel.ts"; +import { DiscordChannel } from "../../types/discord.ts"; /** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. Bot needs MANAGE_THREADS permissions in the server if deleting thread. */ export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string) { - await bot.rest.runMethod( + await bot.rest.runMethod( bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(channelId), diff --git a/helpers/channels/editChannel.ts b/helpers/channels/editChannel.ts index 9c6455795..d62e3ba00 100644 --- a/helpers/channels/editChannel.ts +++ b/helpers/channels/editChannel.ts @@ -1,7 +1,8 @@ -import type { Channel } from "../../types/channels/channel.ts"; -import type { ModifyChannel } from "../../types/channels/modifyChannel.ts"; import type { Bot } from "../../bot.ts"; -import { DiscordenoChannel } from "../../transformers/channel.ts"; +import { Channel } from "../../transformers/channel.ts"; +import { DiscordChannel } from "../../types/discord.ts"; +import { ChannelTypes, VideoQualityModes } from "../../types/shared.ts"; +import { OverwriteReadable } from "./editChannelOverwrite.ts"; /** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel, reason?: string) { @@ -21,7 +22,7 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh request.amount = 2; request.timestamp = Date.now() + 600000; } else { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // 2 have already been used add to queue request.items.push({ channelId, options, resolve, reject }); if (editChannelProcessing) return; @@ -31,30 +32,35 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh } } - const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(channelId), { - name: options.name, - topic: options.topic, - bitrate: options.bitrate, - user_limit: options.userLimit, - rate_limit_per_user: options.rateLimitPerUser, - position: options.position, - parent_id: options.parentId === null ? null : options.parentId?.toString(), - nsfw: options.nsfw, - type: options.type, - archived: options.archived, - auto_archive_duration: options.autoArchiveDuration, - locked: options.locked, - invitable: options.invitable, - permission_overwrites: options.permissionOverwrites - ? options.permissionOverwrites?.map((overwrite) => ({ - id: overwrite.id.toString(), - type: overwrite.type, - allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null, - deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null, - })) - : undefined, - reason, - }); + const result = await bot.rest.runMethod( + bot.rest, + "patch", + bot.constants.endpoints.CHANNEL_BASE(channelId), + { + name: options.name, + topic: options.topic, + bitrate: options.bitrate, + user_limit: options.userLimit, + rate_limit_per_user: options.rateLimitPerUser, + position: options.position, + parent_id: options.parentId === null ? null : options.parentId?.toString(), + nsfw: options.nsfw, + type: options.type, + archived: options.archived, + auto_archive_duration: options.autoArchiveDuration, + locked: options.locked, + invitable: options.invitable, + permission_overwrites: options.permissionOverwrites + ? options.permissionOverwrites?.map((overwrite) => ({ + id: overwrite.id.toString(), + type: overwrite.type, + allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null, + deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null, + })) + : undefined, + reason, + }, + ); return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) }); } @@ -66,7 +72,7 @@ interface EditChannelRequest { items: { channelId: bigint; options: ModifyChannel; - resolve: (channel: DiscordenoChannel) => void; + resolve: (channel: Channel) => void; // deno-lint-ignore no-explicit-any reject: (error: any) => void; }[]; @@ -115,3 +121,38 @@ function processEditChannelQueue(bot: Bot) { editChannelProcessing = false; } } + +export interface ModifyChannel { + /** 1-100 character channel name */ + name?: string; + /** The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature */ + type?: ChannelTypes; + /** The position of the channel in the left-hand listing */ + position?: number | null; + /** 0-1024 character channel topic */ + topic?: string | null; + /** Whether the channel is nsfw */ + nsfw?: boolean | null; + /** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */ + rateLimitPerUser?: number | null; + /** The bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers) */ + bitrate?: number | null; + /** The user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit */ + userLimit?: number | null; + /** Channel or category-specific permissions */ + permissionOverwrites?: OverwriteReadable[] | null; + /** Id of the new parent category for a channel */ + parentId?: bigint | null; + /** Voice region id for the voice channel, automatic when set to null */ + rtcRegion?: string | null; + /** The camera video quality mode of the voice channel */ + videoQualityMode?: VideoQualityModes; + /** Whether the thread is archived */ + archived?: boolean; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration?: 60 | 1440 | 4320 | 10080; + /** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */ + locked?: boolean; + /** whether non-moderators can add other non-moderators to a thread; only available on private threads */ + invitable?: boolean; +} diff --git a/helpers/channels/editChannelOverwrite.ts b/helpers/channels/editChannelOverwrite.ts index e47c9c654..b2df23422 100644 --- a/helpers/channels/editChannelOverwrite.ts +++ b/helpers/channels/editChannelOverwrite.ts @@ -1,21 +1,42 @@ -import type { Overwrite } from "../../types/channels/overwrite.ts"; import type { Bot } from "../../bot.ts"; +import { OverwriteTypes, PermissionStrings } from "../../types/shared.ts"; /** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ export async function editChannelOverwrite( bot: Bot, channelId: bigint, - overwriteId: bigint, - options: Omit, + overwrite: OverwriteReadable, ) { await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), + bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwrite.id), { - allow: options.allow ? bot.utils.calculateBits(options.allow) : "0", - deny: options.deny ? bot.utils.calculateBits(options.deny) : "0", - type: options.type, + allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0", + deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0", + type: overwrite.type, }, ); } + +export interface OverwriteReadable { + /** Role or user id */ + id: bigint; + /** Either 0 (role) or 1 (member) */ + type: OverwriteTypes; + /** Permission bit set */ + allow?: PermissionStrings[]; + /** Permission bit set */ + deny?: PermissionStrings[]; +} + +export interface Overwrite { + /** Role or user id */ + id: bigint; + /** Either 0 (role) or 1 (member) */ + type: OverwriteTypes; + /** Permission bit set */ + allow?: bigint; + /** Permission bit set */ + deny?: bigint; +} diff --git a/helpers/channels/followChannel.ts b/helpers/channels/followChannel.ts index 8e8e44ca6..f03134e28 100644 --- a/helpers/channels/followChannel.ts +++ b/helpers/channels/followChannel.ts @@ -1,9 +1,9 @@ -import type { FollowedChannel } from "../../types/channels/followedChannel.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordFollowedChannel } from "../../types/discord.ts"; /** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */ export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) { - const data = await bot.rest.runMethod( + const data = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId), diff --git a/helpers/channels/getChannel.ts b/helpers/channels/getChannel.ts index 23f025acb..06ab574a1 100644 --- a/helpers/channels/getChannel.ts +++ b/helpers/channels/getChannel.ts @@ -1,9 +1,13 @@ import type { Bot } from "../../bot.ts"; -import type { Channel } from "../../types/channels/channel.ts"; +import { DiscordChannel } from "../../types/discord.ts"; /** Fetches a single channel object from the api. */ export async function getChannel(bot: Bot, channelId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.CHANNEL_BASE(channelId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.CHANNEL_BASE(channelId), + ); return bot.transformers.channel(bot, { channel: result, diff --git a/helpers/channels/getChannelWebhooks.ts b/helpers/channels/getChannelWebhooks.ts index bf564cb4a..ab212136c 100644 --- a/helpers/channels/getChannelWebhooks.ts +++ b/helpers/channels/getChannelWebhooks.ts @@ -1,14 +1,17 @@ -import type { Webhook } from "../../types/webhooks/webhook.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordWebhook } from "../../types/discord.ts"; /** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */ export async function getChannelWebhooks(bot: Bot, channelId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), ); - return new Collection(result.map((webhook) => [webhook.id, webhook])); + return new Collection(result.map((hook) => { + const webhook = bot.transformers.webhook(bot, hook); + return [webhook.id, webhook]; + })); } diff --git a/helpers/channels/getChannels.ts b/helpers/channels/getChannels.ts index dee5eba57..f79c0a9cb 100644 --- a/helpers/channels/getChannels.ts +++ b/helpers/channels/getChannels.ts @@ -1,10 +1,14 @@ -import type { Channel } from "../../types/channels/channel.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordChannel } from "../../types/discord.ts"; /** Returns a list of guild channel objects. */ export async function getChannels(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_CHANNELS(guildId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.GUILD_CHANNELS(guildId), + ); return new Collection( result.map((res) => bot.transformers.channel(bot, { channel: res, guildId })).map((c) => [c.id, c]), diff --git a/helpers/channels/getPins.ts b/helpers/channels/getPins.ts index 5c39ae863..2ea5c1c06 100644 --- a/helpers/channels/getPins.ts +++ b/helpers/channels/getPins.ts @@ -1,9 +1,13 @@ -import type { Message } from "../../types/messages/message.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMessage } from "../../types/discord.ts"; /** Get pinned messages in this channel. */ export async function getPins(bot: Bot, channelId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.CHANNEL_PINS(channelId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.CHANNEL_PINS(channelId), + ); return result.map((msg) => bot.transformers.message(bot, msg)); } diff --git a/helpers/channels/getStageInstance.ts b/helpers/channels/getStageInstance.ts index 48ae08ae3..21fdef5d0 100644 --- a/helpers/channels/getStageInstance.ts +++ b/helpers/channels/getStageInstance.ts @@ -1,9 +1,9 @@ -import type { StageInstance } from "../../types/channels/stageInstance.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordStageInstance } from "../../types/discord.ts"; /** Gets the stage instance associated with the Stage channel, if it exists. */ export async function getStageInstance(bot: Bot, channelId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.STAGE_INSTANCE(channelId), diff --git a/helpers/channels/swapChannels.ts b/helpers/channels/swapChannels.ts index d61d7ef43..0f7b9b3be 100644 --- a/helpers/channels/swapChannels.ts +++ b/helpers/channels/swapChannels.ts @@ -1,4 +1,3 @@ -import type { ModifyGuildChannelPositions } from "../../types/guilds/modifyGuildChannelPosition.ts"; import type { Bot } from "../../bot.ts"; /** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permission. Only channels to be modified are required. */ @@ -21,3 +20,15 @@ export async function swapChannels(bot: Bot, guildId: bigint, channelPositions: }), ); } + +/** https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions */ +export interface ModifyGuildChannelPositions { + /** Channel id */ + id: string; + /** Sorting position of the channel */ + position: number | null; + /** Syncs the permission overwrites with the new parent, if moving to a new category */ + lockPositions?: boolean | null; + /** The new parent ID for the channel that is moved */ + parentId?: string | null; +} diff --git a/helpers/channels/threads/getActiveThreads.ts b/helpers/channels/threads/getActiveThreads.ts index 7c0252edc..0b660d6b1 100644 --- a/helpers/channels/threads/getActiveThreads.ts +++ b/helpers/channels/threads/getActiveThreads.ts @@ -1,11 +1,10 @@ import type { Bot } from "../../../bot.ts"; -import type { ListActiveThreads } from "../../../types/channels/threads/listActiveThreads.ts"; +import { DiscordListActiveThreads } from "../../../types/discord.ts"; import { Collection } from "../../../util/collection.ts"; -// import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; /** Returns all active threads in the guild, including public and private threads. Threads are ordered by their `id`, in descending order. */ export async function getActiveThreads(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.THREAD_ACTIVE(guildId), diff --git a/helpers/channels/threads/getArchivedThreads.ts b/helpers/channels/threads/getArchivedThreads.ts index 8a8da3dc1..30902c7b7 100644 --- a/helpers/channels/threads/getArchivedThreads.ts +++ b/helpers/channels/threads/getArchivedThreads.ts @@ -1,7 +1,6 @@ -import { ListActiveThreads } from "../../../types/channels/threads/listActiveThreads.ts"; -import { ListPublicArchivedThreads } from "../../../types/channels/threads/listPublicArchivedThreads.ts"; import { Collection } from "../../../util/collection.ts"; import type { Bot } from "../../../bot.ts"; +import { DiscordListActiveThreads } from "../../../types/discord.ts"; /** Get the archived threads for this channel, defaults to public */ export async function getArchivedThreads( @@ -11,7 +10,7 @@ export async function getArchivedThreads( type?: "public" | "private" | "privateJoinedThreads"; }, ) { - const result = (await bot.rest.runMethod( + const result = (await bot.rest.runMethod( bot.rest, "get", options?.type === "privateJoinedThreads" @@ -43,3 +42,12 @@ export async function getArchivedThreads( ), }; } + +// TODO: add docs link +export interface ListPublicArchivedThreads { + // TODO: convert unix to ISO9601 timestamp + /** Returns threads before this timestamp. UNIX or ISO8601 timestamp */ + before?: number | string; + /** Optional maximum number of threads to return */ + limit?: number; +} diff --git a/helpers/channels/threads/getThreadMember.ts b/helpers/channels/threads/getThreadMember.ts index 04be5f2c3..6f2fd7654 100644 --- a/helpers/channels/threads/getThreadMember.ts +++ b/helpers/channels/threads/getThreadMember.ts @@ -1,9 +1,9 @@ import type { Bot } from "../../../bot.ts"; -import { ThreadMember } from "../../../types/channels/threads/threadMember.ts"; +import { DiscordThreadMember } from "../../../types/discord.ts"; /** Returns thread members objects that are members of the thread. */ export async function getThreadMember(bot: Bot, threadId: bigint, userId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.THREAD_USER(threadId, userId), diff --git a/helpers/channels/threads/getThreadMembers.ts b/helpers/channels/threads/getThreadMembers.ts index 2b00ce0c8..6200935f8 100644 --- a/helpers/channels/threads/getThreadMembers.ts +++ b/helpers/channels/threads/getThreadMembers.ts @@ -1,20 +1,18 @@ import type { Bot } from "../../../bot.ts"; -import { ThreadMember } from "../../../types/channels/threads/threadMember.ts"; +import { DiscordThreadMember } from "../../../types/discord.ts"; +import { Collection } from "../../../util/collection.ts"; /** Returns thread members objects that are members of the thread. */ export async function getThreadMembers(bot: Bot, threadId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.THREAD_MEMBERS(threadId), ); - return result; + // return result; - // return new Collection(result.map((res) => [bot.transformers.snowflake(result.userId), { - // id?: string; - // /** The id of the user */ - // userId?: string; - // /** The time the current user last joined the thread */ - // joinTimestamp: string; - // }])); + return new Collection(result.map((res) => { + const member = bot.transformers.threadMember(bot, res); + return [member.id, member]; + })); } diff --git a/helpers/channels/threads/startThreadWithMessage.ts b/helpers/channels/threads/startThreadWithMessage.ts index 61dbbf5b0..44dbbff84 100644 --- a/helpers/channels/threads/startThreadWithMessage.ts +++ b/helpers/channels/threads/startThreadWithMessage.ts @@ -1,15 +1,14 @@ -import type { Channel } from "../../../types/channels/channel.ts"; -import type { StartThreadBase } from "../../../types/channels/threads/startThread.ts"; import type { Bot } from "../../../bot.ts"; +import { DiscordChannel } from "../../../types/discord.ts"; /** Creates a new public thread from an existing message. Returns a thread channel. */ export async function startThreadWithMessage( bot: Bot, channelId: bigint, messageId: bigint, - options: StartThreadBase, + options: StartThreadWithMessage, ) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), @@ -21,3 +20,14 @@ export async function startThreadWithMessage( return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) }); } + +export interface StartThreadWithMessage { + /** 1-100 character thread name */ + name: string; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration: 60 | 1440 | 4320 | 10080; + /** Amount of seconds a user has to wait before sending another message (0-21600) */ + rateLimitPerUser?: number | null; + /** The reason you are creating the thread */ + reason?: string; +} diff --git a/helpers/channels/threads/startThreadWithoutMessage.ts b/helpers/channels/threads/startThreadWithoutMessage.ts index 600bdb780..556467763 100644 --- a/helpers/channels/threads/startThreadWithoutMessage.ts +++ b/helpers/channels/threads/startThreadWithoutMessage.ts @@ -1,10 +1,10 @@ -import type { Channel } from "../../../types/channels/channel.ts"; -import type { StartThreadWithoutMessage } from "../../../types/channels/threads/startThread.ts"; import type { Bot } from "../../../bot.ts"; +import { DiscordChannel } from "../../../types/discord.ts"; +import { ChannelTypes } from "../../../types/shared.ts"; /** Creates a new private thread. Returns a thread channel. */ export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, options: StartThreadWithoutMessage) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), @@ -19,3 +19,18 @@ export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, opt guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined, }); } + +export interface StartThreadWithoutMessage { + /** 1-100 character thread name */ + name: string; + /** Duration in minutes to automatically archive the thread after recent activity */ + autoArchiveDuration: 60 | 1440 | 4320 | 10080; + /** Amount of seconds a user has to wait before sending another message (0-21600) */ + rateLimitPerUser?: number | null; + /** The reason you are creating the thread */ + reason?: string; + /** the type of thread to create */ + type: ChannelTypes.GuildNewsThread | ChannelTypes.GuildPublicThread | ChannelTypes.GuildPrivateThread; + /** whether non-moderators can add other non-moderators to a thread; only available when creating a private thread */ + invitable?: boolean; +} diff --git a/helpers/channels/updateStageInstance.ts b/helpers/channels/updateStageInstance.ts index 581e81468..c0c8d3502 100644 --- a/helpers/channels/updateStageInstance.ts +++ b/helpers/channels/updateStageInstance.ts @@ -1,10 +1,14 @@ -import type { StageInstance } from "../../types/channels/stageInstance.ts"; import type { Bot } from "../../bot.ts"; -import { AtLeastOne } from "../../types/util.ts"; +import { DiscordStageInstance } from "../../types/discord.ts"; +import { AtLeastOne } from "../../types/shared.ts"; /** Updates fields of an existing Stage instance. Requires the user to be a moderator of the Stage channel. */ -export async function updateStageInstance(bot: Bot, channelId: bigint, data: AtLeastOne>) { - const result = await bot.rest.runMethod( +export async function updateStageInstance( + bot: Bot, + channelId: bigint, + data: AtLeastOne>, +) { + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), diff --git a/helpers/channels/updateVoiceState.ts b/helpers/channels/updateVoiceState.ts index b11ed30af..7b220a534 100644 --- a/helpers/channels/updateVoiceState.ts +++ b/helpers/channels/updateVoiceState.ts @@ -1,5 +1,3 @@ -import type { UpdateOthersVoiceState } from "../../types/guilds/updateOthersVoiceState.ts"; -import type { UpdateSelfVoiceState } from "../../types/guilds/updateSelfVoiceState.ts"; import type { Bot } from "../../bot.ts"; /** @@ -45,3 +43,23 @@ export async function updateUserVoiceState(bot: Bot, guildId: bigint, options: U }, ); } + +/** https://discord.com/developers/docs/resources/guild#update-current-user-voice-state */ +export interface UpdateSelfVoiceState { + /** The id of the channel the user is currently in */ + channelId: bigint; + /** Toggles the user's suppress state */ + suppress?: boolean; + /** Sets the user's request to speak */ + requestToSpeakTimestamp?: number | null; +} + +/** https://discord.com/developers/docs/resources/guild#update-user-voice-state */ +export interface UpdateOthersVoiceState { + /** The id of the channel the user is currently in */ + channelId: bigint; + /** Toggles the user's suppress state */ + suppress?: boolean; + /** The user id to target */ + userId: bigint; +} diff --git a/helpers/discovery/addDiscoverySubcategory.ts b/helpers/discovery/addDiscoverySubcategory.ts index a089ed1ac..05fdf9885 100644 --- a/helpers/discovery/addDiscoverySubcategory.ts +++ b/helpers/discovery/addDiscoverySubcategory.ts @@ -1,9 +1,9 @@ -import type { AddGuildDiscoverySubcategory } from "../../types/discovery/addGuildDiscoverySubcategory.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordAddGuildDiscoverySubcategory } from "../../types/discord.ts"; /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) { - await bot.rest.runMethod( + await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId), diff --git a/helpers/discovery/editDiscovery.ts b/helpers/discovery/editDiscovery.ts index 10b32650b..d469ef6d9 100644 --- a/helpers/discovery/editDiscovery.ts +++ b/helpers/discovery/editDiscovery.ts @@ -1,10 +1,9 @@ -import type { DiscoveryMetadata } from "../../types/discovery/discoveryMetadata.ts"; -import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modifyGuildDiscoveryMetadata.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordDiscoveryMetadata } from "../../types/discord.ts"; /** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.DISCOVERY_METADATA(guildId), @@ -29,3 +28,13 @@ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuild categoryIds: result.category_ids, }; } + +// TODO: add docs link +export interface ModifyGuildDiscoveryMetadata { + /** The id of the primary discovery category. Default: 0 */ + primaryCategoryId?: number | null; + /** Up to 10 discovery search kekywords. Default: null */ + keywords?: string[] | null; + /** Whether guild info is shown when custom emojis are clicked. Default: true */ + emojiDiscoverabilityEnabled?: boolean | null; +} diff --git a/helpers/discovery/getDiscovery.ts b/helpers/discovery/getDiscovery.ts index 3bfaceaa6..fe3fa154f 100644 --- a/helpers/discovery/getDiscovery.ts +++ b/helpers/discovery/getDiscovery.ts @@ -1,9 +1,9 @@ -import type { DiscoveryMetadata } from "../../types/discovery/discoveryMetadata.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordDiscoveryMetadata } from "../../types/discord.ts"; /** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */ export async function getDiscovery(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.DISCOVERY_METADATA(guildId), diff --git a/helpers/discovery/getDiscoveryCategories.ts b/helpers/discovery/getDiscoveryCategories.ts index 48a8bff5e..ab60cce94 100644 --- a/helpers/discovery/getDiscoveryCategories.ts +++ b/helpers/discovery/getDiscoveryCategories.ts @@ -1,17 +1,16 @@ -import type { DiscoveryCategory } from "../../types/discovery/discoveryCategory.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; +import { DiscordDiscoveryCategory } from "../../types/discord.ts"; /** Returns a Collection (mapped by Id of the discovery category object) of discovery category objects that can be used when editing guilds */ export async function getDiscoveryCategories(bot: Bot) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.DISCOVERY_CATEGORIES, ); - return new Collection>( + return new Collection( result.map((category) => [category.id, category]), ); } diff --git a/helpers/discovery/validDiscoveryTerm.ts b/helpers/discovery/validDiscoveryTerm.ts index fe3f059f5..1e43c0299 100644 --- a/helpers/discovery/validDiscoveryTerm.ts +++ b/helpers/discovery/validDiscoveryTerm.ts @@ -1,8 +1,8 @@ -import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validateDiscoverySearchTerm.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordValidateDiscoverySearchTerm } from "../../types/discord.ts"; export async function validDiscoveryTerm(bot: Bot, term: string) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.DISCOVERY_VALID_TERM, diff --git a/helpers/emojis/createEmoji.ts b/helpers/emojis/createEmoji.ts index f15ed3057..6db78fa86 100644 --- a/helpers/emojis/createEmoji.ts +++ b/helpers/emojis/createEmoji.ts @@ -1,6 +1,5 @@ -import type { CreateGuildEmoji } from "../../types/emojis/createGuildEmoji.ts"; -import type { Emoji } from "../../types/emojis/emoji.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordEmoji } from "../../types/discord.ts"; /** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuildEmoji) { @@ -8,15 +7,32 @@ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuil options.image = await bot.utils.urlToBase64(options.image); } - const emoji = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILD_EMOJIS(guildId), { - name: options.name, - image: options.image, - roles: options.roles?.map((role) => role.toString()), - reason: options.reason, - }); + const emoji = await bot.rest.runMethod( + bot.rest, + "post", + bot.constants.endpoints.GUILD_EMOJIS(guildId), + { + name: options.name, + image: options.image, + roles: options.roles?.map((role) => role.toString()), + reason: options.reason, + }, + ); return { ...emoji, id: bot.transformers.snowflake(emoji.id!), }; } + +/** https://discord.com/developers/docs/resources/emoji#create-guild-emoji */ +export interface CreateGuildEmoji { + /** Name of the emoji */ + name: string; + /** The 128x128 emoji image */ + image: string; + /** Roles allowed to use this emoji */ + roles?: bigint[]; + /** The reason you are creating this emoji */ + reason?: string; +} diff --git a/helpers/emojis/editEmoji.ts b/helpers/emojis/editEmoji.ts index 1cbee8a3d..3928ecdfc 100644 --- a/helpers/emojis/editEmoji.ts +++ b/helpers/emojis/editEmoji.ts @@ -1,13 +1,26 @@ -import type { Emoji } from "../../types/emojis/emoji.ts"; -import type { ModifyGuildEmoji } from "../../types/emojis/modifyGuildEmoji.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordEmoji } from "../../types/discord.ts"; /** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: ModifyGuildEmoji) { - const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.GUILD_EMOJI(guildId, id), { - name: options.name, - roles: options.roles?.map((role) => role.toString()), - }); + const result = await bot.rest.runMethod( + bot.rest, + "patch", + bot.constants.endpoints.GUILD_EMOJI(guildId, id), + { + name: options.name, + // NEED TERNARY TO SUPPORT NULL AS VALID + roles: options.roles ? options.roles.map((role) => role.toString()) : options.roles, + }, + ); return bot.transformers.emoji(bot, result); } + +/** https://discord.com/developers/docs/resources/emoji#modify-guild-emoji */ +export interface ModifyGuildEmoji { + /** Name of the emoji */ + name?: string; + /** Roles allowed to use this emoji */ + roles?: bigint[] | null; +} diff --git a/helpers/emojis/getEmoji.ts b/helpers/emojis/getEmoji.ts index 4074b2221..000ccc338 100644 --- a/helpers/emojis/getEmoji.ts +++ b/helpers/emojis/getEmoji.ts @@ -1,11 +1,11 @@ -import type { Emoji } from "../../types/emojis/emoji.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordEmoji } from "../../types/discord.ts"; /** * Returns an emoji for the given guild and emoji Id. */ export async function getEmoji(bot: Bot, guildId: bigint, emojiId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId), diff --git a/helpers/emojis/getEmojis.ts b/helpers/emojis/getEmojis.ts index 30f549879..b011032bd 100644 --- a/helpers/emojis/getEmojis.ts +++ b/helpers/emojis/getEmojis.ts @@ -1,12 +1,16 @@ import type { Bot } from "../../bot.ts"; -import type { Emoji } from "../../types/emojis/emoji.ts"; +import { DiscordEmoji } from "../../types/discord.ts"; import { Collection } from "../../util/collection.ts"; /** * Returns a list of emojis for the given guild. */ export async function getEmojis(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_EMOJIS(guildId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.GUILD_EMOJIS(guildId), + ); return new Collection(result.map((e) => [bot.transformers.snowflake(e.id!), bot.transformers.emoji(bot, e)])); } diff --git a/helpers/guilds/createGuild.ts b/helpers/guilds/createGuild.ts index 1acd2eda3..97db482d1 100644 --- a/helpers/guilds/createGuild.ts +++ b/helpers/guilds/createGuild.ts @@ -1,10 +1,17 @@ -import type { CreateGuild } from "../../types/guilds/createGuild.ts"; -import type { Guild } from "../../types/guilds/guild.ts"; import type { Bot } from "../../bot.ts"; +import { Channel } from "../../transformers/channel.ts"; +import { Role } from "../../transformers/role.ts"; +import { DiscordGuild } from "../../types/discord.ts"; +import { + DefaultMessageNotificationLevels, + ExplicitContentFilterLevels, + SystemChannelFlags, + VerificationLevels, +} from "../../types/shared.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 async function createGuild(bot: Bot, options: CreateGuild) { - const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILDS, { + const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILDS, { name: options.name, afk_channel_id: options.afkChannelId, afk_timeout: options.afkTimeout, @@ -20,3 +27,29 @@ export async function createGuild(bot: Bot, options: CreateGuild) { return bot.transformers.guild(bot, { guild: result, shardId: 0 }); } + +/** https://discord.com/developers/docs/resources/guild#create-guild */ +export interface CreateGuild { + /** Name of the guild (1-100 characters) */ + name: string; + /** Base64 128x128 image for the guild icon */ + icon?: string; + /** Verification level */ + verificationLevel?: VerificationLevels; + /** Default message notification level */ + defaultMessageNotifications?: DefaultMessageNotificationLevels; + /** Explicit content filter level */ + explicitContentFilter?: ExplicitContentFilterLevels; + /** New guild roles (first role is the everyone role) */ + roles?: Role[]; + /** New guild's channels */ + channels?: Partial[]; + /** Id for afk channel */ + afkChannelId?: string; + /** Afk timeout in seconds */ + afkTimeout?: number; + /** The id of the channel where guild notices such as welcome messages and boost events are posted */ + systemChannelId?: string; + /** System channel flags */ + systemChannelFlags?: SystemChannelFlags; +} diff --git a/helpers/guilds/editGuild.ts b/helpers/guilds/editGuild.ts index 24d505d35..58d4fd83e 100644 --- a/helpers/guilds/editGuild.ts +++ b/helpers/guilds/editGuild.ts @@ -1,6 +1,12 @@ import type { Bot } from "../../bot.ts"; -import type { Guild } from "../../types/guilds/guild.ts"; -import type { ModifyGuild } from "../../types/guilds/modifyGuild.ts"; +import { DiscordGuild } from "../../types/discord.ts"; +import { + DefaultMessageNotificationLevels, + ExplicitContentFilterLevels, + GuildFeatures, + SystemChannelFlags, + VerificationLevels, +} from "../../types/shared.ts"; /** Modify a guilds settings. Requires the MANAGE_GUILD permission. */ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild, shardId: number) { @@ -16,7 +22,7 @@ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild, options.splash = await bot.utils.urlToBase64(options.splash); } - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.GUILDS_BASE(guildId), @@ -28,3 +34,43 @@ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild, shardId, }); } + +/** https://discord.com/developers/docs/resources/guild#modify-guild */ +export interface ModifyGuild { + /** Guild name */ + name?: string; + /** Verification level */ + verificationLevel?: VerificationLevels | null; + /** Default message notification filter level */ + defaultMessageNotifications?: DefaultMessageNotificationLevels | null; + /** Explicit content filter level */ + explicitContentFilter?: ExplicitContentFilterLevels | null; + /** Id for afk channel */ + afkChannelId?: bigint | null; + /** Afk timeout in seconds */ + afkTimeout?: number; + /** Base64 1024x1024 png/jpeg/gif image for the guild icon (can be animated gif when the server has the `ANIMATED_ICON` feature) */ + icon?: string | null; + /** User id to transfer guild ownership to (must be owner) */ + ownerId?: bigint; + /** Base64 16:9 png/jpeg image for the guild splash (when the server has `INVITE_SPLASH` feature) */ + splash?: string | null; + /** Base64 16:9 png/jpeg image for the guild discovery spash (when the server has the `DISCOVERABLE` feature) */ + discoverySplash?: string | null; + /** Base64 16:9 png/jpeg image for the guild banner (when the server has BANNER feature) */ + banner?: string | null; + /** The id of the channel where guild notices such as welcome messages and boost events are posted */ + systemChannelId?: bigint | null; + /** System channel flags */ + systemChannelFlags?: SystemChannelFlags; + /** The id of the channel where Community guilds display rules and/or guidelines */ + rulesChannelId?: bigint | null; + /** The id of the channel where admins and moderators of Community guilds receive notices from Discord */ + publicUpdatesChannelId?: bigint | null; + /** The preferred locale of a Community guild used in server discovery and notices from Discord; defaults to "en-US" */ + preferredLocale?: string | null; + /** Enabled guild features */ + features?: GuildFeatures[]; + /** Whether the guild's boost progress bar should be enabled */ + premiumProgressBarEnabled?: boolean; +} diff --git a/helpers/guilds/editWelcomeScreen.ts b/helpers/guilds/editWelcomeScreen.ts index 4281927d0..c627711f8 100644 --- a/helpers/guilds/editWelcomeScreen.ts +++ b/helpers/guilds/editWelcomeScreen.ts @@ -1,9 +1,8 @@ -import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modifyGuildWelcomeScreen.ts"; -import type { WelcomeScreen } from "../../types/guilds/welcomeScreen.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordWelcomeScreen } from "../../types/discord.ts"; export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: ModifyGuildWelcomeScreen) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId), @@ -21,3 +20,24 @@ export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: Modi return bot.transformers.welcomeScreen(bot, result); } + +/** https://discord.com/developers/docs/resources/guild#modify-guild-welcome-screen */ +export interface ModifyGuildWelcomeScreen { + /** Whether the welcome screen is enabled */ + enabled?: boolean | null; + /** Channels linked in the welcome screen and their display options */ + welcomeScreen?: WelcomeScreenChannel[] | null; + /** The server description to show in the welcome screen */ + description?: string | null; +} + +export interface WelcomeScreenChannel { + /** The channel's id */ + channelId: bigint; + /** The emoji id, if the emoji is custom */ + emojiId?: bigint; + /** The emoji name if custom, the unicode character if standard, or `null` if no emoji is set */ + emojiName?: string; + /** The description shown for the channel */ + description: string; +} diff --git a/helpers/guilds/editWidget.ts b/helpers/guilds/editWidget.ts index f0d3185a5..ee7104b19 100644 --- a/helpers/guilds/editWidget.ts +++ b/helpers/guilds/editWidget.ts @@ -1,9 +1,9 @@ -import type { GuildWidget } from "../../types/guilds/guildWidget.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordGuildWidget } from "../../types/discord.ts"; /** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */ export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.GUILD_WIDGET(guildId), diff --git a/helpers/guilds/getAuditLogs.ts b/helpers/guilds/getAuditLogs.ts index acadb9f1a..996e64d89 100644 --- a/helpers/guilds/getAuditLogs.ts +++ b/helpers/guilds/getAuditLogs.ts @@ -1,6 +1,6 @@ -import type { AuditLog } from "../../types/auditLog/auditLog.ts"; -import type { GetGuildAuditLog } from "../../types/auditLog/getGuildAuditLog.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordAuditLog } from "../../types/discord.ts"; +import { AuditLogEvents } from "../../types/shared.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) { @@ -8,7 +8,7 @@ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuild if (options?.before) options.before = options.before.toString(); if (options?.limit) options.limit = options.limit >= 1 && options.limit <= 100 ? options.limit : 50; - const auditlog = await bot.rest.runMethod( + const auditlog = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId), @@ -52,3 +52,15 @@ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuild scheduledEvents: auditlog.guild_scheduled_events?.map((event) => bot.transformers.scheduledEvent(bot, event)), }; } + +/** https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log-query-string-parameters */ +export interface GetGuildAuditLog { + /** Filter the log for actions made by a user */ + userId?: bigint | string; + /** The type of audit log event */ + actionType?: AuditLogEvents; + /** Filter the log before a certain entry id */ + before?: bigint | string; + /** How many entries are returned (default 50, minimum 1, maximum 100) */ + limit?: number; +} diff --git a/helpers/guilds/getAvailableVoiceRegions.ts b/helpers/guilds/getAvailableVoiceRegions.ts index a8a21cf25..87680c057 100644 --- a/helpers/guilds/getAvailableVoiceRegions.ts +++ b/helpers/guilds/getAvailableVoiceRegions.ts @@ -1,10 +1,10 @@ -import type { VoiceRegion } from "../../types/voice/voiceRegion.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordVoiceRegion } from "../../types/discord.ts"; import { Collection } from "../../util/collection.ts"; /** Returns an array of voice regions that can be used when creating servers. */ export async function getAvailableVoiceRegions(bot: Bot) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS); return new Collection( result.map((region) => { diff --git a/helpers/guilds/getBan.ts b/helpers/guilds/getBan.ts index 3d1b8f17a..6b0348968 100644 --- a/helpers/guilds/getBan.ts +++ b/helpers/guilds/getBan.ts @@ -1,9 +1,13 @@ -import type { Ban } from "../../types/guilds/ban.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordBan } from "../../types/discord.ts"; /** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */ export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_BAN(guildId, memberId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.GUILD_BAN(guildId, memberId), + ); return { reason: result.reason, diff --git a/helpers/guilds/getBans.ts b/helpers/guilds/getBans.ts index 22b442294..f8f8a6ba1 100644 --- a/helpers/guilds/getBans.ts +++ b/helpers/guilds/getBans.ts @@ -1,13 +1,13 @@ -import type { Ban } from "../../types/guilds/ban.ts"; import type { Bot } from "../../bot.ts"; import { Collection } from "../../util/collection.ts"; -import { DiscordenoUser } from "../../transformers/member.ts"; +import { DiscordBan } from "../../types/discord.ts"; +import { User } from "../../transformers/member.ts"; /** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */ export async function getBans(bot: Bot, guildId: bigint) { - const results = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_BANS(guildId)); + const results = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_BANS(guildId)); - return new Collection( + return new Collection( results.map((res) => [ bot.transformers.snowflake(res.user.id), { diff --git a/helpers/guilds/getGuild.ts b/helpers/guilds/getGuild.ts index 5e9b51c7b..22b5608a5 100644 --- a/helpers/guilds/getGuild.ts +++ b/helpers/guilds/getGuild.ts @@ -1,5 +1,5 @@ -import type { Guild } from "../../types/guilds/guild.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordGuild } from "../../types/discord.ts"; /** * This function fetches a guild's data. This is not the same data as a GUILD_CREATE. @@ -12,7 +12,7 @@ export async function getGuild( counts: true, }, ) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILDS_BASE(guildId), { + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILDS_BASE(guildId), { with_counts: options.counts, }); diff --git a/helpers/guilds/getGuildPreview.ts b/helpers/guilds/getGuildPreview.ts index f5d57e5e4..17e44e7b4 100644 --- a/helpers/guilds/getGuildPreview.ts +++ b/helpers/guilds/getGuildPreview.ts @@ -1,9 +1,9 @@ -import type { GuildPreview } from "../../types/guilds/guildPreview.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordGuildPreview } from "../../types/discord.ts"; /** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */ export async function getGuildPreview(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_PREVIEW(guildId), diff --git a/helpers/guilds/getPruneCount.ts b/helpers/guilds/getPruneCount.ts index 3fcce2d86..c775ba131 100644 --- a/helpers/guilds/getPruneCount.ts +++ b/helpers/guilds/getPruneCount.ts @@ -1,4 +1,3 @@ -import type { GetGuildPruneCountQuery } from "../../types/guilds/getGuildPruneCount.ts"; import type { Bot } from "../../bot.ts"; /** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */ @@ -22,3 +21,11 @@ export async function getPruneCount(bot: Bot, guildId: bigint, options?: GetGuil return result.pruned as number; } + +/** https://discord.com/developers/docs/resources/guild#get-guild-prune-count */ +export interface GetGuildPruneCountQuery { + /** Number of days to count prune for (1 or more), default: 7 */ + days?: number; + /** Role(s) to include, default: none */ + includeRoles: string | string[]; +} diff --git a/helpers/guilds/getVanityUrl.ts b/helpers/guilds/getVanityUrl.ts index 8a43b7ed9..650e3bb16 100644 --- a/helpers/guilds/getVanityUrl.ts +++ b/helpers/guilds/getVanityUrl.ts @@ -1,9 +1,9 @@ -import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */ export async function getVanityUrl(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod>( + const result = await bot.rest.runMethod>( bot.rest, "get", bot.constants.endpoints.GUILD_VANITY_URL(guildId), diff --git a/helpers/guilds/getVoiceRegions.ts b/helpers/guilds/getVoiceRegions.ts index 1a55cae8d..96f7225fd 100644 --- a/helpers/guilds/getVoiceRegions.ts +++ b/helpers/guilds/getVoiceRegions.ts @@ -1,10 +1,10 @@ -import type { VoiceRegion } from "../../types/voice/voiceRegion.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordVoiceRegion } from "../../types/discord.ts"; /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ export async function getVoiceRegions(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_REGIONS(guildId), diff --git a/helpers/guilds/getWelcomeScreen.ts b/helpers/guilds/getWelcomeScreen.ts index 15f999cad..1aa80a304 100644 --- a/helpers/guilds/getWelcomeScreen.ts +++ b/helpers/guilds/getWelcomeScreen.ts @@ -1,9 +1,9 @@ -import type { WelcomeScreen } from "../../types/guilds/welcomeScreen.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordWelcomeScreen } from "../../types/discord.ts"; /** Returns the Welcome Screen object for the guild. Requires the `MANAGE_GUILD` permission. */ export async function getWelcomeScreen(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId), diff --git a/helpers/guilds/getWidget.ts b/helpers/guilds/getWidget.ts index 7ca80927e..4ad6a2219 100644 --- a/helpers/guilds/getWidget.ts +++ b/helpers/guilds/getWidget.ts @@ -1,30 +1,13 @@ -import type { GuildWidgetDetails } from "../../types/guilds/guildWidgetDetails.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordGuildWidget } from "../../types/discord.ts"; /** Returns the widget for the guild. */ export async function getWidget(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json`, ); - return { - id: bot.transformers.snowflake(result.id), - name: result.name, - instantInvite: result.instant_invite, - channels: result.channels.map((channel) => ({ - id: bot.transformers.snowflake(channel.id), - name: channel.name, - position: channel.position, - })), - members: result.members.map((member) => ({ - id: bot.transformers.snowflake(member.id), - username: member.username, - discriminator: Number(member.discriminator), - avatar: member.avatar ? bot.utils.iconHashToBigInt(member.avatar) : undefined, - status: member.status, - })), - presenceCount: result.presence_count, - }; + return bot.transformers.widget(bot, result); } diff --git a/helpers/guilds/getWidgetImageUrl.ts b/helpers/guilds/getWidgetImageUrl.ts index 0b222d63a..b1a604eb3 100644 --- a/helpers/guilds/getWidgetImageUrl.ts +++ b/helpers/guilds/getWidgetImageUrl.ts @@ -1,7 +1,25 @@ import type { Bot } from "../../bot.ts"; -import type { GetGuildWidgetImageQuery } from "../../types/guilds/getGuildWidgetImage.ts"; /** Returns the widget image URL for the guild. */ export async function getWidgetImageURL(bot: Bot, guildId: bigint, options?: GetGuildWidgetImageQuery) { return `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`; } + +/** https://discord.com/developers/docs/resources/guild#get-guild-widget-image-query-string-params */ +export interface GetGuildWidgetImageQuery { + /** + * Style of the widget returned, default: shield + * + * Shield: Widget with Discord icon and guild members online count. + * Banner1: Large image with guild icon, name and online count. "POWERED BY DISCORD" as the footer of the widget + * Banner2: Smaller widget style with guild icon, name and online count. Split on the right with Discord logo + * Banner3: Large image with guild icon, name and online count. In the footer, Discord logo on the left and "Chat Now" on the right + * Banner4: Large Discord logo at the top of the widget. Guild icon, name and online count in the middle portion of the widget and a "JOIN MY SERVER" button at the bottom + */ + style?: + | "shield" + | "banner1" + | "banner2" + | "banner3" + | "banner4"; +} diff --git a/helpers/guilds/getWidgetSettings.ts b/helpers/guilds/getWidgetSettings.ts index 5d6c49bf5..a4980f6ae 100644 --- a/helpers/guilds/getWidgetSettings.ts +++ b/helpers/guilds/getWidgetSettings.ts @@ -1,9 +1,13 @@ -import type { GuildWidget } from "../../types/guilds/guildWidget.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordGuildWidget } from "../../types/discord.ts"; /** Returns the guild widget object. Requires the MANAGE_GUILD permission. */ export async function getWidgetSettings(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.GUILD_WIDGET(guildId), + ); return bot.transformers.widget(bot, result); } diff --git a/helpers/guilds/guildBannerUrl.ts b/helpers/guilds/guildBannerUrl.ts index 08f5e4b04..d94231c6b 100644 --- a/helpers/guilds/guildBannerUrl.ts +++ b/helpers/guilds/guildBannerUrl.ts @@ -1,6 +1,5 @@ -import type { ImageFormat } from "../../types/misc/imageFormat.ts"; -import type { ImageSize } from "../../types/misc/imageSize.ts"; import type { Bot } from "../../bot.ts"; +import { ImageFormat, ImageSize } from "../members/avatarUrl.ts"; /** The full URL of the banner from Discords CDN. Undefined if no banner is set. */ export function guildBannerURL( diff --git a/helpers/guilds/guildIconUrl.ts b/helpers/guilds/guildIconUrl.ts index f69196f4c..a4c7dbe9c 100644 --- a/helpers/guilds/guildIconUrl.ts +++ b/helpers/guilds/guildIconUrl.ts @@ -1,6 +1,5 @@ -import type { ImageFormat } from "../../types/misc/imageFormat.ts"; -import type { ImageSize } from "../../types/misc/imageSize.ts"; import type { Bot } from "../../bot.ts"; +import { ImageFormat, ImageSize } from "../members/avatarUrl.ts"; /** The full URL of the icon from Discords CDN. Undefined when no icon is set. */ export function guildIconURL( diff --git a/helpers/guilds/guildSplashUrl.ts b/helpers/guilds/guildSplashUrl.ts index 1bb87886a..9d95c31af 100644 --- a/helpers/guilds/guildSplashUrl.ts +++ b/helpers/guilds/guildSplashUrl.ts @@ -1,6 +1,5 @@ -import type { ImageFormat } from "../../types/misc/imageFormat.ts"; -import type { ImageSize } from "../../types/misc/imageSize.ts"; import type { Bot } from "../../bot.ts"; +import { ImageFormat, ImageSize } from "../members/avatarUrl.ts"; /** The full URL of the splash from Discords CDN. Undefined if no splash is set. */ export function guildSplashURL( diff --git a/helpers/guilds/scheduledEvents/createScheduledEvent.ts b/helpers/guilds/scheduledEvents/createScheduledEvent.ts index a24e23626..3e16ab1c6 100644 --- a/helpers/guilds/scheduledEvents/createScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/createScheduledEvent.ts @@ -1,10 +1,6 @@ import { Bot } from "../../../bot.ts"; -import { - CreateScheduledEvent, - ScheduledEvent, - ScheduledEventEntityType, - ScheduledEventPrivacyLevel, -} from "../../../types/guilds/scheduledEvents.ts"; +import { DiscordScheduledEvent } from "../../../types/discord.ts"; +import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../types/shared.ts"; /** Create a guild scheduled event in the guild. A guild can have a maximum of 100 events with `SCHEDULED` or `ACTIVE` status at any time. */ export async function createScheduledEvent(bot: Bot, guildId: bigint, options: CreateScheduledEvent) { @@ -30,7 +26,7 @@ export async function createScheduledEvent(bot: Bot, guildId: bigint, options: C throw new Error("Cannot schedule event to end before starting."); } - const event = await bot.rest.runMethod( + const event = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.GUILD_SCHEDULED_EVENTS(guildId), @@ -49,3 +45,23 @@ export async function createScheduledEvent(bot: Bot, guildId: bigint, options: C return bot.transformers.scheduledEvent(bot, event); } + +export interface CreateScheduledEvent { + /** the channel id of the scheduled event. */ + channelId?: bigint; + /** location of the event */ + location?: string; + /** the name of the scheduled event */ + name: string; + /** the description of the scheduled event */ + description: string; + /** the time the scheduled event will start */ + scheduledStartTime: number; + /** the time the scheduled event will end if it does end. */ + scheduledEndTime?: number; + /** the privacy level of the scheduled event */ + privacyLevel?: ScheduledEventPrivacyLevel; + /** the type of hosting entity associated with a scheduled event */ + entityType: ScheduledEventEntityType; + reason?: string; +} diff --git a/helpers/guilds/scheduledEvents/editScheduledEvent.ts b/helpers/guilds/scheduledEvents/editScheduledEvent.ts index a7c86a8a8..8f3e31112 100644 --- a/helpers/guilds/scheduledEvents/editScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/editScheduledEvent.ts @@ -1,5 +1,6 @@ import { Bot } from "../../../bot.ts"; -import { EditScheduledEvent, ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts"; +import { DiscordScheduledEvent } from "../../../types/discord.ts"; +import { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus } from "../../../types/shared.ts"; /** Modify a guild scheduled event. To start or end an event, use this endpoint to modify the event's status. */ export async function editScheduledEvent( @@ -21,7 +22,7 @@ export async function editScheduledEvent( throw new Error("Cannot schedule event to end before starting."); } - const event = await bot.rest.runMethod( + const event = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId), @@ -41,3 +42,25 @@ export async function editScheduledEvent( return bot.transformers.scheduledEvent(bot, event); } + +export interface EditScheduledEvent { + /** the channel id of the scheduled event. null if switching to external event. */ + channelId: bigint | null; + /** location of the event */ + location: string; + /** the name of the scheduled event */ + name: string; + /** the description of the scheduled event */ + description: string; + /** the time the scheduled event will start */ + scheduledStartTime: number; + /** the time the scheduled event will end if it does end. */ + scheduledEndTime?: number; + /** the privacy level of the scheduled event */ + privacyLevel: ScheduledEventPrivacyLevel; + /** the type of hosting entity associated with a scheduled event */ + entityType: ScheduledEventEntityType; + /** the status of the scheduled event */ + status: ScheduledEventStatus; + reason?: string; +} diff --git a/helpers/guilds/scheduledEvents/getScheduledEvent.ts b/helpers/guilds/scheduledEvents/getScheduledEvent.ts index e6bbd89d4..787507573 100644 --- a/helpers/guilds/scheduledEvents/getScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/getScheduledEvent.ts @@ -1,5 +1,5 @@ import { Bot } from "../../../bot.ts"; -import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts"; +import { DiscordScheduledEvent } from "../../../types/discord.ts"; /** Get a guild scheduled event. */ export async function getScheduledEvent( @@ -8,7 +8,7 @@ export async function getScheduledEvent( eventId: bigint, options?: { withUserCount?: boolean }, ) { - const event = await bot.rest.runMethod( + const event = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId), diff --git a/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts b/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts index bb8ae9e13..e25d9e389 100644 --- a/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts +++ b/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts @@ -1,8 +1,6 @@ import { Bot } from "../../../bot.ts"; -import { DiscordenoMember, DiscordenoUser } from "../../../transformers/member.ts"; -import { GetScheduledEventUsers } from "../../../types/guilds/scheduledEvents.ts"; -import { GuildMember } from "../../../types/members/guildMember.ts"; -import { User } from "../../../types/users/user.ts"; +import { Member, User } from "../../../transformers/member.ts"; +import { DiscordMember, DiscordUser } from "../../../types/discord.ts"; import { Collection } from "../../../util/collection.ts"; export async function getScheduledEventUsers( @@ -10,24 +8,22 @@ export async function getScheduledEventUsers( guildId: bigint, eventId: bigint, options?: GetScheduledEventUsers & { withMember?: false }, -): Promise>; +): Promise>; export async function getScheduledEventUsers( bot: Bot, guildId: bigint, eventId: bigint, options?: GetScheduledEventUsers & { withMember: true }, -): Promise>; +): Promise>; export async function getScheduledEventUsers( bot: Bot, guildId: bigint, eventId: bigint, options?: GetScheduledEventUsers, ): Promise< - Collection | Collection + Collection | Collection > { - // TODO: is the guild member omit user - - const result = await bot.rest.runMethod<{ user: User; member?: GuildMember }[]>( + const result = await bot.rest.runMethod<{ user: DiscordUser; member?: DiscordMember }[]>( bot.rest, "get", bot.constants.endpoints.GUILD_SCHEDULED_EVENT_USERS(guildId, eventId), @@ -55,3 +51,14 @@ export async function getScheduledEventUsers( }), ); } + +export interface GetScheduledEventUsers { + /** number of users to return (up to maximum 100), defaults to 100 */ + limit?: number; + /** whether to also have member objects provided, defaults to false */ + withMember?: boolean; + /** consider only users before given user id */ + before?: bigint; + /** consider only users after given user id */ + after?: bigint; +} diff --git a/helpers/guilds/scheduledEvents/getScheduledEvents.ts b/helpers/guilds/scheduledEvents/getScheduledEvents.ts index 0cc5ab440..6afa64fe6 100644 --- a/helpers/guilds/scheduledEvents/getScheduledEvents.ts +++ b/helpers/guilds/scheduledEvents/getScheduledEvents.ts @@ -1,11 +1,11 @@ import { Bot } from "../../../bot.ts"; -import { DiscordenoScheduledEvent } from "../../../transformers/scheduledEvent.ts"; -import { GetScheduledEvents, ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts"; +import { ScheduledEvent } from "../../../transformers/scheduledEvent.ts"; +import { DiscordScheduledEvent } from "../../../types/discord.ts"; import { Collection } from "../../../util/collection.ts"; /** Get a list of guild scheduled event for the given guild. */ export async function getScheduledEvents(bot: Bot, guildId: bigint, options?: GetScheduledEvents) { - const events = await bot.rest.runMethod( + const events = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_SCHEDULED_EVENTS(guildId), @@ -14,10 +14,15 @@ export async function getScheduledEvents(bot: Bot, guildId: bigint, options?: Ge }, ); - return new Collection( + return new Collection( events.map((e) => { const event = bot.transformers.scheduledEvent(bot, e); return [event.id, event]; }), ); } + +export interface GetScheduledEvents { + /** include number of users subscribed to each event */ + withUserCount?: boolean; +} diff --git a/helpers/integrations/getIntegrations.ts b/helpers/integrations/getIntegrations.ts index ac685f85e..b8092a316 100644 --- a/helpers/integrations/getIntegrations.ts +++ b/helpers/integrations/getIntegrations.ts @@ -1,10 +1,10 @@ -import type { Integration } from "../../types/integrations/integration.ts"; import type { Bot } from "../../bot.ts"; import { Collection } from "../../util/collection.ts"; +import { DiscordIntegration } from "../../types/discord.ts"; /** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */ export async function getIntegrations(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_INTEGRATIONS(guildId), diff --git a/helpers/interactions/commands/batchEditApplicationCommandPermissions.ts b/helpers/interactions/commands/batchEditApplicationCommandPermissions.ts index ed61e0544..1e388db96 100644 --- a/helpers/interactions/commands/batchEditApplicationCommandPermissions.ts +++ b/helpers/interactions/commands/batchEditApplicationCommandPermissions.ts @@ -1,6 +1,6 @@ import type { Bot } from "../../../bot.ts"; -import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/applicationCommandPermissions.ts"; -import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts"; +import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts"; +import { ApplicationCommandPermissionTypes } from "../../../types/shared.ts"; /** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */ export async function batchEditApplicationCommandPermissions( @@ -8,7 +8,7 @@ export async function batchEditApplicationCommandPermissions( guildId: bigint, options: { id: string; permissions: ApplicationCommandPermissions[] }[], ) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "put", bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), @@ -17,3 +17,13 @@ export async function batchEditApplicationCommandPermissions( return result.map((res) => bot.transformers.applicationCommandPermission(bot, res)); } + +/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandpermissions */ +export interface ApplicationCommandPermissions { + /** The id of the role or user */ + id: string; + /** Role or User */ + type: ApplicationCommandPermissionTypes; + /** `true` to allow, `false`, to disallow */ + permission: boolean; +} diff --git a/helpers/interactions/commands/createApplicationCommand.ts b/helpers/interactions/commands/createApplicationCommand.ts index 552d5dedf..8bde7fe92 100644 --- a/helpers/interactions/commands/createApplicationCommand.ts +++ b/helpers/interactions/commands/createApplicationCommand.ts @@ -1,7 +1,6 @@ -import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts"; -import type { CreateApplicationCommand } from "../../../types/interactions/commands/createGlobalApplicationCommand.ts"; import type { Bot } from "../../../bot.ts"; -import { ApplicationCommandOption } from "../../../types/interactions/commands/applicationCommandOption.ts"; +import { ApplicationCommandOption, ApplicationCommandTypes } from "../../../mod.ts"; +import { DiscordApplicationCommand } from "../../../types/discord.ts"; /** * There are two kinds of Application Commands: global commands and guild commands. Global commands are available for every guild that adds your app; guild commands are specific to the guild you specify when making them. Command names are unique per application within each scope (global and guild). That means: @@ -15,7 +14,7 @@ import { ApplicationCommandOption } from "../../../types/interactions/commands/a * Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use. */ export async function createApplicationCommand(bot: Bot, options: CreateApplicationCommand, guildId?: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", guildId @@ -47,3 +46,15 @@ export function makeOptionsForCommand(options: ApplicationCommandOption[]) { max_value: option.maxValue, })); } + +/** https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command-json-params */ +export interface CreateApplicationCommand { + /** 1-31 character name matching lowercase `^[\w-]{1,32}$` */ + name: string; + /** 1-100 character description */ + description: string; + /** The type of the command */ + type?: ApplicationCommandTypes; + /** The parameters for the command */ + options?: ApplicationCommandOption[]; +} diff --git a/helpers/interactions/commands/editApplicationCommandPermissions.ts b/helpers/interactions/commands/editApplicationCommandPermissions.ts index 1fc915185..1f9893e8a 100644 --- a/helpers/interactions/commands/editApplicationCommandPermissions.ts +++ b/helpers/interactions/commands/editApplicationCommandPermissions.ts @@ -1,6 +1,6 @@ -import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/applicationCommandPermissions.ts"; import type { Bot } from "../../../bot.ts"; -import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts"; +import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts"; +import { ApplicationCommandPermissions } from "./batchEditApplicationCommandPermissions.ts"; /** Edits command permissions for a specific command for your application in a guild. */ export async function editApplicationCommandPermissions( @@ -9,7 +9,7 @@ export async function editApplicationCommandPermissions( commandId: bigint, options: ApplicationCommandPermissions[], ) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "put", bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), diff --git a/helpers/interactions/commands/editInteractionResponse.ts b/helpers/interactions/commands/editInteractionResponse.ts index 3ae31efef..184b2ec68 100644 --- a/helpers/interactions/commands/editInteractionResponse.ts +++ b/helpers/interactions/commands/editInteractionResponse.ts @@ -1,9 +1,16 @@ -import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/editWebhookMessage.ts"; import type { Bot } from "../../../bot.ts"; -import { MessageComponentTypes } from "../../../types/messages/components/messageComponentTypes.ts"; +import { MessageComponentTypes } from "../../../types/shared.ts"; +import { EditWebhookMessage } from "../../webhooks/editWebhookMessage.ts"; /** To edit your response to a application command. If a messageId is not provided it will default to editing the original response. */ -export async function editInteractionResponse(bot: Bot, token: string, options: DiscordenoEditWebhookMessage) { +export async function editInteractionResponse( + bot: Bot, + token: string, + options: EditWebhookMessage & { + /** Id of the message you want to edit if undefined the initial response message will be edited */ + messageId?: bigint; + }, +) { const result = await bot.rest.runMethod( bot.rest, "patch", diff --git a/helpers/interactions/commands/getApplicationCommand.ts b/helpers/interactions/commands/getApplicationCommand.ts index 5c27470c9..000bdc42a 100644 --- a/helpers/interactions/commands/getApplicationCommand.ts +++ b/helpers/interactions/commands/getApplicationCommand.ts @@ -1,9 +1,9 @@ -import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts"; import type { Bot } from "../../../bot.ts"; +import { DiscordApplicationCommand } from "../../../types/discord.ts"; /** Fetches the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ export async function getApplicationCommand(bot: Bot, commandId: bigint, guildId?: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", guildId diff --git a/helpers/interactions/commands/getApplicationCommandPermission.ts b/helpers/interactions/commands/getApplicationCommandPermission.ts index 31f4eff2e..1b8908c98 100644 --- a/helpers/interactions/commands/getApplicationCommandPermission.ts +++ b/helpers/interactions/commands/getApplicationCommandPermission.ts @@ -1,9 +1,9 @@ -import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts"; import type { Bot } from "../../../bot.ts"; +import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts"; /** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */ export async function getApplicationCommandPermission(bot: Bot, guildId: bigint, commandId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), diff --git a/helpers/interactions/commands/getApplicationCommandPermissions.ts b/helpers/interactions/commands/getApplicationCommandPermissions.ts index 515da9d17..f90016f46 100644 --- a/helpers/interactions/commands/getApplicationCommandPermissions.ts +++ b/helpers/interactions/commands/getApplicationCommandPermissions.ts @@ -1,10 +1,10 @@ import type { Bot } from "../../../bot.ts"; -import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts"; +import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts"; import { Collection } from "../../../util/collection.ts"; /** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */ export async function getApplicationCommandPermissions(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), diff --git a/helpers/interactions/commands/getApplicationCommands.ts b/helpers/interactions/commands/getApplicationCommands.ts index 29c242463..a3289f28a 100644 --- a/helpers/interactions/commands/getApplicationCommands.ts +++ b/helpers/interactions/commands/getApplicationCommands.ts @@ -1,10 +1,10 @@ -import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts"; import { Collection } from "../../../util/collection.ts"; import type { Bot } from "../../../bot.ts"; +import { DiscordApplicationCommand } from "../../../types/discord.ts"; /** Fetch all the commands for your application. If a guild id is not provided, it will fetch global commands. */ export async function getApplicationCommands(bot: Bot, guildId?: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", guildId diff --git a/helpers/interactions/commands/upsertApplicationCommand.ts b/helpers/interactions/commands/upsertApplicationCommand.ts index 411ac228c..f25b2d720 100644 --- a/helpers/interactions/commands/upsertApplicationCommand.ts +++ b/helpers/interactions/commands/upsertApplicationCommand.ts @@ -1,7 +1,8 @@ -import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts"; -import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/editGlobalApplicationCommand.ts"; import type { Bot } from "../../../bot.ts"; import { makeOptionsForCommand } from "./createApplicationCommand.ts"; +import { DiscordApplicationCommand } from "../../../types/discord.ts"; +import { ApplicationCommandOption } from "../../../transformers/applicationCommandOption.ts"; +import { ApplicationCommandTypes } from "../../../types/shared.ts"; /** * Edit an existing application command. If this command did not exist, it will create it. @@ -12,7 +13,7 @@ export async function upsertApplicationCommand( options: EditGlobalApplicationCommand, guildId?: bigint, ) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", guildId @@ -28,3 +29,17 @@ export async function upsertApplicationCommand( return bot.transformers.applicationCommand(bot, result); } + +/** https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command-json-params */ +export interface EditGlobalApplicationCommand { + /** 1-32 character name matching lowercase `^[\w-]{1,32}$` */ + name?: string; + /** 1-100 character description */ + description?: string; + /** The type of the command */ + type?: ApplicationCommandTypes; + /** The parameters for the command */ + options?: ApplicationCommandOption[] | null; + /** Whether the command is enabled by default when the app is added to a guild. Default: true */ + defaultPermission?: boolean; +} diff --git a/helpers/interactions/commands/upsertApplicationCommands.ts b/helpers/interactions/commands/upsertApplicationCommands.ts index 59d5ed26c..533c8cc34 100644 --- a/helpers/interactions/commands/upsertApplicationCommands.ts +++ b/helpers/interactions/commands/upsertApplicationCommands.ts @@ -1,9 +1,9 @@ -import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts"; -import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/editGlobalApplicationCommand.ts"; -import type { MakeRequired } from "../../../types/util.ts"; import type { Bot } from "../../../bot.ts"; import { Collection } from "../../../util/collection.ts"; import { makeOptionsForCommand } from "./createApplicationCommand.ts"; +import { DiscordApplicationCommand } from "../../../types/discord.ts"; +import { EditGlobalApplicationCommand } from "./upsertApplicationCommand.ts"; +import { MakeRequired } from "../../../types/shared.ts"; /** * Bulk edit existing application commands. If a command does not exist, it will create it. @@ -15,7 +15,7 @@ export async function upsertApplicationCommands( options: MakeRequired[], guildId?: bigint, ) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "put", guildId diff --git a/helpers/interactions/followups/editFollowupMessage.ts b/helpers/interactions/followups/editFollowupMessage.ts index 7b4e5a43a..0c995f5a9 100644 --- a/helpers/interactions/followups/editFollowupMessage.ts +++ b/helpers/interactions/followups/editFollowupMessage.ts @@ -1,7 +1,7 @@ import { Bot } from "../../../bot.ts"; -import { MessageComponentTypes } from "../../../types/messages/components/messageComponentTypes.ts"; -import { Message } from "../../../types/messages/message.ts"; -import { EditWebhookMessage } from "../../../types/webhooks/editWebhookMessage.ts"; +import { DiscordMessage } from "../../../types/discord.ts"; +import { MessageComponentTypes } from "../../../types/shared.ts"; +import { EditWebhookMessage } from "../../webhooks/editWebhookMessage.ts"; /** Edits a followup message for an Interaction. Functions the same as edit webhook message, however this uses your interaction token instead of bot token. Does not support ephemeral followups. */ export async function editFollowupMessage( @@ -10,7 +10,7 @@ export async function editFollowupMessage( messageId: bigint, options: EditWebhookMessage, ) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), diff --git a/helpers/interactions/followups/getFollowupMessage.ts b/helpers/interactions/followups/getFollowupMessage.ts index 9c97d8516..937f7d1a2 100644 --- a/helpers/interactions/followups/getFollowupMessage.ts +++ b/helpers/interactions/followups/getFollowupMessage.ts @@ -1,9 +1,9 @@ import { Bot } from "../../../bot.ts"; -import { Message } from "../../../types/messages/message.ts"; +import { DiscordMessage } from "../../../types/discord.ts"; /** Returns a followup message for an Interaction. Functions the same as get webhook message, however this uses your interaction token instead of bot token. Does not support ephemeral followups. */ export async function getFollowupMessage(bot: Bot, interactionToken: string, messageId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), diff --git a/helpers/interactions/getOriginalInteractionResponse.ts b/helpers/interactions/getOriginalInteractionResponse.ts index 0c95fc891..e06f767b2 100644 --- a/helpers/interactions/getOriginalInteractionResponse.ts +++ b/helpers/interactions/getOriginalInteractionResponse.ts @@ -1,9 +1,9 @@ import type { Bot } from "../../bot.ts"; -import type { Message } from "../../types/messages/message.ts"; +import { DiscordMessage } from "../../types/discord.ts"; /** Returns the initial Interaction response. Functions the same as Get Webhook Message */ export async function getOriginalInteractionResponse(bot: Bot, token: string) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), diff --git a/helpers/interactions/sendInteractionResponse.ts b/helpers/interactions/sendInteractionResponse.ts index 0a2dcecbe..e37655cb6 100644 --- a/helpers/interactions/sendInteractionResponse.ts +++ b/helpers/interactions/sendInteractionResponse.ts @@ -1,7 +1,8 @@ -import type { DiscordenoInteractionResponse } from "../../types/discordeno/interactionResponse.ts"; import type { Bot } from "../../bot.ts"; -import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; -import { Message } from "../../types/messages/message.ts"; +import { Embed } from "../../mod.ts"; +import { DiscordMessage } from "../../types/discord.ts"; +import { AllowedMentions, FileContent, MessageComponents } from "../../types/discordeno.ts"; +import { InteractionResponseTypes, MessageComponentTypes } from "../../types/shared.ts"; /** * Send a response to a users application command. The command data will have the id and token necessary to respond. @@ -13,13 +14,8 @@ export async function sendInteractionResponse( bot: Bot, id: bigint, token: string, - options: DiscordenoInteractionResponse, + options: InteractionResponse, ) { - // If the user wants this as a private message mark it ephemeral - if (options.private) { - options.data = { ...options.data, flags: 64 }; - } - // If no mentions are provided, force disable mentions if (!options.data?.allowedMentions) { options.data = { ...options.data, allowedMentions: { parse: [] } }; @@ -160,7 +156,7 @@ export async function sendInteractionResponse( } // If its already been executed, we need to send a followup response - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.WEBHOOK(bot.applicationId, token), @@ -169,3 +165,43 @@ export async function sendInteractionResponse( return bot.transformers.message(bot, result); } + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */ +export interface InteractionResponse { + /** The type of response */ + type: InteractionResponseTypes; + /** An optional response message */ + data?: InteractionApplicationCommandCallbackData; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ +export interface InteractionApplicationCommandCallbackData { + /** The message contents (up to 2000 characters) */ + content?: string; + /** true if this is a TTS message */ + tts?: boolean; + /** Embedded `rich` content (up to 6000 characters) */ + embeds?: Embed[]; + /** Allowed mentions for the message */ + allowedMentions?: AllowedMentions; + /** The contents of the file being sent */ + file?: FileContent | FileContent[]; + /** The customId you want to use for this modal response. */ + customId?: string; + /** The title you want to use for this modal response. */ + title?: string; + /** The components you would like to have sent in this message */ + components?: MessageComponents; + /** message flags combined as a bitfield (only SUPPRESS_EMBEDS and EPHEMERAL can be set) */ + flags?: number; + /** autocomplete choices (max of 25 choices) */ + choices?: ApplicationCommandOptionChoice[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice */ +export interface ApplicationCommandOptionChoice { + /** 1-100 character choice name */ + name: string; + /** Value of the choice, up to 100 characters if string */ + value: string | number; +} diff --git a/helpers/invites/createInvite.ts b/helpers/invites/createInvite.ts index 1cf4a91be..fa85aff66 100644 --- a/helpers/invites/createInvite.ts +++ b/helpers/invites/createInvite.ts @@ -1,10 +1,10 @@ -import type { CreateChannelInvite } from "../../types/invites/createChannelInvite.ts"; import type { Bot } from "../../bot.ts"; -import { Invite } from "../../types/invites/invite.ts"; +import { DiscordInvite } from "../../types/discord.ts"; +import { InviteTargetTypes } from "../../types/shared.ts"; /** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */ export async function createInvite(bot: Bot, channelId: bigint, options: CreateChannelInvite = {}) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.CHANNEL_INVITES(channelId), @@ -34,3 +34,20 @@ export async function createInvite(bot: Bot, channelId: bigint, options: CreateC expiresAt: result.expires_at ? Date.parse(result.expires_at) : undefined, }; } + +export interface CreateChannelInvite { + /** Duration of invite in seconds before expiry, or 0 for never. Between 0 and 604800 (7 days). Default: 86400 (24 hours) */ + maxAge?: number; + /** Max number of users or 0 for unlimited. Between 0 and 100. Default: 0 */ + maxUses?: number; + /** Whether this invite only grants temporary membership. Default: false */ + temporary?: boolean; + /** If true, don't try to reuse simmilar invite (useful for creating many unique one time use invites). Default: false */ + unique?: boolean; + /** The type of target for this voice channel invite */ + targetType?: InviteTargetTypes; + /** The id of the user whose stream to display for this invite, required if `target_type` is 1, the user must be streaming in the channel */ + targetUserId?: string; + /** The id of the embedded application to open for this invite, required if `target_type` is 2, the application must have the `EMBEDDED` flag */ + targetApplicationId?: string; +} diff --git a/helpers/invites/deleteInvite.ts b/helpers/invites/deleteInvite.ts index 76d923a29..41ff820ae 100644 --- a/helpers/invites/deleteInvite.ts +++ b/helpers/invites/deleteInvite.ts @@ -1,7 +1,7 @@ -import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */ export async function deleteInvite(bot: Bot, inviteCode: string) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.INVITE(inviteCode)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.INVITE(inviteCode)); } diff --git a/helpers/invites/getChannelInvites.ts b/helpers/invites/getChannelInvites.ts index fc620be05..ba4c3e08e 100644 --- a/helpers/invites/getChannelInvites.ts +++ b/helpers/invites/getChannelInvites.ts @@ -1,10 +1,10 @@ -import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Gets the invites for this channel. Requires MANAGE_CHANNEL */ export async function getChannelInvites(bot: Bot, channelId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.CHANNEL_INVITES(channelId), diff --git a/helpers/invites/getInvite.ts b/helpers/invites/getInvite.ts index d1a092bc7..ac9711383 100644 --- a/helpers/invites/getInvite.ts +++ b/helpers/invites/getInvite.ts @@ -1,14 +1,18 @@ -import { GetInvite } from "../../types/invites/getInvite.ts"; -import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvite) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.INVITE(inviteCode), { - with_counts: options?.withCounts || false, - with_expiration: options?.withExpiration || false, - guild_scheduled_event_id: options?.scheduledEventId?.toString(), - }); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.INVITE(inviteCode), + { + with_counts: options?.withCounts || false, + with_expiration: options?.withExpiration || false, + guild_scheduled_event_id: options?.scheduledEventId?.toString(), + }, + ); return { code: result.code, @@ -25,3 +29,13 @@ export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvit expiresAt: result.expires_at ? Date.parse(result.expires_at) : undefined, }; } + +/** https://discord.com/developers/docs/resources/invite#get-invite */ +export interface GetInvite { + /** Whether the invite should contain approximate member counts */ + withCounts?: boolean; + /** Whether the invite should contain the expiration date */ + withExpiration?: boolean; + /** the guild scheduled event to include with the invite */ + scheduledEventId?: bigint; +} diff --git a/helpers/invites/getInvites.ts b/helpers/invites/getInvites.ts index 531b4036c..0c68f47b4 100644 --- a/helpers/invites/getInvites.ts +++ b/helpers/invites/getInvites.ts @@ -1,10 +1,10 @@ -import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ export async function getInvites(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_INVITES(guildId), diff --git a/helpers/members/avatarUrl.ts b/helpers/members/avatarUrl.ts index 3dd7518b8..2522b5ab6 100644 --- a/helpers/members/avatarUrl.ts +++ b/helpers/members/avatarUrl.ts @@ -1,5 +1,3 @@ -import type { ImageFormat } from "../../types/misc/imageFormat.ts"; -import type { ImageSize } from "../../types/misc/imageSize.ts"; import type { Bot } from "../../bot.ts"; /** The users custom avatar or the default avatar if you don't have a member object. */ @@ -24,3 +22,12 @@ export function avatarURL( ) : bot.constants.endpoints.USER_DEFAULT_AVATAR(Number(discriminator) % 5); } + +/** + * https://discord.com/developers/docs/reference#image-formatting + * json is only for stickers + */ +export type ImageFormat = "jpg" | "jpeg" | "png" | "webp" | "gif" | "json"; + +/** https://discord.com/developers/docs/reference#image-formatting */ +export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048; diff --git a/helpers/members/banMember.ts b/helpers/members/banMember.ts index ebb63a09e..8e06d5dc4 100644 --- a/helpers/members/banMember.ts +++ b/helpers/members/banMember.ts @@ -1,4 +1,3 @@ -import type { CreateGuildBan } from "../../types/guilds/createGuildBan.ts"; import type { Bot } from "../../bot.ts"; /** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */ @@ -15,3 +14,11 @@ export async function banMember(bot: Bot, guildId: bigint, id: bigint, options?: : {}, ); } + +/** https://discord.com/developers/docs/resources/guild#create-guild-ban */ +export interface CreateGuildBan { + /** Number of days to delete messages for (0-7) */ + deleteMessageDays?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; + /** Reason for the ban */ + reason?: string; +} diff --git a/helpers/members/editMember.ts b/helpers/members/editMember.ts index 93085a204..c4ff45db0 100644 --- a/helpers/members/editMember.ts +++ b/helpers/members/editMember.ts @@ -1,10 +1,9 @@ -import type { ModifyGuildMember } from "../../types/guilds/modifyGuildMember.ts"; -import type { GuildMemberWithUser } from "../../types/members/guildMember.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMemberWithUser } from "../../types/discord.ts"; /** Edit the member */ export async function editMember(bot: Bot, guildId: bigint, memberId: bigint, options: ModifyGuildMember) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.GUILD_MEMBER(guildId, memberId), @@ -22,3 +21,19 @@ export async function editMember(bot: Bot, guildId: bigint, memberId: bigint, op return bot.transformers.member(bot, result, guildId, memberId); } + +/** https://discord.com/developers/docs/resources/guild#modify-guild-member */ +export interface ModifyGuildMember { + /** Value to set users nickname to. Requires the `MANAGE_NICKNAMES` permission */ + nick?: string | null; + /** Array of role ids the member is assigned. Requires the `MANAGE_ROLES` permission */ + roles?: bigint[] | null; + /** Whether the user is muted in voice channels. Will throw a 400 if the user is not in a voice channel. Requires the `MUTE_MEMBERS` permission */ + mute?: boolean | null; + /** Whether the user is deafened in voice channels. Will throw a 400 if the user is not in a voice channel. Requires the `MOVE_MEMBERS` permission */ + deaf?: boolean | null; + /** Id of channel to move user to (if they are connected to voice). Requires the `MOVE_MEMBERS` permission */ + channelId?: bigint | null; + /** when the user's timeout will expire and the user will be able to communicate in the guild again (up to 28 days in the future), set to null to remove timeout. Requires the `MODERATE_MEMBERS` permission */ + communicationDisabledUntil?: number; +} diff --git a/helpers/members/fetchMembers.ts b/helpers/members/fetchMembers.ts index 9a71c34ed..0db10ff25 100644 --- a/helpers/members/fetchMembers.ts +++ b/helpers/members/fetchMembers.ts @@ -1,7 +1,5 @@ -import type { RequestGuildMembers } from "../../types/members/requestGuildMembers.ts"; import type { Bot } from "../../bot.ts"; -import { GatewayIntents } from "../../types/gateway/gatewayIntents.ts"; -import { GatewayOpcodes } from "../../types/codes/gatewayOpcodes.ts"; +import { GatewayIntents, GatewayOpcodes } from "../../types/shared.ts"; /** * Highly recommended to use this function to fetch members instead of getMember from REST. @@ -42,3 +40,19 @@ export function fetchMembers( }); }) as Promise; } + +/** https://discord.com/developers/docs/topics/gateway#request-guild-members */ +export interface RequestGuildMembers { + /** id of the guild to get members for */ + guildId: bigint; + /** String that username starts with, or an empty string to return all members */ + query?: string; + /** Maximum number of members to send matching the query; a limit of 0 can be used with an empty string query to return all members */ + limit: number; + /** Used to specify if we want the presences of the matched members */ + presences?: boolean; + /** Used to specify which users you wish to fetch */ + userIds?: bigint[]; + /** Nonce to identify the Guild Members Chunk response */ + nonce?: string; +} diff --git a/helpers/members/getDmChannel.ts b/helpers/members/getDmChannel.ts index 373121074..41fc8e2f6 100644 --- a/helpers/members/getDmChannel.ts +++ b/helpers/members/getDmChannel.ts @@ -1,11 +1,11 @@ -import type { Channel } from "../../types/channels/channel.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordChannel } from "../../types/discord.ts"; /** Get a user's dm channel. This is required in order to send a DM. */ export async function getDmChannel(bot: Bot, userId: bigint) { if (userId === bot.id) throw new Error(bot.constants.Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF); - const dmChannelData = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.USER_DM, { + const dmChannelData = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.USER_DM, { recipient_id: userId.toString(), }); diff --git a/helpers/members/getMember.ts b/helpers/members/getMember.ts index de3f7f893..8df9f8739 100644 --- a/helpers/members/getMember.ts +++ b/helpers/members/getMember.ts @@ -1,12 +1,9 @@ -import type { GuildMemberWithUser } from "../../types/members/guildMember.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMemberWithUser } from "../../types/discord.ts"; -/** Returns a guild member object for the specified user. - * - * ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.** - */ +/** Returns a guild member object for the specified user. */ export async function getMember(bot: Bot, guildId: bigint, id: bigint) { - const data = await bot.rest.runMethod( + const data = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_MEMBER(guildId, id), diff --git a/helpers/members/getMembers.ts b/helpers/members/getMembers.ts index 60059c625..967981ff6 100644 --- a/helpers/members/getMembers.ts +++ b/helpers/members/getMembers.ts @@ -1,6 +1,5 @@ -import type { GuildMemberWithUser } from "../../types/members/guildMember.ts"; -import type { ListGuildMembers } from "../../types/members/listGuildMembers.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMemberWithUser } from "../../types/discord.ts"; import { Collection } from "../../util/collection.ts"; /** @@ -8,14 +7,13 @@ import { Collection } from "../../util/collection.ts"; * REST(this function): 50/s global(across all shards) rate limit with ALL requests this included * GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m. */ -export async function getMembers(bot: Bot, guildId: bigint, options: ListGuildMembers & { memberCount: number }) { - const result = await bot.rest.runMethod( +export async function getMembers(bot: Bot, guildId: bigint, options: ListGuildMembers) { + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_MEMBERS(guildId), { - limit: options?.limit ?? options.memberCount, - after: options?.after, + limit: 1000, }, ); @@ -26,3 +24,11 @@ export async function getMembers(bot: Bot, guildId: bigint, options: ListGuildMe }), ); } + +/** https://discord.com/developers/docs/resources/guild#list-guild-members */ +export interface ListGuildMembers { + /** Max number of members to return (1-1000). Default: 1000 */ + limit?: number; + /** The highest user id in the previous page. Default: 0 */ + after?: string; +} diff --git a/helpers/members/pruneMembers.ts b/helpers/members/pruneMembers.ts index e10fcf036..4fc9d95f6 100644 --- a/helpers/members/pruneMembers.ts +++ b/helpers/members/pruneMembers.ts @@ -1,4 +1,3 @@ -import type { BeginGuildPrune } from "../../types/guilds/beginGuildPrune.ts"; import type { Bot } from "../../bot.ts"; /** @@ -23,3 +22,13 @@ export async function pruneMembers(bot: Bot, guildId: bigint, options: BeginGuil return result.pruned; } + +/** https://discord.com/developers/docs/resources/guild#begin-guild-prune */ +export interface BeginGuildPrune { + /** Number of days to prune (1 or more), default: 7 */ + days?: number; + /** Whether 'pruned' is returned, discouraged for large guilds, default: true */ + computePruneCount?: boolean; + /** Role(s) ro include, default: none */ + includeRoles?: string[]; +} diff --git a/helpers/messages/editMessage.ts b/helpers/messages/editMessage.ts index 076547304..28a7081fd 100644 --- a/helpers/messages/editMessage.ts +++ b/helpers/messages/editMessage.ts @@ -1,11 +1,13 @@ -import type { EditMessage } from "../../types/messages/editMessage.ts"; -import type { Message } from "../../types/messages/message.ts"; import type { Bot } from "../../bot.ts"; -import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; +import { Attachment } from "../../transformers/attachment.ts"; +import { Embed } from "../../transformers/embed.ts"; +import { DiscordMessage } from "../../types/discord.ts"; +import { AllowedMentions, FileContent, MessageComponents } from "../../types/discordeno.ts"; +import { MessageComponentTypes } from "../../types/shared.ts"; /** Edit the message. */ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint, content: EditMessage) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.CHANNEL_MESSAGE(channelId, messageId), @@ -137,3 +139,21 @@ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint return bot.transformers.message(bot, result); } + +/** https://discord.com/developers/docs/resources/channel#edit-message-json-params */ +export interface EditMessage { + /** The new message contents (up to 2000 characters) */ + content?: string | null; + /** Embedded `rich` content (up to 6000 characters) */ + embeds?: Embed[] | null; + /** Edit the flags of the message (only `SUPRESS_EMBEDS` can currently be set/unset) */ + flags?: 4 | null; + /** The contents of the file being sent/edited */ + file?: FileContent | FileContent[] | null; + /** Allowed mentions for the message */ + allowedMentions?: AllowedMentions; + /** When specified (adding new attachments), attachments which are not provided in this list will be removed. */ + attachments?: Attachment[]; + /** The components you would like to have sent in this message */ + components?: MessageComponents; +} diff --git a/helpers/messages/getMessage.ts b/helpers/messages/getMessage.ts index 4a2c20a88..55ed575c6 100644 --- a/helpers/messages/getMessage.ts +++ b/helpers/messages/getMessage.ts @@ -1,9 +1,9 @@ -import type { Message } from "../../types/messages/message.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMessage } from "../../types/discord.ts"; /** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */ export async function getMessage(bot: Bot, channelId: bigint, id: bigint) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.CHANNEL_MESSAGE(channelId, id), diff --git a/helpers/messages/getMessages.ts b/helpers/messages/getMessages.ts index c9c406604..bb22fc729 100644 --- a/helpers/messages/getMessages.ts +++ b/helpers/messages/getMessages.ts @@ -1,11 +1,5 @@ -import type { - GetMessagesAfter, - GetMessagesAround, - GetMessagesBefore, - GetMessagesLimit, -} from "../../types/messages/getMessages.ts"; -import type { Message } from "../../types/messages/message.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMessage } from "../../types/discord.ts"; /** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */ export async function getMessages( @@ -23,7 +17,7 @@ export async function getMessages( if (bot.utils.hasProperty(options, "after")) options.after = (options.after as bigint).toString(); } - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.CHANNEL_MESSAGES(channelId), @@ -32,3 +26,27 @@ export async function getMessages( return await Promise.all(result.map((res) => bot.transformers.message(bot, res))); } + +/** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ +export interface GetMessagesLimit { + /** Max number of messages to return (1-100) default 50 */ + limit?: number; +} + +/** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ +export interface GetMessagesAround extends GetMessagesLimit { + /** Get messages around this message id */ + around?: bigint; +} + +/** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ +export interface GetMessagesBefore extends GetMessagesLimit { + /** Get messages before this message id */ + before?: bigint; +} + +/** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ +export interface GetMessagesAfter extends GetMessagesLimit { + /** Get messages after this message id */ + after?: bigint; +} diff --git a/helpers/messages/getReactions.ts b/helpers/messages/getReactions.ts index 84a5f9964..8fb8a9c45 100644 --- a/helpers/messages/getReactions.ts +++ b/helpers/messages/getReactions.ts @@ -1,7 +1,6 @@ -import type { GetReactions } from "../../types/messages/messageGetReactions.ts"; -import type { User } from "../../types/users/user.ts"; import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordUser } from "../../types/discord.ts"; /** Get a list of users that reacted with this emoji. */ export async function getReactions( @@ -17,12 +16,23 @@ export async function getReactions( reaction = reaction.substring(3, reaction.length - 1); } - const users = await bot.rest.runMethod( + const users = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, encodeURIComponent(reaction)), options, ); - return new Collection(users.map((user) => [user.id, user])); + return new Collection(users.map((u) => { + const user = bot.transformers.user(bot, u); + return [user.id, user]; + })); +} + +/** https://discord.com/developers/docs/resources/channel#get-reactions-query-string-params */ +export interface GetReactions { + /** Get users after this user Id */ + after?: string; + /** Max number of users to return (1-100) */ + limit?: number; } diff --git a/helpers/messages/publishMessage.ts b/helpers/messages/publishMessage.ts index 2815f9fb6..296a1f629 100644 --- a/helpers/messages/publishMessage.ts +++ b/helpers/messages/publishMessage.ts @@ -1,9 +1,9 @@ -import type { Message } from "../../types/messages/message.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordMessage } from "../../types/discord.ts"; /** Crosspost a message in a News Channel to following channels. */ export async function publishMessage(bot: Bot, channelId: bigint, messageId: bigint) { - const data = await bot.rest.runMethod( + const data = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), diff --git a/helpers/messages/sendMessage.ts b/helpers/messages/sendMessage.ts index 2c4a4d9b4..c14c2bf4d 100644 --- a/helpers/messages/sendMessage.ts +++ b/helpers/messages/sendMessage.ts @@ -1,11 +1,12 @@ -import type { CreateMessage } from "../../types/messages/createMessage.ts"; -import type { Message } from "../../types/messages/message.ts"; import type { Bot } from "../../bot.ts"; -import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; +import { AllowedMentions, FileContent, MessageComponents } from "../../types/mod.ts"; +import { DiscordMessage } from "../../types/discord.ts"; +import { MessageComponentTypes } from "../../types/shared.ts"; +import { Embed } from "../../transformers/embed.ts"; /** Send a message to the channel. Requires SEND_MESSAGES permission. */ export async function sendMessage(bot: Bot, channelId: bigint, content: CreateMessage) { - const result = await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.CHANNEL_MESSAGES(channelId), @@ -140,3 +141,32 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: CreateMe return bot.transformers.message(bot, result); } + +export interface CreateMessage { + /** The message contents (up to 2000 characters) */ + content?: string; + /** true if this is a TTS message */ + tts?: boolean; + /** Embedded `rich` content (up to 6000 characters) */ + embeds?: Embed[]; + /** Allowed mentions for the message */ + allowedMentions?: AllowedMentions; + /** Include to make your message a reply */ + messageReference?: { + /** id of the originating message */ + messageId?: bigint; + /** + * id of the originating message's channel + * Note: `channel_id` is optional when creating a reply, but will always be present when receiving an event/response that includes this data model. + */ + channelId?: bigint; + /** id of the originating message's guild */ + guildId?: bigint; + /** When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true */ + failIfNotExists: boolean; + }; + /** The contents of the file being sent */ + file?: FileContent | FileContent[]; + /** The components you would like to have sent in this message */ + components?: MessageComponents; +} diff --git a/helpers/misc/editBotProfile.ts b/helpers/misc/editBotProfile.ts index 8b09158dd..17d4e8eb4 100644 --- a/helpers/misc/editBotProfile.ts +++ b/helpers/misc/editBotProfile.ts @@ -1,5 +1,5 @@ -import type { User } from "../../types/users/user.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordUser } from "../../types/discord.ts"; /** Modifies the bot's username or avatar. * NOTE: username: if changed may cause the bot's discriminator to be randomized. @@ -7,7 +7,7 @@ import type { Bot } from "../../bot.ts"; export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) { const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL; - const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.USER_BOT, { + const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.USER_BOT, { username: options.username?.trim(), avatar, }); diff --git a/helpers/misc/editBotStatus.ts b/helpers/misc/editBotStatus.ts index 715dd9003..82f940a77 100644 --- a/helpers/misc/editBotStatus.ts +++ b/helpers/misc/editBotStatus.ts @@ -1,8 +1,9 @@ import type { Bot } from "../../bot.ts"; -import { GatewayOpcodes } from "../../types/codes/gatewayOpcodes.ts"; -import type { StatusUpdate } from "../../types/gateway/statusUpdate.ts"; +import { Activity } from "../../transformers/activity.ts"; +import { StatusTypes } from "../../transformers/presence.ts"; +import { GatewayOpcodes } from "../../types/shared.ts"; -export function editBotStatus(bot: Bot, data: Omit) { +export function editBotStatus(bot: Bot, data: StatusUpdate) { bot.gateway.shards.forEach((shard) => { bot.events.debug(`Running forEach loop in editBotStatus function.`); @@ -16,13 +17,13 @@ export function editBotStatus(bot: Bot, data: Omit { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GATEWAY_BOT); +export async function getGatewayBot(bot: Bot) { + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GATEWAY_BOT); return bot.transformers.gatewayBot(result); } diff --git a/helpers/misc/getUser.ts b/helpers/misc/getUser.ts index 0db1bacd7..f8fb79c35 100644 --- a/helpers/misc/getUser.ts +++ b/helpers/misc/getUser.ts @@ -1,9 +1,9 @@ -import type { User } from "../../types/users/user.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordUser } from "../../types/discord.ts"; /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ export async function getUser(bot: Bot, userId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.USER(userId)); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.USER(userId)); return bot.transformers.user(bot, result); } diff --git a/helpers/oauth/getApplicationInfo.ts b/helpers/oauth/getApplicationInfo.ts index 31033edaf..5fc521a35 100644 --- a/helpers/oauth/getApplicationInfo.ts +++ b/helpers/oauth/getApplicationInfo.ts @@ -1,9 +1,13 @@ -import { Application } from "../../types/applications/application.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordApplication } from "../../types/discord.ts"; /** Get the applications info */ export async function getApplicationInfo(bot: Bot) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.OAUTH2_APPLICATION); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.OAUTH2_APPLICATION, + ); return bot.transformers.application(bot, result); } diff --git a/helpers/roles/createRole.ts b/helpers/roles/createRole.ts index 7bad10044..bf4fe7e30 100644 --- a/helpers/roles/createRole.ts +++ b/helpers/roles/createRole.ts @@ -1,10 +1,10 @@ -import type { CreateGuildRole } from "../../types/guilds/createGuildRole.ts"; -import type { Role } from "../../types/permissions/role.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordRole } from "../../types/discord.ts"; +import { PermissionStrings } from "../../types/shared.ts"; /** Create a new role for the guild. Requires the MANAGE_ROLES permission. */ export async function createRole(bot: Bot, guildId: bigint, options: CreateGuildRole, reason?: string) { - const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILD_ROLES(guildId), { + const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILD_ROLES(guildId), { name: options.name, color: options.color, hoist: options.hoist, @@ -13,10 +13,23 @@ export async function createRole(bot: Bot, guildId: bigint, options: CreateGuild reason, }); - const role = bot.transformers.role(bot, { + return bot.transformers.role(bot, { role: result, guildId, }); - - return role; +} + +export interface CreateGuildRole { + /** Name of the role, default: "new role" */ + name?: string; + /** Bitwise value of the enabled/disabled permissions, default: everyone permissions in guild */ + permissions?: PermissionStrings[]; + /** RGB color value, default: 0 */ + color?: number; + /** Whether the role should be displayed separately in the sidebar, default: false */ + hoist?: boolean; + /** Whether the role should be mentionable, default: false */ + mentionable?: boolean; + /** The role's unicode emoji (if the guild has the `ROLE_ICONS` feature) */ + unicodeEmoji?: string; } diff --git a/helpers/roles/editRole.ts b/helpers/roles/editRole.ts index c9163b6e7..e0dc84f45 100644 --- a/helpers/roles/editRole.ts +++ b/helpers/roles/editRole.ts @@ -1,16 +1,36 @@ -import type { CreateGuildRole } from "../../types/guilds/createGuildRole.ts"; -import type { Role } from "../../types/permissions/role.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordRole } from "../../types/discord.ts"; +import { PermissionStrings } from "../../types/shared.ts"; /** Edit a guild role. Requires the MANAGE_ROLES permission. */ -export async function editRole(bot: Bot, guildId: bigint, id: bigint, options: CreateGuildRole) { - const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.GUILD_ROLE(guildId, id), { - name: options.name, - color: options.color, - hoist: options.hoist, - mentionable: options.mentionable, - permissions: options.permissions ? bot.utils.calculateBits(options.permissions) : undefined, - }); +export async function editRole(bot: Bot, guildId: bigint, id: bigint, options: EditGuildRole) { + const result = await bot.rest.runMethod( + bot.rest, + "patch", + bot.constants.endpoints.GUILD_ROLE(guildId, id), + { + name: options.name, + color: options.color, + hoist: options.hoist, + mentionable: options.mentionable, + permissions: options.permissions ? bot.utils.calculateBits(options.permissions) : undefined, + }, + ); return bot.transformers.role(bot, { role: result, guildId }); } + +export interface EditGuildRole { + /** Name of the role, default: "new role" */ + name?: string; + /** Bitwise value of the enabled/disabled permissions, default: everyone permissions in guild */ + permissions?: PermissionStrings[]; + /** RGB color value, default: 0 */ + color?: number; + /** Whether the role should be displayed separately in the sidebar, default: false */ + hoist?: boolean; + /** Whether the role should be mentionable, default: false */ + mentionable?: boolean; + /** The role's unicode emoji (if the guild has the `ROLE_ICONS` feature) */ + unicodeEmoji?: string; +} diff --git a/helpers/roles/getRoles.ts b/helpers/roles/getRoles.ts index fe4c012f4..2b71cb8dd 100644 --- a/helpers/roles/getRoles.ts +++ b/helpers/roles/getRoles.ts @@ -1,16 +1,15 @@ -import type { Role } from "../../types/permissions/role.ts"; import type { Bot } from "../../bot.ts"; import { Collection } from "../../util/collection.ts"; -import { DiscordenoRole } from "../../transformers/role.ts"; +import { DiscordRole } from "../../types/discord.ts"; /** Returns a list of role objects for the guild. * * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your roles will be cached in your guild.** */ export async function getRoles(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_ROLES(guildId)); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_ROLES(guildId)); const roleStructures = result.map((role) => bot.transformers.role(bot, { role, guildId })); - return new Collection(roleStructures.map((role: DiscordenoRole) => [role.id, role])); + return new Collection(roleStructures.map((role) => [role.id, role])); } diff --git a/helpers/templates/createGuildFromTemplate.ts b/helpers/templates/createGuildFromTemplate.ts index 38ff536db..a3263637d 100644 --- a/helpers/templates/createGuildFromTemplate.ts +++ b/helpers/templates/createGuildFromTemplate.ts @@ -1,6 +1,5 @@ -import type { Guild } from "../../types/guilds/guild.ts"; -import type { CreateGuildFromTemplate } from "../../types/templates/createGuildFromTemplate.ts"; import type { Bot } from "../../bot.ts"; +import { DiscordGuild } from "../../types/discord.ts"; /** * Create a new guild based on a template @@ -11,7 +10,7 @@ export async function createGuildFromTemplate(bot: Bot, templateCode: string, da data.icon = await bot.utils.urlToBase64(data.icon); } - const createdGuild = await bot.rest.runMethod( + const createdGuild = await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.GUILD_TEMPLATE(templateCode), @@ -23,3 +22,11 @@ export async function createGuildFromTemplate(bot: Bot, templateCode: string, da shardId: bot.utils.calculateShardId(bot.gateway, bot.transformers.snowflake(createdGuild.id)), }); } + +/** https://discord.com/developers/docs/resources/template#create-guild-from-template-json-params */ +export interface CreateGuildFromTemplate { + /** Name of the guild (2-100 characters) */ + name: string; + /** base64 128x128 image for the guild icon */ + icon?: string; +} diff --git a/helpers/templates/createGuildTemplate.ts b/helpers/templates/createGuildTemplate.ts index b3b5a1fc2..21d04b091 100644 --- a/helpers/templates/createGuildTemplate.ts +++ b/helpers/templates/createGuildTemplate.ts @@ -1,13 +1,9 @@ -import type { Template } from "../../types/templates/template.ts"; import type { Bot } from "../../bot.ts"; +import { Guild } from "../../transformers/guild.ts"; +import { User } from "../../transformers/member.ts"; +import { DiscordTemplate } from "../../types/discord.ts"; -/** - * Creates a template for the guild. - * Requires the `MANAGE_GUILD` permission. - * @param bot - * @param guildId - * @param data - */ +/** Creates a template for the guild. Requires the `MANAGE_GUILD` permission. */ export async function createGuildTemplate(bot: Bot, guildId: bigint, data: Template) { if (data.name.length < 1 || data.name.length > 100) { throw new Error("The name can only be in between 1-100 characters."); @@ -17,7 +13,7 @@ export async function createGuildTemplate(bot: Bot, guildId: bigint, data: Templ throw new Error("The description can only be in between 0-120 characters."); } - return await bot.rest.runMethod