summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/ClientUser.js
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
committersowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
commite4450c8417624b71d779cb4f41692538f9165e10 (patch)
treeb70826542223ecdf8a7a259f61b0a1abb8a217d8 /node_modules/discord.js/src/structures/ClientUser.js
downloadsowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip
first commit
Diffstat (limited to 'node_modules/discord.js/src/structures/ClientUser.js')
-rw-r--r--node_modules/discord.js/src/structures/ClientUser.js187
1 files changed, 187 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/structures/ClientUser.js b/node_modules/discord.js/src/structures/ClientUser.js
new file mode 100644
index 0000000..b93904c
--- /dev/null
+++ b/node_modules/discord.js/src/structures/ClientUser.js
@@ -0,0 +1,187 @@
+'use strict';
+
+const { Routes } = require('discord-api-types/v10');
+const User = require('./User');
+const DataResolver = require('../util/DataResolver');
+
+/**
+ * Represents the logged in client's Discord user.
+ * @extends {User}
+ */
+class ClientUser extends User {
+ _patch(data) {
+ super._patch(data);
+
+ if ('verified' in data) {
+ /**
+ * Whether or not this account has been verified
+ * @type {boolean}
+ */
+ this.verified = data.verified;
+ }
+
+ if ('mfa_enabled' in data) {
+ /**
+ * If the bot's {@link ClientApplication#owner Owner} has MFA enabled on their account
+ * @type {?boolean}
+ */
+ this.mfaEnabled = typeof data.mfa_enabled === 'boolean' ? data.mfa_enabled : null;
+ } else {
+ this.mfaEnabled ??= null;
+ }
+
+ if ('token' in data) this.client.token = data.token;
+ }
+
+ /**
+ * Represents the client user's presence
+ * @type {ClientPresence}
+ * @readonly
+ */
+ get presence() {
+ return this.client.presence;
+ }
+
+ /**
+ * Data used to edit the logged in client
+ * @typedef {Object} ClientUserEditOptions
+ * @property {string} [username] The new username
+ * @property {?(BufferResolvable|Base64Resolvable)} [avatar] The new avatar
+ */
+
+ /**
+ * Edits the logged in client.
+ * @param {ClientUserEditOptions} options The options to provide
+ * @returns {Promise<ClientUser>}
+ */
+ async edit({ username, avatar }) {
+ const data = await this.client.rest.patch(Routes.user(), {
+ body: { username, avatar: avatar && (await DataResolver.resolveImage(avatar)) },
+ });
+
+ this.client.token = data.token;
+ this.client.rest.setToken(data.token);
+ const { updated } = this.client.actions.UserUpdate.handle(data);
+ return updated ?? this;
+ }
+
+ /**
+ * Sets the username of the logged in client.
+ * <info>Changing usernames in Discord is heavily rate limited, with only 2 requests
+ * every hour. Use this sparingly!</info>
+ * @param {string} username The new username
+ * @returns {Promise<ClientUser>}
+ * @example
+ * // Set username
+ * client.user.setUsername('discordjs')
+ * .then(user => console.log(`My new username is ${user.username}`))
+ * .catch(console.error);
+ */
+ setUsername(username) {
+ return this.edit({ username });
+ }
+
+ /**
+ * Sets the avatar of the logged in client.
+ * @param {?(BufferResolvable|Base64Resolvable)} avatar The new avatar
+ * @returns {Promise<ClientUser>}
+ * @example
+ * // Set avatar
+ * client.user.setAvatar('./avatar.png')
+ * .then(user => console.log(`New avatar set!`))
+ * .catch(console.error);
+ */
+ setAvatar(avatar) {
+ return this.edit({ avatar });
+ }
+
+ /**
+ * Options for setting activities
+ * @typedef {Object} ActivitiesOptions
+ * @property {string} name Name of the activity
+ * @property {string} [state] State of the activity
+ * @property {ActivityType} [type] Type of the activity
+ * @property {string} [url] Twitch / YouTube stream URL
+ */
+
+ /**
+ * Data resembling a raw Discord presence.
+ * @typedef {Object} PresenceData
+ * @property {PresenceStatusData} [status] Status of the user
+ * @property {boolean} [afk] Whether the user is AFK
+ * @property {ActivitiesOptions[]} [activities] Activity the user is playing
+ * @property {number|number[]} [shardId] Shard id(s) to have the activity set on
+ */
+
+ /**
+ * Sets the full presence of the client user.
+ * @param {PresenceData} data Data for the presence
+ * @returns {ClientPresence}
+ * @example
+ * // Set the client user's presence
+ * client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
+ */
+ setPresence(data) {
+ return this.client.presence.set(data);
+ }
+
+ /**
+ * A user's status. Must be one of:
+ * * `online`
+ * * `idle`
+ * * `invisible`
+ * * `dnd` (do not disturb)
+ * @typedef {string} PresenceStatusData
+ */
+
+ /**
+ * Sets the status of the client user.
+ * @param {PresenceStatusData} status Status to change to
+ * @param {number|number[]} [shardId] Shard id(s) to have the activity set on
+ * @returns {ClientPresence}
+ * @example
+ * // Set the client user's status
+ * client.user.setStatus('idle');
+ */
+ setStatus(status, shardId) {
+ return this.setPresence({ status, shardId });
+ }
+
+ /**
+ * Options for setting an activity.
+ * @typedef {Object} ActivityOptions
+ * @property {string} name Name of the activity
+ * @property {string} [state] State of the activity
+ * @property {string} [url] Twitch / YouTube stream URL
+ * @property {ActivityType} [type] Type of the activity
+ * @property {number|number[]} [shardId] Shard Id(s) to have the activity set on
+ */
+
+ /**
+ * Sets the activity the client user is playing.
+ * @param {string|ActivityOptions} name Activity being played, or options for setting the activity
+ * @param {ActivityOptions} [options] Options for setting the activity
+ * @returns {ClientPresence}
+ * @example
+ * // Set the client user's activity
+ * client.user.setActivity('discord.js', { type: ActivityType.Watching });
+ */
+ setActivity(name, options = {}) {
+ if (!name) return this.setPresence({ activities: [], shardId: options.shardId });
+
+ const activity = Object.assign({}, options, typeof name === 'object' ? name : { name });
+ return this.setPresence({ activities: [activity], shardId: activity.shardId });
+ }
+
+ /**
+ * Sets/removes the AFK flag for the client user.
+ * @param {boolean} [afk=true] Whether or not the user is AFK
+ * @param {number|number[]} [shardId] Shard Id(s) to have the AFK flag set on
+ * @returns {ClientPresence}
+ */
+ setAFK(afk = true, shardId) {
+ return this.setPresence({ afk, shardId });
+ }
+}
+
+module.exports = ClientUser;