diff --git a/actions.js b/actions.js index 7dc5b53..12b5526 100644 --- a/actions.js +++ b/actions.js @@ -280,9 +280,7 @@ module.exports = client => { let message = channel.messages.cache.get(data.id); let old = null; if(message) { - message.patch(data); - [old] = message._edits; - if(message._edits.length > 1) { message._edits.length = 1; } + old = message.patch(data); } else { message = channel.messages.add(data, false); } @@ -360,6 +358,43 @@ module.exports = client => { c.emit(Constants.Events.PRESENCE_UPDATE, old, presence); } } + client.actions.TypingStart.handle = function(data) { + let guild = data.guild_id ? client.guilds.cache.get(data.guild_id) || client.guilds.add({id:data.guild_id,shardID:shard.is}, false) : void 0; + let channel = client.channels.cache.get(data.channel_id) || client.channels.add({id:data.channel_id,type:guild ? 0 : 1}, guild, false); + let user = client.users.cache.get(data.user_id); + if(user) { + if(data.member) { + if(data.member.user && data.member.user.username && !user.equals(data.member.user)) { + client.actions.UserUpdate.handle(data.member.user); + } + let member = guild.members.cache.get(data.user_id); + if(member) { + member._update(data.member); + } else { + guild.members.add(data.member); + } + } + } else { + user = data.member && data.member.user ? client.users.add(data.member.user, client.options.fetchAllMembers) : client.users.add({id:data.user_id}, false); + } + let timestamp = new Date(data.timestamp * 1000); + if(channel._typing.has(user.id)) { + let typing = channel._typing.get(user.id); + typing.lastTimestamp = timestamp; + typing.elapsedTime = Date.now() - typing.since; + client.clearTimeout(typing.timeout); + typing.timeout = this.tooLate(channel,user); + } else { + channel._typing.set(user.id, { + user, + since: new Date(), + lastTimestamp: new Date(), + elapsedTime: 0, + timeout: this.tooLate(channel,user) + }); + } + client.emit(Constants.Events.TYPING_START, channel, user); + } client.actions.UserUpdate.handle = function(data) { let c = this.client; let user = c.users.cache.get(data.id); diff --git a/classes.js b/classes.js index 1bd24f4..9b1623b 100644 --- a/classes.js +++ b/classes.js @@ -560,7 +560,7 @@ Discord.GuildMemberManager.prototype.fetch = async function(id, cache) { let { query, time = 60000, withPresences:presences = false } = options; let user_ids = typeof options.user === "string" ? options.user : (Array.isArray(options.user) ? options.user : void 0); let limit = Number.isInteger(options.limit) ? options.limit : 0; - let nonce = Date.now().toString(16) + Math.round(Math.random() * 1000000000).toString(); + let nonce = Discord.Snowflake.generate(); if(nonce.length > 32) { j(new RangeError("MEMBER_FETCH_NONCE_LENGTH")); return; diff --git a/client.js b/client.js index f1cd507..d7dba3d 100644 --- a/client.js +++ b/client.js @@ -15,7 +15,8 @@ Discord.Client = class Client extends Discord.Client { cacheRoles:false, cacheOverwrites:false, cacheEmojis:false, - disabledEvents: [] + disabledEvents: [], + messageEditHistoryMaxSize: 1 }, options ); diff --git a/handlers.js b/handlers.js index 92dcd63..adf70c5 100644 --- a/handlers.js +++ b/handlers.js @@ -230,44 +230,9 @@ PacketHandlers.PRESENCE_UPDATE = (client, packet, shard) => { client.actions.PresenceUpdate.handle(packet.d); } -PacketHandlers.TYPING_START = (client, { d: data }, shard) => { - let guild = data.guild_id ? client.guilds.cache.get(data.guild_id) || client.guilds.add({id:data.guild_id,shardID:shard.is}, false) : void 0; - let channel = client.channels.cache.get(data.channel_id) || client.channels.add({id:data.channel_id,type:guild ? 0 : 1}, guild, false); - let user = client.users.cache.get(data.user_id); - if(user && data.member) { - if(data.member.user && data.member.user.username && !user.equals(data.member.user)) { - client.actions.UserUpdate.handle(data.member.user); - } - let member = guild.members.cache.get(data.user_id); - if(member) { - member._update(data.member); - } else { - guild.members.add(data.member); - } - } else if(!user) { - if(data.member && data.user) { - user = client.users.add(data.member.user, client.options.fetchAllMembers); - } else { - user = client.users.add({id:data.user_id}, false); - } - } - let timestamp = new Date(data.timestamp * 1000); - if(channel._typing.has(user.id)) { - let typing = channel._typing.get(user.id); - typing.lastTimestamp = timestamp; - typing.elapsedTime = Date.now() - typing.since; - client.clearTimeout(typing.timeout); - typing.timeout = client.setTimeout(() => { channel._typing.delete(user.id); }, 10000); - } else { - channel._typing.set(user.id, { - user, - since: new Date(), - lastTimestamp: new Date(), - elapsedTime: 0, - timeout: client.setTimeout(() => { channel._typing.delete(user.id); }, 10000) - }); - } - client.emit(Constants.Events.TYPING_START, channel, user); +PacketHandlers.TYPING_START = (client, packet, shard) => { + packet.d.shardID = shard.id; + client.actions.TypingStart.handle(packet.d); } PacketHandlers.USER_UPDATE = (client, packet) => { diff --git a/package.json b/package.json index f5a225e..53ac393 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "author": "Timotej Valentin Rojko", "license": "Apache-2.0", "dependencies": { - "discord.js": "12.3.1" + "discord.js": "12.4.0" }, "engines": { "node": ">=12.0.0"