fix: ts errors

This commit is contained in:
Skillz4Killz
2023-03-26 12:34:41 +00:00
parent fe81c94fc0
commit 39bac9fe0e
141 changed files with 546 additions and 417 deletions
+34 -23
View File
@@ -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<EventHandlers>
/** A logger utility to make it easy to log nice and useful things in the bot code. */
logger: ReturnType<typeof createLogger>
/** 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<typeof createBotGatewayHandlers>
/** Start the bot connection to the gateway. */
start: () => Promise<void>
/** 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
@@ -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<BotGatewayHandlerOptions>,
): Record<GatewayDispatchEventNames, (bot: Bot, data: DiscordGatewayPayload, shardId: number) => 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<typeof createBotGatewayHandlers> {}
@@ -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<void> {
const channel = bot.transformers.channel(bot, {
channel: payload.d as DiscordChannel,
})
@@ -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<void> {
const payload = data.d as DiscordChannel
if (!payload.guild_id) return
@@ -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<void> {
const payload = data.d as DiscordChannelPinsUpdate
bot.events.channelPinsUpdate?.({
@@ -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<void> {
const payload = data.d as DiscordChannel
const channel = bot.transformers.channel(bot, { channel: payload })
@@ -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<void> {
const payload = data.d as DiscordStageInstance
bot.events.stageInstanceCreate?.({
@@ -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<void> {
const payload = data.d as DiscordStageInstance
bot.events.stageInstanceDelete?.({
@@ -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<void> {
const payload = data.d as DiscordStageInstance
bot.events.stageInstanceUpdate?.({
@@ -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<void> {
const payload = data.d as DiscordChannel
bot.events.threadCreate?.(bot.transformers.channel(bot, { channel: payload }))
@@ -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<void> {
const payload = data.d as DiscordChannel
bot.events.threadDelete?.(bot.transformers.channel(bot, { channel: payload }))
@@ -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<void> {
const payload = data.d as DiscordThreadListSync
const guildId = bot.transformers.snowflake(payload.guild_id)
@@ -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<void> {
const payload = data.d as DiscordThreadMembersUpdate
bot.events.threadMembersUpdate?.({
@@ -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<void> {
const payload = data.d as DiscordThreadMemberUpdate
bot.events.threadMemberUpdate?.({
@@ -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<void> {
const payload = data.d as DiscordChannel
bot.events.threadUpdate?.(bot.transformers.channel(bot, { channel: payload }))
@@ -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<void> {
const payload = data.d as DiscordGuildEmojisUpdate
bot.events.guildEmojisUpdate?.({
@@ -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<void> {
// 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))
@@ -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<void> {
const payload = data.d as DiscordGuildBanAddRemove
bot.events.guildBanAdd?.(bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id))
}
@@ -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<void> {
const payload = data.d as DiscordGuildBanAddRemove
await bot.events.guildBanRemove?.(bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id))
@@ -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<void> {
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 }))
}
@@ -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<void> {
const payload = data.d as DiscordUnavailableGuild
bot.events.guildDelete?.(bot.transformers.snowflake(payload.id), shardId)
}
@@ -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<void> {
const payload = data.d as DiscordGuildIntegrationsUpdate
bot.events.integrationUpdate?.({
@@ -0,0 +1,12 @@
import type { Bot, DiscordGatewayPayload, DiscordGuildStickersUpdate } from '../..'
export async function handleGuildStickersUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise<void> {
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)
})
)
}
@@ -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<void> {
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 }))
}
@@ -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<void> {
const payload = data.d as DiscordAutoModerationActionExecution
bot.events.automodActionExecution?.(bot.events.automodActionExecution(payload))
bot.events.automodActionExecution?.(bot.transformers.automodActionExecution(bot, payload))
}
@@ -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<void> {
const payload = data.d as DiscordAutoModerationRule
bot.events.automodRuleCreate?.(bot.events.automodRule(payload))
bot.events.automodRuleCreate?.(bot.transformers.automodRule(bot, payload))
}
@@ -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<void> {
const payload = data.d as DiscordAutoModerationRule
bot.events.automodRuleDelete?.(bot.events.automodRule(payload))
bot.events.automodRuleDelete?.(bot.transformers.automodRule(bot, payload))
}
@@ -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<void> {
const payload = data.d as DiscordAutoModerationRule
bot.events.automodRuleUpdate?.(bot.transformers.automodRule(bot, payload))
}
@@ -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'
@@ -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";
@@ -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<void> {
const payload = data.d as DiscordScheduledEvent
bot.events.scheduledEventCreate?.(bot.transformers.scheduledEvent(bot, payload))
}
@@ -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<void> {
const payload = data.d as DiscordScheduledEvent
bot.events.scheduledEventDelete?.(bot.transformers.scheduledEvent(bot, payload))
}
@@ -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<void> {
const payload = data.d as DiscordScheduledEvent
bot.events.scheduledEventUpdate?.(bot.transformers.scheduledEvent(bot, payload))
}
@@ -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<void> {
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),
@@ -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<void> {
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),
+12
View File
@@ -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'
@@ -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<void> {
bot.events.integrationCreate?.(bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate))
}
@@ -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<void> {
const payload = data.d as DiscordIntegrationDelete
bot.events.integrationDelete?.({
@@ -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<void> {
bot.events.integrationUpdate?.(bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate))
}
@@ -0,0 +1,6 @@
import type { Bot, DiscordGatewayPayload, DiscordGuildApplicationCommandPermissions } from "../..";
export async function handleApplicationCommandPermissionsUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise<void> {
const payload = data.d as DiscordGuildApplicationCommandPermissions
bot.events.applicationCommandPermissionsUpdate?.(bot.transformers.applicationCommandPermission(bot, payload))
}
@@ -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<void> {
bot.events.interactionCreate?.(bot.transformers.interaction(bot, data.d as DiscordInteraction))
}
@@ -0,0 +1,2 @@
export * from './APPLICATION_COMMAND_PERMISSIONS_UPDATE.js'
export * from './INTERACTION_CREATE.js'
@@ -1 +0,0 @@
export * from "./INTERACTION_CREATE.js";
@@ -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<void> {
bot.events.inviteCreate?.(bot.transformers.invite(bot, data.d as DiscordInviteCreate))
}
@@ -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<void> {
const payload = data.d as DiscordInviteDelete
bot.events.inviteDelete?.({
@@ -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<any> {
const payload = data.d as DiscordGuildMembersChunk
const guildId = bot.transformers.snowflake(payload.guild_id)
@@ -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<void> {
const payload = data.d as DiscordGuildMemberAdd
const guildId = bot.transformers.snowflake(payload.guild_id)
const user = bot.transformers.user(bot, payload.user)
@@ -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<void> {
const payload = data.d as DiscordGuildMemberRemove
const guildId = bot.transformers.snowflake(payload.guild_id)
const user = bot.transformers.user(bot, payload.user)
@@ -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<void> {
const payload = data.d as DiscordGuildMemberUpdate
const user = bot.transformers.user(bot, payload.user)
@@ -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<void> {
const payload = data.d as DiscordMessage
bot.events.messageCreate?.(bot.events.message(payload))
bot.events.messageCreate?.(bot.transformers.message(bot, payload))
}
@@ -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<void> {
const payload = data.d as DiscordMessageDelete
bot.events.messageDelete?.({
@@ -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<void> {
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,
})
}
@@ -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<void> {
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),
})
}
@@ -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<void> {
const payload = data.d as DiscordMessageReactionRemove
bot.events.reactionRemove?.({
@@ -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<void> {
const payload = data.d as DiscordMessageReactionRemoveAll
bot.events.reactionRemoveAll?.({
@@ -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<void> {
const payload = data.d as DiscordMessageReactionRemoveEmoji
bot.events.reactionRemoveEmoji?.({
@@ -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<void> {
const payload = data.d as DiscordMessage
if (!payload.edited_timestamp) return
@@ -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<void> {
bot.events.presenceUpdate?.(bot.transformers.presence(bot, data.d as DiscordPresenceUpdate))
}
+1 -1
View File
@@ -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<void> {
const payload = data.d as DiscordReady
// Triggered on each shard
bot.events.ready?.(
@@ -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<void> {
const payload = data.d as DiscordTypingStart
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
@@ -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<void> {
const payload = data.d as DiscordUser
bot.events.botUpdate?.(bot.transformers.user(bot, payload))
}
-12
View File
@@ -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";
@@ -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<void> {
const payload = data.d as DiscordGuildRoleCreate
bot.events.roleCreate?.(
bot.transformers.role(bot, {
@@ -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<void> {
const payload = data.d as DiscordGuildRoleDelete
bot.events.roleDelete?.({
roleId: bot.transformers.snowflake(payload.role_id),
@@ -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<void> {
const payload = data.d as DiscordGuildRoleUpdate
bot.events.roleUpdate?.(
@@ -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<void> {
const payload = data.d as DiscordVoiceServerUpdate
bot.events.voiceServerUpdate?.({
@@ -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<void> {
const payload = data.d as DiscordVoiceState
if (!payload.guild_id) return
@@ -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<void> {
const payload = data.d as DiscordWebhookUpdate
bot.events.webhooksUpdate?.({
channelId: bot.transformers.snowflake(payload.channel_id),
+2 -2
View File
@@ -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'
@@ -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<Transformers>) {
export function createTransformers(options: Partial<Transformers>): 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,
}
}
@@ -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,
+3 -2
View File
@@ -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,
@@ -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),
@@ -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,
@@ -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),
@@ -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),
@@ -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,
@@ -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,
@@ -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,
+8 -7
View File
@@ -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),
+3 -5
View File
@@ -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[]
+1
View File
@@ -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,
+2 -1
View File
@@ -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),
@@ -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,
+2 -1
View File
@@ -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,
@@ -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'
+2 -1
View File
@@ -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),
+7 -4
View File
@@ -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<typeof interaction>
}
// 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<typeof opt>
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function transformInteractionDataResolved(bot: Bot, resolved: DiscordInteractionDataResolved, guildId?: bigint) {
const transformed: {
messages?: Collection<bigint, Message>
@@ -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)]
}),
)
}

Some files were not shown because too many files have changed in this diff Show More