diff --git a/packages/bot/src/bot.ts b/packages/bot/src/bot.ts index f8610c345..afe558285 100644 --- a/packages/bot/src/bot.ts +++ b/packages/bot/src/bot.ts @@ -3,25 +3,27 @@ import { createGatewayManager, ShardSocketCloseCodes } from '@discordeno/gateway import type { CreateRestManagerOptions, RestManager } from '@discordeno/rest' import { createRestManager } from '@discordeno/rest' import type { DiscordEmoji, DiscordGatewayPayload, DiscordReady, GatewayIntents } from '@discordeno/types' -import { Collection, createLogger } from '@discordeno/utils' -import type { Transformers } from './transformer' -import type { AuditLogEntry } from './transformers/auditLogEntry' -import type { AutoModerationActionExecution } from './transformers/automodActionExecution' -import type { AutoModerationRule } from './transformers/automodRule' -import type { Channel } from './transformers/channel' -import type { Emoji } from './transformers/emoji' -import type { Guild } from './transformers/guild' -import type { Integration } from './transformers/integration' -import type { Interaction } from './transformers/interaction' -import type { Invite } from './transformers/invite' -import type { Member, User } from './transformers/member' -import type { Message } from './transformers/message' -import type { PresenceUpdate } from './transformers/presence' -import type { Role } from './transformers/role' -import type { ScheduledEvent } from './transformers/scheduledEvent' -import type { ThreadMember } from './transformers/threadMember' -import type { VoiceState } from './transformers/voiceState' -import type { bigintToSnowflake, snowflakeToBigint } from './utils.js' +import { createLogger, getBotIdFromToken, type Collection } from '@discordeno/utils' +import { createBotGatewayHandlers } from './handlers.js' +import { createTransformers, type Transformers } from './transformers.js' +import type { ApplicationCommandPermission } from './transformers/applicationCommandPermission.js' +import type { AuditLogEntry } from './transformers/auditLogEntry.js' +import type { AutoModerationActionExecution } from './transformers/automodActionExecution.js' +import type { AutoModerationRule } from './transformers/automodRule.js' +import type { Channel } from './transformers/channel.js' +import type { Emoji } from './transformers/emoji.js' +import type { Guild } from './transformers/guild.js' +import type { Integration } from './transformers/integration.js' +import type { Interaction } from './transformers/interaction.js' +import type { Invite } from './transformers/invite.js' +import type { Member, User } from './transformers/member.js' +import type { Message } from './transformers/message.js' +import type { PresenceUpdate } from './transformers/presence.js' +import type { Role } from './transformers/role.js' +import type { ScheduledEvent } from './transformers/scheduledEvent.js' +import type { Sticker } from './transformers/sticker.js' +import type { ThreadMember } from './transformers/threadMember.js' +import type { VoiceState } from './transformers/voiceState.js' /** * Create a bot object that will maintain the rest and gateway connection. @@ -53,7 +55,13 @@ export function createBot(options: CreateBotOptions): Bot { options.rest.token = options.token options.gateway.intents = options.intents + const id = getBotIdFromToken(options.token) + const bot: Bot = { + id, + applicationId: id, + transformers: createTransformers({}), + handlers: createBotGatewayHandlers({}), rest: createRestManager(options.rest), gateway: createGatewayManager(options.gateway), events: options.events ?? {}, @@ -88,7 +96,9 @@ export interface CreateBotOptions { } export interface Bot { + /** The id of the bot. */ id: bigint + /** The application id of the bot. This is usually the same as id but in the case of old bots can be different. */ applicationId: bigint /** The rest manager. */ rest: RestManager @@ -98,11 +108,10 @@ export interface Bot { events: Partial /** A logger utility to make it easy to log nice and useful things in the bot code. */ logger: ReturnType + /** The functions that should transform discord objects to discordeno shaped objects. */ transformers: Transformers - utils: { - snowflakeToBigint: typeof snowflakeToBigint - bigintToSnowflake: typeof bigintToSnowflake - } + /** The handler functions that should handle incoming discord payloads from gateway and call an event. */ + handlers: ReturnType /** Start the bot connection to the gateway. */ start: () => Promise /** Shuts down all the bot connections to the gateway. */ @@ -111,6 +120,7 @@ export interface Bot { export interface EventHandlers { debug: (text: string, ...args: any[]) => unknown + applicationCommandPermissionsUpdate: (command: ApplicationCommandPermission) => unknown auditLogEntryCreate: (log: AuditLogEntry, guildId: bigint) => unknown automodRuleCreate: (rule: AutoModerationRule) => unknown automodRuleUpdate: (rule: AutoModerationRule) => unknown @@ -149,6 +159,7 @@ export interface EventHandlers { guildMemberAdd: (member: Member, user: User) => unknown guildMemberRemove: (user: User, guildId: bigint) => unknown guildMemberUpdate: (member: Member, user: User) => unknown + guildStickersUpdate: (stickers: Sticker[]) => unknown messageCreate: (message: Message) => unknown messageDelete: (payload: { id: bigint; channelId: bigint; guildId?: bigint }, message?: Message) => unknown messageDeleteBulk: (payload: { ids: bigint[]; channelId: bigint; guildId?: bigint }) => unknown diff --git a/packages/bot/src/handler.ts b/packages/bot/src/handlers.ts similarity index 83% rename from packages/bot/src/handler.ts rename to packages/bot/src/handlers.ts index b5d09486c..e560250f2 100644 --- a/packages/bot/src/handler.ts +++ b/packages/bot/src/handlers.ts @@ -1,28 +1,20 @@ -import * as handlers from './handlers/mod.js' +import * as handlers from './handlers/index.js' import type { Bot, DiscordGatewayPayload, GatewayDispatchEventNames } from './index.js' -import type { BotGatewayHandlerOptions } from './types.js' +import type { BotGatewayHandlerOptions } from './typings.js' export function createBotGatewayHandlers( options: Partial, ): Record any> { return { - // misc - READY: options.READY ?? handlers.handleReady, - // channels + APPLICATION_COMMAND_PERMISSIONS_UPDATE: options.APPLICATION_COMMAND_PERMISSIONS_UPDATE ?? handlers.handleApplicationCommandPermissionsUpdate, + AUTO_MODERATION_ACTION_EXECUTION: options.AUTO_MODERATION_ACTION_EXECUTION ?? handlers.handleAutoModerationActionExecution, + AUTO_MODERATION_RULE_CREATE: options.AUTO_MODERATION_RULE_CREATE ?? handlers.handleAutoModerationRuleCreate, + AUTO_MODERATION_RULE_DELETE: options.AUTO_MODERATION_RULE_DELETE ?? handlers.handleAutoModerationRuleDelete, + AUTO_MODERATION_RULE_UPDATE: options.AUTO_MODERATION_RULE_UPDATE ?? handlers.handleAutoModerationRuleUpdate, CHANNEL_CREATE: options.CHANNEL_CREATE ?? handlers.handleChannelCreate, CHANNEL_DELETE: options.CHANNEL_DELETE ?? handlers.handleChannelDelete, 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_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate, - STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ?? handlers.handleStageInstanceCreate, - STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ?? handlers.handleStageInstanceUpdate, - STAGE_INSTANCE_DELETE: options.STAGE_INSTANCE_DELETE ?? handlers.handleStageInstanceDelete, - - // guilds GUILD_AUDIT_LOG_ENTRY_CREATE: options.GUILD_AUDIT_LOG_ENTRY_CREATE ?? handlers.handleGuildAuditLogEntryCreate, GUILD_BAN_ADD: options.GUILD_BAN_ADD ?? handlers.handleGuildBanAdd, GUILD_BAN_REMOVE: options.GUILD_BAN_REMOVE ?? handlers.handleGuildBanRemove, @@ -37,19 +29,19 @@ export function createBotGatewayHandlers( GUILD_ROLE_CREATE: options.GUILD_ROLE_CREATE ?? handlers.handleGuildRoleCreate, GUILD_ROLE_DELETE: options.GUILD_ROLE_DELETE ?? handlers.handleGuildRoleDelete, GUILD_ROLE_UPDATE: options.GUILD_ROLE_UPDATE ?? handlers.handleGuildRoleUpdate, - GUILD_UPDATE: options.GUILD_UPDATE ?? handlers.handleGuildUpdate, - // guild events GUILD_SCHEDULED_EVENT_CREATE: options.GUILD_SCHEDULED_EVENT_CREATE ?? handlers.handleGuildScheduledEventCreate, GUILD_SCHEDULED_EVENT_DELETE: options.GUILD_SCHEDULED_EVENT_DELETE ?? handlers.handleGuildScheduledEventDelete, GUILD_SCHEDULED_EVENT_UPDATE: options.GUILD_SCHEDULED_EVENT_UPDATE ?? handlers.handleGuildScheduledEventUpdate, GUILD_SCHEDULED_EVENT_USER_ADD: options.GUILD_SCHEDULED_EVENT_USER_ADD ?? handlers.handleGuildScheduledEventUserAdd, GUILD_SCHEDULED_EVENT_USER_REMOVE: options.GUILD_SCHEDULED_EVENT_USER_REMOVE ?? handlers.handleGuildScheduledEventUserRemove, - // interactions + GUILD_STICKERS_UPDATE: options.GUILD_STICKERS_UPDATE ?? handlers.handleGuildStickersUpdate, + GUILD_UPDATE: options.GUILD_UPDATE ?? handlers.handleGuildUpdate, INTERACTION_CREATE: options.INTERACTION_CREATE ?? handlers.handleInteractionCreate, - // invites + INTEGRATION_CREATE: options.INTEGRATION_CREATE ?? handlers.handleIntegrationCreate, + INTEGRATION_UPDATE: options.INTEGRATION_UPDATE ?? handlers.handleIntegrationUpdate, + INTEGRATION_DELETE: options.INTEGRATION_DELETE ?? handlers.handleIntegrationDelete, INVITE_CREATE: options.INVITE_CREATE ?? handlers.handleInviteCreate, INVITE_DELETE: options.INVITE_DELETE ?? handlers.handleInviteCreate, - // messages MESSAGE_CREATE: options.MESSAGE_CREATE ?? handlers.handleMessageCreate, MESSAGE_DELETE_BULK: options.MESSAGE_DELETE_BULK ?? handlers.handleMessageDeleteBulk, MESSAGE_DELETE: options.MESSAGE_DELETE ?? handlers.handleMessageDelete, @@ -58,18 +50,23 @@ export function createBotGatewayHandlers( MESSAGE_REACTION_REMOVE_EMOJI: options.MESSAGE_REACTION_REMOVE_EMOJI ?? handlers.handleMessageReactionRemoveEmoji, MESSAGE_REACTION_REMOVE: options.MESSAGE_REACTION_REMOVE ?? handlers.handleMessageReactionRemove, MESSAGE_UPDATE: options.MESSAGE_UPDATE ?? handlers.handleMessageUpdate, - // presence PRESENCE_UPDATE: options.PRESENCE_UPDATE ?? handlers.handlePresenceUpdate, + READY: options.READY ?? handlers.handleReady, + STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ?? handlers.handleStageInstanceCreate, + STAGE_INSTANCE_DELETE: options.STAGE_INSTANCE_DELETE ?? handlers.handleStageInstanceDelete, + STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ?? handlers.handleStageInstanceUpdate, + THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate, + THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete, + THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate, + THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync, + THREAD_MEMBER_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate, + THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate, TYPING_START: options.TYPING_START ?? handlers.handleTypingStart, USER_UPDATE: options.USER_UPDATE ?? handlers.handleUserUpdate, - // voice VOICE_SERVER_UPDATE: options.VOICE_SERVER_UPDATE ?? handlers.handleVoiceServerUpdate, VOICE_STATE_UPDATE: options.VOICE_STATE_UPDATE ?? handlers.handleVoiceStateUpdate, - // webhooks WEBHOOKS_UPDATE: options.WEBHOOKS_UPDATE ?? handlers.handleWebhooksUpdate, - // integrations - INTEGRATION_CREATE: options.INTEGRATION_CREATE ?? handlers.handleIntegrationCreate, - INTEGRATION_UPDATE: options.INTEGRATION_UPDATE ?? handlers.handleIntegrationUpdate, - INTEGRATION_DELETE: options.INTEGRATION_DELETE ?? handlers.handleIntegrationDelete, } } + +export interface GatewayHandlers extends ReturnType {} diff --git a/packages/bot/src/handlers/channels/CHANNEL_CREATE.ts b/packages/bot/src/handlers/channels/CHANNEL_CREATE.ts index 98209eaf7..f5f1dae00 100644 --- a/packages/bot/src/handlers/channels/CHANNEL_CREATE.ts +++ b/packages/bot/src/handlers/channels/CHANNEL_CREATE.ts @@ -1,7 +1,7 @@ -import type { DiscordChannel, DiscordenoShard, DiscordGatewayPayload } from '@discordeno/bot' +import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/bot' import type { Bot } from '../../index.js' -export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload, shard: DiscordenoShard) { +export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload, shardId: number): Promise { const channel = bot.transformers.channel(bot, { channel: payload.d as DiscordChannel, }) diff --git a/packages/bot/src/handlers/channels/CHANNEL_DELETE.ts b/packages/bot/src/handlers/channels/CHANNEL_DELETE.ts index 4d0e1ccf5..44c8480b5 100644 --- a/packages/bot/src/handlers/channels/CHANNEL_DELETE.ts +++ b/packages/bot/src/handlers/channels/CHANNEL_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordChannel if (!payload.guild_id) return diff --git a/packages/bot/src/handlers/channels/CHANNEL_PINS_UPDATE.ts b/packages/bot/src/handlers/channels/CHANNEL_PINS_UPDATE.ts index 2e95f8524..ff58a1624 100644 --- a/packages/bot/src/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/packages/bot/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordChannelPinsUpdate, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordChannelPinsUpdate bot.events.channelPinsUpdate?.({ diff --git a/packages/bot/src/handlers/channels/CHANNEL_UPDATE.ts b/packages/bot/src/handlers/channels/CHANNEL_UPDATE.ts index e95c0b16f..45ef20a43 100644 --- a/packages/bot/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/packages/bot/src/handlers/channels/CHANNEL_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordChannel const channel = bot.transformers.channel(bot, { channel: payload }) diff --git a/packages/bot/src/handlers/channels/STAGE_INSTANCE_CREATE.ts b/packages/bot/src/handlers/channels/STAGE_INSTANCE_CREATE.ts index 3f9504498..3f211abb0 100644 --- a/packages/bot/src/handlers/channels/STAGE_INSTANCE_CREATE.ts +++ b/packages/bot/src/handlers/channels/STAGE_INSTANCE_CREATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordStageInstance } from '@discordeno/types' import type { Bot } from '../../bot.js' -export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordStageInstance bot.events.stageInstanceCreate?.({ diff --git a/packages/bot/src/handlers/channels/STAGE_INSTANCE_DELETE.ts b/packages/bot/src/handlers/channels/STAGE_INSTANCE_DELETE.ts index 70081696e..4be5f6633 100644 --- a/packages/bot/src/handlers/channels/STAGE_INSTANCE_DELETE.ts +++ b/packages/bot/src/handlers/channels/STAGE_INSTANCE_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordStageInstance } from '@discordeno/types' import type { Bot } from '../../bot.js' -export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordStageInstance bot.events.stageInstanceDelete?.({ diff --git a/packages/bot/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts b/packages/bot/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts index 9dff85a98..145be387c 100644 --- a/packages/bot/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts +++ b/packages/bot/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordStageInstance } from '@discordeno/types' import type { Bot } from '../../bot.js' -export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordStageInstance bot.events.stageInstanceUpdate?.({ diff --git a/packages/bot/src/handlers/channels/THREAD_CREATE.ts b/packages/bot/src/handlers/channels/THREAD_CREATE.ts index 7833fe923..fe6a94d2b 100644 --- a/packages/bot/src/handlers/channels/THREAD_CREATE.ts +++ b/packages/bot/src/handlers/channels/THREAD_CREATE.ts @@ -1,7 +1,7 @@ import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordChannel bot.events.threadCreate?.(bot.transformers.channel(bot, { channel: payload })) diff --git a/packages/bot/src/handlers/channels/THREAD_DELETE.ts b/packages/bot/src/handlers/channels/THREAD_DELETE.ts index 3c74ee586..d8fcfb58a 100644 --- a/packages/bot/src/handlers/channels/THREAD_DELETE.ts +++ b/packages/bot/src/handlers/channels/THREAD_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordChannel bot.events.threadDelete?.(bot.transformers.channel(bot, { channel: payload })) diff --git a/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts b/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts index 7dafb77ee..fb5845cdd 100644 --- a/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts +++ b/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordThreadListSync } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) { +export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordThreadListSync const guildId = bot.transformers.snowflake(payload.guild_id) diff --git a/packages/bot/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts b/packages/bot/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts index ab382c42f..d767ac0b0 100644 --- a/packages/bot/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts +++ b/packages/bot/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordThreadMembersUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordThreadMembersUpdate bot.events.threadMembersUpdate?.({ diff --git a/packages/bot/src/handlers/channels/THREAD_MEMBER_UPDATE.ts b/packages/bot/src/handlers/channels/THREAD_MEMBER_UPDATE.ts index 45ab4b9dd..867dfebbe 100644 --- a/packages/bot/src/handlers/channels/THREAD_MEMBER_UPDATE.ts +++ b/packages/bot/src/handlers/channels/THREAD_MEMBER_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordThreadMemberUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordThreadMemberUpdate bot.events.threadMemberUpdate?.({ diff --git a/packages/bot/src/handlers/channels/THREAD_UPDATE.ts b/packages/bot/src/handlers/channels/THREAD_UPDATE.ts index 0d73d8ae6..1825d09df 100644 --- a/packages/bot/src/handlers/channels/THREAD_UPDATE.ts +++ b/packages/bot/src/handlers/channels/THREAD_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordChannel bot.events.threadUpdate?.(bot.transformers.channel(bot, { channel: payload })) diff --git a/packages/bot/src/handlers/channels/mod.ts b/packages/bot/src/handlers/channels/index.ts similarity index 100% rename from packages/bot/src/handlers/channels/mod.ts rename to packages/bot/src/handlers/channels/index.ts diff --git a/packages/bot/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/packages/bot/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index 30c233409..3f83dc8eb 100644 --- a/packages/bot/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/packages/bot/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -1,8 +1,8 @@ import type { DiscordGatewayPayload, DiscordGuildEmojisUpdate } from '@discordeno/types' +import { Collection } from '@discordeno/utils' import type { Bot } from '../../bot.js' -import type { Collection } from '../../util/collection.js' -export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildEmojisUpdate bot.events.guildEmojisUpdate?.({ diff --git a/packages/bot/src/handlers/emojis/mod.ts b/packages/bot/src/handlers/emojis/index.ts similarity index 100% rename from packages/bot/src/handlers/emojis/mod.ts rename to packages/bot/src/handlers/emojis/index.ts diff --git a/packages/bot/src/handlers/guilds/GUILD_AUDIT_LOG_ENTRY_CREATE.ts b/packages/bot/src/handlers/guilds/GUILD_AUDIT_LOG_ENTRY_CREATE.ts index b4dc645eb..7e39e3420 100644 --- a/packages/bot/src/handlers/guilds/GUILD_AUDIT_LOG_ENTRY_CREATE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_AUDIT_LOG_ENTRY_CREATE.ts @@ -1,7 +1,7 @@ import type { DiscordAuditLogEntry, DiscordGatewayPayload } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleGuildAuditLogEntryCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildAuditLogEntryCreate(bot: Bot, data: DiscordGatewayPayload): Promise { // TODO: better type here const payload = data.d as DiscordAuditLogEntry & { guild_id: string } bot.events.auditLogEntryCreate?.(bot.transformers.auditLogEntry(bot, payload), bot.transformers.snowflake(payload.guild_id)) diff --git a/packages/bot/src/handlers/guilds/GUILD_BAN_ADD.ts b/packages/bot/src/handlers/guilds/GUILD_BAN_ADD.ts index 95981e14a..ab4f34f3a 100644 --- a/packages/bot/src/handlers/guilds/GUILD_BAN_ADD.ts +++ b/packages/bot/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildBanAddRemove } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildBanAddRemove bot.events.guildBanAdd?.(bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id)) } diff --git a/packages/bot/src/handlers/guilds/GUILD_BAN_REMOVE.ts b/packages/bot/src/handlers/guilds/GUILD_BAN_REMOVE.ts index ab3539c75..44be39509 100644 --- a/packages/bot/src/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildBanAddRemove } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildBanAddRemove await bot.events.guildBanRemove?.(bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id)) diff --git a/packages/bot/src/handlers/guilds/GUILD_CREATE.ts b/packages/bot/src/handlers/guilds/GUILD_CREATE.ts index 64a5f2066..dd53bc2ff 100644 --- a/packages/bot/src/handlers/guilds/GUILD_CREATE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_CREATE.ts @@ -1,8 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuild } from '@discordeno/types' import type { Bot } from '../../bot.js' -import type { Guild } from '../../transformers/guild.js' -export function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordGuild - bot.events.guildCreate?.(bot.transformers.guild(bot, { guild: payload, shardId }) as Guild) + bot.events.guildCreate?.(bot.transformers.guild(bot, { guild: payload, shardId })) } diff --git a/packages/bot/src/handlers/guilds/GUILD_DELETE.ts b/packages/bot/src/handlers/guilds/GUILD_DELETE.ts index e90bdc6b8..3db895c0a 100644 --- a/packages/bot/src/handlers/guilds/GUILD_DELETE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordUnavailableGuild } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordUnavailableGuild bot.events.guildDelete?.(bot.transformers.snowflake(payload.id), shardId) } diff --git a/packages/bot/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/packages/bot/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index e18113b67..9832a747e 100644 --- a/packages/bot/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildIntegrationsUpdate } from '@discordeno/types' import type { Bot } from '../../bot.js' -export async function handleGuildIntegrationsUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildIntegrationsUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildIntegrationsUpdate bot.events.integrationUpdate?.({ diff --git a/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts b/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts new file mode 100644 index 000000000..6cbd16b3c --- /dev/null +++ b/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts @@ -0,0 +1,12 @@ +import type { Bot, DiscordGatewayPayload, DiscordGuildStickersUpdate } from '../..' + +export async function handleGuildStickersUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { + const payload = data.d as DiscordGuildStickersUpdate + + bot.events.guildStickersUpdate?.( + payload.stickers.map((sticker) => { + sticker.guild_id = payload.guild_id + return bot.transformers.sticker(bot, sticker) + }) + ) +} diff --git a/packages/bot/src/handlers/guilds/GUILD_UPDATE.ts b/packages/bot/src/handlers/guilds/GUILD_UPDATE.ts index a9ba8853b..ecfab428c 100644 --- a/packages/bot/src/handlers/guilds/GUILD_UPDATE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_UPDATE.ts @@ -1,9 +1,8 @@ import type { DiscordGatewayPayload, DiscordGuild } from '@discordeno/types' import type { Bot } from '../../bot.js' -import type { Guild } from '../../transformers/guild.js' -export function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordGuild - bot.events.guildUpdate?.(bot.transformers.guild(bot, { guild: payload, shardId }) as Guild) + bot.events.guildUpdate?.(bot.transformers.guild(bot, { guild: payload, shardId })) } diff --git a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_ACTION_EXECUTION.ts b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_ACTION_EXECUTION.ts index dfdc8acd4..75b30d952 100644 --- a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_ACTION_EXECUTION.ts +++ b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_ACTION_EXECUTION.ts @@ -2,7 +2,7 @@ import type { DiscordAutoModerationActionExecution, DiscordGatewayPayload } from import type { Bot } from '../../../bot.js' /** Requires the MANAGE_GUILD permission. */ -export function handleAutoModerationActionExecution(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleAutoModerationActionExecution(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordAutoModerationActionExecution - bot.events.automodActionExecution?.(bot.events.automodActionExecution(payload)) + bot.events.automodActionExecution?.(bot.transformers.automodActionExecution(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_CREATE.ts b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_CREATE.ts index cb94337d5..7685b4986 100644 --- a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_CREATE.ts +++ b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_CREATE.ts @@ -2,7 +2,7 @@ import type { DiscordAutoModerationRule, DiscordGatewayPayload } from '@discorde import type { Bot } from '../../../bot.js' /** Requires the MANAGE_GUILD permission. */ -export function handleAutoModerationRuleCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleAutoModerationRuleCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordAutoModerationRule - bot.events.automodRuleCreate?.(bot.events.automodRule(payload)) + bot.events.automodRuleCreate?.(bot.transformers.automodRule(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_DELETE.ts b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_DELETE.ts index cc9319550..2980b11b6 100644 --- a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_DELETE.ts +++ b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_DELETE.ts @@ -2,7 +2,7 @@ import type { DiscordAutoModerationRule, DiscordGatewayPayload } from '@discorde import type { Bot } from '../../../bot.js' /** Requires the MANAGE_GUILD permission. */ -export function handleAutoModerationRuleDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleAutoModerationRuleDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordAutoModerationRule - bot.events.automodRuleDelete?.(bot.events.automodRule(payload)) + bot.events.automodRuleDelete?.(bot.transformers.automodRule(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_UPDATE.ts b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_UPDATE.ts index 63f3f7e46..be7793ac6 100644 --- a/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_UPDATE.ts +++ b/packages/bot/src/handlers/guilds/automod/AUTO_MODERATION_RULE_UPDATE.ts @@ -2,7 +2,7 @@ import type { DiscordAutoModerationRule, DiscordGatewayPayload } from '@discorde import type { Bot } from '../../../bot.js' /** Requires the MANAGE_GUILD permission. */ -export function handleAutoModerationRuleUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleAutoModerationRuleUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordAutoModerationRule bot.events.automodRuleUpdate?.(bot.transformers.automodRule(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/automod/index.ts b/packages/bot/src/handlers/guilds/automod/index.ts new file mode 100644 index 000000000..c47db435f --- /dev/null +++ b/packages/bot/src/handlers/guilds/automod/index.ts @@ -0,0 +1,4 @@ +export * from './AUTO_MODERATION_ACTION_EXECUTION.js' +export * from './AUTO_MODERATION_RULE_CREATE.js' +export * from './AUTO_MODERATION_RULE_DELETE.js' +export * from './AUTO_MODERATION_RULE_UPDATE.js' diff --git a/packages/bot/src/handlers/guilds/automod/mod.ts b/packages/bot/src/handlers/guilds/automod/mod.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/bot/src/handlers/guilds/mod.ts b/packages/bot/src/handlers/guilds/index.ts similarity index 69% rename from packages/bot/src/handlers/guilds/mod.ts rename to packages/bot/src/handlers/guilds/index.ts index 29e68bfa6..ad793cefd 100644 --- a/packages/bot/src/handlers/guilds/mod.ts +++ b/packages/bot/src/handlers/guilds/index.ts @@ -1,4 +1,5 @@ -export * from "./scheduledEvents/mod.js"; +export * from "./automod/index.js"; +export * from "./scheduledEvents/index.js"; export * from "./GUILD_AUDIT_LOG_ENTRY_CREATE.js"; export * from "./GUILD_BAN_ADD.js"; @@ -6,4 +7,5 @@ export * from "./GUILD_BAN_REMOVE.js"; export * from "./GUILD_CREATE.js"; export * from "./GUILD_DELETE.js"; export * from "./GUILD_INTEGRATIONS_UPDATE.js"; +export * from "./GUILD_STICKERS_UPDATE.js"; export * from "./GUILD_UPDATE.js"; diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts index 84812cb6d..b071779f3 100644 --- a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts +++ b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_CREATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordScheduledEvent } from '@discordeno/types' import type { Bot } from '../../../bot.js' -export function handleGuildScheduledEventCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleGuildScheduledEventCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordScheduledEvent bot.events.scheduledEventCreate?.(bot.transformers.scheduledEvent(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts index 247e5063f..b056808cd 100644 --- a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts +++ b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordScheduledEvent } from '@discordeno/types' import type { Bot } from '../../../bot.js' -export function handleGuildScheduledEventDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildScheduledEventDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordScheduledEvent bot.events.scheduledEventDelete?.(bot.transformers.scheduledEvent(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts index 2c87cc8e0..e60e2137d 100644 --- a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts +++ b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordScheduledEvent } from '@discordeno/types' import type { Bot } from '../../../bot.js' -export function handleGuildScheduledEventUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildScheduledEventUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordScheduledEvent bot.events.scheduledEventUpdate?.(bot.transformers.scheduledEvent(bot, payload)) } diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts index d73cfb2e5..6e2a9839c 100644 --- a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts +++ b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_ADD.ts @@ -1,10 +1,10 @@ import type { DiscordGatewayPayload, DiscordScheduledEventUserAdd } from '@discordeno/types' import type { Bot } from '../../../bot.js' -export function handleGuildScheduledEventUserAdd(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildScheduledEventUserAdd(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordScheduledEventUserAdd - return bot.events.scheduledEventUserAdd?.({ + bot.events.scheduledEventUserAdd?.({ guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id), userId: bot.transformers.snowflake(payload.user_id), guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts index fe11c0662..b4643c410 100644 --- a/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +++ b/packages/bot/src/handlers/guilds/scheduledEvents/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts @@ -1,10 +1,10 @@ import type { DiscordGatewayPayload, DiscordScheduledEventUserRemove } from '@discordeno/types' import type { Bot } from '../../../bot.js' -export function handleGuildScheduledEventUserRemove(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildScheduledEventUserRemove(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordScheduledEventUserRemove - return bot.events.scheduledEventUserRemove?.({ + bot.events.scheduledEventUserRemove?.({ guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id), userId: bot.transformers.snowflake(payload.user_id), guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/mod.ts b/packages/bot/src/handlers/guilds/scheduledEvents/index.ts similarity index 100% rename from packages/bot/src/handlers/guilds/scheduledEvents/mod.ts rename to packages/bot/src/handlers/guilds/scheduledEvents/index.ts diff --git a/packages/bot/src/handlers/index.ts b/packages/bot/src/handlers/index.ts new file mode 100644 index 000000000..243289d18 --- /dev/null +++ b/packages/bot/src/handlers/index.ts @@ -0,0 +1,12 @@ +export * from './channels/index.js' +export * from './emojis/index.js' +export * from './guilds/index.js' +export * from './integrations/index.js' +export * from './interactions/index.js' +export * from './invites/index.js' +export * from './members/index.js' +export * from './messages/index.js' +export * from './misc/index.js' +export * from './roles/index.js' +export * from './voice/index.js' +export * from './webhooks/index.js' diff --git a/packages/bot/src/handlers/integrations/INTEGRATION_CREATE.ts b/packages/bot/src/handlers/integrations/INTEGRATION_CREATE.ts index afe6f51bf..0bf883a9a 100644 --- a/packages/bot/src/handlers/integrations/INTEGRATION_CREATE.ts +++ b/packages/bot/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -1,6 +1,6 @@ import type { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleIntegrationCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleIntegrationCreate(bot: Bot, data: DiscordGatewayPayload): Promise { bot.events.integrationCreate?.(bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate)) } diff --git a/packages/bot/src/handlers/integrations/INTEGRATION_DELETE.ts b/packages/bot/src/handlers/integrations/INTEGRATION_DELETE.ts index e43bd1534..e7ae3f909 100644 --- a/packages/bot/src/handlers/integrations/INTEGRATION_DELETE.ts +++ b/packages/bot/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordIntegrationDelete } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleIntegrationDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleIntegrationDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordIntegrationDelete bot.events.integrationDelete?.({ diff --git a/packages/bot/src/handlers/integrations/INTEGRATION_UPDATE.ts b/packages/bot/src/handlers/integrations/INTEGRATION_UPDATE.ts index 4a339b90c..7c07dfb77 100644 --- a/packages/bot/src/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/packages/bot/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -1,6 +1,6 @@ import type { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleIntegrationUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleIntegrationUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { bot.events.integrationUpdate?.(bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate)) } diff --git a/packages/bot/src/handlers/integrations/mod.ts b/packages/bot/src/handlers/integrations/index.ts similarity index 100% rename from packages/bot/src/handlers/integrations/mod.ts rename to packages/bot/src/handlers/integrations/index.ts diff --git a/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts b/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts new file mode 100644 index 000000000..31bb21f60 --- /dev/null +++ b/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts @@ -0,0 +1,6 @@ +import type { Bot, DiscordGatewayPayload, DiscordGuildApplicationCommandPermissions } from "../.."; + +export async function handleApplicationCommandPermissionsUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { + const payload = data.d as DiscordGuildApplicationCommandPermissions + bot.events.applicationCommandPermissionsUpdate?.(bot.transformers.applicationCommandPermission(bot, payload)) +} \ No newline at end of file diff --git a/packages/bot/src/handlers/interactions/INTERACTION_CREATE.ts b/packages/bot/src/handlers/interactions/INTERACTION_CREATE.ts index aea7d719d..aa62d785d 100644 --- a/packages/bot/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/packages/bot/src/handlers/interactions/INTERACTION_CREATE.ts @@ -1,6 +1,6 @@ import type { DiscordGatewayPayload, DiscordInteraction } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload): Promise { bot.events.interactionCreate?.(bot.transformers.interaction(bot, data.d as DiscordInteraction)) } diff --git a/packages/bot/src/handlers/interactions/index.ts b/packages/bot/src/handlers/interactions/index.ts new file mode 100644 index 000000000..224d68b0e --- /dev/null +++ b/packages/bot/src/handlers/interactions/index.ts @@ -0,0 +1,2 @@ +export * from './APPLICATION_COMMAND_PERMISSIONS_UPDATE.js' +export * from './INTERACTION_CREATE.js' diff --git a/packages/bot/src/handlers/interactions/mod.ts b/packages/bot/src/handlers/interactions/mod.ts deleted file mode 100644 index b4de5f934..000000000 --- a/packages/bot/src/handlers/interactions/mod.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./INTERACTION_CREATE.js"; diff --git a/packages/bot/src/handlers/invites/INVITE_CREATE.ts b/packages/bot/src/handlers/invites/INVITE_CREATE.ts index 89473a63d..aa9077e88 100644 --- a/packages/bot/src/handlers/invites/INVITE_CREATE.ts +++ b/packages/bot/src/handlers/invites/INVITE_CREATE.ts @@ -1,6 +1,6 @@ import type { DiscordGatewayPayload, DiscordInviteCreate } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload): Promise { bot.events.inviteCreate?.(bot.transformers.invite(bot, data.d as DiscordInviteCreate)) } diff --git a/packages/bot/src/handlers/invites/INVITE_DELETE.ts b/packages/bot/src/handlers/invites/INVITE_DELETE.ts index e77f064bc..6fdc70945 100644 --- a/packages/bot/src/handlers/invites/INVITE_DELETE.ts +++ b/packages/bot/src/handlers/invites/INVITE_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordInviteDelete } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordInviteDelete bot.events.inviteDelete?.({ diff --git a/packages/bot/src/handlers/invites/mod.ts b/packages/bot/src/handlers/invites/index.ts similarity index 100% rename from packages/bot/src/handlers/invites/mod.ts rename to packages/bot/src/handlers/invites/index.ts diff --git a/packages/bot/src/handlers/members/GUILD_MEMBERS_CHUNK.ts b/packages/bot/src/handlers/members/GUILD_MEMBERS_CHUNK.ts index ef28ebe57..11ad62143 100644 --- a/packages/bot/src/handlers/members/GUILD_MEMBERS_CHUNK.ts +++ b/packages/bot/src/handlers/members/GUILD_MEMBERS_CHUNK.ts @@ -2,7 +2,7 @@ import type { DiscordGatewayPayload, DiscordGuildMembersChunk } from '@discorden import { PresenceStatus } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildMembersChunk const guildId = bot.transformers.snowflake(payload.guild_id) diff --git a/packages/bot/src/handlers/members/GUILD_MEMBER_ADD.ts b/packages/bot/src/handlers/members/GUILD_MEMBER_ADD.ts index 2e592fc6b..dfe8bd898 100644 --- a/packages/bot/src/handlers/members/GUILD_MEMBER_ADD.ts +++ b/packages/bot/src/handlers/members/GUILD_MEMBER_ADD.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildMemberAdd } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildMemberAdd const guildId = bot.transformers.snowflake(payload.guild_id) const user = bot.transformers.user(bot, payload.user) diff --git a/packages/bot/src/handlers/members/GUILD_MEMBER_REMOVE.ts b/packages/bot/src/handlers/members/GUILD_MEMBER_REMOVE.ts index 38d2e07da..6bcd65049 100644 --- a/packages/bot/src/handlers/members/GUILD_MEMBER_REMOVE.ts +++ b/packages/bot/src/handlers/members/GUILD_MEMBER_REMOVE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildMemberRemove } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload): Promise { 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/packages/bot/src/handlers/members/GUILD_MEMBER_UPDATE.ts b/packages/bot/src/handlers/members/GUILD_MEMBER_UPDATE.ts index 77251f50a..33dc5e540 100644 --- a/packages/bot/src/handlers/members/GUILD_MEMBER_UPDATE.ts +++ b/packages/bot/src/handlers/members/GUILD_MEMBER_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildMemberUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildMemberUpdate const user = bot.transformers.user(bot, payload.user) diff --git a/packages/bot/src/handlers/members/mod.ts b/packages/bot/src/handlers/members/index.ts similarity index 100% rename from packages/bot/src/handlers/members/mod.ts rename to packages/bot/src/handlers/members/index.ts diff --git a/packages/bot/src/handlers/messages/MESSAGE_CREATE.ts b/packages/bot/src/handlers/messages/MESSAGE_CREATE.ts index ded09d135..c0d6cca82 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_CREATE.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_CREATE.ts @@ -1,8 +1,8 @@ import type { DiscordGatewayPayload, DiscordMessage } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageCreate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessage - bot.events.messageCreate?.(bot.events.message(payload)) + bot.events.messageCreate?.(bot.transformers.message(bot, payload)) } diff --git a/packages/bot/src/handlers/messages/MESSAGE_DELETE.ts b/packages/bot/src/handlers/messages/MESSAGE_DELETE.ts index 1b3eb3b4c..ca37a91f7 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_DELETE.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessageDelete } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessageDelete bot.events.messageDelete?.({ diff --git a/packages/bot/src/handlers/messages/MESSAGE_DELETE_BULK.ts b/packages/bot/src/handlers/messages/MESSAGE_DELETE_BULK.ts index 1d75d239d..9f1e2e2d1 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_DELETE_BULK.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_DELETE_BULK.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessageDeleteBulk } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessageDeleteBulk const channelId = bot.transformers.snowflake(payload.channel_id) @@ -9,7 +9,7 @@ export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayl bot.events.messageDeleteBulk?.({ ids: payload.ids.map((id) => bot.transformers.snowflake(id)), - channelId: bot.transformers.snowflake(payload.channel_id), - guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined, + channelId, + guildId, }) } diff --git a/packages/bot/src/handlers/messages/MESSAGE_REACTION_ADD.ts b/packages/bot/src/handlers/messages/MESSAGE_REACTION_ADD.ts index 930d91097..871cad09f 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessageReactionAdd } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessageReactionAdd const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined @@ -13,6 +13,6 @@ export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPay guildId, member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined, user: payload.member ? bot.transformers.user(bot, payload.member.user) : undefined, - emoji: bot.events.emoji(payload.emoji), + emoji: bot.transformers.emoji(bot, payload.emoji), }) } diff --git a/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts b/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts index 81645bf7c..a4264269c 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessageReactionRemove } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageReactionRemove(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageReactionRemove(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessageReactionRemove bot.events.reactionRemove?.({ diff --git a/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts b/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts index 24e57cc95..f57a41d81 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessageReactionRemoveAll } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageReactionRemoveAll(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageReactionRemoveAll(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessageReactionRemoveAll bot.events.reactionRemoveAll?.({ diff --git a/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts b/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts index 8c8dacdca..a10502cf3 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessageReactionRemoveEmoji } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageReactionRemoveEmoji(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageReactionRemoveEmoji(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessageReactionRemoveEmoji bot.events.reactionRemoveEmoji?.({ diff --git a/packages/bot/src/handlers/messages/MESSAGE_UPDATE.ts b/packages/bot/src/handlers/messages/MESSAGE_UPDATE.ts index 8076aa2be..2af0246bc 100644 --- a/packages/bot/src/handlers/messages/MESSAGE_UPDATE.ts +++ b/packages/bot/src/handlers/messages/MESSAGE_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordMessage } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleMessageUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleMessageUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordMessage if (!payload.edited_timestamp) return diff --git a/packages/bot/src/handlers/messages/mod.ts b/packages/bot/src/handlers/messages/index.ts similarity index 100% rename from packages/bot/src/handlers/messages/mod.ts rename to packages/bot/src/handlers/messages/index.ts diff --git a/packages/bot/src/handlers/misc/PRESENCE_UPDATE.ts b/packages/bot/src/handlers/misc/PRESENCE_UPDATE.ts index 695ac9aa3..794f332bd 100644 --- a/packages/bot/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/packages/bot/src/handlers/misc/PRESENCE_UPDATE.ts @@ -1,6 +1,6 @@ import type { DiscordGatewayPayload, DiscordPresenceUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { bot.events.presenceUpdate?.(bot.transformers.presence(bot, data.d as DiscordPresenceUpdate)) } diff --git a/packages/bot/src/handlers/misc/READY.ts b/packages/bot/src/handlers/misc/READY.ts index 7615f89e4..709b9a858 100644 --- a/packages/bot/src/handlers/misc/READY.ts +++ b/packages/bot/src/handlers/misc/READY.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordReady } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleReady(bot: Bot, data: DiscordGatewayPayload, shardId: number) { +export async function handleReady(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordReady // Triggered on each shard bot.events.ready?.( diff --git a/packages/bot/src/handlers/misc/TYPING_START.ts b/packages/bot/src/handlers/misc/TYPING_START.ts index c8799d107..01cef0eba 100644 --- a/packages/bot/src/handlers/misc/TYPING_START.ts +++ b/packages/bot/src/handlers/misc/TYPING_START.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordTypingStart } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleTypingStart(bot: Bot, data: DiscordGatewayPayload) { +export async function handleTypingStart(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordTypingStart const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined diff --git a/packages/bot/src/handlers/misc/USER_UPDATE.ts b/packages/bot/src/handlers/misc/USER_UPDATE.ts index 742395451..d790efffe 100644 --- a/packages/bot/src/handlers/misc/USER_UPDATE.ts +++ b/packages/bot/src/handlers/misc/USER_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordUser } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleUserUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleUserUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordUser bot.events.botUpdate?.(bot.transformers.user(bot, payload)) } diff --git a/packages/bot/src/handlers/misc/mod.ts b/packages/bot/src/handlers/misc/index.ts similarity index 100% rename from packages/bot/src/handlers/misc/mod.ts rename to packages/bot/src/handlers/misc/index.ts diff --git a/packages/bot/src/handlers/mod.ts b/packages/bot/src/handlers/mod.ts deleted file mode 100644 index 505b37914..000000000 --- a/packages/bot/src/handlers/mod.ts +++ /dev/null @@ -1,12 +0,0 @@ -export * from "./channels/mod.js"; -export * from "./emojis/mod.js"; -export * from "./guilds/mod.js"; -export * from "./integrations/mod.js"; -export * from "./interactions/mod.js"; -export * from "./invites/mod.js"; -export * from "./members/mod.js"; -export * from "./messages/mod.js"; -export * from "./misc/mod.js"; -export * from "./roles/mod.js"; -export * from "./voice/mod.js"; -export * from "./webhooks/mod.js"; diff --git a/packages/bot/src/handlers/roles/GUILD_ROLE_CREATE.ts b/packages/bot/src/handlers/roles/GUILD_ROLE_CREATE.ts index ee9acb9bf..5e5138c8f 100644 --- a/packages/bot/src/handlers/roles/GUILD_ROLE_CREATE.ts +++ b/packages/bot/src/handlers/roles/GUILD_ROLE_CREATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildRoleCreate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildRoleCreate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildRoleCreate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildRoleCreate bot.events.roleCreate?.( bot.transformers.role(bot, { diff --git a/packages/bot/src/handlers/roles/GUILD_ROLE_DELETE.ts b/packages/bot/src/handlers/roles/GUILD_ROLE_DELETE.ts index 9a4b24fc4..0440cd755 100644 --- a/packages/bot/src/handlers/roles/GUILD_ROLE_DELETE.ts +++ b/packages/bot/src/handlers/roles/GUILD_ROLE_DELETE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildRoleDelete } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildRoleDelete bot.events.roleDelete?.({ roleId: bot.transformers.snowflake(payload.role_id), diff --git a/packages/bot/src/handlers/roles/GUILD_ROLE_UPDATE.ts b/packages/bot/src/handlers/roles/GUILD_ROLE_UPDATE.ts index d6b253289..63f641242 100644 --- a/packages/bot/src/handlers/roles/GUILD_ROLE_UPDATE.ts +++ b/packages/bot/src/handlers/roles/GUILD_ROLE_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordGuildRoleUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleGuildRoleUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleGuildRoleUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordGuildRoleUpdate bot.events.roleUpdate?.( diff --git a/packages/bot/src/handlers/roles/mod.ts b/packages/bot/src/handlers/roles/index.ts similarity index 100% rename from packages/bot/src/handlers/roles/mod.ts rename to packages/bot/src/handlers/roles/index.ts diff --git a/packages/bot/src/handlers/voice/VOICE_SERVER_UPDATE.ts b/packages/bot/src/handlers/voice/VOICE_SERVER_UPDATE.ts index 11461f593..c3962dc8e 100644 --- a/packages/bot/src/handlers/voice/VOICE_SERVER_UPDATE.ts +++ b/packages/bot/src/handlers/voice/VOICE_SERVER_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordVoiceServerUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleVoiceServerUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleVoiceServerUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordVoiceServerUpdate bot.events.voiceServerUpdate?.({ diff --git a/packages/bot/src/handlers/voice/VOICE_STATE_UPDATE.ts b/packages/bot/src/handlers/voice/VOICE_STATE_UPDATE.ts index 4006c67e5..025622bb1 100644 --- a/packages/bot/src/handlers/voice/VOICE_STATE_UPDATE.ts +++ b/packages/bot/src/handlers/voice/VOICE_STATE_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordVoiceState } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleVoiceStateUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleVoiceStateUpdate(bot: Bot, data: DiscordGatewayPayload): Promise { const payload = data.d as DiscordVoiceState if (!payload.guild_id) return diff --git a/packages/bot/src/handlers/voice/mod.ts b/packages/bot/src/handlers/voice/index.ts similarity index 100% rename from packages/bot/src/handlers/voice/mod.ts rename to packages/bot/src/handlers/voice/index.ts diff --git a/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts b/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts index 5937fe0f4..c2e92a70b 100644 --- a/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts +++ b/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordWebhookUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload) { +export async function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) : Promise { const payload = data.d as DiscordWebhookUpdate bot.events.webhooksUpdate?.({ channelId: bot.transformers.snowflake(payload.channel_id), diff --git a/packages/bot/src/handlers/webhooks/mod.ts b/packages/bot/src/handlers/webhooks/index.ts similarity index 100% rename from packages/bot/src/handlers/webhooks/mod.ts rename to packages/bot/src/handlers/webhooks/index.ts diff --git a/packages/bot/src/index.ts b/packages/bot/src/index.ts index 432d86276..994653bd8 100644 --- a/packages/bot/src/index.ts +++ b/packages/bot/src/index.ts @@ -3,6 +3,6 @@ export * from '@discordeno/rest' export * from '@discordeno/types' export * from '@discordeno/utils' export * from './bot.js' -export * from './handler.js' -export * from './transformer.js' +export * from './handlers.js' +export * from './transformers.js' export * from './utils.js' diff --git a/packages/bot/src/transformer.ts b/packages/bot/src/transformers.ts similarity index 52% rename from packages/bot/src/transformer.ts rename to packages/bot/src/transformers.ts index 759e1627a..d7f1eda3f 100644 --- a/packages/bot/src/transformer.ts +++ b/packages/bot/src/transformers.ts @@ -43,30 +43,29 @@ import type { DiscordVoiceState, DiscordWebhook, DiscordWelcomeScreen, - InteractionResponse, } from '@discordeno/types' -import { bigintToSnowflake, Bot, snowflakeToBigint } from './index.js' -import { Activity, transformActivity } from './transformers/activity' -import { Application, transformApplication } from './transformers/application' -import { ApplicationCommand, transformApplicationCommand } from './transformers/applicationCommand' -import { transformApplicationCommandOption } from './transformers/applicationCommandOption' -import { transformApplicationCommandOptionChoice } from './transformers/applicationCommandOptionChoice' -import { ApplicationCommandPermission, transformApplicationCommandPermission } from './transformers/applicationCommandPermission' -import { Attachment, transformAttachment } from './transformers/attachment' -import { AuditLogEntry, transformAuditLogEntry } from './transformers/auditLogEntry' +import { bigintToSnowflake, snowflakeToBigint, type Bot } from './index.js' +import { transformActivity, type Activity } from './transformers/activity.js' +import { transformApplication, type Application } from './transformers/application.js' +import { transformApplicationCommand, type ApplicationCommand } from './transformers/applicationCommand.js' +import { transformApplicationCommandOption } from './transformers/applicationCommandOption.js' +import { transformApplicationCommandOptionChoice } from './transformers/applicationCommandOptionChoice.js' +import { transformApplicationCommandPermission, type ApplicationCommandPermission } from './transformers/applicationCommandPermission.js' +import { transformAttachment, type Attachment } from './transformers/attachment.js' +import { transformAuditLogEntry, type AuditLogEntry } from './transformers/auditLogEntry.js' import { transformAutoModerationActionExecution, type AutoModerationActionExecution } from './transformers/automodActionExecution.js' -import { AutoModerationRule, transformAutoModerationRule } from './transformers/automodRule' -import { Channel, transformChannel } from './transformers/channel' -import { Component, transformComponent } from './transformers/component' -import { Embed, transformEmbed } from './transformers/embed' -import { Emoji, transformEmoji } from './transformers/emoji' -import { GetGatewayBot, transformGatewayBot } from './transformers/gatewayBot' -import { Guild, transformGuild } from './transformers/guild' -import { Integration, transformIntegration } from './transformers/integration' -import { Interaction, InteractionDataOption, transformInteraction, transformInteractionDataOption } from './transformers/interaction' -import { Invite, transformInvite } from './transformers/invite' -import { Member, transformMember, transformUser, User } from './transformers/member' -import { Message, transformMessage } from './transformers/message' +import { transformAutoModerationRule, type AutoModerationRule } from './transformers/automodRule.js' +import { transformChannel, type Channel } from './transformers/channel.js' +import { transformComponent, type Component } from './transformers/component.js' +import { transformEmbed, type Embed } from './transformers/embed.js' +import { transformEmoji, type Emoji } from './transformers/emoji.js' +import { transformGatewayBot, type GetGatewayBot } from './transformers/gatewayBot.js' +import { transformGuild, type Guild } from './transformers/guild.js' +import { transformIntegration, type Integration } from './transformers/integration.js' +import { transformInteraction, transformInteractionDataOption, type Interaction, type InteractionDataOption } from './transformers/interaction.js' +import { transformInvite, type Invite } from './transformers/invite.js' +import { transformMember, transformUser, type Member, type User } from './transformers/member.js' +import { transformMessage, type Message } from './transformers/message.js' import { transformActivityToDiscordActivity, transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice, @@ -79,25 +78,25 @@ import { transformMemberToDiscordMember, transformTeamToDiscordTeam, transformUserToDiscordUser, -} from './transformers/mod' -import { PresenceUpdate, transformPresence } from './transformers/presence' -import { transformAllowedMentionsToDiscordAllowedMentions } from './transformers/reverse/allowedMentions' +} from './transformers/index.js' +import { transformPresence, type PresenceUpdate } from './transformers/presence.js' +import { transformAllowedMentionsToDiscordAllowedMentions } from './transformers/reverse/allowedMentions.js' import { transformCreateApplicationCommandToDiscordCreateApplicationCommand } from './transformers/reverse/createApplicationCommand.js' import { transformInteractionResponseToDiscordInteractionResponse } from './transformers/reverse/interactionResponse.js' -import { Role, transformRole } from './transformers/role' -import { ScheduledEvent, transformScheduledEvent } from './transformers/scheduledEvent' -import { StageInstance, transformStageInstance } from './transformers/stageInstance' -import { Sticker, StickerPack, transformSticker, transformStickerPack } from './transformers/sticker' -import { Team, transformTeam } from './transformers/team' -import { Template, transformTemplate } from './transformers/template' -import { ThreadMember, transformThreadMember } from './transformers/threadMember' -import { transformVoiceRegion, VoiceRegions } from './transformers/voiceRegion' -import { transformVoiceState, VoiceState } from './transformers/voiceState' -import { transformWebhook, Webhook } from './transformers/webhook' -import { transformWelcomeScreen, WelcomeScreen } from './transformers/welcomeScreen' -import { GuildWidget, transformWidget } from './transformers/widget' -import { GuildWidgetSettings, transformWidgetSettings } from './transformers/widgetSettings' -import type { DiscordComponent, DiscordInteractionResponse } from './types.js' +import { transformRole, type Role } from './transformers/role.js' +import { transformScheduledEvent, type ScheduledEvent } from './transformers/scheduledEvent.js' +import { transformStageInstance, type StageInstance } from './transformers/stageInstance.js' +import { transformSticker, transformStickerPack, type Sticker, type StickerPack } from './transformers/sticker.js' +import { transformTeam, type Team } from './transformers/team.js' +import { transformTemplate, type Template } from './transformers/template.js' +import { transformThreadMember, type ThreadMember } from './transformers/threadMember.js' +import { transformVoiceRegion, type VoiceRegions } from './transformers/voiceRegion.js' +import { transformVoiceState, type VoiceState } from './transformers/voiceState.js' +import { transformWebhook, type Webhook } from './transformers/webhook.js' +import { transformWelcomeScreen, type WelcomeScreen } from './transformers/welcomeScreen.js' +import { transformWidget, type GuildWidget } from './transformers/widget.js' +import { transformWidgetSettings, type GuildWidgetSettings } from './transformers/widgetSettings.js' +import type { BotInteractionResponse, DiscordComponent, DiscordInteractionResponse } from './typings.js' export interface Transformers { reverse: { @@ -114,7 +113,7 @@ export interface Transformers { applicationCommand: (bot: Bot, payload: ApplicationCommand) => DiscordApplicationCommand applicationCommandOption: (bot: Bot, payload: ApplicationCommandOption) => DiscordApplicationCommandOption applicationCommandOptionChoice: (bot: Bot, payload: ApplicationCommandOptionChoice) => DiscordApplicationCommandOptionChoice - interactionResponse: (bot: Bot, payload: InteractionResponse) => DiscordInteractionResponse + interactionResponse: (bot: Bot, payload: BotInteractionResponse) => DiscordInteractionResponse attachment: (bot: Bot, payload: Attachment) => DiscordAttachment } snowflake: (snowflake: BigString) => bigint @@ -158,64 +157,64 @@ export interface Transformers { template: (bot: Bot, payload: DiscordTemplate) => Template } -export function createTransformers(options: Partial) { +export function createTransformers(options: Partial): Transformers { return { reverse: { - allowedMentions: options.reverse?.allowedMentions || transformAllowedMentionsToDiscordAllowedMentions, - embed: options.reverse?.embed || transformEmbedToDiscordEmbed, - component: options.reverse?.component || transformComponentToDiscordComponent, - activity: options.reverse?.activity || transformActivityToDiscordActivity, - member: options.reverse?.member || transformMemberToDiscordMember, - user: options.reverse?.user || transformUserToDiscordUser, - team: options.reverse?.team || transformTeamToDiscordTeam, - application: options.reverse?.application || transformApplicationToDiscordApplication, - snowflake: options.reverse?.snowflake || bigintToSnowflake, - createApplicationCommand: options.reverse?.createApplicationCommand || transformCreateApplicationCommandToDiscordCreateApplicationCommand, - applicationCommand: options.reverse?.applicationCommand || transformApplicationCommandToDiscordApplicationCommand, - applicationCommandOption: options.reverse?.applicationCommandOption || transformApplicationCommandOptionToDiscordApplicationCommandOption, + allowedMentions: options.reverse?.allowedMentions ?? transformAllowedMentionsToDiscordAllowedMentions, + embed: options.reverse?.embed ?? transformEmbedToDiscordEmbed, + component: options.reverse?.component ?? transformComponentToDiscordComponent, + activity: options.reverse?.activity ?? transformActivityToDiscordActivity, + member: options.reverse?.member ?? transformMemberToDiscordMember, + user: options.reverse?.user ?? transformUserToDiscordUser, + team: options.reverse?.team ?? transformTeamToDiscordTeam, + application: options.reverse?.application ?? transformApplicationToDiscordApplication, + snowflake: options.reverse?.snowflake ?? bigintToSnowflake, + createApplicationCommand: options.reverse?.createApplicationCommand ?? transformCreateApplicationCommandToDiscordCreateApplicationCommand, + applicationCommand: options.reverse?.applicationCommand ?? transformApplicationCommandToDiscordApplicationCommand, + applicationCommandOption: options.reverse?.applicationCommandOption ?? transformApplicationCommandOptionToDiscordApplicationCommandOption, applicationCommandOptionChoice: - options.reverse?.applicationCommandOptionChoice || transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice, - interactionResponse: options.reverse?.interactionResponse || transformInteractionResponseToDiscordInteractionResponse, - attachment: options.reverse?.attachment || transformAttachmentToDiscordAttachment, + options.reverse?.applicationCommandOptionChoice ?? transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice, + interactionResponse: options.reverse?.interactionResponse ?? transformInteractionResponseToDiscordInteractionResponse, + attachment: options.reverse?.attachment ?? transformAttachmentToDiscordAttachment, }, - automodRule: options.automodRule || transformAutoModerationRule, - automodActionExecution: options.automodActionExecution || transformAutoModerationActionExecution, - activity: options.activity || transformActivity, - application: options.application || transformApplication, - attachment: options.attachment || transformAttachment, - channel: options.channel || transformChannel, - component: options.component || transformComponent, - embed: options.embed || transformEmbed, - emoji: options.emoji || transformEmoji, - guild: options.guild || transformGuild, - integration: options.integration || transformIntegration, - interaction: options.interaction || transformInteraction, - interactionDataOptions: options.interactionDataOptions || transformInteractionDataOption, - invite: options.invite || transformInvite, - member: options.member || transformMember, - message: options.message || transformMessage, - presence: options.presence || transformPresence, - role: options.role || transformRole, - user: options.user || transformUser, - team: options.team || transformTeam, - voiceState: options.voiceState || transformVoiceState, - snowflake: options.snowflake || snowflakeToBigint, - webhook: options.webhook || transformWebhook, - auditLogEntry: options.auditLogEntry || transformAuditLogEntry, - applicationCommand: options.applicationCommand || transformApplicationCommand, - applicationCommandOption: options.applicationCommandOption || transformApplicationCommandOption, - applicationCommandPermission: options.applicationCommandPermission || transformApplicationCommandPermission, - scheduledEvent: options.scheduledEvent || transformScheduledEvent, - threadMember: options.threadMember || transformThreadMember, - welcomeScreen: options.welcomeScreen || transformWelcomeScreen, - voiceRegion: options.voiceRegion || transformVoiceRegion, - widget: options.widget || transformWidget, - widgetSettings: options.widgetSettings || transformWidgetSettings, - stageInstance: options.stageInstance || transformStageInstance, - sticker: options.sticker || transformSticker, - stickerPack: options.stickerPack || transformStickerPack, - gatewayBot: options.gatewayBot || transformGatewayBot, - applicationCommandOptionChoice: options.applicationCommandOptionChoice || transformApplicationCommandOptionChoice, - template: options.template || transformTemplate, + automodRule: options.automodRule ?? transformAutoModerationRule, + automodActionExecution: options.automodActionExecution ?? transformAutoModerationActionExecution, + activity: options.activity ?? transformActivity, + application: options.application ?? transformApplication, + attachment: options.attachment ?? transformAttachment, + channel: options.channel ?? transformChannel, + component: options.component ?? transformComponent, + embed: options.embed ?? transformEmbed, + emoji: options.emoji ?? transformEmoji, + guild: options.guild ?? transformGuild, + integration: options.integration ?? transformIntegration, + interaction: options.interaction ?? transformInteraction, + interactionDataOptions: options.interactionDataOptions ?? transformInteractionDataOption, + invite: options.invite ?? transformInvite, + member: options.member ?? transformMember, + message: options.message ?? transformMessage, + presence: options.presence ?? transformPresence, + role: options.role ?? transformRole, + user: options.user ?? transformUser, + team: options.team ?? transformTeam, + voiceState: options.voiceState ?? transformVoiceState, + snowflake: options.snowflake ?? snowflakeToBigint, + webhook: options.webhook ?? transformWebhook, + auditLogEntry: options.auditLogEntry ?? transformAuditLogEntry, + applicationCommand: options.applicationCommand ?? transformApplicationCommand, + applicationCommandOption: options.applicationCommandOption ?? transformApplicationCommandOption, + applicationCommandPermission: options.applicationCommandPermission ?? transformApplicationCommandPermission, + scheduledEvent: options.scheduledEvent ?? transformScheduledEvent, + threadMember: options.threadMember ?? transformThreadMember, + welcomeScreen: options.welcomeScreen ?? transformWelcomeScreen, + voiceRegion: options.voiceRegion ?? transformVoiceRegion, + widget: options.widget ?? transformWidget, + widgetSettings: options.widgetSettings ?? transformWidgetSettings, + stageInstance: options.stageInstance ?? transformStageInstance, + sticker: options.sticker ?? transformSticker, + stickerPack: options.stickerPack ?? transformStickerPack, + gatewayBot: options.gatewayBot ?? transformGatewayBot, + applicationCommandOptionChoice: options.applicationCommandOptionChoice ?? transformApplicationCommandOptionChoice, + template: options.template ?? transformTemplate, } } diff --git a/packages/bot/src/transformers/activity.ts b/packages/bot/src/transformers/activity.ts index cb142e6ca..40f4b1722 100644 --- a/packages/bot/src/transformers/activity.ts +++ b/packages/bot/src/transformers/activity.ts @@ -2,6 +2,7 @@ import type { DiscordActivity } from '@discordeno/bot' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformActivity(bot: Bot, payload: DiscordActivity) { const activity = { name: payload.name, diff --git a/packages/bot/src/transformers/application.ts b/packages/bot/src/transformers/application.ts index 7cb85ce4e..081c9313c 100644 --- a/packages/bot/src/transformers/application.ts +++ b/packages/bot/src/transformers/application.ts @@ -1,7 +1,8 @@ -import { DiscordApplication, iconHashToBigInt } from '@discordeno/bot' +import { iconHashToBigInt, type DiscordApplication } from '@discordeno/bot' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformApplication(bot: Bot, payload: DiscordApplication) { const application = { name: payload.name, @@ -20,7 +21,7 @@ export function transformApplication(bot: Bot, payload: DiscordApplication) { id: bot.transformers.snowflake(payload.id), icon: payload.icon ? iconHashToBigInt(payload.icon) : undefined, owner: payload.owner - ? // @ts-ignore the partial here wont break anything + ? // @ts-expect-error the partial here wont break anything bot.transformers.user(bot, payload.owner) : undefined, team: payload.team ? bot.transformers.team(bot, payload.team) : undefined, diff --git a/packages/bot/src/transformers/applicationCommand.ts b/packages/bot/src/transformers/applicationCommand.ts index 7cae93949..bacdab76a 100644 --- a/packages/bot/src/transformers/applicationCommand.ts +++ b/packages/bot/src/transformers/applicationCommand.ts @@ -2,6 +2,7 @@ import type { DiscordApplicationCommand } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformApplicationCommand(bot: Bot, payload: DiscordApplicationCommand) { const applicationCommand = { id: bot.transformers.snowflake(payload.id), diff --git a/packages/bot/src/transformers/applicationCommandOptionChoice.ts b/packages/bot/src/transformers/applicationCommandOptionChoice.ts index b343e06da..9e0126db4 100644 --- a/packages/bot/src/transformers/applicationCommandOptionChoice.ts +++ b/packages/bot/src/transformers/applicationCommandOptionChoice.ts @@ -2,6 +2,7 @@ import type { DiscordApplicationCommandOptionChoice } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformApplicationCommandOptionChoice(bot: Bot, payload: DiscordApplicationCommandOptionChoice) { const applicationCommandChoice = { name: payload.name, diff --git a/packages/bot/src/transformers/applicationCommandPermission.ts b/packages/bot/src/transformers/applicationCommandPermission.ts index cf1cff30b..50d2cf505 100644 --- a/packages/bot/src/transformers/applicationCommandPermission.ts +++ b/packages/bot/src/transformers/applicationCommandPermission.ts @@ -2,6 +2,7 @@ import type { DiscordGuildApplicationCommandPermissions } from '@discordeno/type import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformApplicationCommandPermission(bot: Bot, payload: DiscordGuildApplicationCommandPermissions) { const applicationCommandPermission = { id: bot.transformers.snowflake(payload.id), diff --git a/packages/bot/src/transformers/attachment.ts b/packages/bot/src/transformers/attachment.ts index 7fe1bcde7..31fcd990a 100644 --- a/packages/bot/src/transformers/attachment.ts +++ b/packages/bot/src/transformers/attachment.ts @@ -2,6 +2,7 @@ import type { DiscordAttachment } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformAttachment(bot: Bot, payload: DiscordAttachment) { const attachment = { id: bot.transformers.snowflake(payload.id), diff --git a/packages/bot/src/transformers/auditLogEntry.ts b/packages/bot/src/transformers/auditLogEntry.ts index b92b735f9..7473f961e 100644 --- a/packages/bot/src/transformers/auditLogEntry.ts +++ b/packages/bot/src/transformers/auditLogEntry.ts @@ -2,6 +2,7 @@ import type { DiscordAuditLogEntry } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformAuditLogEntry(bot: Bot, payload: DiscordAuditLogEntry) { const auditLogEntry = { id: bot.transformers.snowflake(payload.id), @@ -122,6 +123,8 @@ export function transformAuditLogEntry(bot: Bot, payload: DiscordAuditLogEntry) id: payload.options.id ? bot.transformers.snowflake(payload.options.id) : undefined, type: Number(payload.options.type), roleName: payload.options.role_name, + autoModerationRuleName: payload.options.auto_moderation_rule_name, + autoModerationRuleTriggerType: payload.options.auto_moderation_rule_trigger_type, } : undefined, reason: payload.reason, diff --git a/packages/bot/src/transformers/automodActionExecution.ts b/packages/bot/src/transformers/automodActionExecution.ts index cf9a62c08..c2ff26fd9 100644 --- a/packages/bot/src/transformers/automodActionExecution.ts +++ b/packages/bot/src/transformers/automodActionExecution.ts @@ -2,6 +2,7 @@ import type { DiscordAutoModerationActionExecution } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformAutoModerationActionExecution(bot: Bot, payload: DiscordAutoModerationActionExecution) { const rule = { content: payload.content, diff --git a/packages/bot/src/transformers/automodRule.ts b/packages/bot/src/transformers/automodRule.ts index 7432e8eb1..163e9e298 100644 --- a/packages/bot/src/transformers/automodRule.ts +++ b/packages/bot/src/transformers/automodRule.ts @@ -2,6 +2,7 @@ import type { DiscordAutoModerationRule } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformAutoModerationRule(bot: Bot, payload: DiscordAutoModerationRule) { const rule = { name: payload.name, diff --git a/packages/bot/src/transformers/channel.ts b/packages/bot/src/transformers/channel.ts index aaba4896c..a508a2e29 100644 --- a/packages/bot/src/transformers/channel.ts +++ b/packages/bot/src/transformers/channel.ts @@ -4,21 +4,22 @@ import type { Optionalize } from '../optionalize.js' const Mask = (1n << 64n) - 1n -export function packOverwrites(allow: string, deny: string, id: string, type: number) { +export function packOverwrites(allow: string, deny: string, id: string, type: number): bigint { return pack64(allow, 0) | pack64(deny, 1) | pack64(id, 2) | pack64(type, 3) } -function unpack64(v: bigint, shift: number) { +function unpack64(v: bigint, shift: number): bigint { return (v >> BigInt(shift * 64)) & Mask } -function pack64(v: string | number, shift: number) { +function pack64(v: string | number, shift: number): bigint { const b = BigInt(v) - if (b < 0 || b > Mask) throw new Error('should have been a 64 bit unsigned integer: ' + v) + if (b < 0 || b > Mask) throw new Error('should have been a 64 bit unsigned integer: ' + v.toString()) return b << BigInt(shift * 64) } -export function separateOverwrites(v: bigint) { +export function separateOverwrites(v: bigint): [number, bigint, bigint, bigint] { return [Number(unpack64(v, 3)), unpack64(v, 2), unpack64(v, 0), unpack64(v, 1)] as [number, bigint, bigint, bigint] } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformChannel(bot: Bot, payload: { channel: DiscordChannel } & { guildId?: bigint }) { const channel = { // UNTRANSFORMED STUFF HERE @@ -33,10 +34,10 @@ export function transformChannel(bot: Bot, payload: { channel: DiscordChannel } // recipients: payload.channel.recipients?.map((r) => bot.transformers.user(bot, r)), rtcRegion: payload.channel.rtc_region ?? undefined, videoQualityMode: payload.channel.video_quality_mode, - guildId: payload.guildId || (payload.channel.guild_id ? bot.transformers.snowflake(payload.channel.guild_id) : 0n), + guildId: payload.guildId ?? (payload.channel.guild_id ? bot.transformers.snowflake(payload.channel.guild_id) : 0n), lastPinTimestamp: payload.channel.last_pin_timestamp ? Date.parse(payload.channel.last_pin_timestamp) : undefined, permissionOverwrites: payload.channel.permission_overwrites - ? payload.channel.permission_overwrites.map((o) => packOverwrites(o.allow || '0', o.deny || '0', o.id, o.type)) + ? payload.channel.permission_overwrites.map((o) => packOverwrites(o.allow ?? '0', o.deny ?? '0', o.id, o.type)) : [], id: bot.transformers.snowflake(payload.channel.id), diff --git a/packages/bot/src/transformers/component.ts b/packages/bot/src/transformers/component.ts index 064ebbafc..fefc0a6b9 100644 --- a/packages/bot/src/transformers/component.ts +++ b/packages/bot/src/transformers/component.ts @@ -1,8 +1,8 @@ -// import type { DiscordComponent } from '@discordeno/types' import type { ButtonStyles, MessageComponentTypes, SelectOption, TextStyles } from '@discordeno/types' import type { Bot } from '../index.js' +import type { DiscordComponent } from '../typings.js' -export function transformComponent(bot: Bot, payload: any /* TODO: Fix, needs DiscordComponent type */): Component { +export function transformComponent(bot: Bot, payload: DiscordComponent): Component { return { type: payload.type, customId: payload.custom_id, @@ -17,7 +17,6 @@ export function transformComponent(bot: Bot, payload: any /* TODO: Fix, needs Di } : undefined, url: payload.url, - // @ts-expect-error TODO: Fix options: payload.options?.map((option) => ({ label: option.label, value: option.value, @@ -37,7 +36,6 @@ export function transformComponent(bot: Bot, payload: any /* TODO: Fix, needs Di minLength: payload.min_length, maxLength: payload.max_length, value: payload.value, - // @ts-expect-error TODO: Fix components: payload.components?.map((component) => bot.transformers.component(bot, component)), } } @@ -80,7 +78,7 @@ export interface Component { maxValues?: number /** The minimum input length for a text input. Between 0-4000. */ minLength?: number - /**The maximum input length for a text input. Between 1-4000. */ + /** The maximum input length for a text input. Between 1-4000. */ maxLength?: number /** a list of child components */ components?: Component[] diff --git a/packages/bot/src/transformers/embed.ts b/packages/bot/src/transformers/embed.ts index c48728883..2375225b6 100644 --- a/packages/bot/src/transformers/embed.ts +++ b/packages/bot/src/transformers/embed.ts @@ -2,6 +2,7 @@ import type { DiscordEmbed } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformEmbed(bot: Bot, payload: DiscordEmbed) { const embed = { title: payload.title, diff --git a/packages/bot/src/transformers/emoji.ts b/packages/bot/src/transformers/emoji.ts index 4afbe4895..ab0ea76da 100644 --- a/packages/bot/src/transformers/emoji.ts +++ b/packages/bot/src/transformers/emoji.ts @@ -3,10 +3,11 @@ import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' import { EmojiToggles } from './toggles/emoji.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformEmoji(bot: Bot, payload: DiscordEmoji) { const emoji = { id: payload.id ? bot.transformers.snowflake(payload.id) : undefined, - name: payload.name || undefined, + name: payload.name ?? undefined, roles: payload.roles?.map((id) => bot.transformers.snowflake(id)), user: payload.user ? bot.transformers.user(bot, payload.user) : undefined, toggles: new EmojiToggles(payload), diff --git a/packages/bot/src/transformers/gatewayBot.ts b/packages/bot/src/transformers/gatewayBot.ts index 7c85eace2..7145e208e 100644 --- a/packages/bot/src/transformers/gatewayBot.ts +++ b/packages/bot/src/transformers/gatewayBot.ts @@ -1,6 +1,7 @@ import type { DiscordGetGatewayBot } from '@discordeno/types' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformGatewayBot(payload: DiscordGetGatewayBot) { const gatewayBot = { url: payload.url, diff --git a/packages/bot/src/transformers/guild.ts b/packages/bot/src/transformers/guild.ts index 555e47335..0bebdb60c 100644 --- a/packages/bot/src/transformers/guild.ts +++ b/packages/bot/src/transformers/guild.ts @@ -5,6 +5,7 @@ import type { Optionalize } from '../optionalize.js' import type { Emoji } from '../transformers/emoji.js' import { GuildToggles } from './toggles/guild.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformGuild(bot: Bot, payload: { guild: DiscordGuild } & { shardId: number }) { const guildId = bot.transformers.snowflake(payload.guild.id) @@ -82,7 +83,7 @@ export function transformGuild(bot: Bot, payload: { guild: DiscordGuild } & { sh }), ), voiceStates: new Collection( - (payload.guild.voice_states || []).map((vs) => bot.transformers.voiceState(bot, { voiceState: vs, guildId })).map((vs) => [vs.userId, vs]), + (payload.guild.voice_states ?? []).map((vs) => bot.transformers.voiceState(bot, { voiceState: vs, guildId })).map((vs) => [vs.userId, vs]), ), id: guildId, diff --git a/packages/bot/src/transformers/mod.ts b/packages/bot/src/transformers/index.ts similarity index 97% rename from packages/bot/src/transformers/mod.ts rename to packages/bot/src/transformers/index.ts index 0931cc1d9..a4e9db236 100644 --- a/packages/bot/src/transformers/mod.ts +++ b/packages/bot/src/transformers/index.ts @@ -19,7 +19,7 @@ export * from './invite.js' export * from './member.js' export * from './message.js' export * from './presence.js' -export * from './reverse/mod.js' +export * from './reverse/index.js' export * from './role.js' export * from './scheduledEvent.js' export * from './stageInstance.js' diff --git a/packages/bot/src/transformers/integration.ts b/packages/bot/src/transformers/integration.ts index 64e06ba69..fb0abee5f 100644 --- a/packages/bot/src/transformers/integration.ts +++ b/packages/bot/src/transformers/integration.ts @@ -1,7 +1,8 @@ import type { DiscordIntegrationCreateUpdate } from '@discordeno/types' -import { Bot, iconHashToBigInt } from '../index.js' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformIntegration(bot: Bot, payload: DiscordIntegrationCreateUpdate) { const integration = { guildId: bot.transformers.snowflake(payload.guild_id), diff --git a/packages/bot/src/transformers/interaction.ts b/packages/bot/src/transformers/interaction.ts index 35f7159a0..b7b388249 100644 --- a/packages/bot/src/transformers/interaction.ts +++ b/packages/bot/src/transformers/interaction.ts @@ -1,16 +1,17 @@ -import type { ChannelTypes, DiscordAttachment, DiscordInteraction, DiscordInteractionDataOption } from '@discordeno/types' +import type { ChannelTypes, DiscordInteraction, DiscordInteractionDataOption } from '@discordeno/types' import { Collection } from '@discordeno/utils' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' -import type { DiscordInteractionDataResolved } from '../types.js' +import type { DiscordInteractionDataResolved } from '../typings.js' import type { Attachment } from './attachment.js' import type { Member, User } from './member.js' import type { Message } from './message.js' import type { Role } from './role.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformInteraction(bot: Bot, payload: DiscordInteraction) { const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined - const user = bot.transformers.user(bot, payload.member?.user || payload.user!) + const user = bot.transformers.user(bot, payload.member?.user ?? payload.user!) const interaction = { // UNTRANSFORMED STUFF HERE @@ -49,6 +50,7 @@ export function transformInteraction(bot: Bot, payload: DiscordInteraction) { return interaction as Optionalize } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformInteractionDataOption(bot: Bot, option: DiscordInteractionDataOption) { const opt = { name: option.name, @@ -61,6 +63,7 @@ export function transformInteractionDataOption(bot: Bot, option: DiscordInteract return opt as Optionalize } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformInteractionDataResolved(bot: Bot, resolved: DiscordInteractionDataResolved, guildId?: bigint) { const transformed: { messages?: Collection @@ -134,7 +137,7 @@ export function transformInteractionDataResolved(bot: Bot, resolved: DiscordInte transformed.attachments = new Collection( Object.entries(resolved.attachments).map(([key, value]) => { const id = bot.transformers.snowflake(key) - return [id, bot.transformers.attachment(bot, value as DiscordAttachment)] + return [id, bot.transformers.attachment(bot, value)] }), ) } diff --git a/packages/bot/src/transformers/invite.ts b/packages/bot/src/transformers/invite.ts index bfc5af6d6..7d9178ee8 100644 --- a/packages/bot/src/transformers/invite.ts +++ b/packages/bot/src/transformers/invite.ts @@ -2,6 +2,7 @@ import type { DiscordInviteCreate } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformInvite(bot: Bot, invite: DiscordInviteCreate) { const transformedInvite = { /** The channel the invite is for */ @@ -24,7 +25,7 @@ export function transformInvite(bot: Bot, invite: DiscordInviteCreate) { targetUser: invite.target_user ? bot.transformers.user(bot, invite.target_user) : undefined, /** The embedded application to open for this voice channel embedded application invite */ targetApplication: invite.target_application - ? // @ts-ignore should not break anything even though its partial. if it does blame wolf :) + ? // @ts-expect-error should not break anything even though its partial. if it does blame wolf :) bot.transformers.application(bot, invite.target_application) : undefined, /** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */ diff --git a/packages/bot/src/transformers/member.ts b/packages/bot/src/transformers/member.ts index 507e1effc..16a51de73 100644 --- a/packages/bot/src/transformers/member.ts +++ b/packages/bot/src/transformers/member.ts @@ -5,6 +5,7 @@ import type { Optionalize } from '../optionalize.js' import { MemberToggles } from './toggles/member.js' import { UserToggles } from './toggles/user.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformUser(bot: Bot, payload: DiscordUser) { const user = { id: bot.transformers.snowflake(payload.id || ''), @@ -22,6 +23,7 @@ export function transformUser(bot: Bot, payload: DiscordUser) { return user as Optionalize } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformMember(bot: Bot, payload: DiscordMember, guildId: bigint, userId: bigint) { const member = { id: userId, diff --git a/packages/bot/src/transformers/message.ts b/packages/bot/src/transformers/message.ts index 37af070df..99aad5573 100644 --- a/packages/bot/src/transformers/message.ts +++ b/packages/bot/src/transformers/message.ts @@ -1,17 +1,18 @@ import type { DiscordMessage } from '@discordeno/types' import { CHANNEL_MENTION_REGEX } from '../constants.js' -import { Bot, iconHashToBigInt } from '../index.js' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' import { MemberToggles } from './toggles/member.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformMessage(bot: Bot, payload: DiscordMessage) { const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined const userId = bot.transformers.snowflake(payload.author.id) const message = { // UNTRANSFORMED STUFF HERE - content: payload.content || '', - isFromBot: payload.author.bot || false, + content: payload.content ?? '', + isFromBot: payload.author.bot ?? false, tag: `${payload.author.username}#${payload.author.discriminator}`, timestamp: Date.parse(payload.timestamp), editedTimestamp: payload.edited_timestamp ? Date.parse(payload.edited_timestamp) : undefined, @@ -84,7 +85,7 @@ export function transformMessage(bot: Bot, payload: DiscordMessage) { // Keep any ids tht discord sends ...(payload.mention_channels ?? []).map((m) => bot.transformers.snowflake(m.id)), // Add any other ids that can be validated in a channel mention format - ...(payload.content?.match(CHANNEL_MENTION_REGEX) || []).map((text) => + ...(payload.content?.match(CHANNEL_MENTION_REGEX) ?? []).map((text) => // converts the <#123> into 123 bot.transformers.snowflake(text.substring(2, text.length - 1)), ), diff --git a/packages/bot/src/transformers/presence.ts b/packages/bot/src/transformers/presence.ts index 8a25d8dbb..534d65b3a 100644 --- a/packages/bot/src/transformers/presence.ts +++ b/packages/bot/src/transformers/presence.ts @@ -1,8 +1,9 @@ -import { DiscordPresenceUpdate, PresenceStatus } from '@discordeno/types' -import { Bot, iconHashToBigInt } from '../index.js' +import { PresenceStatus, type DiscordPresenceUpdate } from '@discordeno/types' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' import { UserToggles } from './toggles/user.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformPresence(bot: Bot, payload: DiscordPresenceUpdate) { const presence = { user: { diff --git a/packages/bot/src/transformers/reverse/application.ts b/packages/bot/src/transformers/reverse/application.ts index 4ea6b65d8..7eef46a0d 100644 --- a/packages/bot/src/transformers/reverse/application.ts +++ b/packages/bot/src/transformers/reverse/application.ts @@ -1,4 +1,4 @@ -import { DiscordApplication, iconBigintToHash } from '@discordeno/bot' +import { iconBigintToHash, type DiscordApplication } from '@discordeno/bot' import type { Bot } from '../../index.js' import type { Application } from '../application.js' diff --git a/packages/bot/src/transformers/reverse/auditLogEntry.ts b/packages/bot/src/transformers/reverse/auditLogEntry.ts index 36f08fc1c..01e7ec7d8 100644 --- a/packages/bot/src/transformers/reverse/auditLogEntry.ts +++ b/packages/bot/src/transformers/reverse/auditLogEntry.ts @@ -13,20 +13,20 @@ export function transformAuditLogEntryToDiscordAuditLogEntry(bot: Bot, payload: return { key: change.key, new_value: ( - change.new as { + change.new as Array<{ id: bigint | undefined name: string | undefined - }[] + }> )?.map((val) => ({ id: val.id ? bot.transformers.reverse.snowflake(val.id) : undefined, name: val.name, })), old_value: ( change.old as - | { + | Array<{ id: bigint | undefined name: string | undefined - }[] + }> | undefined )?.map((val) => ({ id: val?.id ? bot.transformers.reverse.snowflake(val.id) : undefined, @@ -139,10 +139,7 @@ export function transformAuditLogEntryToDiscordAuditLogEntry(bot: Bot, payload: role_name: payload.options.roleName, // make up value to make ts shut up, the orginal value do not persevere in transformer application_id: '', - // TODO: Fix - // @ts-expect-error auto_moderation_rule_name: payload.options.autoModerationRuleName, - // @ts-expect-error auto_moderation_rule_trigger_type: payload.options.autoModerationRuleTriggerType, } : undefined, diff --git a/packages/bot/src/transformers/reverse/component.ts b/packages/bot/src/transformers/reverse/component.ts index 9ac0d522b..d28622dc8 100644 --- a/packages/bot/src/transformers/reverse/component.ts +++ b/packages/bot/src/transformers/reverse/component.ts @@ -1,5 +1,5 @@ import type { Bot } from '../../index.js' -import type { DiscordComponent } from '../../types.js' +import type { DiscordComponent } from '../../typings.js' import type { Component } from '../component.js' export function transformComponentToDiscordComponent(bot: Bot, payload: Component): DiscordComponent { diff --git a/packages/bot/src/transformers/reverse/createApplicationCommand.ts b/packages/bot/src/transformers/reverse/createApplicationCommand.ts index 73a98e6ca..6de459d8a 100644 --- a/packages/bot/src/transformers/reverse/createApplicationCommand.ts +++ b/packages/bot/src/transformers/reverse/createApplicationCommand.ts @@ -1,7 +1,7 @@ import type { CreateApplicationCommand, DiscordCreateApplicationCommand } from '@discordeno/bot' import { calculateBits } from '@discordeno/utils' import type { Bot } from '../../index.js' -import { isContextApplicationCommand } from '../../types.js' +import { isContextApplicationCommand } from '../../typings.js' export function transformCreateApplicationCommandToDiscordCreateApplicationCommand( bot: Bot, diff --git a/packages/bot/src/transformers/reverse/emoji.ts b/packages/bot/src/transformers/reverse/emoji.ts index 5621d10bb..d298ffb35 100644 --- a/packages/bot/src/transformers/reverse/emoji.ts +++ b/packages/bot/src/transformers/reverse/emoji.ts @@ -5,7 +5,7 @@ import type { Emoji } from '../emoji.js' export function transformEmojiToDiscordEmoji(bot: Bot, payload: Emoji): DiscordEmoji { return { id: payload.id ? bot.transformers.reverse.snowflake(payload.id) : undefined, - name: payload.name || undefined, + name: payload.name ?? undefined, roles: payload.roles?.map((id) => bot.transformers.reverse.snowflake(id)), user: payload.user ? bot.transformers.reverse.user(bot, payload.user) : undefined, require_colons: payload.toggles.requireColons, diff --git a/packages/bot/src/transformers/reverse/mod.ts b/packages/bot/src/transformers/reverse/index.ts similarity index 100% rename from packages/bot/src/transformers/reverse/mod.ts rename to packages/bot/src/transformers/reverse/index.ts diff --git a/packages/bot/src/transformers/reverse/interactionResponse.ts b/packages/bot/src/transformers/reverse/interactionResponse.ts index f1a4c586a..a95cb0358 100644 --- a/packages/bot/src/transformers/reverse/interactionResponse.ts +++ b/packages/bot/src/transformers/reverse/interactionResponse.ts @@ -1,5 +1,5 @@ import type { Bot } from '../../index.js' -import type { BotInteractionResponse, DiscordInteractionResponse } from '../../types.js' +import type { BotInteractionResponse, DiscordInteractionResponse } from '../../typings.js' export function transformInteractionResponseToDiscordInteractionResponse(bot: Bot, payload: BotInteractionResponse): DiscordInteractionResponse { // If no mentions are provided, force disable mentions diff --git a/packages/bot/src/transformers/reverse/member.ts b/packages/bot/src/transformers/reverse/member.ts index f76dda277..8a5d5bcaa 100644 --- a/packages/bot/src/transformers/reverse/member.ts +++ b/packages/bot/src/transformers/reverse/member.ts @@ -5,7 +5,7 @@ import type { Member, User } from '../member.js' export function transformUserToDiscordUser(bot: Bot, payload: User): DiscordUser { return { - id: bot.utils.bigintToSnowflake(payload.id), + id: payload.id.toString(), username: payload.username, discriminator: payload.discriminator, avatar: payload.avatar ? iconBigintToHash(payload.avatar) : null, @@ -24,11 +24,11 @@ export function transformUserToDiscordUser(bot: Bot, payload: User): DiscordUser export function transformMemberToDiscordMember(bot: Bot, payload: Member): DiscordMember { return { nick: payload.nick ?? undefined, - roles: payload.roles.map((id) => bot.utils.bigintToSnowflake(id)), + roles: payload.roles.map((id) => id.toString()), joined_at: new Date(payload.joinedAt).toISOString(), premium_since: payload.premiumSince ? new Date(payload.premiumSince).toISOString() : undefined, avatar: payload.avatar ? iconBigintToHash(payload.avatar) : undefined, - permissions: payload.permissions ? bot.utils.bigintToSnowflake(payload.permissions) : undefined, + permissions: payload.permissions?.toString(), communication_disabled_until: payload.communicationDisabledUntil ? new Date(payload.communicationDisabledUntil).toISOString() : undefined, deaf: payload.toggles.deaf, mute: payload.toggles.mute, diff --git a/packages/bot/src/transformers/reverse/presence.ts b/packages/bot/src/transformers/reverse/presence.ts index 568e13796..7e28d4c04 100644 --- a/packages/bot/src/transformers/reverse/presence.ts +++ b/packages/bot/src/transformers/reverse/presence.ts @@ -1,4 +1,4 @@ -import { DiscordPresenceUpdate, PresenceStatus } from '@discordeno/types' +import { PresenceStatus, type DiscordPresenceUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' import type { PresenceUpdate } from '../presence.js' diff --git a/packages/bot/src/transformers/reverse/team.ts b/packages/bot/src/transformers/reverse/team.ts index e9df4d565..17e6cca6f 100644 --- a/packages/bot/src/transformers/reverse/team.ts +++ b/packages/bot/src/transformers/reverse/team.ts @@ -1,16 +1,16 @@ import type { DiscordTeam } from '@discordeno/types' -import { Bot, iconBigintToHash } from '../../index.js' +import { iconBigintToHash, type Bot } from '../../index.js' import type { Team } from '../team.js' export function transformTeamToDiscordTeam(bot: Bot, payload: Team): DiscordTeam { - const id = bot.utils.bigintToSnowflake(payload.id) + const id = payload.id.toString() return { name: payload.name, id, icon: payload.icon ? iconBigintToHash(payload.icon) : null, - owner_user_id: bot.utils.bigintToSnowflake(payload.ownerUserId), + owner_user_id: payload.ownerUserId.toString(), members: payload.members.map((member) => ({ membership_state: member.membershipState, permissions: member.permissions, diff --git a/packages/bot/src/transformers/role.ts b/packages/bot/src/transformers/role.ts index 6d9136c33..fb0845800 100644 --- a/packages/bot/src/transformers/role.ts +++ b/packages/bot/src/transformers/role.ts @@ -1,8 +1,9 @@ import type { DiscordRole } from '@discordeno/types' -import { Bot, iconHashToBigInt } from '../index.js' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' import { RoleToggles } from './toggles/role.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformRole(bot: Bot, payload: { role: DiscordRole } & { guildId: bigint }) { const role = { name: payload.role.name, diff --git a/packages/bot/src/transformers/scheduledEvent.ts b/packages/bot/src/transformers/scheduledEvent.ts index cdeeeee26..f1061336b 100644 --- a/packages/bot/src/transformers/scheduledEvent.ts +++ b/packages/bot/src/transformers/scheduledEvent.ts @@ -1,7 +1,8 @@ import type { DiscordScheduledEvent } from '@discordeno/types' -import { Bot, iconHashToBigInt } from '../index.js' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformScheduledEvent(bot: Bot, payload: DiscordScheduledEvent) { const scheduledEvent = { id: bot.transformers.snowflake(payload.id), @@ -18,7 +19,7 @@ export function transformScheduledEvent(bot: Bot, payload: DiscordScheduledEvent privacyLevel: payload.privacy_level, status: payload.status, entityType: payload.entity_type, - userCount: payload.user_count || 0, + userCount: payload.user_count ?? 0, location: payload.entity_metadata?.location, image: payload.image ? iconHashToBigInt(payload.image) : undefined, } diff --git a/packages/bot/src/transformers/stageInstance.ts b/packages/bot/src/transformers/stageInstance.ts index 3ef9c4036..058855e67 100644 --- a/packages/bot/src/transformers/stageInstance.ts +++ b/packages/bot/src/transformers/stageInstance.ts @@ -2,6 +2,7 @@ import type { DiscordStageInstance } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformStageInstance(bot: Bot, payload: DiscordStageInstance) { const stageInstance = { id: bot.transformers.snowflake(payload.id), diff --git a/packages/bot/src/transformers/sticker.ts b/packages/bot/src/transformers/sticker.ts index 0c2f144b3..41a59dca5 100644 --- a/packages/bot/src/transformers/sticker.ts +++ b/packages/bot/src/transformers/sticker.ts @@ -2,17 +2,18 @@ import type { DiscordSticker, DiscordStickerPack } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformSticker(bot: Bot, payload: DiscordSticker) { const sticker = { - id: bot.utils.snowflakeToBigint(payload.id), - packId: payload.pack_id ? bot.utils.snowflakeToBigint(payload.pack_id) : undefined, + id: bot.transformers.snowflake(payload.id), + packId: payload.pack_id ? bot.transformers.snowflake(payload.pack_id) : undefined, name: payload.name, description: payload.description, tags: payload.tags, type: payload.type, formatType: payload.format_type, available: payload.available, - guildId: payload.guild_id ? bot.utils.snowflakeToBigint(payload.guild_id) : undefined, + guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined, user: payload.user ? bot.transformers.user(bot, payload.user) : undefined, sortValue: payload.sort_value, } @@ -20,6 +21,7 @@ export function transformSticker(bot: Bot, payload: DiscordSticker) { return sticker as Optionalize } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformStickerPack(bot: Bot, payload: DiscordStickerPack) { const pack = { id: bot.transformers.snowflake(payload.id), diff --git a/packages/bot/src/transformers/team.ts b/packages/bot/src/transformers/team.ts index cc6d85f2a..bf05b6ee6 100644 --- a/packages/bot/src/transformers/team.ts +++ b/packages/bot/src/transformers/team.ts @@ -1,7 +1,8 @@ import type { DiscordTeam } from '@discordeno/types' -import { Bot, iconHashToBigInt } from '../index.js' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformTeam(bot: Bot, payload: DiscordTeam) { const id = bot.transformers.snowflake(payload.id) diff --git a/packages/bot/src/transformers/template.ts b/packages/bot/src/transformers/template.ts index 3ed9883dc..db8d9221c 100644 --- a/packages/bot/src/transformers/template.ts +++ b/packages/bot/src/transformers/template.ts @@ -2,6 +2,7 @@ import type { DiscordTemplate } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformTemplate(bot: Bot, payload: DiscordTemplate) { const template = { code: payload.code, diff --git a/packages/bot/src/transformers/threadMember.ts b/packages/bot/src/transformers/threadMember.ts index b444c41f1..b99a241bc 100644 --- a/packages/bot/src/transformers/threadMember.ts +++ b/packages/bot/src/transformers/threadMember.ts @@ -1,8 +1,9 @@ import type { DiscordThreadMember } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' -import type { DiscordThreadMemberGuildCreate } from '../types.js' +import type { DiscordThreadMemberGuildCreate } from '../typings.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformThreadMember(bot: Bot, payload: DiscordThreadMember) { const threadMember = { id: payload.id ? bot.transformers.snowflake(payload.id) : undefined, @@ -14,6 +15,7 @@ export function transformThreadMember(bot: Bot, payload: DiscordThreadMember) { return threadMember as Optionalize } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformThreadMemberGuildCreate(bot: Bot, payload: DiscordThreadMemberGuildCreate) { const threadMember = { joinTimestamp: Date.parse(payload.join_timestamp), diff --git a/packages/bot/src/transformers/toggles/ToggleBitfield.ts b/packages/bot/src/transformers/toggles/ToggleBitfield.ts index 8715c161b..985cefdb1 100644 --- a/packages/bot/src/transformers/toggles/ToggleBitfield.ts +++ b/packages/bot/src/transformers/toggles/ToggleBitfield.ts @@ -6,18 +6,18 @@ export class ToggleBitfield { } /** Tests whether or not this bitfield has the permission requested. */ - contains(bits: number) { + contains(bits: number): boolean { return Boolean(this.bitfield & bits); } /** Adds some bits to the bitfield. */ - add(bits: number) { + add(bits: number): this { this.bitfield |= bits; return this; } /** Removes some bits from the bitfield. */ - remove(bits: number) { + remove(bits: number): this { this.bitfield &= ~bits; return this; } @@ -31,18 +31,18 @@ export class ToggleBitfieldBigint { } /** Tests whether or not this bitfield has the permission requested. */ - contains(bits: bigint) { + contains(bits: bigint): boolean { return Boolean(this.bitfield & bits); } /** Adds some bits to the bitfield. */ - add(bits: bigint) { + add(bits: bigint): this { this.bitfield |= bits; return this; } /** Removes some bits from the bitfield. */ - remove(bits: bigint) { + remove(bits: bigint): this { this.bitfield &= ~bits; return this; } diff --git a/packages/bot/src/transformers/toggles/emoji.ts b/packages/bot/src/transformers/toggles/emoji.ts index d83171a09..d4c8aa829 100644 --- a/packages/bot/src/transformers/toggles/emoji.ts +++ b/packages/bot/src/transformers/toggles/emoji.ts @@ -28,34 +28,34 @@ export class EmojiToggles extends ToggleBitfield { } /** Whether this emoji must be wrapped in colons */ - get requireColons() { + get requireColons(): boolean { return this.has('requireColons') } /** Whether this emoji is managed */ - get managed() { + get managed(): boolean { return this.has('managed') } /** Whether this emoji is animated */ - get animated() { + get animated(): boolean { return this.has('animated') } /** Whether this emoji can be used, may be false due to loss of Server Boosts */ - get available() { + get available(): boolean { return this.has('available') } /** Checks whether or not the permissions exist in this */ - has(permissions: EmojiToggleKeys | EmojiToggleKeys[]) { + has(permissions: EmojiToggleKeys | EmojiToggleKeys[]): boolean { if (!Array.isArray(permissions)) return super.contains(EmojiToggle[permissions]) return super.contains(permissions.reduce((a, b) => (a |= EmojiToggle[b]), 0)) } /** Lists all the toggles for the role and whether or not each is true or false. */ - list() { + list(): Record { const json: Record = {} for (const [key, value] of Object.entries(EmojiToggle)) { json[key] = super.contains(value) diff --git a/packages/bot/src/transformers/toggles/guild.ts b/packages/bot/src/transformers/toggles/guild.ts index d1e80098f..ecfba4fe5 100644 --- a/packages/bot/src/transformers/toggles/guild.ts +++ b/packages/bot/src/transformers/toggles/guild.ts @@ -1,4 +1,4 @@ -import { DiscordGuild, GuildFeatures } from '@discordeno/bot' +import { GuildFeatures, type DiscordGuild } from '@discordeno/bot' import { ToggleBitfieldBigint } from './ToggleBitfield.js' const featureNames = [ @@ -93,7 +93,7 @@ export class GuildToggles extends ToggleBitfieldBigint { constructor(guildOrTogglesBigint: DiscordGuild | bigint) { super() - if (typeof guildOrTogglesBigint == 'bigint') this.bitfield = guildOrTogglesBigint + if (typeof guildOrTogglesBigint === 'bigint') this.bitfield = guildOrTogglesBigint else { const guild = guildOrTogglesBigint // Cause discord be smart like that @@ -133,7 +133,7 @@ export class GuildToggles extends ToggleBitfieldBigint { } } - get features() { + get features(): GuildToggleKeys[] { const features: GuildToggleKeys[] = [] for (const key of Object.keys(GuildToggle)) { if (!featureNames.includes(key)) continue @@ -146,135 +146,154 @@ export class GuildToggles extends ToggleBitfieldBigint { } /** Whether the bot is the owner of the guild */ - get owner() { + get owner(): boolean { return this.has('owner') } /** Whether the server widget is enabled */ - get widgetEnabled() { + get widgetEnabled(): boolean { return this.has('widgetEnabled') } /** Whether this is considered a large guild */ - get large() { + get large(): boolean { return this.has('large') } /** Whether this guild is unavailable due to an outage */ - get unavailable() { + get unavailable(): boolean { return this.has('unavailable') } /** Whether the guild has the boost progress bar enabled */ - get premiumProgressBarEnabled() { + get premiumProgressBarEnabled(): boolean { return this.has('premiumProgressBarEnabled') } /** Whether the guild has access to set an invite splash background */ - get inviteSplash() { + get inviteSplash(): boolean { return this.has('inviteSplash') } + /** Whether the guild has access to set 384 kbps bitrate in voice (previously VIP voice servers) */ - get vipRegions() { + get vipRegions(): boolean { return this.has('vipRegions') } + /** Whether the guild has access to set a vanity URL */ - get vanityUrl() { + get vanityUrl(): boolean { return this.has('vanityUrl') } + /** Whether the guild is verified */ - get verified() { + get verified(): boolean { return this.has('verified') } + /** Whether the guild is partnered */ - get partnered() { + get partnered(): boolean { return this.has('partnered') } + /** Whether the guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates */ - get community() { + get community(): boolean { return this.has('community') } + /** Whether the Guild has been set as a support server on the App Directory */ - get developerSupportServer() { + get developerSupportServer(): boolean { return this.has('developerSupportServer') } + /** Whether the guild has access to set an animated guild banner image */ - get animatedBanner() { + get animatedBanner(): boolean { return this.has('animatedBanner') } + /** Whether the guild has access to create news channels */ - get news() { + get news(): boolean { return this.has('news') } + /** Whether the guild is able to be discovered in the directory */ - get discoverable() { + get discoverable(): boolean { return this.has('discoverable') } + /** Whether the guild is able to be featured in the directory */ - get featurable() { + get featurable(): boolean { return this.has('featurable') } + /** Whether the guild has access to set an animated guild icon */ - get animatedIcon() { + get animatedIcon(): boolean { return this.has('animatedIcon') } + /** Whether the guild has access to set a guild banner image */ - get banner() { + get banner(): boolean { return this.has('banner') } + /** Whether the guild has enabled the welcome screen */ - get welcomeScreenEnabled() { + get welcomeScreenEnabled(): boolean { return this.has('welcomeScreenEnabled') } + /** Whether the guild has enabled [Membership Screening](https://discord.com/developers/docs/resources/guild#membership-screening-object) */ - get memberVerificationGateEnabled() { + get memberVerificationGateEnabled(): boolean { return this.has('memberVerificationGateEnabled') } + /** Whether the guild can be previewed before joining via Membership Screening or the directory */ - get previewEnabled() { + get previewEnabled(): boolean { return this.has('previewEnabled') } + /** Whether the guild has enabled ticketed events */ - get ticketedEventsEnabled() { + get ticketedEventsEnabled(): boolean { return this.has('ticketedEventsEnabled') } + /** Whether the guild has enabled monetization */ - get monetizationEnabled() { + get monetizationEnabled(): boolean { return this.has('monetizationEnabled') } + /** Whether the guild has increased custom sticker slots */ - get moreStickers() { + get moreStickers(): boolean { return this.has('moreStickers') } /** Whether the guild has access to create private threads */ - get privateThreads() { + get privateThreads(): boolean { return this.has('privateThreads') } + /** Whether the guild is able to set role icons */ - get roleIcons() { + get roleIcons(): boolean { return this.has('roleIcons') } /** Whether the guild has set up auto moderation rules */ - get autoModeration() { + get autoModeration(): boolean { return this.has('autoModeration') } /** Whether the guild has paused invites, preventing new users from joining */ - get invitesDisabled() { + get invitesDisabled(): boolean { return this.has('invitesDisabled') } /** Checks whether or not the permissions exist in this */ - has(permissions: GuildToggleKeys | GuildToggleKeys[]) { + has(permissions: GuildToggleKeys | GuildToggleKeys[]): boolean { if (!Array.isArray(permissions)) return super.contains(GuildToggle[permissions]) return super.contains(permissions.reduce((a, b) => (a |= GuildToggle[b]), 0n)) } /** Lists all the toggles for the role and whether or not each is true or false. */ - list() { + list(): Record { const json: Record = {} for (const [key, value] of Object.entries(GuildToggle)) { json[key] = super.contains(value) diff --git a/packages/bot/src/transformers/toggles/member.ts b/packages/bot/src/transformers/toggles/member.ts index 5137e1401..765a23e7c 100644 --- a/packages/bot/src/transformers/toggles/member.ts +++ b/packages/bot/src/transformers/toggles/member.ts @@ -25,29 +25,29 @@ export class MemberToggles extends ToggleBitfield { } /** Whether the user belongs to an OAuth2 application */ - get deaf() { + get deaf(): boolean { return this.has('deaf') } /** Whether the user is muted in voice channels */ - get mute() { + get mute(): boolean { return this.has('mute') } /** Whether the user has not yet passed the guild's Membership Screening requirements */ - get pending() { + get pending(): boolean { return this.has('pending') } /** Checks whether or not the permissions exist in this */ - has(permissions: MemberToggleKeys | MemberToggleKeys[]) { + has(permissions: MemberToggleKeys | MemberToggleKeys[]): boolean { if (!Array.isArray(permissions)) return super.contains(MemberToggle[permissions]) return super.contains(permissions.reduce((a, b) => (a |= MemberToggle[b]), 0)) } /** Lists all the toggles for the role and whether or not each is true or false. */ - list() { + list(): Record { const json: Record = {} for (const [key, value] of Object.entries(MemberToggle)) { json[key] = super.contains(value) diff --git a/packages/bot/src/transformers/toggles/role.ts b/packages/bot/src/transformers/toggles/role.ts index d68083521..581156383 100644 --- a/packages/bot/src/transformers/toggles/role.ts +++ b/packages/bot/src/transformers/toggles/role.ts @@ -28,34 +28,34 @@ export class RoleToggles extends ToggleBitfield { } /** If this role is showed separately in the user listing */ - get hoist() { + get hoist(): boolean { return this.has('hoist') } /** Whether this role is managed by an integration */ - get managed() { + get managed(): boolean { return this.has('managed') } /** Whether this role is mentionable */ - get mentionable() { + get mentionable(): boolean { return this.has('mentionable') } /** Whether this is the guilds premium subscriber role */ - get premiumSubscriber() { + get premiumSubscriber(): boolean { return this.has('premiumSubscriber') } /** Checks whether or not the permissions exist in this */ - has(permissions: RoleToggleKeys | RoleToggleKeys[]) { + has(permissions: RoleToggleKeys | RoleToggleKeys[]): boolean { if (!Array.isArray(permissions)) return super.contains(RoleToggle[permissions]) return super.contains(permissions.reduce((a, b) => (a |= RoleToggle[b]), 0)) } /** Lists all the toggles for the role and whether or not each is true or false. */ - list() { + list(): Record { const json: Record = {} for (const [key, value] of Object.entries(RoleToggle)) { json[key] = super.contains(value) diff --git a/packages/bot/src/transformers/toggles/user.ts b/packages/bot/src/transformers/toggles/user.ts index ebe5df6c2..b69ea1928 100644 --- a/packages/bot/src/transformers/toggles/user.ts +++ b/packages/bot/src/transformers/toggles/user.ts @@ -28,34 +28,34 @@ export class UserToggles extends ToggleBitfield { } /** Whether the user belongs to an OAuth2 application */ - get bot() { + get bot(): boolean { return this.has('bot') } /** Whether the user is an Official Discord System user (part of the urgent message system) */ - get system() { + get system(): boolean { return this.has('system') } /** Whether the user has two factor enabled on their account */ - get mfaEnabled() { + get mfaEnabled(): boolean { return this.has('mfaEnabled') } /** Whether the email on this account has been verified */ - get verified() { + get verified(): boolean { return this.has('verified') } /** Checks whether or not the permissions exist in this */ - has(permissions: UserToggleKeys | UserToggleKeys[]) { + has(permissions: UserToggleKeys | UserToggleKeys[]): boolean { if (!Array.isArray(permissions)) return super.contains(UserToggle[permissions]) return super.contains(permissions.reduce((a, b) => (a |= UserToggle[b]), 0)) } /** Lists all the toggles for the role and whether or not each is true or false. */ - list() { + list(): Record { const json: Record = {} for (const [key, value] of Object.entries(UserToggle)) { json[key] = super.contains(value) diff --git a/packages/bot/src/transformers/toggles/voice.ts b/packages/bot/src/transformers/toggles/voice.ts index c34223bcb..4465fe4e8 100644 --- a/packages/bot/src/transformers/toggles/voice.ts +++ b/packages/bot/src/transformers/toggles/voice.ts @@ -37,49 +37,49 @@ export class VoiceStateToggles extends ToggleBitfield { } /** Whether this user is deafened by the server */ - get deaf() { + get deaf(): boolean { return this.has('deaf') } /** Whether this user is muted by the server */ - get mute() { + get mute(): boolean { return this.has('mute') } /** Whether this user is locally deafened */ - get selfDeaf() { + get selfDeaf(): boolean { return this.has('selfDeaf') } /** Whether this user is locally muted */ - get selfMute() { + get selfMute(): boolean { return this.has('selfMute') } /** Whether this user is streaming using "Go Live" */ - get selfStream() { + get selfStream(): boolean { return this.has('selfStream') } /** Whether this user's camera is enabled */ - get selfVideo() { + get selfVideo(): boolean { return this.has('selfVideo') } /** Whether this user is muted by the current user */ - get suppress() { + get suppress(): boolean { return this.has('suppress') } /** Checks whether or not the permissions exist in this */ - has(permissions: VoiceStateToggleKeys | VoiceStateToggleKeys[]) { + has(permissions: VoiceStateToggleKeys | VoiceStateToggleKeys[]): boolean { if (!Array.isArray(permissions)) return super.contains(VoiceStateToggle[permissions]) return super.contains(permissions.reduce((a, b) => (a |= VoiceStateToggle[b]), 0)) } /** Lists all the toggles for the role and whether or not each is true or false. */ - list() { + list(): Record { const json: Record = {} for (const [key, value] of Object.entries(VoiceStateToggle)) { json[key] = super.contains(value) diff --git a/packages/bot/src/transformers/voiceRegion.ts b/packages/bot/src/transformers/voiceRegion.ts index 461ff7954..a0ae7d8f6 100644 --- a/packages/bot/src/transformers/voiceRegion.ts +++ b/packages/bot/src/transformers/voiceRegion.ts @@ -4,6 +4,7 @@ import type { Optionalize } from '../optionalize.js' // TODO: Rename `VoiceRegions` to `VoiceRegion`. +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformVoiceRegion(bot: Bot, payload: DiscordVoiceRegion) { const voiceRegion = { id: payload.id, diff --git a/packages/bot/src/transformers/voiceState.ts b/packages/bot/src/transformers/voiceState.ts index 0b9bc42d7..4a4d94e9d 100644 --- a/packages/bot/src/transformers/voiceState.ts +++ b/packages/bot/src/transformers/voiceState.ts @@ -3,6 +3,7 @@ import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' import { VoiceStateToggles } from './toggles/voice.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }) { const voiceState = { toggles: new VoiceStateToggles(payload.voiceState), diff --git a/packages/bot/src/transformers/webhook.ts b/packages/bot/src/transformers/webhook.ts index 45a5cb297..d3f3f2227 100644 --- a/packages/bot/src/transformers/webhook.ts +++ b/packages/bot/src/transformers/webhook.ts @@ -1,7 +1,8 @@ import type { DiscordWebhook } from '@discordeno/types' -import { Bot, iconHashToBigInt } from '../index.js' +import { iconHashToBigInt, type Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformWebhook(bot: Bot, payload: DiscordWebhook) { const webhook = { id: bot.transformers.snowflake(payload.id), @@ -9,7 +10,7 @@ export function transformWebhook(bot: Bot, payload: DiscordWebhook) { guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined, channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined, user: payload.user ? bot.transformers.user(bot, payload.user) : undefined, - name: payload.name || '', + name: payload.name ?? '', avatar: payload.avatar ? iconHashToBigInt(payload.avatar) : undefined, token: payload.token, applicationId: payload.application_id ? bot.transformers.snowflake(payload.application_id) : undefined, @@ -24,7 +25,7 @@ export function transformWebhook(bot: Bot, payload: DiscordWebhook) { sourceChannel: payload.source_channel ? { id: bot.transformers.snowflake(payload.source_channel.id!), - name: payload.source_channel.name || '', + name: payload.source_channel.name ?? '', } : undefined, /** The url used for executing the webhook (returned by the webhooks OAuth2 flow) */ diff --git a/packages/bot/src/transformers/welcomeScreen.ts b/packages/bot/src/transformers/welcomeScreen.ts index 2852be551..63a299f74 100644 --- a/packages/bot/src/transformers/welcomeScreen.ts +++ b/packages/bot/src/transformers/welcomeScreen.ts @@ -2,6 +2,7 @@ import type { DiscordWelcomeScreen } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformWelcomeScreen(bot: Bot, payload: DiscordWelcomeScreen) { const welcomeScreen = { description: payload.description ?? undefined, diff --git a/packages/bot/src/transformers/widget.ts b/packages/bot/src/transformers/widget.ts index c54a30599..42a244678 100644 --- a/packages/bot/src/transformers/widget.ts +++ b/packages/bot/src/transformers/widget.ts @@ -3,6 +3,7 @@ import type { DiscordGuildWidget } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformWidget(bot: Bot, payload: DiscordGuildWidget) { const widget = { id: bot.transformers.snowflake(payload.id), diff --git a/packages/bot/src/transformers/widgetSettings.ts b/packages/bot/src/transformers/widgetSettings.ts index 28568be6a..4b3697043 100644 --- a/packages/bot/src/transformers/widgetSettings.ts +++ b/packages/bot/src/transformers/widgetSettings.ts @@ -2,6 +2,7 @@ import type { DiscordGuildWidgetSettings } from '@discordeno/types' import type { Bot } from '../index.js' import type { Optionalize } from '../optionalize.js' +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function transformWidgetSettings(bot: Bot, payload: DiscordGuildWidgetSettings) { const widget = { enabled: payload.enabled, diff --git a/packages/bot/src/types.ts b/packages/bot/src/typings.ts similarity index 86% rename from packages/bot/src/types.ts rename to packages/bot/src/typings.ts index 0e784d462..aabf048f6 100644 --- a/packages/bot/src/types.ts +++ b/packages/bot/src/typings.ts @@ -1,28 +1,28 @@ import { - AllowedMentions, - ApplicationCommandOptionChoice, ApplicationCommandTypes, - ButtonStyles, - CreateApplicationCommand, - CreateContextApplicationCommand, - DiscordAllowedMentions, - DiscordApplicationCommandOptionChoice, - DiscordAttachment, - DiscordChannel, - DiscordEmbed, - DiscordInteractionMember, - DiscordMessage, - DiscordRole, - DiscordSelectOption, - DiscordUser, - FileContent, - InteractionResponseTypes, - MessageComponents, - MessageComponentTypes, - TextStyles, + type AllowedMentions, + type ApplicationCommandOptionChoice, + type ButtonStyles, + type CreateApplicationCommand, + type CreateContextApplicationCommand, + type DiscordAllowedMentions, + type DiscordApplicationCommandOptionChoice, + type DiscordAttachment, + type DiscordChannel, + type DiscordEmbed, + type DiscordInteractionMember, + type DiscordMessage, + type DiscordRole, + type DiscordSelectOption, + type DiscordUser, + type FileContent, + type InteractionResponseTypes, + type MessageComponents, + type MessageComponentTypes, + type TextStyles, } from '@discordeno/types' -import type * as handlers from './handlers/mod.js' -import type { Embed } from './transformers/embed' +import type * as handlers from './handlers/index.js' +import type { Embed } from './transformers/embed.js' export function isContextApplicationCommand(command: CreateApplicationCommand): command is CreateContextApplicationCommand { return command.type === ApplicationCommandTypes.Message || command.type === ApplicationCommandTypes.User @@ -79,7 +79,7 @@ export interface DiscordComponent { max_values?: number /** The minimum input length for a text input. Between 0-4000. */ min_length?: number - /**The maximum input length for a text input. Between 1-4000. */ + /** The maximum input length for a text input. Between 1-4000. */ max_length?: number /** a list of child components */ components?: DiscordComponent[] @@ -101,7 +101,7 @@ export interface BotInteractionCallbackData { /** True if this is a TTS message */ tts?: boolean /** Embedded `rich` content (up to 6000 characters) */ - embeds?: Array + embeds?: Embed[] /** Allowed mentions for the message */ allowedMentions?: AllowedMentions /** The contents of the file being sent */ @@ -118,11 +118,6 @@ export interface BotInteractionCallbackData { choices?: ApplicationCommandOptionChoice[] } -export interface DiscordInteractionResponse { - type: InteractionResponseTypes - data?: DiscordInteractionCallbackData -} - export interface DiscordInteractionDataResolved { /** The Ids and Message objects */ messages?: Record @@ -147,6 +142,12 @@ export interface DiscordThreadMemberGuildCreate { export interface BotGatewayHandlerOptions { READY: typeof handlers.handleReady + APPLICATION_COMMAND_PERMISSIONS_UPDATE: typeof handlers.handleApplicationCommandPermissionsUpdate + AUTO_MODERATION_ACTION_EXECUTION: typeof handlers.handleAutoModerationActionExecution + AUTO_MODERATION_RULE_CREATE: typeof handlers.handleAutoModerationRuleCreate + AUTO_MODERATION_RULE_DELETE: typeof handlers.handleAutoModerationRuleDelete + AUTO_MODERATION_RULE_UPDATE: typeof handlers.handleAutoModerationRuleUpdate + CHANNEL_CREATE: typeof handlers.handleChannelCreate CHANNEL_DELETE: typeof handlers.handleChannelDelete CHANNEL_PINS_UPDATE: typeof handlers.handleChannelPinsUpdate @@ -178,6 +179,7 @@ export interface BotGatewayHandlerOptions { GUILD_SCHEDULED_EVENT_UPDATE: typeof handlers.handleGuildScheduledEventUpdate GUILD_SCHEDULED_EVENT_USER_ADD: typeof handlers.handleGuildScheduledEventUserAdd GUILD_SCHEDULED_EVENT_USER_REMOVE: typeof handlers.handleGuildScheduledEventUserRemove + GUILD_STICKERS_UPDATE: typeof handlers.handleGuildStickersUpdate GUILD_UPDATE: typeof handlers.handleGuildUpdate INTERACTION_CREATE: typeof handlers.handleInteractionCreate INVITE_CREATE: typeof handlers.handleInviteCreate diff --git a/packages/rest/tests/e2e/guild.spec.ts b/packages/rest/tests/e2e/guild.spec.ts index 1ad321619..7689557d8 100644 --- a/packages/rest/tests/e2e/guild.spec.ts +++ b/packages/rest/tests/e2e/guild.spec.ts @@ -110,4 +110,15 @@ describe('Manage Guilds', async () => { it('Get vanity URL', async () => { await expect(rest.getVanityUrl(e2ecache.guild.id)).to.eventually.rejected }) + + // Get a welcome screen + // it('Get welcome screen', async () => { + // const screen = await rest.getWelcomeScreen(e2ecache.guild.id) + // await rest.editWelcomeScreen(e2ecache.guild.id, { + // enabled: true, + // description: 'some description', + // }) + + + // }) }) diff --git a/packages/rest/tests/e2e/message.spec.ts b/packages/rest/tests/e2e/message.spec.ts index 68b42604d..4dd4487fb 100644 --- a/packages/rest/tests/e2e/message.spec.ts +++ b/packages/rest/tests/e2e/message.spec.ts @@ -128,27 +128,26 @@ describe('Manage reactions', async () => { }) }) -describe("Manage pins", () => { -it('Pin, get, and unpin messages', async () => { - const channel = await rest.createChannel(e2ecache.guild.id, { name: 'pinning' }) - const message = await rest.sendMessage(channel.id, { content: 'pin me' }) - const message2 = await rest.sendMessage(channel.id, { content: 'pin me 2' }) +describe('Manage pins', () => { + it('Pin, get, and unpin messages', async () => { + const channel = await rest.createChannel(e2ecache.guild.id, { name: 'pinning' }) + const message = await rest.sendMessage(channel.id, { content: 'pin me' }) + const message2 = await rest.sendMessage(channel.id, { content: 'pin me 2' }) - await rest.pinMessage(channel.id, message.id) - await rest.pinMessage(channel.id, message2.id, 'with a reason') + await rest.pinMessage(channel.id, message.id) + await rest.pinMessage(channel.id, message2.id, 'with a reason') - const pins = await rest.getPinnedMessages(channel.id) - expect(pins.length).to.equal(2) - expect(pins.some(p => p.id === message.id)).to.equal(true) + const pins = await rest.getPinnedMessages(channel.id) + expect(pins.length).to.equal(2) + expect(pins.some((p) => p.id === message.id)).to.equal(true) - await rest.unpinMessage(channel.id, message.id) - await rest.unpinMessage(channel.id, message2.id, 'with a reason') + await rest.unpinMessage(channel.id, message.id) + await rest.unpinMessage(channel.id, message2.id, 'with a reason') - const unpinned = await rest.getPinnedMessages(channel.id) - expect(unpinned.length).to.equal(0) + const unpinned = await rest.getPinnedMessages(channel.id) + expect(unpinned.length).to.equal(0) + }) }) -}) - describe('Rate limit manager testing', () => { it('Send 10 messages to 1 channel', async () => { diff --git a/packages/types/src/shared.ts b/packages/types/src/shared.ts index fed53662b..ccce3e39b 100644 --- a/packages/types/src/shared.ts +++ b/packages/types/src/shared.ts @@ -700,6 +700,7 @@ export type GatewayDispatchEventNames = | 'THREAD_LIST_SYNC' | 'THREAD_MEMBER_UPDATE' | 'THREAD_MEMBERS_UPDATE' + | 'GUILD_AUDIT_LOG_ENTRY_CREATE' | 'GUILD_CREATE' | 'GUILD_UPDATE' | 'GUILD_DELETE' diff --git a/packages/utils/package.json b/packages/utils/package.json index 0ca9c8ada..88f3f59d0 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -16,7 +16,7 @@ "fmt": "eslint --fix \"src/**/*.ts*\"", "lint": "eslint \"src/**/*.ts*\"", "test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'", - "test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js utils", + "test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/bucket.spec.ts' && node ../../scripts/coveragePathFixing.js utils", "test:deno-unit": "swc tests --delete-dir-on-start -C jsc.minify.mangle=false --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist", "test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'", "test:type": "tsc --noEmit", diff --git a/packages/utils/src/bucket.ts b/packages/utils/src/bucket.ts index 05a8ba0c4..d522a676e 100644 --- a/packages/utils/src/bucket.ts +++ b/packages/utils/src/bucket.ts @@ -28,6 +28,22 @@ export class LeakyBucket implements LeakyBucketOptions { return this.max < this.used ? 0 : this.max - this.used } + /** Refills the bucket as needed. */ + refillBucket(): void { + console.log('refilling bucket'); + logger.info(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`) + // Lower the used amount by the refill amount + this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount + // Reset the refillsAt timestamp since it just got refilled + this.refillsAt = undefined + + if (this.used > 0) { + if (this.timeoutId) clearTimeout(this.timeoutId) + this.timeoutId = setTimeout(() => this.refillBucket, this.refillInterval) + this.refillsAt = Date.now() + this.refillInterval + } + } + /** Begin processing the queue. */ async processQueue(): Promise { logger.debug('[Gateway] Processing queue') @@ -49,13 +65,8 @@ export class LeakyBucket implements LeakyBucketOptions { // Create a new timeout for this request if none exists. if (!this.timeoutId) { logger.debug(`[LeakyBucket] Creating new timeout for leaky bucket requests.`) - this.timeoutId = setTimeout(() => { - logger.debug(`[LeakyBucket] Timeout for leaky bucket requests executed. Refilling bucket.`) - // Lower the used amount by the refill amount - this.used -= this.refillAmount - // Reset the refillsAt timestamp since it just got refilled - this.refillsAt = undefined - }, this.refillInterval) + + this.timeoutId = setTimeout(() => this.refillBucket, this.refillInterval) // Set the time for when this refill will occur. this.refillsAt = Date.now() + this.refillInterval } diff --git a/packages/utils/tests/bucket.spec.ts b/packages/utils/tests/bucket.spec.ts index 6275306df..df1a8a8dc 100644 --- a/packages/utils/tests/bucket.spec.ts +++ b/packages/utils/tests/bucket.spec.ts @@ -62,5 +62,26 @@ describe('bucket.ts', () => { }) expect(bucket.queue).to.deep.equal([]) }) + + it('idk', async () => { + const bucket = new LeakyBucket({ + max: 2, + refillInterval: 500, + refillAmount: 2, + }) + + const now = Date.now() + await bucket.acquire() + + console.log((Date.now() - now), bucket.used, bucket.remaining) + await clock.tickAsync(1000) + console.log((Date.now() - now), bucket.used, bucket.remaining) + + await bucket.acquire() + + console.log((Date.now() - now), bucket.used, bucket.remaining) + await clock.tickAsync(1000) + console.log((Date.now() - now), bucket.used, bucket.remaining) + }) }) })