mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 09:20:08 +00:00
fix: remove old pkg
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"all": true,
|
||||
"src": "src",
|
||||
"reporter": ["text", "lcov"],
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["tests"]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"require": "ts-node/register",
|
||||
"loader": "ts-node/esm",
|
||||
"recursive": true,
|
||||
"timeout": 2000,
|
||||
"watch-extensions": "ts",
|
||||
"watch-files": ["src", "tests"],
|
||||
"enable-source-maps": true,
|
||||
"parallel": false
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"minify": true,
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true,
|
||||
"dynamicImport": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
},
|
||||
"target": "es2022",
|
||||
"keepClassNames": true,
|
||||
"loose": true,
|
||||
"minify": {
|
||||
"compress": {
|
||||
"unused": true
|
||||
},
|
||||
"mangle": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6",
|
||||
"strict": false,
|
||||
"strictMode": true,
|
||||
"lazy": false,
|
||||
"noInterop": false
|
||||
},
|
||||
"sourceMaps": "inline"
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
{
|
||||
"name": "@discordeno/client",
|
||||
"version": "18.0.0-alpha.1",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"type": "module",
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordeno/discordeno.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "swc --delete-dir-on-start src --out-dir dist",
|
||||
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
|
||||
"release-build": "yarn build && yarn build:type",
|
||||
"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 client",
|
||||
"test:deno-unit": "swc tests --delete-dir-on-start --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",
|
||||
"test:test-type": "tsc --project tsconfig.test.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordeno/gateway": "18.0.0-alpha.1",
|
||||
"@discordeno/rest": "18.0.0-alpha.1",
|
||||
"@discordeno/utils": "18.0.0-alpha.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@discordeno/types": "18.0.0-alpha.1",
|
||||
"@swc/cli": "^0.1.57",
|
||||
"@swc/core": "^1.3.21",
|
||||
"@types/chai": "^4",
|
||||
"@types/mocha": "^10",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/sinon": "^10.0.13",
|
||||
"c8": "^7.12.0",
|
||||
"chai": "^4.3.7",
|
||||
"eslint": "^8.0.1",
|
||||
"eslint-config-discordeno": "*",
|
||||
"mocha": "^10.1.0",
|
||||
"sinon": "^15.0.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig": "*",
|
||||
"typescript": "^4.9.3"
|
||||
}
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
import type { CreateShardManager, GatewayManager } from '@discordeno/gateway'
|
||||
import type { CreateRestManagerOptions } from '@discordeno/rest'
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
GatewayDispatchEventNames,
|
||||
GatewayIntents,
|
||||
GetGatewayBot
|
||||
} from '@discordeno/types'
|
||||
import { Errors } from '@discordeno/types'
|
||||
import {
|
||||
baseEndpoints,
|
||||
bigintToSnowflake,
|
||||
calculateBits,
|
||||
calculatePermissions,
|
||||
calculateShardId,
|
||||
CHANNEL_MENTION_REGEX,
|
||||
CONTEXT_MENU_COMMANDS_NAME_REGEX,
|
||||
delay,
|
||||
DISCORDENO_VERSION,
|
||||
DISCORD_SNOWFLAKE_REGEX,
|
||||
formatImageURL,
|
||||
getBotIdFromToken,
|
||||
iconBigintToHash,
|
||||
iconHashToBigInt,
|
||||
removeTokenPrefix,
|
||||
SLASH_COMMANDS_NAME_REGEX,
|
||||
snowflakeToBigint,
|
||||
urlToBase64,
|
||||
USER_AGENT,
|
||||
validateLength
|
||||
} from '@discordeno/utils'
|
||||
import {
|
||||
createClientGatewayHandlers,
|
||||
createEventHandlers,
|
||||
type EventHandlers
|
||||
} from './handlers.js'
|
||||
import type { Transformers } from './transformer.js'
|
||||
import { createTransformers } from './transformer.js'
|
||||
|
||||
export function createClient (options: CreateClientOptions): Client {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const client = {
|
||||
id: options.botId ?? getBotIdFromToken(options.token),
|
||||
applicationId:
|
||||
options.applicationId ??
|
||||
options.botId ??
|
||||
getBotIdFromToken(options.token),
|
||||
token: removeTokenPrefix(options.token),
|
||||
events: createEventHandlers(options.events ?? {}),
|
||||
intents: options.intents,
|
||||
activeGuildIds: new Set<bigint>(),
|
||||
constants: createClientConstants(),
|
||||
handlers: createClientGatewayHandlers({}),
|
||||
utils: createUtils(options.utils ?? {}),
|
||||
transformers: createTransformers(options.transformers ?? {}),
|
||||
enabledPlugins: new Set(),
|
||||
handleDiscordPayload:
|
||||
options.handleDiscordPayload ??
|
||||
async function (shard, data: DiscordGatewayPayload) {
|
||||
// TRIGGER RAW EVENT
|
||||
client.events.raw(client, data, shard.id)
|
||||
|
||||
if (!data.t) return
|
||||
|
||||
// RUN DISPATCH CHECK
|
||||
await client.events.dispatchRequirements(client, data, shard.id)
|
||||
client.handlers[data.t as GatewayDispatchEventNames]?.(
|
||||
client,
|
||||
data,
|
||||
shard.id
|
||||
)
|
||||
},
|
||||
cache: {
|
||||
unrepliedInteractions: new Set<bigint>(),
|
||||
fetchAllMembersProcessingRequests: new Map()
|
||||
}
|
||||
} as Client
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function createUtils (options: Partial<HelperUtils>) {
|
||||
return {
|
||||
snowflakeToBigint,
|
||||
bigintToSnowflake,
|
||||
calculateShardId: (gateway: GatewayManager, guildId: bigint) =>
|
||||
calculateShardId(gateway.manager.totalShards, guildId),
|
||||
delay,
|
||||
iconHashToBigInt,
|
||||
iconBigintToHash,
|
||||
validateLength,
|
||||
urlToBase64,
|
||||
formatImageURL,
|
||||
calculateBits,
|
||||
calculatePermissions
|
||||
}
|
||||
}
|
||||
|
||||
export interface HelperUtils {
|
||||
snowflakeToBigint: typeof snowflakeToBigint
|
||||
bigintToSnowflake: typeof bigintToSnowflake
|
||||
calculateShardId: (
|
||||
gateway: GatewayManager,
|
||||
guildId: bigint
|
||||
) => ReturnType<typeof calculateShardId>
|
||||
delay: typeof delay
|
||||
iconHashToBigInt: typeof iconHashToBigInt
|
||||
iconBigintToHash: typeof iconBigintToHash
|
||||
validateLength: typeof validateLength
|
||||
urlToBase64: typeof urlToBase64
|
||||
formatImageURL: typeof formatImageURL
|
||||
calculateBits: typeof calculateBits
|
||||
calculatePermissions: typeof calculatePermissions
|
||||
}
|
||||
|
||||
export interface CreateClientOptions {
|
||||
token: string
|
||||
botId?: bigint
|
||||
applicationId?: bigint
|
||||
secretKey?: string
|
||||
events?: Partial<EventHandlers>
|
||||
intents?: GatewayIntents
|
||||
botGatewayData?: GetGatewayBot
|
||||
rest?: Omit<CreateRestManagerOptions, 'token'>
|
||||
handleDiscordPayload?: CreateShardManager['handleMessage']
|
||||
utils?: Partial<ReturnType<typeof createUtils>>
|
||||
transformers?: Partial<ReturnType<typeof createTransformers>>
|
||||
}
|
||||
|
||||
export type UnPromise<T extends Promise<unknown>> = T extends Promise<infer K>
|
||||
? K
|
||||
: never
|
||||
|
||||
export interface Client {
|
||||
id: bigint
|
||||
applicationId: bigint
|
||||
token: string
|
||||
intents: GatewayIntents
|
||||
urlWSS: string
|
||||
utils: ReturnType<typeof createUtils>
|
||||
transformers: Transformers
|
||||
events: EventHandlers
|
||||
handlers: ReturnType<typeof createClientGatewayHandlers>
|
||||
activeGuildIds: Set<bigint>
|
||||
constants: ReturnType<typeof createClientConstants>
|
||||
cache: {
|
||||
unrepliedInteractions: Set<bigint>
|
||||
fetchAllMembersProcessingRequests: Map<string, Function>
|
||||
}
|
||||
enabledPlugins: Set<string>
|
||||
handleDiscordPayload?: CreateShardManager['handleMessage']
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function createClientConstants () {
|
||||
return {
|
||||
DISCORDENO_VERSION,
|
||||
USER_AGENT,
|
||||
BASE_URL: baseEndpoints.BASE_URL,
|
||||
CDN_URL: baseEndpoints.CDN_URL,
|
||||
regexes: {
|
||||
SLASH_COMMANDS_NAME_REGEX,
|
||||
CONTEXT_MENU_COMMANDS_NAME_REGEX,
|
||||
CHANNEL_MENTION_REGEX,
|
||||
DISCORD_SNOWFLAKE_REGEX
|
||||
},
|
||||
Errors
|
||||
}
|
||||
}
|
||||
@@ -1,528 +0,0 @@
|
||||
import type {
|
||||
DiscordEmoji,
|
||||
DiscordGatewayPayload,
|
||||
DiscordReady,
|
||||
DiscordSticker,
|
||||
GatewayDispatchEventNames
|
||||
} from '@discordeno/types'
|
||||
import type { Collection } from '@discordeno/utils'
|
||||
import type { Client } from './client.js'
|
||||
import * as handlers from './handlers/index.js'
|
||||
import type {
|
||||
ApplicationCommandPermission,
|
||||
AutoModerationActionExecution,
|
||||
AutoModerationRule,
|
||||
Channel,
|
||||
Emoji,
|
||||
Guild,
|
||||
Integration,
|
||||
Interaction,
|
||||
Invite,
|
||||
Member,
|
||||
Message,
|
||||
PresenceUpdate,
|
||||
Role,
|
||||
ScheduledEvent,
|
||||
ThreadMember,
|
||||
User,
|
||||
VoiceState
|
||||
} from './transformer.js'
|
||||
|
||||
export function createEventHandlers (
|
||||
events: Partial<EventHandlers>
|
||||
): EventHandlers {
|
||||
function ignore (): void {}
|
||||
|
||||
return {
|
||||
debug: events.debug ?? ignore,
|
||||
automodRuleCreate: events.automodRuleCreate ?? ignore,
|
||||
automodRuleUpdate: events.automodRuleUpdate ?? ignore,
|
||||
automodRuleDelete: events.automodRuleDelete ?? ignore,
|
||||
automodActionExecution: events.automodActionExecution ?? ignore,
|
||||
threadCreate: events.threadCreate ?? ignore,
|
||||
threadDelete: events.threadDelete ?? ignore,
|
||||
threadMemberUpdate: events.threadMemberUpdate ?? ignore,
|
||||
threadMembersUpdate: events.threadMembersUpdate ?? ignore,
|
||||
threadUpdate: events.threadUpdate ?? ignore,
|
||||
scheduledEventCreate: events.scheduledEventCreate ?? ignore,
|
||||
scheduledEventUpdate: events.scheduledEventUpdate ?? ignore,
|
||||
scheduledEventDelete: events.scheduledEventDelete ?? ignore,
|
||||
scheduledEventUserAdd: events.scheduledEventUserAdd ?? ignore,
|
||||
scheduledEventUserRemove: events.scheduledEventUserRemove ?? ignore,
|
||||
ready: events.ready ?? ignore,
|
||||
dispatchRequirements: events.dispatchRequirements ?? ignore,
|
||||
integrationCreate: events.integrationCreate ?? ignore,
|
||||
integrationDelete: events.integrationDelete ?? ignore,
|
||||
integrationUpdate: events.integrationUpdate ?? ignore,
|
||||
interactionCreate: events.interactionCreate ?? ignore,
|
||||
inviteCreate: events.inviteCreate ?? ignore,
|
||||
inviteDelete: events.inviteDelete ?? ignore,
|
||||
guildMemberAdd: events.guildMemberAdd ?? ignore,
|
||||
guildMemberRemove: events.guildMemberRemove ?? ignore,
|
||||
guildMemberUpdate: events.guildMemberUpdate ?? ignore,
|
||||
messageCreate: events.messageCreate ?? ignore,
|
||||
messageDelete: events.messageDelete ?? ignore,
|
||||
messageDeleteBulk: events.messageDeleteBulk ?? ignore,
|
||||
messageUpdate: events.messageUpdate ?? ignore,
|
||||
reactionAdd: events.reactionAdd ?? ignore,
|
||||
reactionRemove: events.reactionRemove ?? ignore,
|
||||
reactionRemoveAll: events.reactionRemoveAll ?? ignore,
|
||||
reactionRemoveEmoji: events.reactionRemoveEmoji ?? ignore,
|
||||
presenceUpdate: events.presenceUpdate ?? ignore,
|
||||
voiceServerUpdate: events.voiceServerUpdate ?? ignore,
|
||||
voiceStateUpdate: events.voiceStateUpdate ?? ignore,
|
||||
channelCreate: events.channelCreate ?? ignore,
|
||||
channelDelete: events.channelDelete ?? ignore,
|
||||
channelPinsUpdate: events.channelPinsUpdate ?? ignore,
|
||||
channelUpdate: events.channelUpdate ?? ignore,
|
||||
guildEmojisUpdate: events.guildEmojisUpdate ?? ignore,
|
||||
guildStickersUpdate: events.guildStickersUpdate ?? ignore,
|
||||
guildBanAdd: events.guildBanAdd ?? ignore,
|
||||
guildBanRemove: events.guildBanRemove ?? ignore,
|
||||
guildCreate: events.guildCreate ?? ignore,
|
||||
guildDelete: events.guildDelete ?? ignore,
|
||||
guildUpdate: events.guildUpdate ?? ignore,
|
||||
raw: events.raw ?? ignore,
|
||||
stageInstanceCreate: events.stageInstanceCreate ?? ignore,
|
||||
stageInstanceDelete: events.stageInstanceDelete ?? ignore,
|
||||
stageInstanceUpdate: events.stageInstanceUpdate ?? ignore,
|
||||
roleCreate: events.roleCreate ?? ignore,
|
||||
roleDelete: events.roleDelete ?? ignore,
|
||||
roleUpdate: events.roleUpdate ?? ignore,
|
||||
webhooksUpdate: events.webhooksUpdate ?? ignore,
|
||||
botUpdate: events.botUpdate ?? ignore,
|
||||
typingStart: events.typingStart ?? ignore,
|
||||
applicationCommandPermissionsUpdate:
|
||||
events.applicationCommandPermissionsUpdate ?? ignore
|
||||
}
|
||||
}
|
||||
|
||||
export interface EventHandlers {
|
||||
debug: (text: string, ...args: any[]) => unknown
|
||||
applicationCommandPermissionsUpdate: (
|
||||
client: Client,
|
||||
command: ApplicationCommandPermission
|
||||
) => unknown
|
||||
automodRuleCreate: (client: Client, rule: AutoModerationRule) => unknown
|
||||
automodRuleUpdate: (client: Client, rule: AutoModerationRule) => unknown
|
||||
automodRuleDelete: (client: Client, rule: AutoModerationRule) => unknown
|
||||
automodActionExecution: (
|
||||
client: Client,
|
||||
payload: AutoModerationActionExecution
|
||||
) => unknown
|
||||
threadCreate: (client: Client, thread: Channel) => unknown
|
||||
threadDelete: (client: Client, thread: Channel) => unknown
|
||||
threadMemberUpdate: (
|
||||
client: Client,
|
||||
payload: {
|
||||
id: bigint
|
||||
guildId: bigint
|
||||
joinedAt: number
|
||||
flags: number
|
||||
}
|
||||
) => unknown
|
||||
threadMembersUpdate: (
|
||||
client: Client,
|
||||
payload: {
|
||||
id: bigint
|
||||
guildId: bigint
|
||||
addedMembers?: ThreadMember[]
|
||||
removedMemberIds?: bigint[]
|
||||
}
|
||||
) => unknown
|
||||
threadUpdate: (client: Client, thread: Channel) => unknown
|
||||
scheduledEventCreate: (client: Client, event: ScheduledEvent) => unknown
|
||||
scheduledEventUpdate: (client: Client, event: ScheduledEvent) => unknown
|
||||
scheduledEventDelete: (client: Client, event: ScheduledEvent) => unknown
|
||||
/** Sent when a user has subscribed to a guild scheduled event. EXPERIMENTAL! */
|
||||
scheduledEventUserAdd: (
|
||||
client: Client,
|
||||
payload: {
|
||||
guildScheduledEventId: bigint
|
||||
guildId: bigint
|
||||
userId: bigint
|
||||
}
|
||||
) => unknown
|
||||
/** Sent when a user has unsubscribed to a guild scheduled event. EXPERIMENTAL! */
|
||||
scheduledEventUserRemove: (
|
||||
client: Client,
|
||||
payload: {
|
||||
guildScheduledEventId: bigint
|
||||
guildId: bigint
|
||||
userId: bigint
|
||||
}
|
||||
) => unknown
|
||||
ready: (
|
||||
client: Client,
|
||||
payload: {
|
||||
shardId: number
|
||||
v: number
|
||||
user: User
|
||||
guilds: bigint[]
|
||||
sessionId: string
|
||||
shard?: number[]
|
||||
applicationId: bigint
|
||||
},
|
||||
rawPayload: DiscordReady
|
||||
) => unknown
|
||||
interactionCreate: (client: Client, interaction: Interaction) => unknown
|
||||
integrationCreate: (client: Client, integration: Integration) => unknown
|
||||
integrationDelete: (
|
||||
client: Client,
|
||||
payload: { id: bigint, guildId: bigint, applicationId?: bigint }
|
||||
) => unknown
|
||||
integrationUpdate: (client: Client, payload: { guildId: bigint }) => unknown
|
||||
inviteCreate: (client: Client, invite: Invite) => unknown
|
||||
inviteDelete: (
|
||||
client: Client,
|
||||
payload: {
|
||||
channelId: bigint
|
||||
guildId?: bigint
|
||||
code: string
|
||||
}
|
||||
) => unknown
|
||||
guildMemberAdd: (client: Client, member: Member, user: User) => unknown
|
||||
guildMemberRemove: (client: Client, user: User, guildId: bigint) => unknown
|
||||
guildMemberUpdate: (client: Client, member: Member, user: User) => unknown
|
||||
messageCreate: (client: Client, message: Message) => unknown
|
||||
messageDelete: (
|
||||
client: Client,
|
||||
payload: { id: bigint, channelId: bigint, guildId?: bigint },
|
||||
message?: Message
|
||||
) => unknown
|
||||
messageDeleteBulk: (
|
||||
client: Client,
|
||||
payload: { ids: bigint[], channelId: bigint, guildId?: bigint }
|
||||
) => unknown
|
||||
messageUpdate: (
|
||||
client: Client,
|
||||
message: Message,
|
||||
oldMessage?: Message
|
||||
) => unknown
|
||||
reactionAdd: (
|
||||
client: Client,
|
||||
payload: {
|
||||
userId: bigint
|
||||
channelId: bigint
|
||||
messageId: bigint
|
||||
guildId?: bigint
|
||||
member?: Member
|
||||
user?: User
|
||||
emoji: Emoji
|
||||
}
|
||||
) => unknown
|
||||
reactionRemove: (
|
||||
client: Client,
|
||||
payload: {
|
||||
userId: bigint
|
||||
channelId: bigint
|
||||
messageId: bigint
|
||||
guildId?: bigint
|
||||
emoji: Emoji
|
||||
}
|
||||
) => unknown
|
||||
reactionRemoveEmoji: (
|
||||
client: Client,
|
||||
payload: {
|
||||
channelId: bigint
|
||||
messageId: bigint
|
||||
guildId?: bigint
|
||||
emoji: Emoji
|
||||
}
|
||||
) => unknown
|
||||
reactionRemoveAll: (
|
||||
client: Client,
|
||||
payload: {
|
||||
channelId: bigint
|
||||
messageId: bigint
|
||||
guildId?: bigint
|
||||
}
|
||||
) => unknown
|
||||
presenceUpdate: (
|
||||
client: Client,
|
||||
presence: PresenceUpdate,
|
||||
oldPresence?: PresenceUpdate
|
||||
) => unknown
|
||||
voiceServerUpdate: (
|
||||
client: Client,
|
||||
payload: { token: string, endpoint?: string, guildId: bigint }
|
||||
) => unknown
|
||||
voiceStateUpdate: (client: Client, voiceState: VoiceState) => unknown
|
||||
channelCreate: (client: Client, channel: Channel) => unknown
|
||||
dispatchRequirements: (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
) => unknown
|
||||
channelDelete: (client: Client, channel: Channel) => unknown
|
||||
channelPinsUpdate: (
|
||||
client: Client,
|
||||
data: { guildId?: bigint, channelId: bigint, lastPinTimestamp?: number }
|
||||
) => unknown
|
||||
channelUpdate: (client: Client, channel: Channel) => unknown
|
||||
stageInstanceCreate: (
|
||||
client: Client,
|
||||
data: {
|
||||
id: bigint
|
||||
guildId: bigint
|
||||
channelId: bigint
|
||||
topic: string
|
||||
}
|
||||
) => unknown
|
||||
stageInstanceDelete: (
|
||||
client: Client,
|
||||
data: {
|
||||
id: bigint
|
||||
guildId: bigint
|
||||
channelId: bigint
|
||||
topic: string
|
||||
}
|
||||
) => unknown
|
||||
stageInstanceUpdate: (
|
||||
client: Client,
|
||||
data: {
|
||||
id: bigint
|
||||
guildId: bigint
|
||||
channelId: bigint
|
||||
topic: string
|
||||
}
|
||||
) => unknown
|
||||
guildEmojisUpdate: (
|
||||
client: Client,
|
||||
payload: {
|
||||
guildId: bigint
|
||||
emojis: Collection<bigint, DiscordEmoji>
|
||||
}
|
||||
) => unknown
|
||||
guildStickersUpdate: (
|
||||
client: Client,
|
||||
payload: {
|
||||
guildId: bigint
|
||||
stickers: Collection<bigint, DiscordSticker>
|
||||
}
|
||||
) => unknown
|
||||
guildBanAdd: (client: Client, user: User, guildId: bigint) => unknown
|
||||
guildBanRemove: (client: Client, user: User, guildId: bigint) => unknown
|
||||
guildCreate: (client: Client, guild: Guild) => unknown
|
||||
guildDelete: (client: Client, id: bigint, shardId: number) => unknown
|
||||
guildUpdate: (client: Client, guild: Guild) => unknown
|
||||
raw: (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
) => unknown
|
||||
roleCreate: (client: Client, role: Role) => unknown
|
||||
roleDelete: (
|
||||
client: Client,
|
||||
payload: { guildId: bigint, roleId: bigint }
|
||||
) => unknown
|
||||
roleUpdate: (client: Client, role: Role) => unknown
|
||||
webhooksUpdate: (
|
||||
client: Client,
|
||||
payload: { channelId: bigint, guildId: bigint }
|
||||
) => unknown
|
||||
botUpdate: (client: Client, user: User) => unknown
|
||||
typingStart: (
|
||||
client: Client,
|
||||
payload: {
|
||||
guildId: bigint | undefined
|
||||
channelId: bigint
|
||||
userId: bigint
|
||||
timestamp: number
|
||||
member: Member | undefined
|
||||
}
|
||||
) => unknown
|
||||
}
|
||||
|
||||
export interface ClientGatewayHandlerOptions {
|
||||
READY: typeof handlers.handleReady
|
||||
APPLICATION_COMMAND_PERMISSIONS_UPDATE: typeof handlers.handleApplicationCommandPermissionsUpdate
|
||||
AUTO_MODERATION_RULE_CREATE: typeof handlers.handleAutoModerationRuleCreate
|
||||
AUTO_MODERATION_RULE_UPDATE: typeof handlers.handleAutoModerationRuleUpdate
|
||||
AUTO_MODERATION_RULE_DELETE: typeof handlers.handleAutoModerationRuleDelete
|
||||
AUTO_MODERATION_ACTION_EXECUTION: typeof handlers.handleAutoModerationActionExecution
|
||||
CHANNEL_CREATE: typeof handlers.handleChannelCreate
|
||||
CHANNEL_UPDATE: typeof handlers.handleChannelUpdate
|
||||
CHANNEL_DELETE: typeof handlers.handleChannelDelete
|
||||
CHANNEL_PINS_UPDATE: typeof handlers.handleChannelPinsUpdate
|
||||
THREAD_CREATE: typeof handlers.handleThreadCreate
|
||||
THREAD_UPDATE: typeof handlers.handleThreadUpdate
|
||||
THREAD_DELETE: typeof handlers.handleThreadDelete
|
||||
THREAD_LIST_SYNC: typeof handlers.handleThreadListSync
|
||||
THREAD_MEMBER_UPDATE: typeof handlers.handleThreadMemberUpdate
|
||||
THREAD_MEMBERS_UPDATE: typeof handlers.handleThreadMembersUpdate
|
||||
GUILD_CREATE: typeof handlers.handleGuildCreate
|
||||
GUILD_UPDATE: typeof handlers.handleGuildUpdate
|
||||
GUILD_DELETE: typeof handlers.handleGuildDelete
|
||||
GUILD_BAN_ADD: typeof handlers.handleGuildBanAdd
|
||||
GUILD_BAN_REMOVE: typeof handlers.handleGuildBanRemove
|
||||
GUILD_EMOJIS_UPDATE: typeof handlers.handleGuildEmojisUpdate
|
||||
GUILD_STICKERS_UPDATE: typeof handlers.handleGuildStickersUpdate
|
||||
GUILD_INTEGRATIONS_UPDATE: typeof handlers.handleGuildIntegrationsUpdate
|
||||
GUILD_MEMBER_ADD: typeof handlers.handleGuildMemberAdd
|
||||
GUILD_MEMBER_REMOVE: typeof handlers.handleGuildMemberRemove
|
||||
GUILD_MEMBER_UPDATE: typeof handlers.handleGuildMemberUpdate
|
||||
GUILD_MEMBERS_CHUNK: typeof handlers.handleGuildMembersChunk
|
||||
GUILD_ROLE_CREATE: typeof handlers.handleGuildRoleCreate
|
||||
GUILD_ROLE_UPDATE: typeof handlers.handleGuildRoleUpdate
|
||||
GUILD_ROLE_DELETE: typeof handlers.handleGuildRoleDelete
|
||||
GUILD_SCHEDULED_EVENT_CREATE: typeof handlers.handleGuildScheduledEventCreate
|
||||
GUILD_SCHEDULED_EVENT_UPDATE: typeof handlers.handleGuildScheduledEventUpdate
|
||||
GUILD_SCHEDULED_EVENT_DELETE: typeof handlers.handleGuildScheduledEventDelete
|
||||
GUILD_SCHEDULED_EVENT_USER_ADD: typeof handlers.handleGuildScheduledEventUserAdd
|
||||
GUILD_SCHEDULED_EVENT_USER_REMOVE: typeof handlers.handleGuildScheduledEventUserRemove
|
||||
INTEGRATION_CREATE: typeof handlers.handleIntegrationCreate
|
||||
INTEGRATION_UPDATE: typeof handlers.handleIntegrationUpdate
|
||||
INTEGRATION_DELETE: typeof handlers.handleIntegrationDelete
|
||||
INTERACTION_CREATE: typeof handlers.handleInteractionCreate
|
||||
INVITE_CREATE: typeof handlers.handleInviteCreate
|
||||
INVITE_DELETE: typeof handlers.handleInviteCreate
|
||||
MESSAGE_CREATE: typeof handlers.handleMessageCreate
|
||||
MESSAGE_UPDATE: typeof handlers.handleMessageUpdate
|
||||
MESSAGE_DELETE: typeof handlers.handleMessageDelete
|
||||
MESSAGE_DELETE_BULK: typeof handlers.handleMessageDeleteBulk
|
||||
MESSAGE_REACTION_ADD: typeof handlers.handleMessageReactionAdd
|
||||
MESSAGE_REACTION_REMOVE: typeof handlers.handleMessageReactionRemove
|
||||
MESSAGE_REACTION_REMOVE_ALL: typeof handlers.handleMessageReactionRemoveAll
|
||||
MESSAGE_REACTION_REMOVE_EMOJI: typeof handlers.handleMessageReactionRemoveEmoji
|
||||
PRESENCE_UPDATE: typeof handlers.handlePresenceUpdate
|
||||
STAGE_INSTANCE_CREATE: typeof handlers.handleStageInstanceCreate
|
||||
STAGE_INSTANCE_UPDATE: typeof handlers.handleStageInstanceUpdate
|
||||
STAGE_INSTANCE_DELETE: typeof handlers.handleStageInstanceDelete
|
||||
TYPING_START: typeof handlers.handleTypingStart
|
||||
USER_UPDATE: typeof handlers.handleUserUpdate
|
||||
VOICE_STATE_UPDATE: typeof handlers.handleVoiceStateUpdate
|
||||
VOICE_SERVER_UPDATE: typeof handlers.handleVoiceServerUpdate
|
||||
WEBHOOKS_UPDATE: typeof handlers.handleWebhooksUpdate
|
||||
}
|
||||
|
||||
export function createClientGatewayHandlers (
|
||||
options: Partial<ClientGatewayHandlerOptions>
|
||||
): Record<
|
||||
GatewayDispatchEventNames,
|
||||
(client: Client, data: DiscordGatewayPayload, shardId: number) => any
|
||||
> {
|
||||
return {
|
||||
// misc
|
||||
READY: options.READY ?? handlers.handleReady,
|
||||
// command
|
||||
APPLICATION_COMMAND_PERMISSIONS_UPDATE:
|
||||
options.APPLICATION_COMMAND_PERMISSIONS_UPDATE ??
|
||||
handlers.handleApplicationCommandPermissionsUpdate,
|
||||
// automod
|
||||
AUTO_MODERATION_RULE_CREATE:
|
||||
options.AUTO_MODERATION_RULE_CREATE ??
|
||||
handlers.handleAutoModerationRuleCreate,
|
||||
AUTO_MODERATION_RULE_UPDATE:
|
||||
options.AUTO_MODERATION_RULE_UPDATE ??
|
||||
handlers.handleAutoModerationRuleUpdate,
|
||||
AUTO_MODERATION_RULE_DELETE:
|
||||
options.AUTO_MODERATION_RULE_DELETE ??
|
||||
handlers.handleAutoModerationRuleDelete,
|
||||
AUTO_MODERATION_ACTION_EXECUTION:
|
||||
options.AUTO_MODERATION_ACTION_EXECUTION ??
|
||||
handlers.handleAutoModerationActionExecution,
|
||||
// channels
|
||||
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_MEMBER_UPDATE:
|
||||
options.THREAD_MEMBER_UPDATE ?? handlers.handleThreadMembersUpdate,
|
||||
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_BAN_ADD: options.GUILD_BAN_ADD ?? handlers.handleGuildBanAdd,
|
||||
GUILD_BAN_REMOVE: options.GUILD_BAN_REMOVE ?? handlers.handleGuildBanRemove,
|
||||
GUILD_CREATE: options.GUILD_CREATE ?? handlers.handleGuildCreate,
|
||||
GUILD_DELETE: options.GUILD_DELETE ?? handlers.handleGuildDelete,
|
||||
GUILD_EMOJIS_UPDATE:
|
||||
options.GUILD_EMOJIS_UPDATE ?? handlers.handleGuildEmojisUpdate,
|
||||
GUILD_INTEGRATIONS_UPDATE:
|
||||
options.GUILD_INTEGRATIONS_UPDATE ??
|
||||
handlers.handleGuildIntegrationsUpdate,
|
||||
GUILD_MEMBER_ADD: options.GUILD_MEMBER_ADD ?? handlers.handleGuildMemberAdd,
|
||||
GUILD_MEMBER_REMOVE:
|
||||
options.GUILD_MEMBER_REMOVE ?? handlers.handleGuildMemberRemove,
|
||||
GUILD_MEMBER_UPDATE:
|
||||
options.GUILD_MEMBER_UPDATE ?? handlers.handleGuildMemberUpdate,
|
||||
GUILD_MEMBERS_CHUNK:
|
||||
options.GUILD_MEMBERS_CHUNK ?? handlers.handleGuildMembersChunk,
|
||||
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_STICKERS_UPDATE:
|
||||
options.GUILD_STICKERS_UPDATE ?? handlers.handleGuildStickersUpdate,
|
||||
// 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
|
||||
INTERACTION_CREATE:
|
||||
options.INTERACTION_CREATE ?? handlers.handleInteractionCreate,
|
||||
// invites
|
||||
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,
|
||||
MESSAGE_REACTION_ADD:
|
||||
options.MESSAGE_REACTION_ADD ?? handlers.handleMessageReactionAdd,
|
||||
MESSAGE_REACTION_REMOVE_ALL:
|
||||
options.MESSAGE_REACTION_REMOVE_ALL ??
|
||||
handlers.handleMessageReactionRemoveAll,
|
||||
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,
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleChannelCreate (
|
||||
client: Client,
|
||||
payload: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const channel = client.transformers.channel(client, {
|
||||
channel: payload.d as DiscordChannel
|
||||
})
|
||||
|
||||
client.events.channelCreate(client, channel)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleChannelDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
if (!payload.guild_id) return
|
||||
|
||||
client.events.channelDelete(
|
||||
client,
|
||||
client.transformers.channel(client, {
|
||||
channel: payload,
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type {
|
||||
DiscordChannelPinsUpdate,
|
||||
DiscordGatewayPayload
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleChannelPinsUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannelPinsUpdate
|
||||
|
||||
client.events.channelPinsUpdate(client, {
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
lastPinTimestamp: payload.last_pin_timestamp
|
||||
? Date.parse(payload.last_pin_timestamp)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleChannelUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
const channel = client.transformers.channel(client, { channel: payload })
|
||||
|
||||
client.events.channelUpdate(client, channel)
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordStageInstance
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleStageInstanceCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordStageInstance
|
||||
|
||||
client.events.stageInstanceCreate(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
topic: payload.topic
|
||||
})
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordStageInstance
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleStageInstanceDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordStageInstance
|
||||
|
||||
client.events.stageInstanceDelete(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
topic: payload.topic
|
||||
})
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordStageInstance
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleStageInstanceUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordStageInstance
|
||||
|
||||
client.events.stageInstanceUpdate(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
topic: payload.topic
|
||||
})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleThreadCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
|
||||
client.events.threadCreate(
|
||||
client,
|
||||
client.transformers.channel(client, { channel: payload })
|
||||
)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleThreadDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
client.events.threadDelete(
|
||||
client,
|
||||
client.transformers.channel(client, { channel: payload })
|
||||
)
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordThreadListSync
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
import type { Channel } from '../../transformers/index.js'
|
||||
|
||||
export async function handleThreadListSync (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<{
|
||||
guildId: bigint
|
||||
channelIds: bigint[] | undefined
|
||||
threads: Channel[]
|
||||
members: Array<{
|
||||
id: bigint | undefined
|
||||
userId: bigint | undefined
|
||||
joinTimestamp: number
|
||||
}>
|
||||
}> {
|
||||
const payload = data.d as DiscordThreadListSync
|
||||
|
||||
const guildId = client.transformers.snowflake(payload.guild_id)
|
||||
return {
|
||||
guildId,
|
||||
channelIds: payload.channel_ids?.map((id) =>
|
||||
client.transformers.snowflake(id)
|
||||
),
|
||||
threads: payload.threads.map((thread) =>
|
||||
client.transformers.channel(client, { channel: thread, guildId })
|
||||
),
|
||||
members: payload.members.map((member) => ({
|
||||
id: member.id ? client.transformers.snowflake(member.id) : undefined,
|
||||
userId: member.user_id
|
||||
? client.transformers.snowflake(member.user_id)
|
||||
: undefined,
|
||||
joinTimestamp: Date.parse(member.join_timestamp)
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordThreadMembersUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleThreadMembersUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordThreadMembersUpdate
|
||||
client.events.threadMembersUpdate(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
addedMembers: payload.added_members?.map((member) =>
|
||||
client.transformers.threadMember(client, member)
|
||||
),
|
||||
removedMemberIds: payload.removed_member_ids?.map((id) =>
|
||||
client.transformers.snowflake(id)
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordThreadMemberUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleThreadMemberUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordThreadMemberUpdate
|
||||
|
||||
client.events.threadMemberUpdate(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
joinedAt: Date.parse(payload.joined_at),
|
||||
flags: payload.flags
|
||||
})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import type { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleThreadUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
|
||||
client.events.threadUpdate(
|
||||
client,
|
||||
client.transformers.channel(client, { channel: payload })
|
||||
)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
export * from './CHANNEL_CREATE.js'
|
||||
export * from './CHANNEL_DELETE.js'
|
||||
export * from './CHANNEL_PINS_UPDATE.js'
|
||||
export * from './CHANNEL_UPDATE.js'
|
||||
export * from './STAGE_INSTANCE_CREATE.js'
|
||||
export * from './STAGE_INSTANCE_DELETE.js'
|
||||
export * from './STAGE_INSTANCE_UPDATE.js'
|
||||
export * from './THREAD_CREATE.js'
|
||||
export * from './THREAD_DELETE.js'
|
||||
export * from './THREAD_LIST_SYNC.js'
|
||||
export * from './THREAD_MEMBERS_UPDATE.js'
|
||||
export * from './THREAD_MEMBER_UPDATE.js'
|
||||
export * from './THREAD_UPDATE.js'
|
||||
@@ -1,23 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildEmojisUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildEmojisUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildEmojisUpdate
|
||||
|
||||
client.events.guildEmojisUpdate(client, {
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
emojis: new Collection(
|
||||
payload.emojis.map((emoji) => [
|
||||
client.transformers.snowflake(emoji.id!),
|
||||
emoji
|
||||
])
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './GUILD_EMOJIS_UPDATE.js'
|
||||
@@ -1,17 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildBanAddRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildBanAdd (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildBanAddRemove
|
||||
client.events.guildBanAdd(
|
||||
client,
|
||||
client.transformers.user(client, payload.user),
|
||||
client.transformers.snowflake(payload.guild_id)
|
||||
)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildBanAddRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildBanRemove (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildBanAddRemove
|
||||
|
||||
await client.events.guildBanRemove(
|
||||
client,
|
||||
client.transformers.user(client, payload.user),
|
||||
client.transformers.snowflake(payload.guild_id)
|
||||
)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import type { DiscordGatewayPayload, DiscordGuild } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleGuildCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordGuild
|
||||
client.events.guildCreate(
|
||||
client,
|
||||
client.transformers.guild(client, { guild: payload, shardId })
|
||||
)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordUnavailableGuild
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordUnavailableGuild
|
||||
client.events.guildDelete(
|
||||
client,
|
||||
client.transformers.snowflake(payload.id),
|
||||
shardId
|
||||
)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildIntegrationsUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildIntegrationsUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildIntegrationsUpdate
|
||||
|
||||
client.events.integrationUpdate(client, {
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildStickersUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildStickersUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildStickersUpdate
|
||||
client.events.guildStickersUpdate(client, {
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
stickers: new Collection(
|
||||
payload.stickers.map((sticker) => [
|
||||
client.transformers.snowflake(sticker.id),
|
||||
sticker
|
||||
])
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import type { DiscordGatewayPayload, DiscordGuild } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleGuildUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordGuild
|
||||
|
||||
client.events.guildUpdate(
|
||||
client,
|
||||
client.transformers.guild(client, { guild: payload, shardId })
|
||||
)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordAutoModerationActionExecution,
|
||||
DiscordGatewayPayload
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationActionExecution (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordAutoModerationActionExecution
|
||||
client.events.automodActionExecution(
|
||||
client,
|
||||
client.transformers.automodActionExecution(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordAutoModerationRule,
|
||||
DiscordGatewayPayload
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationRuleCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordAutoModerationRule
|
||||
client.events.automodRuleCreate(
|
||||
client,
|
||||
client.transformers.automodRule(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordAutoModerationRule,
|
||||
DiscordGatewayPayload
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationRuleDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordAutoModerationRule
|
||||
client.events.automodRuleDelete(
|
||||
client,
|
||||
client.transformers.automodRule(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordAutoModerationRule,
|
||||
DiscordGatewayPayload
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationRuleUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordAutoModerationRule
|
||||
client.events.automodRuleUpdate(
|
||||
client,
|
||||
client.transformers.automodRule(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
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,9 +0,0 @@
|
||||
export * from './automod/index.js'
|
||||
export * from './GUILD_BAN_ADD.js'
|
||||
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'
|
||||
export * from './scheduledEvents/index.js'
|
||||
@@ -1,17 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEvent
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
export function handleGuildScheduledEventCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordScheduledEvent
|
||||
client.events.scheduledEventCreate(
|
||||
client,
|
||||
client.transformers.scheduledEvent(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEvent
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
export function handleGuildScheduledEventDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordScheduledEvent
|
||||
client.events.scheduledEventDelete(
|
||||
client,
|
||||
client.transformers.scheduledEvent(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEvent
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
export function handleGuildScheduledEventUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordScheduledEvent
|
||||
client.events.scheduledEventUpdate(
|
||||
client,
|
||||
client.transformers.scheduledEvent(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEventUserAdd
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
export function handleGuildScheduledEventUserAdd (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): unknown {
|
||||
const payload = data.d as DiscordScheduledEventUserAdd
|
||||
|
||||
return client.events.scheduledEventUserAdd(client, {
|
||||
guildScheduledEventId: client.transformers.snowflake(
|
||||
payload.guild_scheduled_event_id
|
||||
),
|
||||
userId: client.transformers.snowflake(payload.user_id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEventUserRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../../client.js'
|
||||
|
||||
export function handleGuildScheduledEventUserRemove (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): unknown {
|
||||
const payload = data.d as DiscordScheduledEventUserRemove
|
||||
|
||||
return client.events.scheduledEventUserRemove(client, {
|
||||
guildScheduledEventId: client.transformers.snowflake(
|
||||
payload.guild_scheduled_event_id
|
||||
),
|
||||
userId: client.transformers.snowflake(payload.user_id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export * from './GUILD_SCHEDULED_EVENT_CREATE.js'
|
||||
export * from './GUILD_SCHEDULED_EVENT_DELETE.js'
|
||||
export * from './GUILD_SCHEDULED_EVENT_UPDATE.js'
|
||||
export * from './GUILD_SCHEDULED_EVENT_USER_ADD.js'
|
||||
export * from './GUILD_SCHEDULED_EVENT_USER_REMOVE.js'
|
||||
@@ -1,12 +0,0 @@
|
||||
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,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordIntegrationCreateUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleIntegrationCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
client.events.integrationCreate(
|
||||
client,
|
||||
client.transformers.integration(
|
||||
client,
|
||||
data.d as DiscordIntegrationCreateUpdate
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordIntegrationDelete
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleIntegrationDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordIntegrationDelete
|
||||
|
||||
client.events.integrationDelete(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
applicationId: payload.application_id
|
||||
? client.transformers.snowflake(payload.application_id)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordIntegrationCreateUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleIntegrationUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
client.events.integrationUpdate(
|
||||
client,
|
||||
client.transformers.integration(
|
||||
client,
|
||||
data.d as DiscordIntegrationCreateUpdate
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './INTEGRATION_CREATE.js'
|
||||
export * from './INTEGRATION_DELETE.js'
|
||||
export * from './INTEGRATION_UPDATE.js'
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordInteraction
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleInteractionCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
client.cache.unrepliedInteractions.add(
|
||||
client.transformers.snowflake((data.d as DiscordInteraction).id)
|
||||
)
|
||||
client.events.interactionCreate(
|
||||
client,
|
||||
client.transformers.interaction(client, data.d as DiscordInteraction)
|
||||
)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './INTERACTION_CREATE.js'
|
||||
@@ -1,15 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordInviteCreate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleInviteCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
client.events.inviteCreate(
|
||||
client,
|
||||
client.transformers.invite(client, data.d as DiscordInviteCreate)
|
||||
)
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordInviteDelete
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleInviteDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordInviteDelete
|
||||
|
||||
client.events.inviteDelete(client, {
|
||||
/** The channel of the invite */
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
/** The guild of the invite */
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
/** The unique invite code */
|
||||
code: payload.code
|
||||
})
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './INVITE_CREATE.js'
|
||||
export * from './INVITE_DELETE.js'
|
||||
@@ -1,71 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMembersChunk
|
||||
} from '@discordeno/types'
|
||||
import { PresenceStatus } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
import type { Activity, Member, User } from '../../transformers/index.js'
|
||||
|
||||
export async function handleGuildMembersChunk (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<{
|
||||
guildId: bigint
|
||||
members: Member[]
|
||||
chunkIndex: number
|
||||
chunkCount: number
|
||||
notFound: bigint[] | undefined
|
||||
presences:
|
||||
| Array<{
|
||||
user: User
|
||||
guildId: bigint
|
||||
status: PresenceStatus
|
||||
activities: Activity[]
|
||||
clientStatus: {
|
||||
desktop?: string
|
||||
mobile?: string
|
||||
web?: string
|
||||
}
|
||||
}>
|
||||
| undefined
|
||||
nonce: string | undefined
|
||||
}> {
|
||||
const payload = data.d as DiscordGuildMembersChunk
|
||||
|
||||
const guildId = client.transformers.snowflake(payload.guild_id)
|
||||
|
||||
if (payload.nonce && payload.chunk_index >= payload.chunk_count - 1) {
|
||||
client.cache.fetchAllMembersProcessingRequests.get(payload.nonce)?.(
|
||||
`Member fetching complete. Nonce: ${payload.nonce}`
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
guildId,
|
||||
members: payload.members.map((m) =>
|
||||
client.transformers.member(
|
||||
client,
|
||||
m,
|
||||
guildId,
|
||||
client.transformers.snowflake(m.user.id)
|
||||
)
|
||||
),
|
||||
chunkIndex: payload.chunk_index,
|
||||
chunkCount: payload.chunk_count,
|
||||
notFound: payload.not_found?.map((id) => client.transformers.snowflake(id)),
|
||||
presences: payload.presences?.map((presence) => ({
|
||||
user: client.transformers.user(client, presence.user),
|
||||
guildId,
|
||||
status: PresenceStatus[presence.status],
|
||||
activities: presence.activities.map((activity) =>
|
||||
client.transformers.activity(client, activity)
|
||||
),
|
||||
clientStatus: {
|
||||
desktop: presence.client_status.desktop,
|
||||
mobile: presence.client_status.mobile,
|
||||
web: presence.client_status.web
|
||||
}
|
||||
})),
|
||||
nonce: payload.nonce
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMemberAdd
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildMemberAdd (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMemberAdd
|
||||
const guildId = client.transformers.snowflake(payload.guild_id)
|
||||
const user = client.transformers.user(client, payload.user)
|
||||
const member = client.transformers.member(client, payload, guildId, user.id)
|
||||
client.events.guildMemberAdd(client, member, user)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMemberRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildMemberRemove (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMemberRemove
|
||||
const guildId = client.transformers.snowflake(payload.guild_id)
|
||||
const user = client.transformers.user(client, payload.user)
|
||||
|
||||
client.events.guildMemberRemove(client, user, guildId)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMemberUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildMemberUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMemberUpdate
|
||||
|
||||
const user = client.transformers.user(client, payload.user)
|
||||
client.events.guildMemberUpdate(
|
||||
client,
|
||||
client.transformers.member(
|
||||
client,
|
||||
payload,
|
||||
client.transformers.snowflake(payload.guild_id),
|
||||
user.id
|
||||
),
|
||||
user
|
||||
)
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from './GUILD_MEMBERS_CHUNK.js'
|
||||
export * from './GUILD_MEMBER_ADD.js'
|
||||
export * from './GUILD_MEMBER_REMOVE.js'
|
||||
export * from './GUILD_MEMBER_UPDATE.js'
|
||||
@@ -1,14 +0,0 @@
|
||||
import type { DiscordGatewayPayload, DiscordMessage } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessage
|
||||
|
||||
client.events.messageCreate(
|
||||
client,
|
||||
client.transformers.message(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageDelete
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageDelete
|
||||
|
||||
client.events.messageDelete(client, {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageDeleteBulk
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageDeleteBulk (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageDeleteBulk
|
||||
|
||||
const channelId = client.transformers.snowflake(payload.channel_id)
|
||||
const guildId = payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
|
||||
client.events.messageDeleteBulk(client, {
|
||||
ids: payload.ids.map((id) => client.transformers.snowflake(id)),
|
||||
channelId,
|
||||
guildId
|
||||
})
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionAdd
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageReactionAdd (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionAdd
|
||||
|
||||
const guildId = payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
const userId = client.transformers.snowflake(payload.user_id)
|
||||
client.events.reactionAdd(client, {
|
||||
userId,
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
messageId: client.transformers.snowflake(payload.message_id),
|
||||
guildId,
|
||||
member:
|
||||
payload.member && guildId
|
||||
? client.transformers.member(client, payload.member, guildId, userId)
|
||||
: undefined,
|
||||
user: payload.member
|
||||
? client.transformers.user(client, payload.member.user)
|
||||
: undefined,
|
||||
emoji: client.transformers.emoji(client, payload.emoji)
|
||||
})
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageReactionRemove (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionRemove
|
||||
|
||||
client.events.reactionRemove(client, {
|
||||
userId: client.transformers.snowflake(payload.user_id),
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
messageId: client.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
emoji: client.transformers.emoji(client, payload.emoji)
|
||||
})
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionRemoveAll
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageReactionRemoveAll (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionRemoveAll
|
||||
|
||||
client.events.reactionRemoveAll(client, {
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
messageId: client.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionRemoveEmoji
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionRemoveEmoji
|
||||
|
||||
client.events.reactionRemoveEmoji(client, {
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
messageId: client.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
emoji: client.transformers.emoji(client, payload.emoji)
|
||||
})
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import type { DiscordGatewayPayload, DiscordMessage } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleMessageUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessage
|
||||
if (!payload.edited_timestamp) return
|
||||
|
||||
client.events.messageUpdate(
|
||||
client,
|
||||
client.transformers.message(client, payload)
|
||||
)
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export * from './MESSAGE_CREATE.js'
|
||||
export * from './MESSAGE_DELETE.js'
|
||||
export * from './MESSAGE_DELETE_BULK.js'
|
||||
export * from './MESSAGE_REACTION_ADD.js'
|
||||
export * from './MESSAGE_REACTION_REMOVE.js'
|
||||
export * from './MESSAGE_REACTION_REMOVE_ALL.js'
|
||||
export * from './MESSAGE_REACTION_REMOVE_EMOJI.js'
|
||||
export * from './MESSAGE_UPDATE.js'
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildApplicationCommandPermissions
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleApplicationCommandPermissionsUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
client.events.applicationCommandPermissionsUpdate(
|
||||
client,
|
||||
client.transformers.applicationCommandPermission(
|
||||
client,
|
||||
data.d as DiscordGuildApplicationCommandPermissions
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordPresenceUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handlePresenceUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
client.events.presenceUpdate(
|
||||
client,
|
||||
client.transformers.presence(client, data.d as DiscordPresenceUpdate)
|
||||
)
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import type { DiscordGatewayPayload, DiscordReady } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleReady (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordReady
|
||||
// Triggered on each shard
|
||||
client.events.ready(
|
||||
client,
|
||||
{
|
||||
shardId,
|
||||
v: payload.v,
|
||||
user: client.transformers.user(client, payload.user),
|
||||
guilds: payload.guilds.map((p) => client.transformers.snowflake(p.id)),
|
||||
sessionId: payload.session_id,
|
||||
shard: payload.shard,
|
||||
applicationId: client.transformers.snowflake(payload.application.id)
|
||||
},
|
||||
payload
|
||||
)
|
||||
|
||||
client.id = client.transformers.snowflake(payload.user.id)
|
||||
client.applicationId = client.transformers.snowflake(payload.application.id)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordTypingStart
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleTypingStart (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordTypingStart
|
||||
|
||||
const guildId = payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
const userId = client.transformers.snowflake(payload.user_id)
|
||||
|
||||
client.events.typingStart(client, {
|
||||
guildId,
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
userId,
|
||||
timestamp: payload.timestamp,
|
||||
member:
|
||||
payload.member && guildId
|
||||
? client.transformers.member(client, payload.member, guildId, userId)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import type { DiscordGatewayPayload, DiscordUser } from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleUserUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordUser
|
||||
client.events.botUpdate(client, client.transformers.user(client, payload))
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export * from './APPLICATION_COMMAND_PERMISSIONS_UPDATE.js'
|
||||
export * from './PRESENCE_UPDATE.js'
|
||||
export * from './READY.js'
|
||||
export * from './TYPING_START.js'
|
||||
export * from './USER_UPDATE.js'
|
||||
@@ -1,19 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildRoleCreate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildRoleCreate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildRoleCreate
|
||||
client.events.roleCreate(
|
||||
client,
|
||||
client.transformers.role(client, {
|
||||
role: payload.role,
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildRoleDelete
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildRoleDelete (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildRoleDelete
|
||||
client.events.roleDelete(client, {
|
||||
roleId: client.transformers.snowflake(payload.role_id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildRoleUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleGuildRoleUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildRoleUpdate
|
||||
|
||||
client.events.roleUpdate(
|
||||
client,
|
||||
client.transformers.role(client, {
|
||||
role: payload.role,
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './GUILD_ROLE_CREATE.js'
|
||||
export * from './GUILD_ROLE_DELETE.js'
|
||||
export * from './GUILD_ROLE_UPDATE.js'
|
||||
@@ -1,18 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordVoiceServerUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleVoiceServerUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordVoiceServerUpdate
|
||||
|
||||
client.events.voiceServerUpdate(client, {
|
||||
token: payload.token,
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
endpoint: payload.endpoint ?? undefined
|
||||
})
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordVoiceState
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export async function handleVoiceStateUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordVoiceState
|
||||
if (!payload.guild_id) return
|
||||
|
||||
const guildId = client.transformers.snowflake(payload.guild_id)
|
||||
|
||||
client.events.voiceStateUpdate(
|
||||
client,
|
||||
client.transformers.voiceState(client, { voiceState: payload, guildId })
|
||||
)
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './VOICE_SERVER_UPDATE.js'
|
||||
export * from './VOICE_STATE_UPDATE.js'
|
||||
@@ -1,16 +0,0 @@
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
DiscordWebhookUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../../client.js'
|
||||
|
||||
export function handleWebhooksUpdate (
|
||||
client: Client,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordWebhookUpdate
|
||||
client.events.webhooksUpdate(client, {
|
||||
channelId: client.transformers.snowflake(payload.channel_id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './WEBHOOKS_UPDATE.js'
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from './client.js'
|
||||
export * from './handlers/index.js'
|
||||
export * from './transformer.js'
|
||||
export * from './types.js'
|
||||
@@ -1,410 +0,0 @@
|
||||
import type {
|
||||
AllowedMentions,
|
||||
BigString,
|
||||
DiscordActivity,
|
||||
DiscordAllowedMentions,
|
||||
DiscordApplication,
|
||||
DiscordApplicationCommand,
|
||||
DiscordApplicationCommandOption,
|
||||
DiscordApplicationCommandOptionChoice,
|
||||
DiscordAttachment,
|
||||
DiscordAuditLogEntry,
|
||||
DiscordAutoModerationActionExecution,
|
||||
DiscordAutoModerationRule,
|
||||
DiscordChannel,
|
||||
DiscordComponent,
|
||||
DiscordCreateApplicationCommand,
|
||||
DiscordEmbed,
|
||||
DiscordEmoji,
|
||||
DiscordGetGatewayBot,
|
||||
DiscordGuild,
|
||||
DiscordGuildApplicationCommandPermissions,
|
||||
DiscordGuildWidget,
|
||||
DiscordGuildWidgetSettings,
|
||||
DiscordIntegrationCreateUpdate,
|
||||
DiscordInteraction,
|
||||
DiscordInteractionDataOption,
|
||||
DiscordInteractionDataResolved,
|
||||
DiscordInteractionResponse,
|
||||
DiscordInviteCreate,
|
||||
DiscordMember,
|
||||
DiscordMessage,
|
||||
DiscordPresenceUpdate,
|
||||
DiscordRole,
|
||||
DiscordScheduledEvent,
|
||||
DiscordStageInstance,
|
||||
DiscordSticker,
|
||||
DiscordStickerPack,
|
||||
DiscordTeam,
|
||||
DiscordTemplate,
|
||||
DiscordThreadMember,
|
||||
DiscordUser,
|
||||
DiscordVoiceRegion,
|
||||
DiscordVoiceState,
|
||||
DiscordWebhook,
|
||||
DiscordWelcomeScreen,
|
||||
GetGatewayBot
|
||||
} from '@discordeno/types'
|
||||
import { bigintToSnowflake, snowflakeToBigint } from '@discordeno/utils'
|
||||
import type { Client } from './client.js'
|
||||
import type {
|
||||
Activity,
|
||||
Application,
|
||||
ApplicationCommand,
|
||||
ApplicationCommandOption,
|
||||
ApplicationCommandOptionChoice,
|
||||
ApplicationCommandPermission,
|
||||
Attachment,
|
||||
AuditLogEntry,
|
||||
AutoModerationActionExecution,
|
||||
AutoModerationRule,
|
||||
Channel,
|
||||
Component,
|
||||
Embed,
|
||||
Emoji,
|
||||
Guild,
|
||||
GuildWidget,
|
||||
GuildWidgetSettings,
|
||||
Integration,
|
||||
Interaction,
|
||||
InteractionDataOption,
|
||||
InteractionDataResolved,
|
||||
Invite,
|
||||
Member,
|
||||
Message,
|
||||
PresenceUpdate,
|
||||
Role,
|
||||
ScheduledEvent,
|
||||
StageInstance,
|
||||
Sticker,
|
||||
StickerPack,
|
||||
Team,
|
||||
Template,
|
||||
ThreadMember,
|
||||
User,
|
||||
VoiceRegions,
|
||||
VoiceState,
|
||||
Webhook,
|
||||
WelcomeScreen
|
||||
} from './transformers/index.js'
|
||||
import {
|
||||
transformActivity,
|
||||
transformActivityToDiscordActivity,
|
||||
transformAllowedMentionsToDiscordAllowedMentions,
|
||||
transformApplication,
|
||||
transformApplicationCommand,
|
||||
transformApplicationCommandOption,
|
||||
transformApplicationCommandOptionChoice,
|
||||
transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice,
|
||||
transformApplicationCommandOptionToDiscordApplicationCommandOption,
|
||||
transformApplicationCommandPermission,
|
||||
transformApplicationCommandPermissionToDiscordApplicationCommandPermission,
|
||||
transformApplicationCommandToDiscordApplicationCommand,
|
||||
transformApplicationToDiscordApplication,
|
||||
transformAttachment,
|
||||
transformAttachmentToDiscordAttachment,
|
||||
transformAuditLogEntry,
|
||||
transformAuditLogEntryToDiscordAuditLogEntry,
|
||||
transformAutoModerationActionExecution,
|
||||
transformAutoModerationRule,
|
||||
transformChannel,
|
||||
transformComponent,
|
||||
transformComponentToDiscordComponent,
|
||||
transformCreateApplicationCommandToDiscordCreateApplicationCommand,
|
||||
transformEmbed,
|
||||
transformEmbedToDiscordEmbed,
|
||||
transformEmoji,
|
||||
transformEmojiToDiscordEmoji,
|
||||
transformGatewayBot,
|
||||
transformGatewayBotToDiscordGatewayBot,
|
||||
transformGuild,
|
||||
transformIntegration,
|
||||
transformInteraction,
|
||||
transformInteractionDataOption,
|
||||
transformInteractionDataResolved,
|
||||
transformInteractionResponseToDiscordInteractionResponse,
|
||||
transformInvite,
|
||||
transformMember,
|
||||
transformMemberToDiscordMember,
|
||||
transformMessage,
|
||||
transformPresence,
|
||||
transformPresenceToDiscordPresence,
|
||||
transformRole,
|
||||
transformScheduledEvent,
|
||||
transformStageInstance,
|
||||
transformSticker,
|
||||
transformStickerPack,
|
||||
transformTeam,
|
||||
transformTeamToDiscordTeam,
|
||||
transformTemplate,
|
||||
transformThreadMember,
|
||||
transformUser,
|
||||
transformUserToDiscordUser,
|
||||
transformVoiceRegion,
|
||||
transformVoiceState,
|
||||
transformWebhook,
|
||||
transformWelcomeScreen,
|
||||
transformWidget,
|
||||
transformWidgetSettings,
|
||||
transformWidgetSettingsToDiscordWidgetSettings
|
||||
} from './transformers/index.js'
|
||||
import type { CreateApplicationCommand, InteractionResponse } from './types.js'
|
||||
|
||||
export interface Transformers {
|
||||
reverse: {
|
||||
allowedMentions: (
|
||||
client: Client,
|
||||
payload: AllowedMentions
|
||||
) => DiscordAllowedMentions
|
||||
embed: (client: Client, payload: Embed) => DiscordEmbed
|
||||
component: (client: Client, payload: Component) => DiscordComponent
|
||||
activity: (client: Client, payload: Activity) => DiscordActivity
|
||||
member: (client: Client, payload: Member) => DiscordMember
|
||||
user: (client: Client, payload: User) => DiscordUser
|
||||
team: (client: Client, payload: Team) => DiscordTeam
|
||||
application: (client: Client, payload: Application) => DiscordApplication
|
||||
snowflake: (snowflake: BigString) => string
|
||||
createApplicationCommand: (
|
||||
client: Client,
|
||||
payload: CreateApplicationCommand
|
||||
) => DiscordCreateApplicationCommand
|
||||
applicationCommand: (
|
||||
client: Client,
|
||||
payload: ApplicationCommand
|
||||
) => DiscordApplicationCommand
|
||||
applicationCommandOption: (
|
||||
client: Client,
|
||||
payload: ApplicationCommandOption
|
||||
) => DiscordApplicationCommandOption
|
||||
applicationCommandOptionChoice: (
|
||||
client: Client,
|
||||
payload: ApplicationCommandOptionChoice
|
||||
) => DiscordApplicationCommandOptionChoice
|
||||
interactionResponse: (
|
||||
client: Client,
|
||||
payload: InteractionResponse
|
||||
) => DiscordInteractionResponse
|
||||
attachment: (client: Client, payload: Attachment) => DiscordAttachment
|
||||
applicationCommandPermission: (
|
||||
client: Client,
|
||||
payload: ApplicationCommandPermission
|
||||
) => DiscordGuildApplicationCommandPermissions
|
||||
auditLogEntry: (
|
||||
client: Client,
|
||||
payload: AuditLogEntry
|
||||
) => DiscordAuditLogEntry
|
||||
emoji: (client: Client, payload: Emoji) => DiscordEmoji
|
||||
gatewayBot: (payload: GetGatewayBot) => DiscordGetGatewayBot
|
||||
presence: (
|
||||
client: Client,
|
||||
payload: PresenceUpdate
|
||||
) => DiscordPresenceUpdate
|
||||
widgetSettings: (
|
||||
client: Client,
|
||||
payload: GuildWidgetSettings
|
||||
) => DiscordGuildWidgetSettings
|
||||
}
|
||||
snowflake: (snowflake: BigString) => bigint
|
||||
gatewayBot: (payload: DiscordGetGatewayBot) => GetGatewayBot
|
||||
automodRule: (
|
||||
client: Client,
|
||||
payload: DiscordAutoModerationRule
|
||||
) => AutoModerationRule
|
||||
automodActionExecution: (
|
||||
client: Client,
|
||||
payload: DiscordAutoModerationActionExecution
|
||||
) => AutoModerationActionExecution
|
||||
channel: (
|
||||
client: Client,
|
||||
payload: { channel: DiscordChannel } & { guildId?: bigint }
|
||||
) => Channel
|
||||
guild: (
|
||||
client: Client,
|
||||
payload: { guild: DiscordGuild } & { shardId: number }
|
||||
) => Guild
|
||||
user: (client: Client, payload: DiscordUser) => User
|
||||
member: (
|
||||
client: Client,
|
||||
payload: DiscordMember,
|
||||
guildId: bigint,
|
||||
userId: bigint
|
||||
) => Member
|
||||
message: (client: Client, payload: DiscordMessage) => Message
|
||||
role: (
|
||||
client: Client,
|
||||
payload: { role: DiscordRole } & { guildId: bigint }
|
||||
) => Role
|
||||
voiceState: (
|
||||
client: Client,
|
||||
payload: { voiceState: DiscordVoiceState } & { guildId: bigint }
|
||||
) => VoiceState
|
||||
interaction: (client: Client, payload: DiscordInteraction) => Interaction
|
||||
interactionDataOption: (
|
||||
client: Client,
|
||||
payload: DiscordInteractionDataOption
|
||||
) => InteractionDataOption
|
||||
interactionDataResolved: (
|
||||
client: Client,
|
||||
payload: DiscordInteractionDataResolved
|
||||
) => InteractionDataResolved
|
||||
integration: (
|
||||
client: Client,
|
||||
payload: DiscordIntegrationCreateUpdate
|
||||
) => Integration
|
||||
invite: (client: Client, invite: DiscordInviteCreate) => Invite
|
||||
application: (client: Client, payload: DiscordApplication) => Application
|
||||
team: (client: Client, payload: DiscordTeam) => Team
|
||||
emoji: (client: Client, payload: DiscordEmoji) => Emoji
|
||||
activity: (client: Client, payload: DiscordActivity) => Activity
|
||||
presence: (client: Client, payload: DiscordPresenceUpdate) => PresenceUpdate
|
||||
attachment: (client: Client, payload: DiscordAttachment) => Attachment
|
||||
embed: (client: Client, payload: DiscordEmbed) => Embed
|
||||
component: (client: Client, payload: DiscordComponent) => Component
|
||||
webhook: (client: Client, payload: DiscordWebhook) => Webhook
|
||||
auditLogEntry: (
|
||||
client: Client,
|
||||
payload: DiscordAuditLogEntry
|
||||
) => AuditLogEntry
|
||||
applicationCommand: (
|
||||
client: Client,
|
||||
payload: DiscordApplicationCommand
|
||||
) => ApplicationCommand
|
||||
applicationCommandOption: (
|
||||
client: Client,
|
||||
payload: DiscordApplicationCommandOption
|
||||
) => ApplicationCommandOption
|
||||
applicationCommandPermission: (
|
||||
client: Client,
|
||||
payload: DiscordGuildApplicationCommandPermissions
|
||||
) => ApplicationCommandPermission
|
||||
scheduledEvent: (
|
||||
client: Client,
|
||||
payload: DiscordScheduledEvent
|
||||
) => ScheduledEvent
|
||||
threadMember: (client: Client, payload: DiscordThreadMember) => ThreadMember
|
||||
welcomeScreen: (
|
||||
client: Client,
|
||||
payload: DiscordWelcomeScreen
|
||||
) => WelcomeScreen
|
||||
voiceRegion: (client: Client, payload: DiscordVoiceRegion) => VoiceRegions
|
||||
widget: (client: Client, payload: DiscordGuildWidget) => GuildWidget
|
||||
widgetSettings: (
|
||||
client: Client,
|
||||
payload: DiscordGuildWidgetSettings
|
||||
) => GuildWidgetSettings
|
||||
stageInstance: (
|
||||
client: Client,
|
||||
payload: DiscordStageInstance
|
||||
) => StageInstance
|
||||
sticker: (client: Client, payload: DiscordSticker) => Sticker
|
||||
stickerPack: (client: Client, payload: DiscordStickerPack) => StickerPack
|
||||
applicationCommandOptionChoice: (
|
||||
client: Client,
|
||||
payload: DiscordApplicationCommandOptionChoice
|
||||
) => ApplicationCommandOptionChoice
|
||||
template: (client: Client, payload: DiscordTemplate) => Template
|
||||
}
|
||||
|
||||
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,
|
||||
applicationCommandOptionChoice:
|
||||
options.reverse?.applicationCommandOptionChoice ??
|
||||
transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice,
|
||||
interactionResponse:
|
||||
options.reverse?.interactionResponse ??
|
||||
transformInteractionResponseToDiscordInteractionResponse,
|
||||
attachment:
|
||||
options.reverse?.attachment ?? transformAttachmentToDiscordAttachment,
|
||||
applicationCommandPermission:
|
||||
options.reverse?.applicationCommandPermission ??
|
||||
transformApplicationCommandPermissionToDiscordApplicationCommandPermission,
|
||||
auditLogEntry:
|
||||
options.reverse?.auditLogEntry ??
|
||||
transformAuditLogEntryToDiscordAuditLogEntry,
|
||||
emoji: options.reverse?.emoji ?? transformEmojiToDiscordEmoji,
|
||||
gatewayBot:
|
||||
options.reverse?.gatewayBot ?? transformGatewayBotToDiscordGatewayBot,
|
||||
presence: options.reverse?.presence ?? transformPresenceToDiscordPresence,
|
||||
widgetSettings:
|
||||
options.reverse?.widgetSettings ??
|
||||
transformWidgetSettingsToDiscordWidgetSettings
|
||||
},
|
||||
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,
|
||||
interactionDataOption:
|
||||
options.interactionDataOption ?? transformInteractionDataOption,
|
||||
interactionDataResolved:
|
||||
options.interactionDataResolved ?? transformInteractionDataResolved,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
export * from './transformers/index.js'
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { DiscordActivity, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformActivity (client: Client, payload: DiscordActivity) {
|
||||
const activity = {
|
||||
name: payload.name,
|
||||
type: payload.type,
|
||||
url: payload.url ?? undefined,
|
||||
createdAt: payload.created_at,
|
||||
startedAt: payload.timestamps?.start,
|
||||
endedAt: payload.timestamps?.end,
|
||||
applicationId: payload.application_id
|
||||
? client.transformers.snowflake(payload.application_id)
|
||||
: undefined,
|
||||
details: payload.details ?? undefined,
|
||||
state: payload.state ?? undefined,
|
||||
emoji: payload.emoji
|
||||
? {
|
||||
name: payload.emoji.name,
|
||||
animated: payload.emoji.animated,
|
||||
id: payload.emoji.id
|
||||
? client.transformers.snowflake(payload.emoji.id)
|
||||
: undefined
|
||||
}
|
||||
: undefined,
|
||||
partyId: payload.party?.id,
|
||||
partyCurrentSize: payload.party?.size?.[0],
|
||||
partyMaxSize: payload.party?.size?.[1],
|
||||
largeImage: payload.assets?.large_image,
|
||||
largeText: payload.assets?.large_text,
|
||||
smallImage: payload.assets?.small_image,
|
||||
smallText: payload.assets?.small_text,
|
||||
join: payload.secrets?.join,
|
||||
spectate: payload.secrets?.spectate,
|
||||
match: payload.secrets?.match,
|
||||
instance: payload.instance,
|
||||
flags: payload.flags,
|
||||
buttons: payload.buttons
|
||||
}
|
||||
|
||||
return activity as Optionalize<typeof activity>
|
||||
}
|
||||
|
||||
export interface Activity extends ReturnType<typeof transformActivity> {}
|
||||
@@ -1,47 +0,0 @@
|
||||
import type {
|
||||
DiscordApplication,
|
||||
DiscordUser,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplication (
|
||||
client: Client,
|
||||
payload: DiscordApplication
|
||||
) {
|
||||
const application = {
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
rpcOrigins: payload.rpc_origins,
|
||||
botPublic: payload.bot_public,
|
||||
botRequireCodeGrant: payload.bot_require_code_grant,
|
||||
termsOfServiceUrl: payload.terms_of_service_url,
|
||||
privacyPolicyUrl: payload.privacy_policy_url,
|
||||
verifyKey: payload.verify_key,
|
||||
primarySkuId: payload.primary_sku_id,
|
||||
slug: payload.slug,
|
||||
coverImage: payload.cover_image
|
||||
? client.utils.iconHashToBigInt(payload.cover_image)
|
||||
: undefined,
|
||||
flags: payload.flags,
|
||||
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
icon: payload.icon
|
||||
? client.utils.iconHashToBigInt(payload.icon)
|
||||
: undefined,
|
||||
owner: payload.owner
|
||||
? client.transformers.user(client, payload.owner as DiscordUser)
|
||||
: undefined,
|
||||
team: payload.team
|
||||
? client.transformers.team(client, payload.team)
|
||||
: undefined,
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
}
|
||||
|
||||
return application as Optionalize<typeof application>
|
||||
}
|
||||
|
||||
export interface Application extends ReturnType<typeof transformApplication> {}
|
||||
@@ -1,35 +0,0 @@
|
||||
import type { DiscordApplicationCommand, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplicationCommand (
|
||||
client: Client,
|
||||
payload: DiscordApplicationCommand
|
||||
) {
|
||||
const applicationCommand = {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
applicationId: client.transformers.snowflake(payload.application_id),
|
||||
guildId: payload.guild_id
|
||||
? client.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
name: payload.name,
|
||||
nameLocalizations: payload.name_localizations ?? undefined,
|
||||
description: payload.description,
|
||||
descriptionLocalizations: payload.description_localizations ?? undefined,
|
||||
defaultMemberPermissions: payload.default_member_permissions
|
||||
? client.transformers.snowflake(payload.default_member_permissions)
|
||||
: undefined,
|
||||
dmPermission: payload.dm_permission ?? false,
|
||||
type: payload.type,
|
||||
version: payload.version,
|
||||
|
||||
options: payload.options?.map((option) =>
|
||||
client.transformers.applicationCommandOption(client, option)
|
||||
)
|
||||
}
|
||||
|
||||
return applicationCommand as Optionalize<typeof applicationCommand>
|
||||
}
|
||||
|
||||
export interface ApplicationCommand
|
||||
extends ReturnType<typeof transformApplicationCommand> {}
|
||||
@@ -1,67 +0,0 @@
|
||||
import type {
|
||||
ApplicationCommandOptionTypes,
|
||||
ChannelTypes,
|
||||
DiscordApplicationCommandOption,
|
||||
Localization
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
import type { ApplicationCommandOptionChoice } from './applicationCommandOptionChoice.js'
|
||||
|
||||
export function transformApplicationCommandOption (
|
||||
client: Client,
|
||||
payload: DiscordApplicationCommandOption
|
||||
): ApplicationCommandOption {
|
||||
return {
|
||||
type: payload.type,
|
||||
name: payload.name,
|
||||
nameLocalizations: payload.name_localizations ?? undefined,
|
||||
description: payload.description,
|
||||
descriptionLocalizations: payload.description_localizations ?? undefined,
|
||||
required: payload.required ?? false,
|
||||
choices: payload.choices?.map((choice) =>
|
||||
client.transformers.applicationCommandOptionChoice(client, choice)
|
||||
),
|
||||
autocomplete: payload.autocomplete,
|
||||
channelTypes: payload.channel_types,
|
||||
minValue: payload.min_value,
|
||||
maxValue: payload.max_value,
|
||||
minLength: payload.min_length,
|
||||
maxLength: payload.max_length,
|
||||
options: payload.options?.map((option) =>
|
||||
client.transformers.applicationCommandOption(client, option)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// THIS TRANSFORMER HAS A CIRCULAR REFERENCE TO CALL ITSELF FOR OPTIONS SO AN AUTOMATED TYPE CAN NOT BE CREATED!
|
||||
|
||||
export interface ApplicationCommandOption {
|
||||
/** Value of Application Command Option Type */
|
||||
type: ApplicationCommandOptionTypes
|
||||
/** 1-32 character name matching lowercase `^[\w-]{1,32}$` */
|
||||
name: string
|
||||
/** Localization object for the `name` field. Values follow the same restrictions as `name` */
|
||||
nameLocalizations?: Localization
|
||||
/** 1-100 character description */
|
||||
description: string
|
||||
/** Localization object for the `description` field. Values follow the same restrictions as `description` */
|
||||
descriptionLocalizations?: Localization
|
||||
/** If the parameter is required or optional--default `false` */
|
||||
required?: boolean
|
||||
/** Choices for `string` and `int` types for the user to pick from */
|
||||
choices?: ApplicationCommandOptionChoice[]
|
||||
/** If the option is a subcommand or subcommand group type, this nested options will be the parameters */
|
||||
options?: ApplicationCommandOption[]
|
||||
/** If the option is a channel type, the channels shown will be restricted to these types */
|
||||
channelTypes?: ChannelTypes[]
|
||||
/** Minimum number desired. */
|
||||
minValue?: number
|
||||
/** Maximum number desired. */
|
||||
maxValue?: number
|
||||
/** Minimum length desired. */
|
||||
minLength?: number
|
||||
/** Maximum length desired. */
|
||||
maxLength?: number
|
||||
/** if autocomplete interactions are enabled for this `String`, `Integer`, or `Number` type option */
|
||||
autocomplete?: boolean
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import type {
|
||||
DiscordApplicationCommandOptionChoice,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplicationCommandOptionChoice (
|
||||
client: Client,
|
||||
payload: DiscordApplicationCommandOptionChoice
|
||||
) {
|
||||
const applicationCommandChoice = {
|
||||
name: payload.name,
|
||||
nameLocalizations: payload.name_localizations ?? undefined,
|
||||
value: payload.value
|
||||
}
|
||||
|
||||
return applicationCommandChoice as Optionalize<
|
||||
typeof applicationCommandChoice
|
||||
>
|
||||
}
|
||||
|
||||
export interface ApplicationCommandOptionChoice
|
||||
extends ReturnType<typeof transformApplicationCommandOptionChoice> {}
|
||||
@@ -1,29 +0,0 @@
|
||||
import type {
|
||||
DiscordGuildApplicationCommandPermissions,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplicationCommandPermission (
|
||||
client: Client,
|
||||
payload: DiscordGuildApplicationCommandPermissions
|
||||
) {
|
||||
const applicationCommandPermission = {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
applicationId: client.transformers.snowflake(payload.application_id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
permissions: payload.permissions.map((perm) => ({
|
||||
id: client.transformers.snowflake(perm.id),
|
||||
type: perm.type,
|
||||
permission: perm.permission
|
||||
}))
|
||||
}
|
||||
|
||||
return applicationCommandPermission as Optionalize<
|
||||
typeof applicationCommandPermission
|
||||
>
|
||||
}
|
||||
|
||||
export interface ApplicationCommandPermission
|
||||
extends ReturnType<typeof transformApplicationCommandPermission> {}
|
||||
@@ -1,25 +0,0 @@
|
||||
import type { DiscordAttachment, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAttachment (
|
||||
client: Client,
|
||||
payload: DiscordAttachment
|
||||
) {
|
||||
const attachment = {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
filename: payload.filename,
|
||||
contentType: payload.content_type,
|
||||
size: payload.size,
|
||||
url: payload.url,
|
||||
proxyUrl: payload.proxy_url,
|
||||
height: payload.height ?? undefined,
|
||||
width: payload.width ?? undefined,
|
||||
ephemeral: payload.ephemeral,
|
||||
description: payload.description
|
||||
}
|
||||
|
||||
return attachment as Optionalize<typeof attachment>
|
||||
}
|
||||
|
||||
export interface Attachment extends ReturnType<typeof transformAttachment> {}
|
||||
@@ -1,158 +0,0 @@
|
||||
import type { DiscordAuditLogEntry, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAuditLogEntry (
|
||||
client: Client,
|
||||
payload: DiscordAuditLogEntry
|
||||
) {
|
||||
const auditLogEntry = {
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
changes: payload.changes?.map((change) => {
|
||||
switch (change.key) {
|
||||
case '$add':
|
||||
case '$remove':
|
||||
return {
|
||||
key: change.key,
|
||||
new: change.new_value?.map((val) => ({
|
||||
id: val.id ? client.transformers.snowflake(val.id) : undefined,
|
||||
name: val.name
|
||||
})),
|
||||
old: change.old_value?.map((val) => ({
|
||||
id: val?.id ? client.transformers.snowflake(val.id) : undefined,
|
||||
name: val?.name
|
||||
}))
|
||||
}
|
||||
case 'discovery_splash_hash':
|
||||
case 'banner_hash':
|
||||
case 'rules_channel_id':
|
||||
case 'public_updates_channel_id':
|
||||
case 'icon_hash':
|
||||
case 'image_hash':
|
||||
case 'splash_hash':
|
||||
case 'owner_id':
|
||||
case 'widget_channel_id':
|
||||
case 'system_channel_id':
|
||||
case 'application_id':
|
||||
case 'permissions':
|
||||
case 'allow':
|
||||
case 'deny':
|
||||
case 'channel_id':
|
||||
case 'inviter_id':
|
||||
case 'avatar_hash':
|
||||
case 'id':
|
||||
return {
|
||||
key: change.key,
|
||||
old: change.old_value
|
||||
? client.transformers.snowflake(change.old_value)
|
||||
: undefined,
|
||||
new: change.new_value
|
||||
? client.transformers.snowflake(change.new_value)
|
||||
: undefined
|
||||
}
|
||||
case 'name':
|
||||
case 'description':
|
||||
case 'preferred_locale':
|
||||
case 'region':
|
||||
case 'afk_channel_id':
|
||||
case 'vanity_url_code':
|
||||
case 'topic':
|
||||
case 'code':
|
||||
case 'nick':
|
||||
case 'location':
|
||||
return {
|
||||
key: change.key,
|
||||
old: change.old_value,
|
||||
new: change.new_value
|
||||
}
|
||||
case 'afk_timeout':
|
||||
case 'mfa_level':
|
||||
case 'verification_level':
|
||||
case 'explicit_content_filter':
|
||||
case 'default_message_notifications':
|
||||
case 'prune_delete_days':
|
||||
case 'position':
|
||||
case 'bitrate':
|
||||
case 'rate_limit_per_user':
|
||||
case 'color':
|
||||
case 'max_uses':
|
||||
case 'uses':
|
||||
case 'max_age':
|
||||
case 'expire_behavior':
|
||||
case 'expire_grace_period':
|
||||
case 'user_limit':
|
||||
case 'privacy_level':
|
||||
case 'entity_type':
|
||||
case 'status':
|
||||
return {
|
||||
key: change.key,
|
||||
old: change.old_value ? Number(change.old_value) : undefined,
|
||||
new: change.new_value ? Number(change.new_value) : undefined
|
||||
}
|
||||
case 'widget_enabled':
|
||||
case 'nsfw':
|
||||
case 'hoist':
|
||||
case 'mentionable':
|
||||
case 'temporary':
|
||||
case 'deaf':
|
||||
case 'mute':
|
||||
case 'enable_emoticons':
|
||||
return {
|
||||
key: change.key,
|
||||
old: change.old_value ?? false,
|
||||
new: change.new_value ?? false
|
||||
}
|
||||
case 'permission_overwrites':
|
||||
return {
|
||||
key: change.key,
|
||||
old: change.old_value,
|
||||
new: change.new_value
|
||||
}
|
||||
default:
|
||||
return {
|
||||
key: change.key,
|
||||
old: change.old_value,
|
||||
new: change.new_value
|
||||
}
|
||||
}
|
||||
}),
|
||||
userId: payload.user_id
|
||||
? client.transformers.snowflake(payload.user_id)
|
||||
: undefined,
|
||||
targetId: payload.target_id
|
||||
? client.transformers.snowflake(payload.target_id)
|
||||
: undefined,
|
||||
actionType: payload.action_type,
|
||||
options: payload.options
|
||||
? {
|
||||
autoModerationRuleName: payload.options.auto_moderation_rule_name,
|
||||
autoModerationRuleTriggerType:
|
||||
payload.options.auto_moderation_rule_trigger_type,
|
||||
deleteMemberDays: payload.options.delete_member_days
|
||||
? Number(payload.options.delete_member_days)
|
||||
: 0,
|
||||
membersRemoved: payload.options.members_removed
|
||||
? Number(payload.options.members_removed)
|
||||
: 0,
|
||||
channelId: payload.options.channel_id
|
||||
? client.transformers.snowflake(payload.options.channel_id)
|
||||
: undefined,
|
||||
messageId: payload.options.message_id
|
||||
? client.transformers.snowflake(payload.options.message_id)
|
||||
: undefined,
|
||||
count: payload.options.count ? Number(payload.options.count) : 0,
|
||||
id: payload.options.id
|
||||
? client.transformers.snowflake(payload.options.id)
|
||||
: undefined,
|
||||
type: Number(payload.options.type),
|
||||
roleName: payload.options.role_name
|
||||
}
|
||||
: undefined,
|
||||
reason: payload.reason
|
||||
}
|
||||
|
||||
return auditLogEntry as Optionalize<typeof auditLogEntry>
|
||||
}
|
||||
|
||||
export interface AuditLogEntry
|
||||
extends ReturnType<typeof transformAuditLogEntry> {}
|
||||
@@ -1,44 +0,0 @@
|
||||
import type {
|
||||
DiscordAutoModerationActionExecution,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAutoModerationActionExecution (
|
||||
client: Client,
|
||||
payload: DiscordAutoModerationActionExecution
|
||||
) {
|
||||
const rule = {
|
||||
content: payload.content,
|
||||
ruleTriggerType: payload.rule_trigger_type,
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
ruleId: client.transformers.snowflake(payload.rule_id),
|
||||
userId: client.transformers.snowflake(payload.user_id),
|
||||
channelId: payload.channel_id
|
||||
? client.transformers.snowflake(payload.channel_id)
|
||||
: undefined,
|
||||
messageId: payload.message_id
|
||||
? client.transformers.snowflake(payload.message_id)
|
||||
: undefined,
|
||||
alertSystemMessageId: payload.alert_system_message_id
|
||||
? client.transformers.snowflake(payload.alert_system_message_id)
|
||||
: undefined,
|
||||
matchedKeyword: payload.matched_keyword ?? '',
|
||||
matchedContent: payload.matched_content ?? '',
|
||||
action: {
|
||||
type: payload.action.type,
|
||||
metadata: {
|
||||
durationSeconds: payload.action.metadata.duration_seconds,
|
||||
channelId: payload.action.metadata.channel_id
|
||||
? client.transformers.snowflake(payload.action.metadata.channel_id)
|
||||
: undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rule as Optionalize<typeof rule>
|
||||
}
|
||||
|
||||
export interface AutoModerationActionExecution
|
||||
extends ReturnType<typeof transformAutoModerationActionExecution> {}
|
||||
@@ -1,48 +0,0 @@
|
||||
import type { DiscordAutoModerationRule, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAutoModerationRule (
|
||||
client: Client,
|
||||
payload: DiscordAutoModerationRule
|
||||
) {
|
||||
const rule = {
|
||||
name: payload.name,
|
||||
eventType: payload.event_type,
|
||||
triggerType: payload.trigger_type,
|
||||
enabled: payload.enabled,
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
creatorId: client.transformers.snowflake(payload.creator_id),
|
||||
exemptRoles: payload.exempt_roles.map((id) =>
|
||||
client.transformers.snowflake(id)
|
||||
),
|
||||
exemptChannels: payload.exempt_channels.map((id) =>
|
||||
client.transformers.snowflake(id)
|
||||
),
|
||||
triggerMetadata: payload.trigger_metadata
|
||||
? {
|
||||
keywordFilter: payload.trigger_metadata.keyword_filter,
|
||||
presets: payload.trigger_metadata.presets,
|
||||
allowList: payload.trigger_metadata.allow_list,
|
||||
mentionTotalLimit: payload.trigger_metadata.mention_total_limit
|
||||
}
|
||||
: undefined,
|
||||
actions: payload.actions.map((action) => ({
|
||||
type: action.type,
|
||||
metadata: action.metadata
|
||||
? {
|
||||
channelId: action.metadata.channel_id
|
||||
? client.transformers.snowflake(action.metadata.channel_id)
|
||||
: undefined,
|
||||
durationSeconds: action.metadata.duration_seconds
|
||||
}
|
||||
: undefined
|
||||
}))
|
||||
}
|
||||
|
||||
return rule as Optionalize<typeof rule>
|
||||
}
|
||||
|
||||
export interface AutoModerationRule
|
||||
extends ReturnType<typeof transformAutoModerationRule> {}
|
||||
@@ -1,103 +0,0 @@
|
||||
import type { DiscordChannel, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
const Mask = (1n << 64n) - 1n
|
||||
|
||||
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): bigint {
|
||||
return (v >> BigInt(shift * 64)) & Mask
|
||||
}
|
||||
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}`)
|
||||
}
|
||||
return b << BigInt(shift * 64)
|
||||
}
|
||||
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 (
|
||||
client: Client,
|
||||
payload: { channel: DiscordChannel } & { guildId?: bigint }
|
||||
) {
|
||||
const channel = {
|
||||
// UNTRANSFORMED STUFF HERE
|
||||
type: payload.channel.type,
|
||||
position: payload.channel.position,
|
||||
name: payload.channel.name,
|
||||
topic: payload.channel.topic ?? undefined,
|
||||
nsfw: payload.channel.nsfw,
|
||||
bitrate: payload.channel.bitrate,
|
||||
userLimit: payload.channel.user_limit,
|
||||
rateLimitPerUser: payload.channel.rate_limit_per_user,
|
||||
// recipients: payload.channel.recipients?.map((r) => client.transformers.user(client, r)),
|
||||
rtcRegion: payload.channel.rtc_region ?? undefined,
|
||||
videoQualityMode: payload.channel.video_quality_mode,
|
||||
guildId:
|
||||
payload.guildId ??
|
||||
(payload.channel.guild_id
|
||||
? client.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)
|
||||
)
|
||||
: [],
|
||||
|
||||
id: client.transformers.snowflake(payload.channel.id),
|
||||
permissions: payload.channel.permissions
|
||||
? client.transformers.snowflake(payload.channel.permissions)
|
||||
: undefined,
|
||||
lastMessageId: payload.channel.last_message_id
|
||||
? client.transformers.snowflake(payload.channel.last_message_id)
|
||||
: undefined,
|
||||
ownerId: payload.channel.owner_id
|
||||
? client.transformers.snowflake(payload.channel.owner_id)
|
||||
: undefined,
|
||||
applicationId: payload.channel.application_id
|
||||
? client.transformers.snowflake(payload.channel.application_id)
|
||||
: undefined,
|
||||
parentId: payload.channel.parent_id
|
||||
? client.transformers.snowflake(payload.channel.parent_id)
|
||||
: undefined,
|
||||
memberCount: payload.channel.member_count,
|
||||
messageCount: payload.channel.message_count,
|
||||
archiveTimestamp: payload.channel.thread_metadata?.archive_timestamp
|
||||
? Date.parse(payload.channel.thread_metadata.archive_timestamp)
|
||||
: undefined,
|
||||
autoArchiveDuration: payload.channel.thread_metadata?.auto_archive_duration,
|
||||
botIsMember: Boolean(payload.channel.member),
|
||||
archived: payload.channel.thread_metadata?.archived,
|
||||
locked: payload.channel.thread_metadata?.locked,
|
||||
invitable: payload.channel.thread_metadata?.invitable,
|
||||
createTimestamp: payload.channel.thread_metadata?.create_timestamp
|
||||
? Date.parse(payload.channel.thread_metadata.create_timestamp)
|
||||
: undefined,
|
||||
newlyCreated: payload.channel.newly_created,
|
||||
flags: payload.channel.flags
|
||||
}
|
||||
|
||||
return channel as Optionalize<typeof channel>
|
||||
}
|
||||
|
||||
export interface Channel extends ReturnType<typeof transformChannel> {}
|
||||
@@ -1,99 +0,0 @@
|
||||
import type {
|
||||
ButtonStyles,
|
||||
DiscordComponent,
|
||||
MessageComponentTypes,
|
||||
SelectOption,
|
||||
TextStyles
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
export function transformComponent (
|
||||
client: Client,
|
||||
payload: DiscordComponent
|
||||
): Component {
|
||||
return {
|
||||
type: payload.type,
|
||||
customId: payload.custom_id,
|
||||
disabled: payload.disabled,
|
||||
style: payload.style,
|
||||
label: payload.label,
|
||||
emoji: payload.emoji
|
||||
? {
|
||||
id: payload.emoji.id
|
||||
? client.transformers.snowflake(payload.emoji.id)
|
||||
: undefined,
|
||||
name: payload.emoji.name,
|
||||
animated: payload.emoji.animated
|
||||
}
|
||||
: undefined,
|
||||
url: payload.url,
|
||||
options: payload.options?.map((option) => ({
|
||||
label: option.label,
|
||||
value: option.value,
|
||||
description: option.description,
|
||||
emoji: option.emoji
|
||||
? {
|
||||
id: option.emoji.id
|
||||
? client.transformers.snowflake(option.emoji.id)
|
||||
: undefined,
|
||||
name: option.emoji.name,
|
||||
animated: option.emoji.animated
|
||||
}
|
||||
: undefined,
|
||||
default: option.default
|
||||
})),
|
||||
placeholder: payload.placeholder,
|
||||
minValues: payload.min_values,
|
||||
maxValues: payload.max_values,
|
||||
minLength: payload.min_length,
|
||||
maxLength: payload.max_length,
|
||||
value: payload.value,
|
||||
components: payload.components?.map((component) =>
|
||||
client.transformers.component(client, component)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// THIS TRANSFORMER HAS A CIRCULAR REFERENCE TO CALL ITSELF FOR COMPONENTS SO AN AUTOMATED TYPE CAN NOT BE CREATED!
|
||||
|
||||
export interface Component {
|
||||
/** component type */
|
||||
type: MessageComponentTypes
|
||||
/** a developer-defined identifier for the component, max 100 characters */
|
||||
customId?: string
|
||||
/** whether this component is required to be filled, default true */
|
||||
required?: boolean
|
||||
/** whether the component is disabled, default false */
|
||||
disabled?: boolean
|
||||
/** For different styles/colors of the buttons */
|
||||
style?: ButtonStyles | TextStyles
|
||||
/** text that appears on the button (max 80 characters) */
|
||||
label?: string
|
||||
/** the dev-define value of the option, max 100 characters for select or 4000 for input. */
|
||||
value?: string
|
||||
/** Emoji object that includes fields of name, id, and animated supporting unicode and custom emojis. */
|
||||
emoji?: {
|
||||
/** Emoji id */
|
||||
id?: bigint
|
||||
/** Emoji name */
|
||||
name?: string
|
||||
/** Whether this emoji is animated */
|
||||
animated?: boolean
|
||||
}
|
||||
/** optional url for link-style buttons that can navigate a user to the web. Only type 5 Link buttons can have a url */
|
||||
url?: string
|
||||
/** The choices! Maximum of 25 items. */
|
||||
options?: SelectOption[]
|
||||
/** A custom placeholder text if nothing is selected. Maximum 150 characters. */
|
||||
placeholder?: string
|
||||
/** The minimum number of items that must be selected. Default 1. Between 1-25. */
|
||||
minValues?: number
|
||||
/** The maximum number of items that can be selected. Default 1. Between 1-25. */
|
||||
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. */
|
||||
maxLength?: number
|
||||
/** a list of child components */
|
||||
components?: Component[]
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import type { DiscordEmbed, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformEmbed (client: Client, payload: DiscordEmbed) {
|
||||
const embed = {
|
||||
title: payload.title,
|
||||
type: payload.type,
|
||||
description: payload.description,
|
||||
url: payload.url,
|
||||
timestamp: payload.timestamp ? Date.parse(payload.timestamp) : undefined,
|
||||
color: payload.color,
|
||||
footer: payload.footer
|
||||
? {
|
||||
text: payload.footer.text,
|
||||
iconUrl: payload.footer.icon_url,
|
||||
proxyIconUrl: payload.footer.proxy_icon_url
|
||||
}
|
||||
: undefined,
|
||||
image: payload.image
|
||||
? {
|
||||
url: payload.image.url,
|
||||
proxyUrl: payload.image.proxy_url,
|
||||
height: payload.image.height,
|
||||
width: payload.image.width
|
||||
}
|
||||
: undefined,
|
||||
thumbnail: payload.thumbnail
|
||||
? {
|
||||
url: payload.thumbnail.url,
|
||||
proxyUrl: payload.thumbnail.proxy_url,
|
||||
height: payload.thumbnail.height,
|
||||
width: payload.thumbnail.width
|
||||
}
|
||||
: undefined,
|
||||
video: payload.video
|
||||
? {
|
||||
url: payload.video.url,
|
||||
proxyUrl: payload.video.proxy_url,
|
||||
height: payload.video.height,
|
||||
width: payload.video.width
|
||||
}
|
||||
: undefined,
|
||||
provider: payload.provider,
|
||||
author: payload.author
|
||||
? {
|
||||
name: payload.author.name,
|
||||
url: payload.author.url,
|
||||
iconUrl: payload.author.icon_url,
|
||||
proxyIconUrl: payload.author.proxy_icon_url
|
||||
}
|
||||
: undefined,
|
||||
fields: payload.fields
|
||||
}
|
||||
|
||||
return embed as Optionalize<typeof embed>
|
||||
}
|
||||
|
||||
export interface Embed extends ReturnType<typeof transformEmbed> {}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type { DiscordEmoji, Optionalize } from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
import { EmojiToggles } from './toggles/emoji.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformEmoji (client: Client, payload: DiscordEmoji) {
|
||||
const emoji = {
|
||||
id: payload.id ? client.transformers.snowflake(payload.id) : undefined,
|
||||
name: payload.name,
|
||||
roles: payload.roles?.map((id) => client.transformers.snowflake(id)),
|
||||
user: payload.user
|
||||
? client.transformers.user(client, payload.user)
|
||||
: undefined,
|
||||
toggles: new EmojiToggles(payload)
|
||||
}
|
||||
|
||||
return emoji as Optionalize<typeof emoji>
|
||||
}
|
||||
|
||||
export interface Emoji extends ReturnType<typeof transformEmoji> {}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type {
|
||||
DiscordGetGatewayBot,
|
||||
GetGatewayBot,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
|
||||
export function transformGatewayBot (
|
||||
payload: DiscordGetGatewayBot
|
||||
): GetGatewayBot {
|
||||
const gatewayClient = {
|
||||
url: payload.url,
|
||||
shards: payload.shards,
|
||||
sessionStartLimit: {
|
||||
total: payload.session_start_limit.total,
|
||||
remaining: payload.session_start_limit.remaining,
|
||||
resetAfter: payload.session_start_limit.reset_after,
|
||||
maxConcurrency: payload.session_start_limit.max_concurrency
|
||||
}
|
||||
}
|
||||
|
||||
return gatewayClient as Optionalize<typeof gatewayClient>
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
import type { DiscordGuild, Optionalize } from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { Client } from '../client.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 (
|
||||
client: Client,
|
||||
payload: { guild: DiscordGuild } & { shardId: number }
|
||||
) {
|
||||
const guildId = client.transformers.snowflake(payload.guild.id)
|
||||
|
||||
const guild = {
|
||||
afkTimeout: payload.guild.afk_timeout,
|
||||
approximateMemberCount: payload.guild.approximate_member_count,
|
||||
approximatePresenceCount: payload.guild.approximate_presence_count,
|
||||
defaultMessageNotifications: payload.guild.default_message_notifications,
|
||||
description: payload.guild.description,
|
||||
explicitContentFilter: payload.guild.explicit_content_filter,
|
||||
toggles: new GuildToggles(payload.guild),
|
||||
maxMembers: payload.guild.max_members,
|
||||
maxPresences: payload.guild.max_presences ?? undefined,
|
||||
maxVideoChannelUsers: payload.guild.max_video_channel_users,
|
||||
mfaLevel: payload.guild.mfa_level,
|
||||
name: payload.guild.name,
|
||||
nsfwLevel: payload.guild.nsfw_level,
|
||||
preferredLocale: payload.guild.preferred_locale,
|
||||
premiumSubscriptionCount: payload.guild.premium_subscription_count,
|
||||
premiumTier: payload.guild.premium_tier,
|
||||
stageInstances: payload.guild.stage_instances?.map((si) => ({
|
||||
/** The id of this Stage instance */
|
||||
id: client.transformers.snowflake(si.id),
|
||||
/** The guild id of the associated Stage channel */
|
||||
guildId,
|
||||
/** The id of the associated Stage channel */
|
||||
channelId: client.transformers.snowflake(si.channel_id),
|
||||
/** The topic of the Stage instance (1-120 characters) */
|
||||
topic: si.topic
|
||||
})),
|
||||
systemChannelFlags: payload.guild.system_channel_flags,
|
||||
vanityUrlCode: payload.guild.vanity_url_code,
|
||||
verificationLevel: payload.guild.verification_level,
|
||||
welcomeScreen: payload.guild.welcome_screen
|
||||
? {
|
||||
description: payload.guild.welcome_screen.description ?? undefined,
|
||||
welcomeChannels: payload.guild.welcome_screen.welcome_channels.map(
|
||||
(wc) => ({
|
||||
channelId: client.transformers.snowflake(wc.channel_id),
|
||||
description: wc.description,
|
||||
emojiId: wc.emoji_id
|
||||
? client.transformers.snowflake(wc.emoji_id)
|
||||
: undefined,
|
||||
emojiName: wc.emoji_name ?? undefined
|
||||
})
|
||||
)
|
||||
}
|
||||
: undefined,
|
||||
discoverySplash: payload.guild.discovery_splash
|
||||
? client.utils.iconHashToBigInt(payload.guild.discovery_splash)
|
||||
: undefined,
|
||||
|
||||
joinedAt: payload.guild.joined_at
|
||||
? Date.parse(payload.guild.joined_at)
|
||||
: undefined,
|
||||
memberCount: payload.guild.member_count ?? 0,
|
||||
shardId: payload.shardId,
|
||||
icon: payload.guild.icon
|
||||
? client.utils.iconHashToBigInt(payload.guild.icon)
|
||||
: undefined,
|
||||
banner: payload.guild.banner
|
||||
? client.utils.iconHashToBigInt(payload.guild.banner)
|
||||
: undefined,
|
||||
splash: payload.guild.splash
|
||||
? client.utils.iconHashToBigInt(payload.guild.splash)
|
||||
: undefined,
|
||||
channels: new Collection(
|
||||
payload.guild.channels?.map((channel) => {
|
||||
const result = client.transformers.channel(client, {
|
||||
channel,
|
||||
guildId
|
||||
})
|
||||
return [result.id, result]
|
||||
})
|
||||
),
|
||||
members: new Collection(
|
||||
payload.guild.members?.map((member) => {
|
||||
const result = client.transformers.member(
|
||||
client,
|
||||
member,
|
||||
guildId,
|
||||
client.transformers.snowflake(member.user!.id)
|
||||
)
|
||||
return [result.id, result]
|
||||
})
|
||||
),
|
||||
roles: new Collection(
|
||||
payload.guild.roles?.map((role) => {
|
||||
const result = client.transformers.role(client, { role, guildId })
|
||||
return [result.id, result]
|
||||
})
|
||||
),
|
||||
emojis: new Collection(
|
||||
(payload.guild.emojis ?? []).map((emoji) => {
|
||||
const em: Emoji = client.transformers.emoji(client, emoji)
|
||||
return [em.id!, em]
|
||||
})
|
||||
),
|
||||
voiceStates: new Collection(
|
||||
(payload.guild.voice_states ?? [])
|
||||
.map((vs) =>
|
||||
client.transformers.voiceState(client, { voiceState: vs, guildId })
|
||||
)
|
||||
.map((vs) => [vs.userId, vs])
|
||||
),
|
||||
|
||||
id: guildId,
|
||||
// WEIRD EDGE CASE WITH BOT CREATED SERVERS
|
||||
ownerId: payload.guild.owner_id
|
||||
? client.transformers.snowflake(payload.guild.owner_id)
|
||||
: 0n,
|
||||
permissions: payload.guild.permissions
|
||||
? client.transformers.snowflake(payload.guild.permissions)
|
||||
: 0n,
|
||||
afkChannelId: payload.guild.afk_channel_id
|
||||
? client.transformers.snowflake(payload.guild.afk_channel_id)
|
||||
: undefined,
|
||||
widgetChannelId: payload.guild.widget_channel_id
|
||||
? client.transformers.snowflake(payload.guild.widget_channel_id)
|
||||
: undefined,
|
||||
applicationId: payload.guild.application_id
|
||||
? client.transformers.snowflake(payload.guild.application_id)
|
||||
: undefined,
|
||||
systemChannelId: payload.guild.system_channel_id
|
||||
? client.transformers.snowflake(payload.guild.system_channel_id)
|
||||
: undefined,
|
||||
rulesChannelId: payload.guild.rules_channel_id
|
||||
? client.transformers.snowflake(payload.guild.rules_channel_id)
|
||||
: undefined,
|
||||
publicUpdatesChannelId: payload.guild.public_updates_channel_id
|
||||
? client.transformers.snowflake(payload.guild.public_updates_channel_id)
|
||||
: undefined,
|
||||
premiumProgressBarEnabled: payload.guild.premium_progress_bar_enabled
|
||||
}
|
||||
|
||||
return guild as Optionalize<typeof guild>
|
||||
}
|
||||
|
||||
export interface Guild extends ReturnType<typeof transformGuild> {}
|
||||
@@ -1,37 +0,0 @@
|
||||
export * from './activity.js'
|
||||
export * from './application.js'
|
||||
export * from './applicationCommand.js'
|
||||
export * from './applicationCommandOption.js'
|
||||
export * from './applicationCommandOptionChoice.js'
|
||||
export * from './applicationCommandPermission.js'
|
||||
export * from './attachment.js'
|
||||
export * from './auditLogEntry.js'
|
||||
export * from './automodActionExecution.js'
|
||||
export * from './automodRule.js'
|
||||
export * from './channel.js'
|
||||
export * from './component.js'
|
||||
export * from './embed.js'
|
||||
export * from './emoji.js'
|
||||
export * from './gatewayBot.js'
|
||||
export * from './guild.js'
|
||||
export * from './integration.js'
|
||||
export * from './interaction.js'
|
||||
export * from './invite.js'
|
||||
export * from './member.js'
|
||||
export * from './message.js'
|
||||
export * from './presence.js'
|
||||
export * from './reverse/index.js'
|
||||
export * from './role.js'
|
||||
export * from './scheduledEvent.js'
|
||||
export * from './stageInstance.js'
|
||||
export * from './sticker.js'
|
||||
export * from './team.js'
|
||||
export * from './template.js'
|
||||
export * from './threadMember.js'
|
||||
export * from './toggles/index.js'
|
||||
export * from './voiceRegion.js'
|
||||
export * from './voiceState.js'
|
||||
export * from './webhook.js'
|
||||
export * from './welcomeScreen.js'
|
||||
export * from './widget.js'
|
||||
export * from './widgetSettings.js'
|
||||
@@ -1,54 +0,0 @@
|
||||
import type {
|
||||
DiscordIntegrationCreateUpdate,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import type { Client } from '../client.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformIntegration (
|
||||
client: Client,
|
||||
payload: DiscordIntegrationCreateUpdate
|
||||
) {
|
||||
const integration = {
|
||||
guildId: client.transformers.snowflake(payload.guild_id),
|
||||
id: client.transformers.snowflake(payload.id),
|
||||
name: payload.name,
|
||||
type: payload.type,
|
||||
enabled: payload.enabled,
|
||||
syncing: payload.syncing,
|
||||
roleId: payload.role_id
|
||||
? client.transformers.snowflake(payload.role_id)
|
||||
: undefined,
|
||||
enableEmoticons: payload.enable_emoticons,
|
||||
expireBehavior: payload.expire_behavior,
|
||||
expireGracePeriod: payload.expire_grace_period,
|
||||
user: payload.user
|
||||
? client.transformers.user(client, payload.user)
|
||||
: undefined,
|
||||
account: {
|
||||
id: client.transformers.snowflake(payload.account.id),
|
||||
name: payload.account.name
|
||||
},
|
||||
syncedAt: payload.synced_at ? Date.parse(payload.synced_at) : undefined,
|
||||
subscriberCount: payload.subscriber_count,
|
||||
revoked: payload.revoked,
|
||||
application: payload.application
|
||||
? {
|
||||
id: client.transformers.snowflake(payload.application.id),
|
||||
name: payload.application.name,
|
||||
icon: payload.application.icon
|
||||
? client.utils.iconHashToBigInt(payload.application.icon)
|
||||
: undefined,
|
||||
description: payload.application.description,
|
||||
client: payload.application.bot
|
||||
? client.transformers.user(client, payload.application.bot)
|
||||
: undefined
|
||||
}
|
||||
: undefined,
|
||||
scopes: payload.scopes
|
||||
}
|
||||
|
||||
return integration as Optionalize<typeof integration>
|
||||
}
|
||||
|
||||
export interface Integration extends ReturnType<typeof transformIntegration> {}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user