feat: message poll

#1150 #1147
This commit is contained in:
Elysia
2024-07-03 21:31:45 +07:00
parent e6e9febe8c
commit 485dab55bf
16 changed files with 545 additions and 87 deletions

7
typings/enums.d.ts vendored
View File

@@ -87,6 +87,11 @@ export const enum ForumLayoutType {
GALLERY_VIEW = 2,
}
export const enum MessagePollLayoutType {
DEFAULT = 1,
IMAGE_ONLY_ANSWERS,
}
export const enum MessageTypes {
DEFAULT,
RECIPIENT_ADD,
@@ -282,7 +287,7 @@ export enum ApplicationRoleConnectionMetadataTypes {
BOOLEAN_NOT_EQUAL,
}
export const enum RelationshipTypes {
export const enum RelationshipType {
NONE = 0,
FRIEND = 1,
BLOCKED = 2,

220
typings/index.d.ts vendored
View File

@@ -98,9 +98,10 @@ import {
SortOrderType,
ForumLayoutType,
ApplicationRoleConnectionMetadataTypes,
RelationshipTypes,
RelationshipType,
SelectMenuComponentTypes,
InviteType,
MessagePollLayoutType,
} from './enums';
import {
APIApplicationRoleConnectionMetadata,
@@ -1284,16 +1285,16 @@ export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {
export class GuildAuditLogsEntry<
TActionRaw extends GuildAuditLogsResolvable = 'ALL',
TAction = TActionRaw extends keyof GuildAuditLogsIds
? GuildAuditLogsIds[TActionRaw]
: TActionRaw extends null
? 'ALL'
: TActionRaw,
? GuildAuditLogsIds[TActionRaw]
: TActionRaw extends null
? 'ALL'
: TActionRaw,
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][1]
: 'ALL',
? GuildAuditLogsTypes[TAction][1]
: 'ALL',
TTargetType extends GuildAuditLogsTarget = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][0]
: 'UNKNOWN',
? GuildAuditLogsTypes[TAction][0]
: 'UNKNOWN',
> {
private constructor(guild: Guild, data: RawGuildAuditLogEntryData, logs?: GuildAuditLogs);
public action: TAction;
@@ -1550,7 +1551,7 @@ export class HTTPError extends Error {
}
// tslint:disable-next-line:no-empty-interface - Merge RateLimitData into RateLimitError to not have to type it again
export interface RateLimitError extends RateLimitData {}
export interface RateLimitError extends RateLimitData { }
export class RateLimitError extends Error {
private constructor(data: RateLimitData);
public name: 'RateLimitError';
@@ -1846,6 +1847,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public type: MessageType;
public readonly url: string;
public webhookId: Snowflake | null;
public poll: MessagePoll | null;
public flags: Readonly<MessageFlags>;
public reference: MessageReference | null;
public position: number | null;
@@ -1879,6 +1881,9 @@ export class Message<Cached extends boolean = boolean> extends Base {
public markUnread(): Promise<void>;
public markRead(): Promise<void>;
public report(breadcrumbs: number[], elements?: object): Promise<{ report_id: Snowflake }>;
public vote(...ids: number[]): Promise<void>;
public endPoll(): Promise<RawMessageData>;
public getAnswerVoter(answerId: number, afterUserId?: Snowflake, limit?: number): Promise<{ users: Partial<RawUserData> }>;
}
export class CallState extends Base {
@@ -1890,12 +1895,20 @@ export class CallState extends Base {
public setRTCRegion(): Promise<void>;
}
export interface MessagePollUserVote {
user_id: Snowflake;
message_id: Snowflake;
channel_id: Snowflake;
answer_id: number;
guild_id?: Snowflake;
}
export class MessageActionRow<
T extends MessageActionRowComponent | ModalActionRowComponent = MessageActionRowComponent,
U = T extends ModalActionRowComponent ? ModalActionRowComponentResolvable : MessageActionRowComponentResolvable,
V = T extends ModalActionRowComponent
? APIActionRowComponent<APIModalActionRowComponent>
: APIActionRowComponent<APIMessageActionRowComponent>,
? APIActionRowComponent<APIModalActionRowComponent>
: APIActionRowComponent<APIMessageActionRowComponent>,
> extends BaseMessageComponent {
// tslint:disable-next-line:ban-ts-ignore
// @ts-ignore (TS:2344, Caused by TypeScript 4.8)
@@ -2263,6 +2276,39 @@ export class Modal {
public toJSON(): RawModalSubmitInteractionData;
}
export interface MessagePollMedia {
text?: string;
emoji?: RawEmojiData;
}
export interface MessagePollResultAnswerCount {
answer: MessagePollMedia;
count: number;
selfVoted: boolean;
}
export interface MessagePollResult {
isFinalized: boolean;
answerCounts: Collection<number, MessagePollResultAnswerCount>;
}
export class MessagePoll {
public constructor(data: MessagePoll | object);
public question: MessagePollMedia | null;
public answers: Collection<number, MessagePollMedia>;
public layoutType: MessagePollLayoutType | null;
public allowMultiSelect: boolean;
public expiry: Date | null;
public results: MessagePollResult | null;
public duration: number | null;
public toJSON(): object;
public setQuestion(text: string): this;
public setAnswers(answers: MessagePollMedia[]): this;
public addAnswer(answer: MessagePollMedia): this;
public setAllowMultiSelect(state: boolean): this;
public setDuration(duration: number): this;
}
export class ModalSubmitFieldsResolver {
constructor(components: PartialModalActionRow[]);
private readonly _fields: PartialTextInputData[];
@@ -3063,6 +3109,13 @@ export class Typing extends Base {
};
}
export interface UserClan {
identityGuildId?: Snowflake;
identityEnabled?: boolean;
tag?: string;
badge?: string;
}
export class User extends PartialTextBasedChannel(Base) {
protected constructor(client: Client, data: RawUserData);
private _equals(user: APIUser): boolean;
@@ -3090,11 +3143,13 @@ export class User extends PartialTextBasedChannel(Base) {
public username: string;
public readonly note: string | undefined;
public readonly voice?: VoiceState;
public readonly relationship: RelationshipTypes;
public readonly relationship: RelationshipType;
public readonly friendNickname: string | null | undefined;
public clan: UserClan | null;
public avatarURL(options?: ImageURLOptions): string | null;
public avatarDecorationURL(options?: StaticImageURLOptions): string | null;
public bannerURL(options?: ImageURLOptions): string | null;
public clanBadgeURL(): string | null;
public createDM(force?: boolean): Promise<DMChannel>;
public deleteDM(): Promise<DMChannel>;
public displayAvatarURL(options?: ImageURLOptions): string;
@@ -3484,6 +3539,7 @@ export const Constants: {
dynamic: boolean,
): string;
AvatarDecoration(userId: Snowflake, hash: string, format: AllowedImageFormat, size: AllowedImageSize): string;
ClanBadge(guildId: Snowflake, hash: string): string;
Banner(id: Snowflake, hash: string, format: DynamicImageFormat, size: AllowedImageSize, dynamic: boolean): string;
DefaultAvatar(index: number): string;
DiscoverySplash(guildId: Snowflake, hash: string, format: AllowedImageFormat, size: AllowedImageSize): string;
@@ -3525,7 +3581,7 @@ export const Constants: {
GuildScheduledEventStatuses: EnumHolder<typeof GuildScheduledEventStatuses>;
IntegrationExpireBehaviors: IntegrationExpireBehaviors[];
SelectMenuComponentTypes: EnumHolder<typeof SelectMenuComponentTypes>;
RelationshipTypes: EnumHolder<typeof RelationshipTypes>;
RelationshipTypes: EnumHolder<typeof RelationshipType>;
MembershipStates: EnumHolder<typeof MembershipStates>;
MessageButtonStyles: EnumHolder<typeof MessageButtonStyles>;
MessageComponentTypes: EnumHolder<typeof MessageComponentTypes>;
@@ -3685,13 +3741,13 @@ export class ApplicationCommandPermissionsManager<
public remove(
options:
| (FetchSingleOptions & {
users: UserResolvable | UserResolvable[];
roles?: RoleResolvable | RoleResolvable[];
})
users: UserResolvable | UserResolvable[];
roles?: RoleResolvable | RoleResolvable[];
})
| (FetchSingleOptions & {
users?: UserResolvable | UserResolvable[];
roles: RoleResolvable | RoleResolvable[];
}),
users?: UserResolvable | UserResolvable[];
roles: RoleResolvable | RoleResolvable[];
}),
): Promise<ApplicationCommandPermissions[]>;
public set(
options: FetchSingleOptions & { permissions: ApplicationCommandPermissionData[] },
@@ -3725,22 +3781,22 @@ export class RelationshipManager extends BaseManager {
client: Client,
data: {
user: RawUserData;
type: RelationshipTypes;
type: RelationshipType;
since?: string;
nickname: string | null | undefined;
id: Snowflake;
}[],
);
public cache: Collection<Snowflake, RelationshipTypes>;
public cache: Collection<Snowflake, RelationshipType>;
public friendNicknames: Collection<Snowflake, string | null>;
public sinceCache: Collection<Snowflake, Date>;
public readonly friendCache: Collection<Snowflake, User>;
public readonly blockedCache: Collection<Snowflake, User>;
public readonly incomingCache: Collection<Snowflake, User>;
public readonly outgoingCache: Collection<Snowflake, User>;
public toJSON(): { type: RelationshipTypes; since: string; nickname: string | null | undefined; id: Snowflake }[];
public toJSON(): { type: RelationshipType; since: string; nickname: string | null | undefined; id: Snowflake }[];
public resolveId(user: UserResolvable): Snowflake | undefined;
public fetch(user?: UserResolvable, options?: BaseFetchOptions): Promise<RelationshipTypes | RelationshipManager>;
public fetch(user?: UserResolvable, options?: BaseFetchOptions): Promise<RelationshipType | RelationshipManager>;
public deleteRelationship(user: UserResolvable): Promise<boolean>;
public sendFriendRequest(options: FriendRequestOptions): Promise<boolean>;
public addFriend(user: UserResolvable): Promise<boolean>;
@@ -4627,12 +4683,12 @@ export interface ApplicationCommandChannelOption extends BaseApplicationCommandO
export interface ApplicationCommandAutocompleteOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type:
| 'STRING'
| 'NUMBER'
| 'INTEGER'
| ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.NUMBER
| ApplicationCommandOptionTypes.INTEGER;
| 'STRING'
| 'NUMBER'
| 'INTEGER'
| ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.NUMBER
| ApplicationCommandOptionTypes.INTEGER;
autocomplete: true;
}
@@ -4904,9 +4960,9 @@ export interface AutoModerationRuleCreateOptions {
reason?: string;
}
export interface AutoModerationRuleEditOptions extends Partial<Omit<AutoModerationRuleCreateOptions, 'triggerType'>> {}
export interface AutoModerationRuleEditOptions extends Partial<Omit<AutoModerationRuleCreateOptions, 'triggerType'>> { }
export interface AutoModerationTriggerMetadataOptions extends Partial<AutoModerationTriggerMetadata> {}
export interface AutoModerationTriggerMetadataOptions extends Partial<AutoModerationTriggerMetadata> { }
export interface AutoModerationActionOptions {
type: AutoModerationActionType | AutoModerationActionTypes;
@@ -5013,8 +5069,8 @@ export type CacheFactory = (
export type CacheWithLimitsOptions = {
[K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager<infer K, infer V, any>
? LimitedCollectionOptions<K, V> | number
: never;
? LimitedCollectionOptions<K, V> | number
: never;
};
export interface CategoryCreateChannelOptions {
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
@@ -5207,18 +5263,18 @@ export interface ClientEvents extends BaseClientEvents {
guildAuditLogEntryCreate: [auditLogEntry: GuildAuditLogsEntry, guild: Guild];
unhandledPacket: [packet: { t?: string; d: any }, shard: number];
relationshipAdd: [userId: Snowflake, shouldNotify: boolean];
relationshipRemove: [userId: Snowflake, type: RelationshipTypes, nickname: string | null];
relationshipRemove: [userId: Snowflake, type: RelationshipType, nickname: string | null];
relationshipUpdate: [
userId: Snowflake,
oldData: {
nickname: string | null;
since: Date;
type: RelationshipTypes;
type: RelationshipType;
},
newData: {
nickname: string | null;
since: Date;
type: RelationshipTypes;
type: RelationshipType;
},
];
channelRecipientAdd: [channel: GroupDMChannel, user: User];
@@ -5227,6 +5283,8 @@ export interface ClientEvents extends BaseClientEvents {
callCreate: [call: CallState];
callUpdate: [call: CallState];
callDelete: [call: CallState];
messagePollVoteAdd: [data: MessagePollUserVote];
messagePollVoteRemove: [data: MessagePollUserVote];
}
export interface ClientFetchInviteOptions {
@@ -5367,12 +5425,12 @@ export interface ConstantsClientApplicationAssetTypes {
export type AutocompleteFocusedOption = Pick<CommandInteractionOption, 'name'> & {
focused: true;
type:
| 'STRING'
| 'INTEGER'
| 'NUMBER'
| ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.INTEGER
| ApplicationCommandOptionTypes.NUMBER;
| 'STRING'
| 'INTEGER'
| 'NUMBER'
| ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.INTEGER
| ApplicationCommandOptionTypes.NUMBER;
value: string;
};
@@ -5508,6 +5566,8 @@ export interface ConstantsEvents {
CALL_CREATE: 'callCreate';
CALL_UPDATE: 'callUpdate';
CALL_DELETE: 'callDelete';
MESSAGE_POLL_VOTE_ADD: 'messagePollVoteAdd';
MESSAGE_POLL_VOTE_REMOVE: 'messagePollVoteRemove';
}
export interface ConstantsOpcodes {
@@ -5931,20 +5991,20 @@ export interface GuildAuditLogsEntryExtraField {
MESSAGE_UNPIN: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake };
MEMBER_DISCONNECT: { count: number };
CHANNEL_OVERWRITE_CREATE:
| Role
| GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member };
| Role
| GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member };
CHANNEL_OVERWRITE_UPDATE:
| Role
| GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member };
| Role
| GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member };
CHANNEL_OVERWRITE_DELETE:
| Role
| GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member };
| Role
| GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member };
STAGE_INSTANCE_CREATE: StageChannel | { id: Snowflake };
STAGE_INSTANCE_DELETE: StageChannel | { id: Snowflake };
STAGE_INSTANCE_UPDATE: StageChannel | { id: Snowflake };
@@ -5975,8 +6035,8 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
INVITE: Invite;
MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User;
INTEGRATION: Integration;
CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown };
THREAD: ThreadChannel | { id: Snowflake; [x: string]: unknown };
CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake;[x: string]: unknown };
THREAD: ThreadChannel | { id: Snowflake;[x: string]: unknown };
STAGE_INSTANCE: StageInstance;
STICKER: Sticker;
GUILD_SCHEDULED_EVENT: GuildScheduledEvent;
@@ -6214,8 +6274,8 @@ export type GuildScheduledEventManagerFetchResult<
export type GuildScheduledEventManagerFetchSubscribersResult<T extends FetchGuildScheduledEventSubscribersOptions> =
T extends { withMember: true }
? Collection<Snowflake, GuildScheduledEventUser<true>>
: Collection<Snowflake, GuildScheduledEventUser<false>>;
? Collection<Snowflake, GuildScheduledEventUser<true>>
: Collection<Snowflake, GuildScheduledEventUser<false>>;
export type GuildScheduledEventPrivacyLevel = keyof typeof GuildScheduledEventPrivacyLevels;
@@ -6402,8 +6462,8 @@ export type ModalActionRowComponentResolvable =
export interface MessageActionRowOptions<
T extends
| MessageActionRowComponentResolvable
| ModalActionRowComponentResolvable = MessageActionRowComponentResolvable,
| MessageActionRowComponentResolvable
| ModalActionRowComponentResolvable = MessageActionRowComponentResolvable,
> extends BaseMessageComponentOptions {
components: T[];
}
@@ -6581,6 +6641,7 @@ export interface MessageOptions {
stickers?: StickerResolvable[];
attachments?: MessageAttachment[];
flags?: BitFieldResolvable<'SUPPRESS_EMBEDS' | 'SUPPRESS_NOTIFICATIONS' | 'IS_VOICE_MESSAGE', number>;
poll?: MessagePoll;
}
export type MessageReactionResolvable = MessageReaction | Snowflake | string;
@@ -6654,8 +6715,8 @@ export type MFALevel = keyof typeof MFALevels;
export interface ModalOptions {
components:
| MessageActionRow<ModalActionRowComponent>[]
| MessageActionRowOptions<ModalActionRowComponentResolvable>[];
| MessageActionRow<ModalActionRowComponent>[]
| MessageActionRowOptions<ModalActionRowComponentResolvable>[];
customId: string;
title: string;
}
@@ -6756,9 +6817,14 @@ export type PermissionString =
| 'MANAGE_EVENTS'
| 'VIEW_CREATOR_MONETIZATION_ANALYTICS'
| 'USE_SOUNDBOARD'
| 'CREATE_GUILD_EXPRESSIONS'
| 'CREATE_EVENTS'
| 'USE_EXTERNAL_SOUNDS'
| 'SEND_VOICE_MESSAGES'
| 'USE_CLYDE_AI'
| 'SET_VOICE_CHANNEL_STATUS';
| 'SET_VOICE_CHANNEL_STATUS'
| 'SEND_POLLS'
| 'USE_EXTERNAL_APPS';
export type RecursiveArray<T> = ReadonlyArray<T | RecursiveArray<T>>;
@@ -6818,19 +6884,19 @@ export type Partialize<
id: Snowflake;
partial: true;
} & {
[K in keyof Omit<T, 'client' | 'id' | 'partial' | E>]: K extends N ? null : K extends M ? T[K] | null : T[K];
};
[K in keyof Omit<T, 'client' | 'id' | 'partial' | E>]: K extends N ? null : K extends M ? T[K] | null : T[K];
};
export interface PartialDMChannel extends Partialize<DMChannel, null, null, 'lastMessageId'> {
lastMessageId: undefined;
}
export interface PartialGuildMember extends Partialize<GuildMember, 'joinedAt' | 'joinedTimestamp'> {}
export interface PartialGuildMember extends Partialize<GuildMember, 'joinedAt' | 'joinedTimestamp'> { }
export interface PartialMessage
extends Partialize<Message, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {}
extends Partialize<Message, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> { }
export interface PartialMessageReaction extends Partialize<MessageReaction, 'count'> {}
export interface PartialMessageReaction extends Partialize<MessageReaction, 'count'> { }
export interface PartialOverwriteData {
id: Snowflake | number;
@@ -6845,7 +6911,7 @@ export interface PartialRoleData extends RoleData {
export type PartialTypes = 'USER' | 'CHANNEL' | 'GUILD_MEMBER' | 'MESSAGE' | 'REACTION' | 'GUILD_SCHEDULED_EVENT';
export interface PartialUser extends Partialize<User, 'username' | 'tag' | 'discriminator'> {}
export interface PartialUser extends Partialize<User, 'username' | 'tag' | 'discriminator'> { }
export type PresenceStatusData = ClientPresenceStatus | 'invisible';
@@ -7039,8 +7105,8 @@ export interface SweeperDefinitions {
export type SweeperOptions = {
[K in keyof SweeperDefinitions]?: SweeperDefinitions[K][2] extends true
? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions
: SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>;
? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions
: SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>;
};
export interface LimitedCollectionOptions<K, V> {
@@ -7179,12 +7245,12 @@ export interface WebhookClientDataURL {
export type FriendRequestOptions =
| {
user: UserResolvable;
}
user: UserResolvable;
}
| {
username: string;
discriminator: number | null;
};
username: string;
discriminator: number | null;
};
export type WebhookClientOptions = Pick<
ClientOptions,