refactor: remove typing caching (#6114)

Co-authored-by: DTrombett <73136330+DTrombett@users.noreply.github.com>
This commit is contained in:
Antonio Román
2021-07-16 13:20:05 +02:00
committed by GitHub
parent 4206e35b23
commit 576eee8de2
13 changed files with 140 additions and 200 deletions

37
typings/index.d.ts vendored
View File

@@ -1649,6 +1649,24 @@ export class ThreadMemberFlags extends BitField<ThreadMemberFlagsString> {
public static resolve(bit?: BitFieldResolvable<ThreadMemberFlagsString, number>): number;
}
export class Typing extends Base {
public constructor(
channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel,
user: PartialUser,
data?: object,
);
public channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel;
public user: PartialUser;
public startedTimestamp: number;
public readonly startedAt: Date;
public readonly guild: Guild | null;
public readonly member: GuildMember | null;
public inGuild(): this is this & {
channel: TextChannel | NewsChannel | ThreadChannel;
readonly guild: Guild;
};
}
export class User extends PartialTextBasedChannel(Base) {
public constructor(client: Client, data: unknown);
public avatar: string | null;
@@ -1672,9 +1690,6 @@ export class User extends PartialTextBasedChannel(Base) {
public fetch(force?: boolean): Promise<User>;
public fetchFlags(force?: boolean): Promise<UserFlags>;
public toString(): UserMention;
public typingDurationIn(channel: ChannelResolvable): number;
public typingIn(channel: ChannelResolvable): boolean;
public typingSinceIn(channel: ChannelResolvable): Date;
}
export class UserFlags extends BitField<UserFlagsString> {
@@ -2420,13 +2435,10 @@ export interface PartialTextBasedChannelFields {
}
export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
_typing: Map<string, TypingData>;
lastMessageId: Snowflake | null;
readonly lastMessage: Message | null;
lastPinTimestamp: number | null;
readonly lastPinAt: Date | null;
typing: boolean;
typingCount: number;
awaitMessageComponent<T extends MessageComponentInteraction = MessageComponentInteraction>(
options?: AwaitMessageComponentOptions<T>,
): Promise<T>;
@@ -2439,8 +2451,7 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
options?: InteractionCollectorOptions<T>,
): InteractionCollector<T>;
createMessageCollector(options?: MessageCollectorOptions): MessageCollector;
startTyping(count?: number): Promise<void>;
stopTyping(force?: boolean): void;
sendTyping(): Promise<void>;
}
export function PartialWebhookMixin<T>(Base?: Constructable<T>): Constructable<T & PartialWebhookFields>;
@@ -2835,7 +2846,7 @@ export interface ClientEvents {
mewMembers: Collection<Snowflake, ThreadMember>,
];
threadUpdate: [oldThread: ThreadChannel, newThread: ThreadChannel];
typingStart: [channel: Channel | PartialDMChannel, user: User | PartialUser];
typingStart: [typing: Typing];
userUpdate: [oldUser: User | PartialUser, newUser: User];
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
webhookUpdate: [channel: TextChannel];
@@ -3962,14 +3973,6 @@ export type SystemChannelFlagsResolvable = BitFieldResolvable<SystemChannelFlags
export type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY' | 'APPLICATION_COMMAND'>;
export interface TypingData {
user: User | PartialUser;
since: Date;
lastTimestamp: Date;
elapsedTime: number;
timeout: NodeJS.Timeout;
}
export interface StageInstanceEditOptions {
topic?: string;
privacyLevel?: PrivacyLevel | number;

View File

@@ -10,6 +10,7 @@ import {
Collection,
Constants,
DMChannel,
Guild,
GuildApplicationCommandManager,
GuildChannelManager,
GuildEmoji,
@@ -27,7 +28,9 @@ import {
MessageReaction,
NewsChannel,
Options,
PartialDMChannel,
PartialTextBasedChannelFields,
PartialUser,
Permissions,
ReactionCollector,
Role,
@@ -41,6 +44,7 @@ import {
TextBasedChannelFields,
TextChannel,
ThreadChannel,
Typing,
User,
VoiceChannel,
} from '..';
@@ -607,13 +611,22 @@ assertType<Promise<Collection<Snowflake, GuildEmoji>>>(guildEmojiManager.fetch()
assertType<Promise<Collection<Snowflake, GuildEmoji>>>(guildEmojiManager.fetch(undefined, {}));
assertType<Promise<GuildEmoji | null>>(guildEmojiManager.fetch('0'));
// Test partials structures
client.on('typingStart', (channel, user) => {
if (channel.partial) assertType<undefined>(channel.lastMessageId);
if (user.partial) return assertType<null>(user.username);
assertType<string>(user.username);
});
declare const typing: Typing;
assertType<PartialUser>(typing.user);
if (typing.user.partial) assertType<null>(typing.user.username);
assertType<TextChannel | PartialDMChannel | NewsChannel | ThreadChannel>(typing.channel);
if (typing.channel.partial) assertType<undefined>(typing.channel.lastMessageId);
assertType<GuildMember | null>(typing.member);
assertType<Guild | null>(typing.guild);
if (typing.inGuild()) {
assertType<Guild>(typing.channel.guild);
assertType<Guild>(typing.guild);
}
// Test partials structures
client.on('guildMemberRemove', member => {
if (member.partial) return assertType<null>(member.joinedAt);
assertType<Date | null>(member.joinedAt);