discord-self-lite 0.1.1 → 0.1.3
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
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
|
|
@@ -88,6 +103,7 @@ const client = new Client();
|
|
|
88
103
|
- `message.content` - Message content
|
|
89
104
|
- `message.author` - Message author
|
|
90
105
|
- `message.channel` - Message channel
|
|
106
|
+
- `message.guild` - Message guild (null for DMs)
|
|
91
107
|
- `message.components` - Message components (buttons, etc.)
|
|
92
108
|
|
|
93
109
|
### Channel
|
|
@@ -103,6 +119,22 @@ const client = new Client();
|
|
|
103
119
|
- `channel.name` - Channel name
|
|
104
120
|
- `channel.type` - Channel type
|
|
105
121
|
|
|
122
|
+
### Guild
|
|
123
|
+
|
|
124
|
+
#### Methods
|
|
125
|
+
|
|
126
|
+
- `guild.getChannels()` - Get cached channels for this guild
|
|
127
|
+
- `guild.fetchChannels()` - Fetch all channels for this guild from API
|
|
128
|
+
- `guild.getChannel(channelId)` - Get a specific channel from cache
|
|
129
|
+
- `guild.fetchChannel(channelId)` - Fetch a specific channel from API
|
|
130
|
+
|
|
131
|
+
#### Properties
|
|
132
|
+
|
|
133
|
+
- `guild.id` - Guild ID
|
|
134
|
+
- `guild.name` - Guild name
|
|
135
|
+
- `guild.icon` - Guild icon hash
|
|
136
|
+
- `guild.ownerId` - Guild owner ID
|
|
137
|
+
|
|
106
138
|
### WebhookClient
|
|
107
139
|
|
|
108
140
|
Send messages to Discord webhooks with support for embeds and more.
|
package/package.json
CHANGED
package/src/classes/Guild.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const Channel = require("./Channel");
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Represents a Discord guild (server)
|
|
3
5
|
*/
|
|
@@ -79,7 +81,9 @@ class Guild {
|
|
|
79
81
|
const data = await this.rest.fetchChannels(this.id);
|
|
80
82
|
const channels = [];
|
|
81
83
|
for (const channelData of data) {
|
|
82
|
-
|
|
84
|
+
// Create channel with full data and cache it
|
|
85
|
+
const channel = new Channel(this.client, this.rest, channelData);
|
|
86
|
+
this.client.channels.set(channelData.id, channel);
|
|
83
87
|
channels.push(channel);
|
|
84
88
|
}
|
|
85
89
|
return channels;
|
package/src/classes/Message.js
CHANGED
|
@@ -36,6 +36,14 @@ class Message {
|
|
|
36
36
|
return this.client.getChannel(this.channelId);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Get the guild this message was sent in
|
|
41
|
+
* @returns {Guild|null} The guild instance, or null if message was sent in DM
|
|
42
|
+
*/
|
|
43
|
+
get guild() {
|
|
44
|
+
return this.guildId ? this.client.getGuild(this.guildId) : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
/**
|
|
40
48
|
* Reply to this message
|
|
41
49
|
* @param {string|object} payload - Message content or payload object
|
|
@@ -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;
|
|
@@ -312,7 +312,7 @@ class RestManager {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
|
-
* Click a button on a message
|
|
315
|
+
* Click a button on a message (interaction)
|
|
316
316
|
* @param {string} channelId - The channel ID
|
|
317
317
|
* @param {string} messageId - The message ID
|
|
318
318
|
* @param {string} applicationId - The application ID
|
|
@@ -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;
|