mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat(types,rest,bot): Updated message pin endpoints (#4228)
* feat: Updated message pin endpoints * Apply suggestions from code review Co-authored-by: Link <lts20050703@gmail.com> --------- Co-authored-by: Link <lts20050703@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import type {
|
||||
MessageCall,
|
||||
MessageInteraction,
|
||||
MessageInteractionMetadata,
|
||||
MessagePin,
|
||||
MessageReference,
|
||||
MessageSnapshot,
|
||||
Nameplate,
|
||||
@@ -92,6 +93,7 @@ export interface TransformersObjects {
|
||||
messageCall: MessageCall
|
||||
messageInteraction: MessageInteraction
|
||||
messageInteractionMetadata: MessageInteractionMetadata
|
||||
messagePin: MessagePin
|
||||
messageReference: MessageReference
|
||||
messageSnapshot: MessageSnapshot
|
||||
nameplate: Nameplate
|
||||
@@ -544,6 +546,11 @@ export function createDesiredPropertiesObject<T extends RecursivePartial<Transfo
|
||||
targetUser: defaultValue,
|
||||
...desiredProperties.messageInteractionMetadata,
|
||||
},
|
||||
messagePin: {
|
||||
message: defaultValue,
|
||||
pinnedAt: defaultValue,
|
||||
...desiredProperties.messagePin,
|
||||
},
|
||||
messageInteraction: {
|
||||
id: defaultValue,
|
||||
member: defaultValue,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// biome-ignore lint/correctness/noUnusedImports: <explanation>
|
||||
import type { RestManager } from '@discordeno/rest'
|
||||
import type {
|
||||
AddDmRecipientOptions,
|
||||
AddGuildMemberOptions,
|
||||
@@ -68,6 +70,7 @@ import type {
|
||||
ExecuteWebhook,
|
||||
GetApplicationCommandPermissionOptions,
|
||||
GetBans,
|
||||
GetChannelPinsOptions,
|
||||
GetEntitlements,
|
||||
GetGroupDmOptions,
|
||||
GetGuildAuditLog,
|
||||
@@ -129,6 +132,7 @@ import type {
|
||||
LobbyMember,
|
||||
Member,
|
||||
Message,
|
||||
MessagePin,
|
||||
Role,
|
||||
ScheduledEvent,
|
||||
Sku,
|
||||
@@ -442,6 +446,14 @@ export function createBotHelpers<TProps extends TransformersDesiredProperties, T
|
||||
getOriginalInteractionResponse: async (token) => {
|
||||
return bot.transformers.message(bot, { message: snakelize(await bot.rest.getOriginalInteractionResponse(token)), shardId: 0 })
|
||||
},
|
||||
getChannelPins: async (channelId, options) => {
|
||||
const res = snakelize(await bot.rest.getChannelPins(channelId, options))
|
||||
|
||||
return {
|
||||
hasMore: res.has_more,
|
||||
items: bot.transformers.messagePin(bot, res.items),
|
||||
}
|
||||
},
|
||||
getPinnedMessages: async (channelId) => {
|
||||
return (await bot.rest.getPinnedMessages(channelId)).map((res) => bot.transformers.message(bot, { message: snakelize(res), shardId: 0 }))
|
||||
},
|
||||
@@ -1007,6 +1019,11 @@ export type BotHelpers<TProps extends TransformersDesiredProperties, TBehavior e
|
||||
getStickerPack: (stickerPackId: BigString) => Promise<StickerPack>
|
||||
getStickerPacks: () => Promise<StickerPack[]>
|
||||
getOriginalInteractionResponse: (token: string) => Promise<SetupDesiredProps<Message, TProps, TBehavior>>
|
||||
getChannelPins: (
|
||||
channelId: BigString,
|
||||
options?: GetChannelPinsOptions,
|
||||
) => Promise<{ items: SetupDesiredProps<MessagePin, TProps, TBehavior>; hasMore: boolean }>
|
||||
/** @deprecated Use {@link BotHelpers.getChannelPins} instead */
|
||||
getPinnedMessages: (channelId: BigString) => Promise<SetupDesiredProps<Message, TProps, TBehavior>[]>
|
||||
getPrivateArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<Camelize<DiscordListArchivedThreads>>
|
||||
getPrivateJoinedArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<Camelize<DiscordListArchivedThreads>>
|
||||
|
||||
@@ -50,6 +50,7 @@ import type {
|
||||
DiscordMessageCall,
|
||||
DiscordMessageComponent,
|
||||
DiscordMessageInteractionMetadata,
|
||||
DiscordMessagePin,
|
||||
DiscordMessageSnapshot,
|
||||
DiscordNameplate,
|
||||
DiscordPoll,
|
||||
@@ -132,6 +133,7 @@ import {
|
||||
type Message,
|
||||
type MessageCall,
|
||||
type MessageInteractionMetadata,
|
||||
type MessagePin,
|
||||
type MessageSnapshot,
|
||||
type Nameplate,
|
||||
type Poll,
|
||||
@@ -369,6 +371,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
payload: DiscordMessageInteractionMetadata,
|
||||
metadata: SetupDesiredProps<MessageInteractionMetadata, TProps, TBehavior>,
|
||||
) => any
|
||||
messagePin: (bot: Bot<TProps, TBehavior>, payload: DiscordMessagePin, call: SetupDesiredProps<MessagePin, TProps, TBehavior>) => any
|
||||
messageSnapshot: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: DiscordMessageSnapshot,
|
||||
@@ -526,6 +529,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: DiscordMessageInteractionMetadata,
|
||||
) => SetupDesiredProps<MessageInteractionMetadata, TProps, TBehavior>
|
||||
messagePin: (bot: Bot<TProps, TBehavior>, payload: DiscordMessagePin) => SetupDesiredProps<MessagePin, TProps, TBehavior>
|
||||
messageSnapshot: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: { messageSnapshot: DiscordMessageSnapshot; shardId: number },
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
type DiscordMessage,
|
||||
type DiscordMessageCall,
|
||||
type DiscordMessageInteractionMetadata,
|
||||
type DiscordMessagePin,
|
||||
type DiscordMessageSnapshot,
|
||||
MessageFlags,
|
||||
} from '@discordeno/types'
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
type Message,
|
||||
type MessageCall,
|
||||
type MessageInteractionMetadata,
|
||||
type MessagePin,
|
||||
type MessageSnapshot,
|
||||
snowflakeToTimestamp,
|
||||
} from '../index.js'
|
||||
@@ -261,6 +263,16 @@ export function transformMessage(
|
||||
return bot.transformers.customizers.message(bot, payload.message, message)
|
||||
}
|
||||
|
||||
export function transformMessagePin(bot: InternalBot, payload: DiscordMessagePin): MessagePin {
|
||||
const props = bot.transformers.desiredProperties.messagePin
|
||||
const messagePin = {} as MessagePin
|
||||
|
||||
if (props.pinnedAt && payload.pinned_at) messagePin.pinnedAt = Date.parse(payload.pinned_at)
|
||||
if (props.message && payload.message) messagePin.message = bot.transformers.message(bot, { message: payload.message, shardId: 0 })
|
||||
|
||||
return bot.transformers.customizers.messagePin(bot, payload, messagePin)
|
||||
}
|
||||
|
||||
export function transformMessageSnapshot(
|
||||
bot: InternalBot,
|
||||
payload: { messageSnapshot: DiscordMessageSnapshot; shardId: number },
|
||||
|
||||
@@ -1329,6 +1329,13 @@ export interface MessageCall {
|
||||
endedTimestamp: number
|
||||
}
|
||||
|
||||
export interface MessagePin {
|
||||
/** the time the message was pinned */
|
||||
pinnedAt: number
|
||||
/** the pinned message */
|
||||
message: Message
|
||||
}
|
||||
|
||||
export interface Reaction {
|
||||
/** Whether the current user reacted using this emoji */
|
||||
me: boolean
|
||||
|
||||
Reference in New Issue
Block a user