Initial commit

This commit is contained in:
March 7th
2022-03-19 17:37:45 +07:00
commit ac49705f3e
282 changed files with 39756 additions and 0 deletions
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ChannelCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ChannelDelete.handle(packet.d);
};
@@ -0,0 +1,22 @@
'use strict';
const Events = require('../../../util/Events');
module.exports = (client, { d: data }) => {
const channel = client.channels.cache.get(data.channel_id);
const time = data.last_pin_timestamp ? Date.parse(data.last_pin_timestamp) : null;
if (channel) {
// Discord sends null for last_pin_timestamp if the last pinned message was removed
channel.lastPinTimestamp = time;
/**
* Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event,
* not much information can be provided easily here - you need to manually check the pins yourself.
* @event Client#channelPinsUpdate
* @param {TextBasedChannels} channel The channel that the pins update occurred in
* @param {Date} time The time of the pins update
*/
client.emit(Events.ChannelPinsUpdate, channel, time);
}
};
@@ -0,0 +1,16 @@
'use strict';
const Events = require('../../../util/Events');
module.exports = (client, packet) => {
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
if (old && updated) {
/**
* Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
* @event Client#channelUpdate
* @param {DMChannel|GuildChannel} oldChannel The channel before the update
* @param {DMChannel|GuildChannel} newChannel The channel after the update
*/
client.emit(Events.ChannelUpdate, old, updated);
}
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildBanAdd.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildBanRemove.handle(packet.d);
};
@@ -0,0 +1,26 @@
'use strict';
const Events = require('../../../util/Events');
const Status = require('../../../util/Status');
module.exports = (client, { d: data }, shard) => {
let guild = client.guilds.cache.get(data.id);
if (guild) {
if (!guild.available && !data.unavailable) {
// A newly available guild
guild._patch(data);
}
} else {
// A new guild
data.shardId = shard.id;
guild = client.guilds._add(data);
if (client.ws.status === Status.Ready) {
/**
* Emitted whenever the client joins a guild.
* @event Client#guildCreate
* @param {Guild} guild The created guild
*/
client.emit(Events.GuildCreate, guild);
}
}
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildEmojisUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildIntegrationsUpdate.handle(packet.d);
};
@@ -0,0 +1,36 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const Events = require('../../../util/Events');
module.exports = (client, { d: data }) => {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
const members = new Collection();
for (const member of data.members) members.set(member.user.id, guild.members._add(member));
if (data.presences) {
for (const presence of data.presences) guild.presences._add(Object.assign(presence, { guild }));
}
/**
* Represents the properties of a guild members chunk
* @typedef {Object} GuildMembersChunk
* @property {number} index Index of the received chunk
* @property {number} count Number of chunks the client should receive
* @property {?string} nonce Nonce for this chunk
*/
/**
* Emitted whenever a chunk of guild members is received (all members come from the same guild).
* @event Client#guildMembersChunk
* @param {Collection<Snowflake, GuildMember>} members The members in the chunk
* @param {Guild} guild The guild related to the member chunk
* @param {GuildMembersChunk} chunk Properties of the received chunk
*/
client.emit(Events.GuildMembersChunk, members, guild, {
count: data.chunk_count,
index: data.chunk_index,
nonce: data.nonce,
});
};
@@ -0,0 +1,20 @@
'use strict';
const Events = require('../../../util/Events');
const Status = require('../../../util/Status');
module.exports = (client, { d: data }, shard) => {
const guild = client.guilds.cache.get(data.guild_id);
if (guild) {
guild.memberCount++;
const member = guild.members._add(data);
if (shard.status === Status.Ready) {
/**
* Emitted whenever a user joins a guild.
* @event Client#guildMemberAdd
* @param {GuildMember} member The member that has joined a guild
*/
client.emit(Events.GuildMemberAdd, member);
}
}
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet, shard) => {
client.actions.GuildMemberRemove.handle(packet.d, shard);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet, shard) => {
client.actions.GuildMemberUpdate.handle(packet.d, shard);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildRoleCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildRoleDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildRoleUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildScheduledEventCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildScheduledEventDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildScheduledEventUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildScheduledEventUserAdd.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildScheduledEventUserRemove.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildStickersUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.GuildUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.InteractionCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.InviteCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.InviteDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageDeleteBulk.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageReactionAdd.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageReactionRemove.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageReactionRemoveAll.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.MessageReactionRemoveEmoji.handle(packet.d);
};
@@ -0,0 +1,16 @@
'use strict';
const Events = require('../../../util/Events');
module.exports = (client, packet) => {
const { old, updated } = client.actions.MessageUpdate.handle(packet.d);
if (old && updated) {
/**
* Emitted whenever a message is updated - e.g. embed or content change.
* @event Client#messageUpdate
* @param {Message} oldMessage The message before the update
* @param {Message} newMessage The message after the update
*/
client.emit(Events.MessageUpdate, old, updated);
}
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.PresenceUpdate.handle(packet.d);
};
+41
View File
@@ -0,0 +1,41 @@
'use strict';
const ClientApplication = require('../../../structures/ClientApplication');
const User = require('../../../structures/User');
let ClientUser;
module.exports = (client, { d: data }, shard) => {
//console.log(data);
client.session_id = data.session_id;
if (client.user) {
client.user._patch(data.user);
} else {
ClientUser ??= require('../../../structures/ClientUser');
client.user = new ClientUser(client, data.user);
client.users.cache.set(client.user.id, client.user);
}
client.user.setAFK(true);
for (const guild of data.guilds) {
guild.shardId = shard.id;
client.guilds._add(guild);
}
for (const r of data.relationships) {
if(r.type == 1) {
client.friends.cache.set(r.id, new User(client, r.user));
} else if(r.type == 2) {
client.blocked.cache.set(r.id, new User(client, r.user));
}
}
if (client.application) {
client.application._patch(data.application);
} else {
client.application = new ClientApplication(client, data.application);
}
shard.checkReady();
};
+14
View File
@@ -0,0 +1,14 @@
'use strict';
const Events = require('../../../util/Events');
module.exports = (client, packet, shard) => {
const replayed = shard.sequence - shard.closeSequence;
/**
* Emitted when a shard resumes successfully.
* @event Client#shardResume
* @param {number} id The shard id that resumed
* @param {number} replayedEvents The amount of replayed events
*/
client.emit(Events.ShardResume, shard.id, replayed);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.StageInstanceCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.StageInstanceDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.StageInstanceUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ThreadCreate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ThreadDelete.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ThreadListSync.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ThreadMembersUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.ThreadMemberUpdate.handle(packet.d);
};
@@ -0,0 +1,16 @@
'use strict';
const Events = require('../../../util/Events');
module.exports = (client, packet) => {
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
if (old && updated) {
/**
* Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change.
* @event Client#threadUpdate
* @param {ThreadChannel} oldThread The thread before the update
* @param {ThreadChannel} newThread The thread after the update
*/
client.emit(Events.ThreadUpdate, old, updated);
}
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.TypingStart.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.UserUpdate.handle(packet.d);
};
@@ -0,0 +1,6 @@
'use strict';
module.exports = (client, packet) => {
client.emit('debug', `[VOICE] received voice server: ${JSON.stringify(packet)}`);
client.voice.onVoiceServer(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.VoiceStateUpdate.handle(packet.d);
};
@@ -0,0 +1,5 @@
'use strict';
module.exports = (client, packet) => {
client.actions.WebhooksUpdate.handle(packet.d);
};
+58
View File
@@ -0,0 +1,58 @@
'use strict';
const handlers = Object.fromEntries([
['READY', require('./READY')],
['RESUMED', require('./RESUMED')],
['GUILD_CREATE', require('./GUILD_CREATE')],
['GUILD_DELETE', require('./GUILD_DELETE')],
['GUILD_UPDATE', require('./GUILD_UPDATE')],
['INVITE_CREATE', require('./INVITE_CREATE')],
['INVITE_DELETE', require('./INVITE_DELETE')],
['GUILD_MEMBER_ADD', require('./GUILD_MEMBER_ADD')],
['GUILD_MEMBER_REMOVE', require('./GUILD_MEMBER_REMOVE')],
['GUILD_MEMBER_UPDATE', require('./GUILD_MEMBER_UPDATE')],
['GUILD_MEMBERS_CHUNK', require('./GUILD_MEMBERS_CHUNK')],
['GUILD_INTEGRATIONS_UPDATE', require('./GUILD_INTEGRATIONS_UPDATE')],
['GUILD_ROLE_CREATE', require('./GUILD_ROLE_CREATE')],
['GUILD_ROLE_DELETE', require('./GUILD_ROLE_DELETE')],
['GUILD_ROLE_UPDATE', require('./GUILD_ROLE_UPDATE')],
['GUILD_BAN_ADD', require('./GUILD_BAN_ADD')],
['GUILD_BAN_REMOVE', require('./GUILD_BAN_REMOVE')],
['GUILD_EMOJIS_UPDATE', require('./GUILD_EMOJIS_UPDATE')],
['CHANNEL_CREATE', require('./CHANNEL_CREATE')],
['CHANNEL_DELETE', require('./CHANNEL_DELETE')],
['CHANNEL_UPDATE', require('./CHANNEL_UPDATE')],
['CHANNEL_PINS_UPDATE', require('./CHANNEL_PINS_UPDATE')],
['MESSAGE_CREATE', require('./MESSAGE_CREATE')],
['MESSAGE_DELETE', require('./MESSAGE_DELETE')],
['MESSAGE_UPDATE', require('./MESSAGE_UPDATE')],
['MESSAGE_DELETE_BULK', require('./MESSAGE_DELETE_BULK')],
['MESSAGE_REACTION_ADD', require('./MESSAGE_REACTION_ADD')],
['MESSAGE_REACTION_REMOVE', require('./MESSAGE_REACTION_REMOVE')],
['MESSAGE_REACTION_REMOVE_ALL', require('./MESSAGE_REACTION_REMOVE_ALL')],
['MESSAGE_REACTION_REMOVE_EMOJI', require('./MESSAGE_REACTION_REMOVE_EMOJI')],
['THREAD_CREATE', require('./THREAD_CREATE')],
['THREAD_UPDATE', require('./THREAD_UPDATE')],
['THREAD_DELETE', require('./THREAD_DELETE')],
['THREAD_LIST_SYNC', require('./THREAD_LIST_SYNC')],
['THREAD_MEMBER_UPDATE', require('./THREAD_MEMBER_UPDATE')],
['THREAD_MEMBERS_UPDATE', require('./THREAD_MEMBERS_UPDATE')],
['USER_UPDATE', require('./USER_UPDATE')],
['PRESENCE_UPDATE', require('./PRESENCE_UPDATE')],
['TYPING_START', require('./TYPING_START')],
['VOICE_STATE_UPDATE', require('./VOICE_STATE_UPDATE')],
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')],
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')],
['INTERACTION_CREATE', require('./INTERACTION_CREATE')],
['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE')],
['STAGE_INSTANCE_UPDATE', require('./STAGE_INSTANCE_UPDATE')],
['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE')],
['GUILD_STICKERS_UPDATE', require('./GUILD_STICKERS_UPDATE')],
['GUILD_SCHEDULED_EVENT_CREATE', require('./GUILD_SCHEDULED_EVENT_CREATE')],
['GUILD_SCHEDULED_EVENT_UPDATE', require('./GUILD_SCHEDULED_EVENT_UPDATE')],
['GUILD_SCHEDULED_EVENT_DELETE', require('./GUILD_SCHEDULED_EVENT_DELETE')],
['GUILD_SCHEDULED_EVENT_USER_ADD', require('./GUILD_SCHEDULED_EVENT_USER_ADD')],
['GUILD_SCHEDULED_EVENT_USER_REMOVE', require('./GUILD_SCHEDULED_EVENT_USER_REMOVE')],
]);
module.exports = handlers;