mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat(bot,rest,types): Add polls support (#3542)
* Add polls support * Add default for limit on GetPollAnswerVotes * Apply code rewiew suggestion Co-authored-by: LTS20050703 <lts20050703@gmail.com> --------- Co-authored-by: LTS20050703 <lts20050703@gmail.com>
This commit is contained in:
@@ -40,6 +40,7 @@ import {
|
||||
type DiscordMemberWithUser,
|
||||
type DiscordMessage,
|
||||
type DiscordPartialGuild,
|
||||
type DiscordPollResult,
|
||||
type DiscordPrunedCount,
|
||||
type DiscordRole,
|
||||
type DiscordScheduledEvent,
|
||||
@@ -1352,6 +1353,14 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
return await rest.post<DiscordChannel>(rest.routes.channels.threads.all(channelId), { body, reason })
|
||||
},
|
||||
|
||||
async getPollAnswerVoters(channelId, messageId, answerId, options) {
|
||||
return await rest.get<DiscordPollResult>(rest.routes.channels.polls.votes(channelId, messageId, answerId, options))
|
||||
},
|
||||
|
||||
async endPoll(channelId, messageId) {
|
||||
return await rest.post<DiscordMessage>(rest.routes.channels.polls.expire(channelId, messageId))
|
||||
},
|
||||
|
||||
async syncGuildTemplate(guildId) {
|
||||
return await rest.put<DiscordTemplate>(rest.routes.guilds.templates.all(guildId))
|
||||
},
|
||||
|
||||
@@ -218,6 +218,22 @@ export function createRoutes(): RestRoutes {
|
||||
typing: (channelId) => {
|
||||
return `/channels/${channelId}/typing`
|
||||
},
|
||||
|
||||
polls: {
|
||||
votes: (channelId, messageId, answerId, options) => {
|
||||
let url = `/channels/${channelId}/polls/${messageId}/answers/${answerId}?`
|
||||
|
||||
if (options) {
|
||||
if (options.after) url += `after=${options.after}`
|
||||
if (options.limit) url += `&limit=${options.limit}`
|
||||
}
|
||||
|
||||
return url
|
||||
},
|
||||
expire: (channelId, messageId) => {
|
||||
return `/channels/${channelId}/polls/${messageId}/expire`
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Guild Endpoints
|
||||
|
||||
@@ -36,6 +36,7 @@ import type {
|
||||
CamelizedDiscordMessage,
|
||||
CamelizedDiscordModifyGuildWelcomeScreen,
|
||||
CamelizedDiscordPartialGuild,
|
||||
CamelizedDiscordPollResult,
|
||||
CamelizedDiscordPrunedCount,
|
||||
CamelizedDiscordRole,
|
||||
CamelizedDiscordScheduledEvent,
|
||||
@@ -97,6 +98,7 @@ import type {
|
||||
GetGuildPruneCountQuery,
|
||||
GetInvite,
|
||||
GetMessagesOptions,
|
||||
GetPollAnswerVotes,
|
||||
GetReactions,
|
||||
GetScheduledEventUsers,
|
||||
GetScheduledEvents,
|
||||
@@ -2544,6 +2546,34 @@ export interface RestManager {
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-without-message}
|
||||
*/
|
||||
startThreadWithoutMessage: (channelId: BigString, options: StartThreadWithoutMessage, reason?: string) => Promise<CamelizedDiscordChannel>
|
||||
/**
|
||||
* Get a list of users that voted for this specific answer.
|
||||
*
|
||||
* @param channelId - The ID of the channel in which the message with the poll lives
|
||||
* @param messageId - The ID of the message in which the poll lives
|
||||
* @param answerId - The ID of the answer to get the users that voted that answer
|
||||
* @param options - The options for the request
|
||||
* @returns The list of users that voted for the specific answer.
|
||||
*/
|
||||
getPollAnswerVoters: (
|
||||
channelId: BigString,
|
||||
messageId: BigString,
|
||||
answerId: number,
|
||||
options?: GetPollAnswerVotes,
|
||||
) => Promise<CamelizedDiscordPollResult>
|
||||
/**
|
||||
* Immediately ends the poll.
|
||||
*
|
||||
* @param channelId - The ID of the channel in which the message with the poll lives
|
||||
* @param messageId - The ID of the message in which the poll lives
|
||||
* @returns The message with the expired poll
|
||||
*
|
||||
* @remarks
|
||||
* You cannot end polls from other users.
|
||||
*
|
||||
* Fires a _Message Update_ gateway event
|
||||
*/
|
||||
endPoll: (channelId: BigString, messageId: BigString) => Promise<CamelizedDiscordMessage>
|
||||
/**
|
||||
* Synchronises a template with the current state of a guild.
|
||||
*
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
GetGuildPruneCountQuery,
|
||||
GetInvite,
|
||||
GetMessagesOptions,
|
||||
GetPollAnswerVotes,
|
||||
GetReactions,
|
||||
GetScheduledEventUsers,
|
||||
GetUserGuilds,
|
||||
@@ -103,6 +104,10 @@ export interface RestRoutes {
|
||||
/** Route for handling a specific reaction on a message. */
|
||||
message: (channelId: BigString, messageId: BigString, emoji: string, options?: GetReactions) => string
|
||||
}
|
||||
polls: {
|
||||
votes: (channelId: BigString, messageId: BigString, answerId: number, options?: GetPollAnswerVotes) => string
|
||||
expire: (channelId: BigString, messageId: BigString) => string
|
||||
}
|
||||
}
|
||||
/** Routes for guild related endpoints. */
|
||||
guilds: {
|
||||
|
||||
Reference in New Issue
Block a user