mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
Rewrite presence a little bit (#1853)
* such presence many good * Update PresenceStore.js * Update index.js * Update ClientPresenceStore.js * Update Presence.js * Update ClientPresenceStore.js * Update ClientUser.js * Update Presence.js * add timestamps and party * Update Presence.js * Update PresenceStore.js * Update ClientPresenceStore.js * Update ClientPresenceStore.js
This commit is contained in:
57
src/stores/ClientPresenceStore.js
Normal file
57
src/stores/ClientPresenceStore.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const PresenceStore = require('./PresenceStore');
|
||||
const Collection = require('../util/Collection');
|
||||
const Constants = require('../util/Constants');
|
||||
const { Presence } = require('../structures/Presence');
|
||||
|
||||
class ClientPresenceStore extends PresenceStore {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.clientPresence = new Presence(this.client, {
|
||||
status: 'online',
|
||||
afk: false,
|
||||
since: null,
|
||||
activity: null,
|
||||
});
|
||||
}
|
||||
|
||||
async setClientPresence({ status, since, afk, activity }) {
|
||||
const applicationID = activity && (activity.application ? activity.application.id || activity.application : null);
|
||||
let assets = new Collection();
|
||||
if (activity && activity.assets && applicationID) {
|
||||
try {
|
||||
const a = await this.client.api.oauth2.applications(applicationID).assets.get();
|
||||
for (const asset of a) assets.set(asset.name, asset.id);
|
||||
} catch (err) {} // eslint-disable-line no-empty
|
||||
}
|
||||
|
||||
const packet = {
|
||||
afk: afk != null ? afk : false, // eslint-disable-line eqeqeq
|
||||
since: since != null ? since : null, // eslint-disable-line eqeqeq
|
||||
status: status || this.clientPresence.status,
|
||||
game: activity ? {
|
||||
type: typeof activity.type === 'number' ? activity.type : Constants.ActivityTypes.indexOf(activity.type),
|
||||
name: activity.name,
|
||||
url: activity.url,
|
||||
details: activity.details || undefined,
|
||||
state: activity.state || undefined,
|
||||
assets: activity.assets ? {
|
||||
large_text: activity.assets.largeText || undefined,
|
||||
small_text: activity.assets.smallText || undefined,
|
||||
large_image: assets.get(activity.assets.largeImage) || activity.assets.largeImage,
|
||||
small_image: assets.get(activity.assets.smallImage) || activity.assets.smallImage,
|
||||
} : undefined,
|
||||
timestamps: activity.timestamps || undefined,
|
||||
party: activity.party || undefined,
|
||||
application_id: applicationID || undefined,
|
||||
secrets: activity.secrets || undefined,
|
||||
instance: activity.instance || undefined,
|
||||
} : null,
|
||||
};
|
||||
|
||||
this.clientPresence.patch(packet);
|
||||
this.client.ws.send({ op: Constants.OPCodes.STATUS_UPDATE, d: packet });
|
||||
return this.clientPresence;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientPresenceStore;
|
||||
Reference in New Issue
Block a user