Skip to content

Commit

Permalink
discord.js 12.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timotejroiko committed Oct 21, 2020
1 parent 7773789 commit e8dec51
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
41 changes: 38 additions & 3 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Discord.Client = class Client extends Discord.Client {
cacheRoles:false,
cacheOverwrites:false,
cacheEmojis:false,
disabledEvents: []
disabledEvents: [],
messageEditHistoryMaxSize: 1
},
options
);
Expand Down
41 changes: 3 additions & 38 deletions handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e8dec51

Please sign in to comment.