mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
refactor: remove transformers in helpers/channel
This commit is contained in:
@@ -7,7 +7,7 @@ import type { RestManager } from '../../../restManager.js'
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param sourceChannelId - The ID of the announcement channel to follow.
|
||||
* @param targetChannelId - The ID of the target channel - the channel to cross-post to.
|
||||
* @returns An instance of {@link FollowedChannel}.
|
||||
* @returns An instance of {@link DiscordFollowedChannel}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission in the __target channel__.
|
||||
@@ -20,7 +20,7 @@ export async function followAnnouncementChannel (
|
||||
rest: RestManager,
|
||||
sourceChannelId: BigString,
|
||||
targetChannelId: BigString
|
||||
): Promise<bigint> {
|
||||
): Promise<DiscordFollowedChannel> {
|
||||
const result = await rest.runMethod<DiscordFollowedChannel>(
|
||||
rest,
|
||||
'POST',
|
||||
@@ -30,5 +30,5 @@ export async function followAnnouncementChannel (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.snowflake(result.webhook_id)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import type {
|
||||
BigString,
|
||||
DiscordChannel,
|
||||
OverwriteReadable,
|
||||
SnakeToCamelCaseNested,
|
||||
SortOrderTypes,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import { ChannelTypes } from '@discordeno/types'
|
||||
import { calculateBits } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Channel } from '../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../transformer.js'
|
||||
|
||||
/**
|
||||
* Creates a channel within a guild.
|
||||
@@ -16,7 +17,7 @@ import type { Channel } from '../../transformers/channel.js'
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param guildId - The ID of the guild to create the channel within.
|
||||
* @param options - The parameters for the creation of the channel.
|
||||
* @returns An instance of the created {@link Channel}.
|
||||
* @returns An instance of the created {@link DiscordChannel}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_CHANNELS` permission.
|
||||
@@ -33,7 +34,7 @@ export async function createChannel (
|
||||
rest: RestManager,
|
||||
guildId: BigString,
|
||||
options: CreateGuildChannel
|
||||
): Promise<Channel> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordChannel>> {
|
||||
// BITRATE IS IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000
|
||||
|
||||
@@ -89,10 +90,7 @@ export async function createChannel (
|
||||
: {}
|
||||
)
|
||||
|
||||
return rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: rest.transformers.snowflake(guildId)
|
||||
})
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
export interface CreateGuildChannel extends WithReason {
|
||||
|
||||
@@ -3,13 +3,14 @@ import type {
|
||||
ChannelTypes,
|
||||
DiscordChannel,
|
||||
OverwriteReadable,
|
||||
SnakeToCamelCaseNested,
|
||||
SortOrderTypes,
|
||||
VideoQualityModes,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import { calculateBits } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Channel } from '../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../transformer.js'
|
||||
|
||||
/**
|
||||
* Edits a channel's settings.
|
||||
@@ -17,7 +18,7 @@ import type { Channel } from '../../transformers/channel.js'
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel to edit.
|
||||
* @param options - The parameters for the edit of the channel.
|
||||
* @returns An instance of the edited {@link Channel}.
|
||||
* @returns An instance of the edited {@link DiscordChannel}.
|
||||
*
|
||||
* @remarks
|
||||
* If editing a channel of type {@link ChannelTypes.GroupDm}:
|
||||
@@ -45,7 +46,7 @@ export async function editChannel (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options: ModifyChannel
|
||||
): Promise<Channel> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordChannel>> {
|
||||
if (options.name ?? options.topic) {
|
||||
const request = editChannelNameTopicQueue.get(channelId)
|
||||
if (request == null) {
|
||||
@@ -62,13 +63,15 @@ export async function editChannel (
|
||||
request.amount = 2
|
||||
request.timestamp = Date.now() + 600000
|
||||
} else {
|
||||
return await new Promise<Channel>((resolve, reject) => {
|
||||
// 2 have already been used add to queue
|
||||
request.items.push({ channelId, options, resolve, reject })
|
||||
if (editChannelProcessing) return
|
||||
editChannelProcessing = true
|
||||
processEditChannelQueue(rest)
|
||||
})
|
||||
return await new Promise<SnakeToCamelCaseNested<DiscordChannel>>(
|
||||
(resolve, reject) => {
|
||||
// 2 have already been used add to queue
|
||||
request.items.push({ channelId, options, resolve, reject })
|
||||
if (editChannelProcessing) return
|
||||
editChannelProcessing = true
|
||||
processEditChannelQueue(rest)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +125,7 @@ export async function editChannel (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: rest.transformers.snowflake(result.guild_id!)
|
||||
})
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
interface EditChannelRequest {
|
||||
@@ -135,7 +135,7 @@ interface EditChannelRequest {
|
||||
items: Array<{
|
||||
channelId: BigString
|
||||
options: ModifyChannel
|
||||
resolve: (channel: Channel) => void
|
||||
resolve: (channel: SnakeToCamelCaseNested<DiscordChannel>) => void
|
||||
// deno-lint-ignore no-explicit-any
|
||||
reject: (error: any) => void
|
||||
}>
|
||||
|
||||
@@ -4,10 +4,11 @@ import type {
|
||||
DiscordChannel,
|
||||
FileContent,
|
||||
MessageComponents,
|
||||
SnakeToCamelCaseNested,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { Channel } from '../../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
import type { Embed } from '../../../transformers/embed.js'
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,7 @@ import type { Embed } from '../../../transformers/embed.js'
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the forum channel to create the thread within.
|
||||
* @param options - The parameters for the creation of the thread.
|
||||
* @returns An instance of {@link Channel} with a nested {@link Message} object.
|
||||
* @returns An instance of {@link DiscordChannel} with a nested {@link Message} object.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `CREATE_MESSAGES` permission.
|
||||
@@ -32,7 +33,7 @@ export async function createForumThread (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options: CreateForumPostWithMessage
|
||||
): Promise<Channel> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordChannel>> {
|
||||
const result = await rest.runMethod<DiscordChannel>(
|
||||
rest,
|
||||
'POST',
|
||||
@@ -62,10 +63,7 @@ export async function createForumThread (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: rest.transformers.snowflake(result.guild_id!)
|
||||
})
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
export interface CreateForumPostWithMessage extends WithReason {
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import type { BigString, DiscordChannel } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordChannel,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Channel } from '../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets a channel by its ID.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel to get.
|
||||
* @returns An instance of {@link Channel}.
|
||||
* @returns An instance of {@link DiscordChannel}.
|
||||
*
|
||||
* @remarks
|
||||
* If the channel is a thread, a {@link ThreadMember} object is included in the result.
|
||||
@@ -17,7 +21,7 @@ import type { Channel } from '../../transformers/channel.js'
|
||||
export async function getChannel (
|
||||
rest: RestManager,
|
||||
channelId: BigString
|
||||
): Promise<Channel> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordChannel>> {
|
||||
const result = await rest.runMethod<DiscordChannel>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -25,10 +29,5 @@ export async function getChannel (
|
||||
)
|
||||
|
||||
// IF A CHANNEL DOESN'T EXIST, DISCORD RETURNS `{}`
|
||||
return rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: result.guild_id
|
||||
? rest.transformers.snowflake(result.guild_id)
|
||||
: undefined
|
||||
})
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import type { BigString, DiscordInviteMetadata } from '@discordeno/types'
|
||||
import { TargetTypes } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordInviteMetadata,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { InviteMetadata } from '../guilds/invites/index.js'
|
||||
import { snakeToCamelCaseNested } from '../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets the list of invites for a channel.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel to get the invites of.
|
||||
* @returns A collection of {@link InviteMetadata} objects assorted by invite code.
|
||||
* @returns A collection of {@link DiscordInviteMetadata} objects assorted by invite code.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_CHANNELS` permission.
|
||||
@@ -21,7 +24,7 @@ import type { InviteMetadata } from '../guilds/invites/index.js'
|
||||
export async function getChannelInvites (
|
||||
rest: RestManager,
|
||||
channelId: BigString
|
||||
): Promise<Collection<string, InviteMetadata>> {
|
||||
): Promise<Collection<string, SnakeToCamelCaseNested<DiscordInviteMetadata>>> {
|
||||
const results = await rest.runMethod<DiscordInviteMetadata[]>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -29,45 +32,10 @@ export async function getChannelInvites (
|
||||
)
|
||||
|
||||
return new Collection(
|
||||
results.map<[string, InviteMetadata]>((result) => {
|
||||
const invite = {
|
||||
code: result.code,
|
||||
guildId: result.guild?.id
|
||||
? rest.transformers.snowflake(result.guild.id)
|
||||
: undefined,
|
||||
channelId: result.channel?.id
|
||||
? rest.transformers.snowflake(result.channel.id)
|
||||
: undefined,
|
||||
inviter: result.inviter
|
||||
? rest.transformers.user(rest, result.inviter)
|
||||
: undefined,
|
||||
targetType: result.target_type
|
||||
? result.target_type === 1
|
||||
? TargetTypes.Stream
|
||||
: TargetTypes.EmbeddedApplication
|
||||
: undefined,
|
||||
targetUser: result.target_user
|
||||
? rest.transformers.user(rest, result.target_user)
|
||||
: undefined,
|
||||
targetApplicationId: result.target_application?.id
|
||||
? rest.transformers.snowflake(result.target_application.id)
|
||||
: undefined,
|
||||
approximatePresenceCount: result.approximate_presence_count,
|
||||
approximateMemberCount: result.approximate_member_count,
|
||||
expiresAt: result.expires_at
|
||||
? Date.parse(result.expires_at)
|
||||
: undefined,
|
||||
guildScheduledEvent: result.guild_scheduled_event
|
||||
? rest.transformers.scheduledEvent(rest, result.guild_scheduled_event)
|
||||
: undefined,
|
||||
// Metadata structure
|
||||
uses: result.uses,
|
||||
maxUses: result.max_uses,
|
||||
maxAge: result.max_age,
|
||||
temporary: result.temporary,
|
||||
createdAt: Date.parse(result.created_at)
|
||||
results.map<[string, SnakeToCamelCaseNested<DiscordInviteMetadata>]>(
|
||||
(result) => {
|
||||
return [result.code, snakeToCamelCaseNested(result)]
|
||||
}
|
||||
return [invite.code, invite]
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import type { BigString, DiscordChannel } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordChannel,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Channel } from '../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets the list of channels for a guild.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param guildId - The ID of the guild to get the channels of.
|
||||
* @returns A collection of {@link Channel} objects assorted by channel ID.
|
||||
* @returns A collection of {@link DiscordChannel} objects assorted by channel ID.
|
||||
*
|
||||
* @remarks
|
||||
* Excludes threads.
|
||||
@@ -18,21 +22,16 @@ import type { Channel } from '../../transformers/channel.js'
|
||||
export async function getChannels (
|
||||
rest: RestManager,
|
||||
guildId: BigString
|
||||
): Promise<Collection<bigint, Channel>> {
|
||||
): Promise<Collection<string, SnakeToCamelCaseNested<DiscordChannel>>> {
|
||||
const results = await rest.runMethod<DiscordChannel[]>(
|
||||
rest,
|
||||
'GET',
|
||||
rest.constants.routes.GUILD_CHANNELS(guildId)
|
||||
)
|
||||
|
||||
const id = rest.transformers.snowflake(guildId)
|
||||
|
||||
return new Collection(
|
||||
results.map((result) => {
|
||||
const channel = rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: id
|
||||
})
|
||||
const channel = snakeToCamelCaseNested(result)
|
||||
return [channel.id, channel]
|
||||
})
|
||||
)
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import type {
|
||||
BigString,
|
||||
DiscordStageInstance,
|
||||
SnakeToCamelCaseNested,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { StageInstance } from '../../../transformers/stageInstance.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Creates a stage instance associated with a stage channel.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param options - The parameters for the creation of the stage instance.
|
||||
* @returns An instance of the created {@link StageInstance}.
|
||||
* @returns An instance of the created {@link DiscordStageInstance}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the user to be a moderator of the stage channel.
|
||||
@@ -23,7 +24,7 @@ import type { StageInstance } from '../../../transformers/stageInstance.js'
|
||||
export async function createStageInstance (
|
||||
rest: RestManager,
|
||||
options: CreateStageInstance
|
||||
): Promise<StageInstance> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordStageInstance>> {
|
||||
const result = await rest.runMethod<DiscordStageInstance>(
|
||||
rest,
|
||||
'POST',
|
||||
@@ -36,7 +37,7 @@ export async function createStageInstance (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.stageInstance(rest, result)
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
export interface CreateStageInstance extends WithReason {
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import type {
|
||||
BigString,
|
||||
DiscordStageInstance,
|
||||
SnakeToCamelCaseNested,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { StageInstance } from '../../../transformers/stageInstance.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Edits a stage instance.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the stage channel the stage instance is associated with.
|
||||
* @returns An instance of the updated {@link StageInstance}.
|
||||
* @returns An instance of the updated {@link DiscordStageInstance}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the user to be a moderator of the stage channel.
|
||||
@@ -24,7 +25,7 @@ export async function editStageInstance (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
data: EditStageInstanceOptions
|
||||
): Promise<StageInstance> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordStageInstance>> {
|
||||
const result = await rest.runMethod<DiscordStageInstance>(
|
||||
rest,
|
||||
'PATCH',
|
||||
@@ -34,7 +35,7 @@ export async function editStageInstance (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.stageInstance(rest, result)
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
export interface EditStageInstanceOptions extends WithReason {
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
import type { BigString, DiscordStageInstance } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordStageInstance,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { StageInstance } from '../../../transformers/stageInstance.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets the stage instance associated with a stage channel, if one exists.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the stage channel the stage instance is associated with.
|
||||
* @returns An instance of {@link StageInstance}.
|
||||
* @returns An instance of {@link DiscordStageInstance}.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/stage-instance#get-stage-instance}
|
||||
*/
|
||||
export async function getStageInstance (
|
||||
rest: RestManager,
|
||||
channelId: BigString
|
||||
): Promise<StageInstance> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordStageInstance>> {
|
||||
const result = await rest.runMethod<DiscordStageInstance>(
|
||||
rest,
|
||||
'GET',
|
||||
rest.constants.routes.STAGE_INSTANCE(channelId)
|
||||
)
|
||||
|
||||
return rest.transformers.stageInstance(rest, result)
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import type { BigString, DiscordListActiveThreads } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordChannel,
|
||||
DiscordListActiveThreads,
|
||||
DiscordThreadMember,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { Channel } from '../../../transformers/channel.js'
|
||||
import type { ThreadMember } from '../../../transformers/threadMember.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets the list of all active threads for a guild.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param guildId - The ID of the guild to get the threads of.
|
||||
* @returns An instance of {@link ActiveThreads}.
|
||||
* @returns An instance of {@link DiscordActiveThreads}.
|
||||
*
|
||||
* @remarks
|
||||
* Returns both public and private threads.
|
||||
@@ -21,7 +26,7 @@ import type { ThreadMember } from '../../../transformers/threadMember.js'
|
||||
export async function getActiveThreads (
|
||||
rest: RestManager,
|
||||
guildId: BigString
|
||||
): Promise<ActiveThreads> {
|
||||
): Promise<DiscordActiveThreads> {
|
||||
const results = await rest.runMethod<DiscordListActiveThreads>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -31,20 +36,20 @@ export async function getActiveThreads (
|
||||
return {
|
||||
threads: new Collection(
|
||||
results.threads.map((result) => {
|
||||
const thread = rest.transformers.channel(rest, { channel: result })
|
||||
const thread = snakeToCamelCaseNested(result)
|
||||
return [thread.id, thread]
|
||||
})
|
||||
),
|
||||
members: new Collection(
|
||||
results.members.map((result) => {
|
||||
const member = rest.transformers.threadMember(rest, result)
|
||||
const member = snakeToCamelCaseNested(result)
|
||||
return [member.id!, member]
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export interface ActiveThreads {
|
||||
threads: Collection<bigint, Channel>
|
||||
members: Collection<bigint, ThreadMember>
|
||||
export interface DiscordActiveThreads {
|
||||
threads: Collection<string, SnakeToCamelCaseNested<DiscordChannel>>
|
||||
members: Collection<string, SnakeToCamelCaseNested<DiscordThreadMember>>
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { BigString, DiscordListArchivedThreads } from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
import type {
|
||||
ArchivedThreads,
|
||||
DiscordArchivedThreads,
|
||||
ListArchivedThreads
|
||||
} from './getPublicArchivedThreads.js'
|
||||
|
||||
@@ -12,7 +13,7 @@ import type {
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel to get the archived threads for.
|
||||
* @param options - The parameters for the fetching of threads.
|
||||
* @returns An instance of {@link ArchivedThreads}.
|
||||
* @returns An instance of {@link DiscordArchivedThreads}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `READ_MESSAGE_HISTORY` permission.
|
||||
@@ -28,7 +29,7 @@ export async function getPrivateArchivedThreads (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options?: ListArchivedThreads
|
||||
): Promise<ArchivedThreads> {
|
||||
): Promise<DiscordArchivedThreads> {
|
||||
const results = await rest.runMethod<DiscordListArchivedThreads>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -38,13 +39,13 @@ export async function getPrivateArchivedThreads (
|
||||
return {
|
||||
threads: new Collection(
|
||||
results.threads.map((result) => {
|
||||
const thread = rest.transformers.channel(rest, { channel: result })
|
||||
const thread = snakeToCamelCaseNested(result)
|
||||
return [thread.id, thread]
|
||||
})
|
||||
),
|
||||
members: new Collection(
|
||||
results.members.map((result) => {
|
||||
const member = rest.transformers.threadMember(rest, result)
|
||||
const member = snakeToCamelCaseNested(result)
|
||||
return [member.id!, member]
|
||||
})
|
||||
),
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { BigString, DiscordListArchivedThreads } from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
import type {
|
||||
ArchivedThreads,
|
||||
DiscordArchivedThreads,
|
||||
ListArchivedThreads
|
||||
} from './getPublicArchivedThreads.js'
|
||||
|
||||
@@ -12,7 +13,7 @@ import type {
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel to get the archived threads for.
|
||||
* @param options - The parameters for the fetching of threads.
|
||||
* @returns An instance of {@link ArchivedThreads}.
|
||||
* @returns An instance of {@link DiscordArchivedThreads}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `READ_MESSAGE_HISTORY` permission.
|
||||
@@ -27,7 +28,7 @@ export async function getPrivateJoinedArchivedThreads (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options?: ListArchivedThreads
|
||||
): Promise<ArchivedThreads> {
|
||||
): Promise<DiscordArchivedThreads> {
|
||||
const results = await rest.runMethod<DiscordListArchivedThreads>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -37,13 +38,13 @@ export async function getPrivateJoinedArchivedThreads (
|
||||
return {
|
||||
threads: new Collection(
|
||||
results.threads.map((result) => {
|
||||
const thread = rest.transformers.channel(rest, { channel: result })
|
||||
const thread = snakeToCamelCaseNested(result)
|
||||
return [thread.id, thread]
|
||||
})
|
||||
),
|
||||
members: new Collection(
|
||||
results.members.map((result) => {
|
||||
const member = rest.transformers.threadMember(rest, result)
|
||||
const member = snakeToCamelCaseNested(result)
|
||||
return [member.id!, member]
|
||||
})
|
||||
),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { BigString, DiscordListArchivedThreads } from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { ActiveThreads } from './getActiveThreads.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
import type { DiscordActiveThreads } from './getActiveThreads.js'
|
||||
|
||||
/**
|
||||
* Gets the list of public archived threads for a channel.
|
||||
@@ -25,7 +26,7 @@ export async function getPublicArchivedThreads (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options?: ListArchivedThreads
|
||||
): Promise<ArchivedThreads> {
|
||||
): Promise<DiscordArchivedThreads> {
|
||||
const results = await rest.runMethod<DiscordListArchivedThreads>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -35,13 +36,13 @@ export async function getPublicArchivedThreads (
|
||||
return {
|
||||
threads: new Collection(
|
||||
results.threads.map((result) => {
|
||||
const thread = rest.transformers.channel(rest, { channel: result })
|
||||
const thread = snakeToCamelCaseNested(result)
|
||||
return [thread.id, thread]
|
||||
})
|
||||
),
|
||||
members: new Collection(
|
||||
results.members.map((result) => {
|
||||
const member = rest.transformers.threadMember(rest, result)
|
||||
const member = snakeToCamelCaseNested(result)
|
||||
return [member.id!, member]
|
||||
})
|
||||
),
|
||||
@@ -57,6 +58,6 @@ export interface ListArchivedThreads {
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export type ArchivedThreads = ActiveThreads & {
|
||||
export type DiscordArchivedThreads = DiscordActiveThreads & {
|
||||
hasMore: boolean
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import type { BigString, DiscordThreadMember } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordThreadMember,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { ThreadMember } from '../../../transformers/threadMember.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets a thread member by their user ID.
|
||||
@@ -8,7 +12,7 @@ import type { ThreadMember } from '../../../transformers/threadMember.js'
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the thread to get the thread member of.
|
||||
* @param userId - The user ID of the thread member to get.
|
||||
* @returns An instance of {@link ThreadMember}.
|
||||
* @returns An instance of {@link DiscordThreadMember}.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#get-thread-member}
|
||||
*/
|
||||
@@ -16,12 +20,12 @@ export async function getThreadMember (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
userId: BigString
|
||||
): Promise<ThreadMember> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordThreadMember>> {
|
||||
const result = await rest.runMethod<DiscordThreadMember>(
|
||||
rest,
|
||||
'GET',
|
||||
rest.constants.routes.THREAD_USER(channelId, userId)
|
||||
)
|
||||
|
||||
return rest.transformers.threadMember(rest, result)
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import type { BigString, DiscordThreadMember } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordThreadMember,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { ThreadMember } from '../../../transformers/threadMember.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Gets the list of thread members for a thread.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the thread to get the thread members of.
|
||||
* @returns A collection of {@link ThreadMember} assorted by user ID.
|
||||
* @returns A collection of {@link DiscordThreadMember} assorted by user ID.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the application to have the `GUILD_MEMBERS` privileged intent enabled.
|
||||
@@ -18,7 +22,7 @@ import type { ThreadMember } from '../../../transformers/threadMember.js'
|
||||
export async function getThreadMembers (
|
||||
rest: RestManager,
|
||||
channelId: BigString
|
||||
): Promise<Collection<bigint, ThreadMember>> {
|
||||
): Promise<Collection<string, SnakeToCamelCaseNested<DiscordThreadMember>>> {
|
||||
const results = await rest.runMethod<DiscordThreadMember[]>(
|
||||
rest,
|
||||
'GET',
|
||||
@@ -27,7 +31,7 @@ export async function getThreadMembers (
|
||||
|
||||
return new Collection(
|
||||
results.map((result) => {
|
||||
const member = rest.transformers.threadMember(rest, result)
|
||||
const member = snakeToCamelCaseNested(result)
|
||||
return [member.id!, member]
|
||||
})
|
||||
)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import type { BigString, DiscordChannel, WithReason } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordChannel,
|
||||
SnakeToCamelCaseNested,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { Channel } from '../../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Creates a thread, using an existing message as its point of origin.
|
||||
@@ -27,7 +32,7 @@ export async function startThreadWithMessage (
|
||||
channelId: BigString,
|
||||
messageId: BigString,
|
||||
options: StartThreadWithMessage
|
||||
): Promise<Channel> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordChannel>> {
|
||||
const result = await rest.runMethod<DiscordChannel>(
|
||||
rest,
|
||||
'POST',
|
||||
@@ -40,10 +45,7 @@ export async function startThreadWithMessage (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: rest.transformers.snowflake(result.guild_id!)
|
||||
})
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
export interface StartThreadWithMessage extends WithReason {
|
||||
|
||||
@@ -2,10 +2,11 @@ import type {
|
||||
BigString,
|
||||
ChannelTypes,
|
||||
DiscordChannel,
|
||||
SnakeToCamelCaseNested,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../../restManager.js'
|
||||
import type { Channel } from '../../../transformers/channel.js'
|
||||
import { snakeToCamelCaseNested } from '../../../transformer.js'
|
||||
|
||||
/**
|
||||
* Creates a thread without using a message as the thread's point of origin.
|
||||
@@ -13,7 +14,7 @@ import type { Channel } from '../../../transformers/channel.js'
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel in which to create the thread.
|
||||
* @param options - The parameters to use for the creation of the thread.
|
||||
* @returns An instance of the created {@link Channel | Thread}.
|
||||
* @returns An instance of the created {@link DiscordChannel | Thread}.
|
||||
*
|
||||
* @remarks
|
||||
* Creating a private thread requires the server to be boosted.
|
||||
@@ -26,7 +27,7 @@ export async function startThreadWithoutMessage (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options: StartThreadWithoutMessage
|
||||
): Promise<Channel> {
|
||||
): Promise<SnakeToCamelCaseNested<DiscordChannel>> {
|
||||
const result = await rest.runMethod<DiscordChannel>(
|
||||
rest,
|
||||
'POST',
|
||||
@@ -41,12 +42,7 @@ export async function startThreadWithoutMessage (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.channel(rest, {
|
||||
channel: result,
|
||||
guildId: result.guild_id
|
||||
? rest.transformers.snowflake(result.guild_id)
|
||||
: undefined
|
||||
})
|
||||
return snakeToCamelCaseNested(result)
|
||||
}
|
||||
|
||||
export interface StartThreadWithoutMessage extends WithReason {
|
||||
|
||||
@@ -42,7 +42,8 @@ import type {
|
||||
DiscordVoiceState,
|
||||
DiscordWebhook,
|
||||
DiscordWelcomeScreen,
|
||||
GetGatewayBot
|
||||
GetGatewayBot,
|
||||
SnakeToCamelCaseNested
|
||||
} from '@discordeno/types'
|
||||
import { bigintToSnowflake, snowflakeToBigint } from '@discordeno/utils'
|
||||
import type { RestManager } from './restManager.js'
|
||||
@@ -141,6 +142,31 @@ import {
|
||||
} from './transformers/index.js'
|
||||
import type { CreateApplicationCommand, InteractionResponse } from './types.js'
|
||||
|
||||
export const snakeToCamelCaseNested = <T>(
|
||||
object: T
|
||||
): SnakeToCamelCaseNested<T> => {
|
||||
if (Array.isArray(object)) {
|
||||
return object.map((element) =>
|
||||
snakeToCamelCaseNested(element)
|
||||
) as SnakeToCamelCaseNested<T>
|
||||
}
|
||||
if (typeof object === 'object' && object !== null) {
|
||||
const obj = {} as SnakeToCamelCaseNested<T>;
|
||||
(Object.keys(object) as Array<keyof T>).forEach((key) => {
|
||||
(obj[
|
||||
(typeof key === 'string'
|
||||
? key.replace(/([-_][a-z])/gi, ($1) => {
|
||||
return $1.toUpperCase().replace('-', '').replace('_', '')
|
||||
})
|
||||
: key) as keyof SnakeToCamelCaseNested<T>
|
||||
] as SnakeToCamelCaseNested<(T & object)[keyof T]>) =
|
||||
snakeToCamelCaseNested(object[key])
|
||||
})
|
||||
return obj
|
||||
}
|
||||
return object as SnakeToCamelCaseNested<T>
|
||||
}
|
||||
|
||||
export interface Transformers {
|
||||
reverse: {
|
||||
allowedMentions: (
|
||||
|
||||
@@ -1537,3 +1537,18 @@ export type PickPartial<T, K extends keyof T> = {
|
||||
export type OmitFirstFnArg<F> = F extends (x: any, ...args: infer P) => infer R
|
||||
? (...args: P) => R
|
||||
: never
|
||||
|
||||
export type SnakeToCamelCase<S extends string> =
|
||||
S extends `${infer T}_${infer U}`
|
||||
? `${T}${Capitalize<SnakeToCamelCase<U>>}`
|
||||
: S
|
||||
|
||||
export type SnakeToCamelCaseNested<T> = T extends any[]
|
||||
? Array<SnakeToCamelCaseNested<T[number]>>
|
||||
: T extends object
|
||||
? {
|
||||
[K in keyof T as SnakeToCamelCase<K & string>]: SnakeToCamelCaseNested<
|
||||
T[K]
|
||||
>;
|
||||
}
|
||||
: T
|
||||
|
||||
Reference in New Issue
Block a user