fix: dirty trick on prototypes

This commit is contained in:
Yuzu 2022-07-06 13:44:12 -05:00
parent ea91bd6230
commit 3a5dbdfc77
3 changed files with 21 additions and 3 deletions

View File

@ -59,6 +59,24 @@ export const MESSAGE_CREATE: RawHandler<DiscordMessage> = (session, _shardId, me
};
export const MESSAGE_UPDATE: RawHandler<DiscordMessage> = (session, _shardId, new_message) => {
// message is partial
if (!new_message.edited_timestamp) {
const message = {
// TODO: improve this
// ...new_message,
id: new_message.id,
guildId: new_message.guild_id,
channelId: new_message.channel_id,
};
// all methods of Message can run on partial messages
// we aknowledge people that their callback could be partial but giving them all functions of Message
Object.setPrototypeOf(message, Message.prototype);
session.emit("messageUpdate", message);
return;
}
session.emit("messageUpdate", new Message(session, new_message));
};
@ -212,7 +230,7 @@ type MessageReaction = any;
export interface Events {
"ready": Handler<[Ready, number]>;
"messageCreate": Handler<[Message]>;
"messageUpdate": Handler<[Message]>;
"messageUpdate": Handler<[Partial<Message>]>;
"messageDelete": Handler<[{ id: Snowflake, channelId: Snowflake, guildId?: Snowflake }]>;
"messageReactionAdd": Handler<[MessageReaction]>;
"messageReactionRemove": Handler<[MessageReaction]>;

View File

@ -65,7 +65,7 @@ export class Session extends EventEmitter {
const defHandler: DiscordRawEventHandler = (shard, data) => {
Actions.raw(this, shard.id, data);
if (!data.t) {
if (!data.t || !data.d) {
return;
}

View File

@ -153,7 +153,7 @@ export class Message implements Model {
attachments: Attachment[];
embeds: DiscordEmbed[];
member?: Member;
thread?: ThreadChannel;
// thread?: ThreadChannel;
components: Component[];
webhook?: WebhookAuthor;