discord-self-lite 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/package.json +1 -1
- package/src/classes/User.js +87 -0
- package/src/connection/ws/WebSocket.js +2 -1
package/README.md
CHANGED
|
@@ -71,6 +71,21 @@ const client = new Client();
|
|
|
71
71
|
- `ready` - Fired when client is ready
|
|
72
72
|
- `messageCreate` - Fired when a message is created
|
|
73
73
|
|
|
74
|
+
### User
|
|
75
|
+
|
|
76
|
+
#### Methods
|
|
77
|
+
|
|
78
|
+
- `user.setStatus(status)` - Set user status ('online', 'idle', 'dnd', 'invisible')
|
|
79
|
+
- `user.setPresence(presence)` - Set full presence data
|
|
80
|
+
- `user.setActivity(activity)` - Set user activity
|
|
81
|
+
|
|
82
|
+
#### Properties
|
|
83
|
+
|
|
84
|
+
- `user.id` - User ID
|
|
85
|
+
- `user.username` - Username
|
|
86
|
+
- `user.discriminator` - Discriminator (4-digit number)
|
|
87
|
+
- `user.avatar` - Avatar hash
|
|
88
|
+
|
|
74
89
|
### Message
|
|
75
90
|
|
|
76
91
|
#### Methods
|
package/package.json
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Discord user
|
|
3
|
+
*/
|
|
4
|
+
class User {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new User instance
|
|
7
|
+
* @param {Client} client - The Discord client
|
|
8
|
+
* @param {object} data - Raw user data from Discord API
|
|
9
|
+
*/
|
|
10
|
+
constructor(client, data) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
this.data = data;
|
|
13
|
+
|
|
14
|
+
// Copy all user properties
|
|
15
|
+
for (const [key, value] of Object.entries(data)) {
|
|
16
|
+
const camelKey = key.replace(/_([a-z])/g, (_, letter) =>
|
|
17
|
+
letter.toUpperCase(),
|
|
18
|
+
);
|
|
19
|
+
this[camelKey] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Set the user's presence/status
|
|
25
|
+
* @param {object} presence - Presence data
|
|
26
|
+
* @param {string} [presence.status] - Status: 'online', 'idle', 'dnd', 'invisible'
|
|
27
|
+
* @param {Array} [presence.activities] - Array of activity objects
|
|
28
|
+
* @param {boolean} [presence.afk] - Whether the user is AFK
|
|
29
|
+
* @param {number} [presence.since] - Unix timestamp of when the status was set
|
|
30
|
+
* @returns {void}
|
|
31
|
+
*/
|
|
32
|
+
setPresence(presence) {
|
|
33
|
+
if (!this.client.ws || !this.client.ws.ready) {
|
|
34
|
+
throw new Error("Client is not connected");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const presenceData = {
|
|
38
|
+
status: presence.status || "online",
|
|
39
|
+
since: presence.since || 0,
|
|
40
|
+
activities: presence.activities || [],
|
|
41
|
+
afk: presence.afk || false,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Send presence update via WebSocket
|
|
45
|
+
this.client.ws.send({
|
|
46
|
+
op: 3,
|
|
47
|
+
d: presenceData,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Update client's stored presence
|
|
51
|
+
this.client.options.presence = presenceData;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Set the user's status (convenience method)
|
|
56
|
+
* @param {string} status - Status: 'online', 'idle', 'dnd', 'invisible'
|
|
57
|
+
* @returns {void}
|
|
58
|
+
*/
|
|
59
|
+
setStatus(status) {
|
|
60
|
+
this.setPresence({
|
|
61
|
+
status: status,
|
|
62
|
+
since: this.client.options.presence.since,
|
|
63
|
+
activities: this.client.options.presence.activities,
|
|
64
|
+
afk: this.client.options.presence.afk,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Set the user's activity
|
|
70
|
+
* @param {object} activity - Activity data
|
|
71
|
+
* @param {string} activity.name - Activity name
|
|
72
|
+
* @param {string} [activity.type=0] - Activity type (0=Playing, 1=Streaming, 2=Listening, 3=Watching, 5=Competing)
|
|
73
|
+
* @param {string} [activity.url] - Stream URL (for type 1)
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
setActivity(activity) {
|
|
77
|
+
const activities = activity ? [activity] : [];
|
|
78
|
+
this.setPresence({
|
|
79
|
+
status: this.client.options.presence.status,
|
|
80
|
+
since: this.client.options.presence.since,
|
|
81
|
+
activities: activities,
|
|
82
|
+
afk: this.client.options.presence.afk,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = User;
|
|
@@ -3,6 +3,7 @@ const { EventEmitter } = require("events");
|
|
|
3
3
|
const Message = require("../../classes/Message");
|
|
4
4
|
const Guild = require("../../classes/Guild");
|
|
5
5
|
const Channel = require("../../classes/Channel");
|
|
6
|
+
const User = require("../../classes/User");
|
|
6
7
|
const WebSocketError = require("../../classes/WebSocketError");
|
|
7
8
|
|
|
8
9
|
class DiscordWebSocket extends EventEmitter {
|
|
@@ -129,7 +130,7 @@ class DiscordWebSocket extends EventEmitter {
|
|
|
129
130
|
case "READY":
|
|
130
131
|
this.sessionId = message.d.session_id;
|
|
131
132
|
this.client.sessionId = message.d.session_id;
|
|
132
|
-
this.client.user = message.d.user;
|
|
133
|
+
this.client.user = new User(this.client, message.d.user);
|
|
133
134
|
this.ready = true;
|
|
134
135
|
this.client.emit("ready", message.d);
|
|
135
136
|
break;
|