refactor: Move me and add fetchMe()

#9029 djs
This commit is contained in:
March 7th
2023-01-10 18:08:05 +07:00
parent 579edfa8fe
commit f53d329462
15 changed files with 77 additions and 29 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ class BaseGuildVoiceChannel extends GuildChannel {
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
return (
this.guild.me.communicationDisabledUntilTimestamp < Date.now() &&
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() &&
permissions.has(Permissions.FLAGS.CONNECT, false)
);
}
+8 -7
View File
@@ -26,7 +26,6 @@ const VoiceStateManager = require('../managers/VoiceStateManager');
const {
ChannelTypes,
DefaultMessageNotificationLevels,
PartialTypes,
VerificationLevels,
ExplicitContentFilterLevels,
Status,
@@ -41,6 +40,7 @@ const Util = require('../util/Util');
let deprecationEmittedForSetChannelPositions = false;
let deprecationEmittedForSetRolePositions = false;
let deprecationEmittedForDeleted = false;
let deprecationEmittedForMe = false;
/**
* @type {WeakSet<Guild>}
@@ -608,15 +608,16 @@ class Guild extends AnonymousGuild {
/**
* The client user as a GuildMember of this guild.
* @type {?GuildMember}
* @deprecated Use {@link GuildMemberManager#me} instead.
* @readonly
*/
get me() {
return (
this.members.resolve(this.client.user.id) ??
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
? this.members._add({ user: { id: this.client.user.id } }, true)
: null)
);
if (!deprecationEmittedForMe) {
process.emitWarning('Guild#me is deprecated. Use Guild#members#me instead.', 'DeprecationWarning');
deprecationEmittedForMe = true;
}
return this.members.me;
}
/**
+1 -1
View File
@@ -415,7 +415,7 @@ class GuildChannel extends Channel {
// This flag allows managing even if timed out
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
if (this.guild.me.communicationDisabledUntilTimestamp > Date.now()) return false;
if (this.guild.members.me.communicationDisabledUntilTimestamp > Date.now()) return false;
const bitfield = VoiceBasedChannelTypes.includes(this.type)
? Permissions.FLAGS.MANAGE_CHANNELS | Permissions.FLAGS.CONNECT
+1 -1
View File
@@ -56,7 +56,7 @@ class GuildEmoji extends BaseGuildEmoji {
*/
get deletable() {
if (!this.guild.me) throw new Error('GUILD_UNCACHED_ME');
return !this.managed && this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS_AND_STICKERS);
return !this.managed && this.guild.members.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS_AND_STICKERS);
}
/**
+3 -3
View File
@@ -334,7 +334,7 @@ class GuildMember extends Base {
if (this.user.id === this.client.user.id) return false;
if (this.client.user.id === this.guild.ownerId) return true;
if (!this.guild.me) throw new Error('GUILD_UNCACHED_ME');
return this.guild.me.roles.highest.comparePositionTo(this.roles.highest) > 0;
return this.guild.members.me.roles.highest.comparePositionTo(this.roles.highest) > 0;
}
/**
@@ -343,7 +343,7 @@ class GuildMember extends Base {
* @readonly
*/
get kickable() {
return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS);
return this.manageable && this.guild.members.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS);
}
/**
@@ -352,7 +352,7 @@ class GuildMember extends Base {
* @readonly
*/
get bannable() {
return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.BAN_MEMBERS);
return this.manageable && this.guild.members.me.permissions.has(Permissions.FLAGS.BAN_MEMBERS);
}
/**
+1 -1
View File
@@ -245,7 +245,7 @@ class Invite extends Base {
if (!guild.me) throw new Error('GUILD_UNCACHED_ME');
return (
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) ||
guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD)
guild.members.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD)
);
}
+2 -2
View File
@@ -638,7 +638,7 @@ class Message extends Base {
return Boolean(
this.author.id === this.client.user.id ||
(permissions.has(Permissions.FLAGS.MANAGE_MESSAGES, false) &&
this.guild.me.communicationDisabledUntilTimestamp < Date.now()),
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now()),
);
}
@@ -1040,7 +1040,7 @@ class Message extends Base {
this.mentions.everyone ||
this.mentions.repliedUser?.id === this.client.user.id ||
this.mentions.users.has(this.client.user.id) ||
(this.guildId && this.mentions.roles.some(r => this.guild.me._roles?.includes(r.id)))
(this.guildId && this.mentions.roles.some(r => this.guild.members.me._roles?.includes(r.id)))
? 1
: 0,
},
+2 -2
View File
@@ -529,7 +529,7 @@ class ThreadChannel extends Channel {
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
return (
this.guild.me.communicationDisabledUntilTimestamp < Date.now() &&
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() &&
permissions.has(Permissions.FLAGS.MANAGE_THREADS, false)
);
}
@@ -561,7 +561,7 @@ class ThreadChannel extends Channel {
!(this.archived && this.locked && !this.manageable) &&
(this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) &&
permissions.has(Permissions.FLAGS.SEND_MESSAGES_IN_THREADS, false) &&
this.guild.me.communicationDisabledUntilTimestamp < Date.now()
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now()
);
}
+1 -1
View File
@@ -120,7 +120,7 @@ class VoiceChannel extends BaseGuildVoiceChannel {
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
return (
this.guild.me.communicationDisabledUntilTimestamp < Date.now() && permissions.has(Permissions.FLAGS.SPEAK, false)
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() && permissions.has(Permissions.FLAGS.SPEAK, false)
);
}
+4 -4
View File
@@ -220,10 +220,10 @@ class VoiceState extends Base {
* @param {boolean} [request=true] Whether or not the client is requesting to become a speaker.
* @example
* // Making the client request to speak in a stage channel (raise its hand)
* guild.me.voice.setRequestToSpeak(true);
* guild.members.me.voice.setRequestToSpeak(true);
* @example
* // Making the client cancel a request to speak
* guild.me.voice.setRequestToSpeak(false);
* guild.members.me.voice.setRequestToSpeak(false);
* @returns {Promise<void>}
*/
async setRequestToSpeak(request = true) {
@@ -246,10 +246,10 @@ class VoiceState extends Base {
* @param {boolean} [suppressed=true] Whether or not the user should be suppressed.
* @example
* // Making the client a speaker
* guild.me.voice.setSuppressed(false);
* guild.members.me.voice.setSuppressed(false);
* @example
* // Making the client an audience member
* guild.me.voice.setSuppressed(true);
* guild.members.me.voice.setSuppressed(true);
* @example
* // Inviting another user to speak
* voiceState.setSuppressed(false);