mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
Migrate most of the Client Data Store to Clien
This commit is contained in:
@@ -15,11 +15,12 @@ class DMChannel extends Channel {
|
||||
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
const recipient = new User(this.client, data.recipients[0]);
|
||||
/**
|
||||
* The recipient on the other end of the DM
|
||||
* @type {User}
|
||||
*/
|
||||
this.recipient = this.client.store.add('users', new User(this.client, data.recipients[0]));
|
||||
this.recipient = this.client.users.set(recipient.id, recipient);
|
||||
/**
|
||||
* The ID of the last sent message, if available
|
||||
* @type {?String}
|
||||
|
||||
@@ -283,7 +283,7 @@ class Guild {
|
||||
|
||||
if (data.presences) {
|
||||
for (const presence of data.presences) {
|
||||
const user = this.client.store.get('users', presence.user.id);
|
||||
const user = this.client.users.get(presence.user.id);
|
||||
if (user) {
|
||||
user.status = presence.status;
|
||||
user.game = presence.game;
|
||||
|
||||
@@ -84,7 +84,7 @@ class Message {
|
||||
*/
|
||||
this.id = data.id;
|
||||
for (const mention of data.mentions) {
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
let user = this.client.users.get(mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
@@ -96,7 +96,7 @@ class Message {
|
||||
|
||||
patch(data) {
|
||||
if (data.author) {
|
||||
this.author = this.client.store.get('users', data.author.id);
|
||||
this.author = this.client.users.get(data.author.id);
|
||||
}
|
||||
if (data.content) {
|
||||
this.content = data.content;
|
||||
@@ -124,7 +124,7 @@ class Message {
|
||||
}
|
||||
if (data.mentions) {
|
||||
for (const mention of data.mentions) {
|
||||
let user = this.client.store.get('users', mention.id);
|
||||
let user = this.client.users.get(mention.id);
|
||||
if (user) {
|
||||
this.mentions.push(user);
|
||||
} else {
|
||||
|
||||
@@ -18,10 +18,6 @@ class ClientDataStore extends AbstractDataStore {
|
||||
this.user = null;
|
||||
this.email = null;
|
||||
this.password = null;
|
||||
|
||||
this.register('users');
|
||||
this.register('guilds');
|
||||
this.register('channels');
|
||||
}
|
||||
|
||||
get pastReady() {
|
||||
@@ -29,8 +25,9 @@ class ClientDataStore extends AbstractDataStore {
|
||||
}
|
||||
|
||||
newGuild(data) {
|
||||
const already = this.get('guilds', data.id);
|
||||
const guild = this.add('guilds', new Guild(this.client, data));
|
||||
const already = this.client.guilds.get(data.id);
|
||||
const guild = new Guild(this.client, data);
|
||||
this.client.guilds.set(guild.id, guild);
|
||||
if (this.pastReady && !already) {
|
||||
this.client.emit(Constants.Events.GUILD_CREATE, guild);
|
||||
}
|
||||
@@ -39,12 +36,14 @@ class ClientDataStore extends AbstractDataStore {
|
||||
}
|
||||
|
||||
newUser(data) {
|
||||
return this.add('users', new User(this.client, data));
|
||||
const user = new User(this.client, data);
|
||||
this.client.users.set(user.id, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
newChannel(data, $guild) {
|
||||
let guild = $guild;
|
||||
const already = this.get('channels', data.id);
|
||||
const already = this.client.channels.get(data.id);
|
||||
let channel;
|
||||
if (data.type === Constants.ChannelTypes.DM) {
|
||||
channel = new DMChannel(this.client, data);
|
||||
@@ -66,25 +65,25 @@ class ClientDataStore extends AbstractDataStore {
|
||||
this.client.emit(Constants.Events.CHANNEL_CREATE, channel);
|
||||
}
|
||||
|
||||
return this.add('channels', channel);
|
||||
return this.client.channels.set(channel.id, channel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
killGuild(guild) {
|
||||
const already = this.get('guilds', guild.id);
|
||||
this.remove('guilds', guild);
|
||||
const already = this.client.guilds.get(guild.id);
|
||||
this.client.guilds.delete(guild.id);
|
||||
if (already && this.pastReady) {
|
||||
this.client.emit(Constants.Events.GUILD_DELETE, guild);
|
||||
}
|
||||
}
|
||||
|
||||
killUser(user) {
|
||||
this.remove('users', user);
|
||||
this.users.delete(user.id);
|
||||
}
|
||||
|
||||
killChannel(channel) {
|
||||
this.remove('channels', channel);
|
||||
this.client.channels.delete(channel.id);
|
||||
if (channel instanceof GuildChannel) {
|
||||
channel.guild.channels.delete(channel.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user