vcord.js 1.0.1
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/package.json +16 -0
- package/vcord/client/Client.js +34 -0
- package/vcord/client/extentions/ApiHandler.js +51 -0
- package/vcord/client/extentions/BaseClient.js +37 -0
- package/vcord/client/extentions/GatewayIntents.js +42 -0
- package/vcord/client/extentions/WsHandler.js +53 -0
- package/vcord/client/extentions/components.js +0 -0
- package/vcord/client/extentions/config.js +4 -0
- package/vcord/client/extentions/intents.js +24 -0
- package/vcord/index.js +7 -0
- package/ws/.gitattributes +1 -0
- package/ws/.github/FUNDING.yml +2 -0
- package/ws/.github/ISSUE_TEMPLATE/bug_report.yml +52 -0
- package/ws/.github/ISSUE_TEMPLATE/config.yml +1 -0
- package/ws/.github/workflows/ci.yml +82 -0
- package/ws/.prettierrc.yaml +5 -0
- package/ws/FUNDING.json +7 -0
- package/ws/LICENSE +20 -0
- package/ws/README.md +548 -0
- package/ws/SECURITY.md +41 -0
- package/ws/bench/parser.benchmark.js +95 -0
- package/ws/bench/sender.benchmark.js +48 -0
- package/ws/bench/speed.js +115 -0
- package/ws/browser.js +8 -0
- package/ws/doc/ws.md +712 -0
- package/ws/eslint.config.js +28 -0
- package/ws/examples/express-session-parse/index.js +111 -0
- package/ws/examples/express-session-parse/package.json +11 -0
- package/ws/examples/express-session-parse/public/app.js +67 -0
- package/ws/examples/express-session-parse/public/index.html +24 -0
- package/ws/examples/server-stats/index.js +35 -0
- package/ws/examples/server-stats/package.json +9 -0
- package/ws/examples/server-stats/public/index.html +63 -0
- package/ws/examples/ssl.js +41 -0
- package/ws/index.js +13 -0
- package/ws/lib/buffer-util.js +131 -0
- package/ws/lib/constants.js +18 -0
- package/ws/lib/event-target.js +292 -0
- package/ws/lib/extension.js +203 -0
- package/ws/lib/limiter.js +55 -0
- package/ws/lib/permessage-deflate.js +514 -0
- package/ws/lib/receiver.js +706 -0
- package/ws/lib/sender.js +602 -0
- package/ws/lib/stream.js +161 -0
- package/ws/lib/subprotocol.js +62 -0
- package/ws/lib/validation.js +152 -0
- package/ws/lib/websocket-server.js +540 -0
- package/ws/lib/websocket.js +1388 -0
- package/ws/package.json +69 -0
- package/ws/test/autobahn-server.js +17 -0
- package/ws/test/autobahn.js +39 -0
- package/ws/test/buffer-util.test.js +15 -0
- package/ws/test/create-websocket-stream.test.js +611 -0
- package/ws/test/duplex-pair.js +73 -0
- package/ws/test/event-target.test.js +253 -0
- package/ws/test/extension.test.js +190 -0
- package/ws/test/fixtures/ca-certificate.pem +12 -0
- package/ws/test/fixtures/ca-key.pem +5 -0
- package/ws/test/fixtures/certificate.pem +12 -0
- package/ws/test/fixtures/client-certificate.pem +12 -0
- package/ws/test/fixtures/client-key.pem +5 -0
- package/ws/test/fixtures/key.pem +5 -0
- package/ws/test/limiter.test.js +41 -0
- package/ws/test/permessage-deflate.test.js +647 -0
- package/ws/test/receiver.test.js +1201 -0
- package/ws/test/sender.test.js +478 -0
- package/ws/test/subprotocol.test.js +91 -0
- package/ws/test/validation.test.js +52 -0
- package/ws/test/websocket-server.test.js +1387 -0
- package/ws/test/websocket.integration.js +55 -0
- package/ws/test/websocket.test.js +5053 -0
- package/ws/wrapper.mjs +8 -0
package/package.json
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"name": "vcord.js",
|
3
|
+
"version": "1.0.1",
|
4
|
+
"main": "vcord/index.js",
|
5
|
+
"scripts": {
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
7
|
+
},
|
8
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "https://github.com/WLappiz/vcord.js.git"
|
11
|
+
},
|
12
|
+
"keywords": [],
|
13
|
+
"author": "WLappiz",
|
14
|
+
"license": "MIT",
|
15
|
+
"description": ""
|
16
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// Client.js
|
2
|
+
const BaseClient = require('./extentions/BaseClient');
|
3
|
+
const ApiHandler = require('./extentions/ApiHandler');
|
4
|
+
|
5
|
+
class Client extends BaseClient {
|
6
|
+
constructor(options = {}) {
|
7
|
+
super(options);
|
8
|
+
this.apiHandler = null;
|
9
|
+
}
|
10
|
+
|
11
|
+
login(token) {
|
12
|
+
super.login(token);
|
13
|
+
this.apiHandler = new ApiHandler(token);
|
14
|
+
}
|
15
|
+
|
16
|
+
async sendMessage(channelId, content) {
|
17
|
+
if (!this.token) {
|
18
|
+
throw new Error('Client is not logged in.');
|
19
|
+
}
|
20
|
+
|
21
|
+
if (!channelId || !content) {
|
22
|
+
throw new Error('Channel ID and content are required to send a message.');
|
23
|
+
}
|
24
|
+
|
25
|
+
try {
|
26
|
+
const message = await this.apiHandler.sendMessage(channelId, content);
|
27
|
+
console.log('Message sent:', message);
|
28
|
+
} catch (error) {
|
29
|
+
console.error('Error sending message:', error);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
module.exports = Client;
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// ApiHandler.js
|
2
|
+
const https = require('https');
|
3
|
+
const { URL } = require('url');
|
4
|
+
|
5
|
+
class ApiHandler {
|
6
|
+
constructor(token) {
|
7
|
+
this.token = token;
|
8
|
+
this.baseUrl = 'https://discord.com/api/v10';
|
9
|
+
}
|
10
|
+
|
11
|
+
sendMessage(channelId, content) {
|
12
|
+
return new Promise((resolve, reject) => {
|
13
|
+
const url = new URL(`/channels/${channelId}/messages`, this.baseUrl);
|
14
|
+
const data = JSON.stringify({ content });
|
15
|
+
|
16
|
+
const options = {
|
17
|
+
method: 'POST',
|
18
|
+
headers: {
|
19
|
+
Authorization: `Bot ${this.token}`,
|
20
|
+
'Content-Type': 'application/json',
|
21
|
+
'Content-Length': data.length
|
22
|
+
}
|
23
|
+
};
|
24
|
+
|
25
|
+
const req = https.request(url, options, res => {
|
26
|
+
let body = '';
|
27
|
+
|
28
|
+
res.on('data', chunk => {
|
29
|
+
body += chunk;
|
30
|
+
});
|
31
|
+
|
32
|
+
res.on('end', () => {
|
33
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
34
|
+
resolve(JSON.parse(body));
|
35
|
+
} else {
|
36
|
+
reject(new Error(`Request failed with status code ${res.statusCode}`));
|
37
|
+
}
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
req.on('error', error => {
|
42
|
+
reject(error);
|
43
|
+
});
|
44
|
+
|
45
|
+
req.write(data);
|
46
|
+
req.end();
|
47
|
+
});
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
module.exports = ApiHandler;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// BaseClient.js
|
2
|
+
const GatewayIntents = require('./GatewayIntents');
|
3
|
+
const WsHandler = require('./WsHandler');
|
4
|
+
|
5
|
+
class BaseClient {
|
6
|
+
constructor(options = {}) {
|
7
|
+
if (!options.intents) {
|
8
|
+
throw new Error('No intents provided. Please specify at least one intent.');
|
9
|
+
}
|
10
|
+
this.intents = new GatewayIntents(options.intents);
|
11
|
+
this.token = null;
|
12
|
+
this.wsHandler = null;
|
13
|
+
}
|
14
|
+
|
15
|
+
hasIntent(intent) {
|
16
|
+
return this.intents.has(intent);
|
17
|
+
}
|
18
|
+
|
19
|
+
login(token) {
|
20
|
+
if (!token) {
|
21
|
+
throw new Error('Token is required to login.');
|
22
|
+
}
|
23
|
+
|
24
|
+
// Validate token format (example: basic validation, assuming token is a string of a specific length)
|
25
|
+
if (typeof token !== 'string' || token.length !== 59) {
|
26
|
+
throw new Error('Invalid token format.');
|
27
|
+
}
|
28
|
+
|
29
|
+
this.token = token;
|
30
|
+
this.wsHandler = new WsHandler(this);
|
31
|
+
this.wsHandler.connect();
|
32
|
+
|
33
|
+
console.log('Logging in with token:', token);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
module.exports = BaseClient;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
const Intents = require('./intents');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @typedef {Object} GatewayIntents
|
5
|
+
* @description Gateway Intents for Discord-like API
|
6
|
+
* @see https://discord.com/developers/docs/topics/gateway#gateway-intents
|
7
|
+
*/
|
8
|
+
class GatewayIntents {
|
9
|
+
static GUILDS = Intents.GUILDS;
|
10
|
+
static GUILD_MEMBERS = Intents.GUILD_MEMBERS;
|
11
|
+
static GUILD_BANS = Intents.GUILD_BANS;
|
12
|
+
static GUILD_EMOJIS = Intents.GUILD_EMOJIS;
|
13
|
+
static GUILD_INTEGRATIONS = Intents.GUILD_INTEGRATIONS;
|
14
|
+
static GUILD_WEBHOOKS = Intents.GUILD_WEBHOOKS;
|
15
|
+
static GUILD_INVITES = Intents.GUILD_INVITES;
|
16
|
+
static GUILD_VOICE_STATES = Intents.GUILD_VOICE_STATES;
|
17
|
+
static GUILD_PRESENCES = Intents.GUILD_PRESENCES;
|
18
|
+
static GUILD_MESSAGES = Intents.GUILD_MESSAGES;
|
19
|
+
static GUILD_MESSAGE_REACTIONS = Intents.GUILD_MESSAGE_REACTIONS;
|
20
|
+
static GUILD_MESSAGE_TYPING = Intents.GUILD_MESSAGE_TYPING;
|
21
|
+
static DIRECT_MESSAGES = Intents.DIRECT_MESSAGES;
|
22
|
+
static DIRECT_MESSAGE_REACTIONS = Intents.DIRECT_MESSAGE_REACTIONS;
|
23
|
+
static DIRECT_MESSAGE_TYPING = Intents.DIRECT_MESSAGE_TYPING;
|
24
|
+
static MESSAGE_CONTENT = Intents.MESSAGE_CONTENT;
|
25
|
+
static GUILD_SCHEDULED_EVENTS = Intents.GUILD_SCHEDULED_EVENTS;
|
26
|
+
static AUTO_MODERATION_CONFIGURATION = Intents.AUTO_MODERATION_CONFIGURATION;
|
27
|
+
static AUTO_MODERATION_EXECUTION = Intents.AUTO_MODERATION_EXECUTION;
|
28
|
+
|
29
|
+
static Default() {
|
30
|
+
return this.GUILDS | this.GUILD_MESSAGES;
|
31
|
+
}
|
32
|
+
|
33
|
+
constructor(intents = 0) {
|
34
|
+
this.intents = intents;
|
35
|
+
}
|
36
|
+
|
37
|
+
has(intent) {
|
38
|
+
return (this.intents & intent) === intent;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
module.exports = GatewayIntents;
|
@@ -0,0 +1,53 @@
|
|
1
|
+
const WebSocket = require('./ws/ws');
|
2
|
+
const { GATEWAY_URL } = require('./config');
|
3
|
+
|
4
|
+
class WsHandler {
|
5
|
+
constructor(client) {
|
6
|
+
this.client = client;
|
7
|
+
this.ws = null;
|
8
|
+
}
|
9
|
+
|
10
|
+
connect() {
|
11
|
+
this.ws = new WebSocket(GATEWAY_URL);
|
12
|
+
|
13
|
+
this.ws.on('open', () => {
|
14
|
+
console.log('Connected to Discord Gateway');
|
15
|
+
this.identify();
|
16
|
+
});
|
17
|
+
|
18
|
+
this.ws.on('message', (data) => {
|
19
|
+
const payload = JSON.parse(data);
|
20
|
+
this.handleEvent(payload);
|
21
|
+
});
|
22
|
+
|
23
|
+
this.ws.on('close', () => {
|
24
|
+
console.log('Disconnected from Discord Gateway');
|
25
|
+
});
|
26
|
+
|
27
|
+
this.ws.on('error', (error) => {
|
28
|
+
console.error('WebSocket error:', error);
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
identify() {
|
33
|
+
const identifyPayload = {
|
34
|
+
op: 2,
|
35
|
+
d: {
|
36
|
+
token: this.client.token,
|
37
|
+
intents: this.client.intents.intents,
|
38
|
+
properties: {
|
39
|
+
$os: 'linux',
|
40
|
+
$browser: 'my_library',
|
41
|
+
$device: 'my_library'
|
42
|
+
}
|
43
|
+
}
|
44
|
+
};
|
45
|
+
this.ws.send(JSON.stringify(identifyPayload));
|
46
|
+
}
|
47
|
+
|
48
|
+
handleEvent(payload) {
|
49
|
+
console.log('Event received:', payload);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
module.exports = WsHandler;
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// Intents.js
|
2
|
+
const Intents = {
|
3
|
+
GUILDS: 1 << 0,
|
4
|
+
GUILD_MEMBERS: 1 << 1, //! Privileged Intents
|
5
|
+
GUILD_BANS: 1 << 2,
|
6
|
+
GUILD_EMOJIS: 1 << 3,
|
7
|
+
GUILD_INTEGRATIONS: 1 << 4,
|
8
|
+
GUILD_WEBHOOKS: 1 << 5,
|
9
|
+
GUILD_INVITES: 1 << 6,
|
10
|
+
GUILD_VOICE_STATES: 1 << 7,
|
11
|
+
GUILD_PRESENCES: 1 << 8, //! Privileged Intents
|
12
|
+
GUILD_MESSAGES: 1 << 9,
|
13
|
+
GUILD_MESSAGE_REACTIONS: 1 << 10,
|
14
|
+
GUILD_MESSAGE_TYPING: 1 << 11,
|
15
|
+
DIRECT_MESSAGES: 1 << 12,
|
16
|
+
DIRECT_MESSAGE_REACTIONS: 1 << 13,
|
17
|
+
DIRECT_MESSAGE_TYPING: 1 << 14,
|
18
|
+
MESSAGE_CONTENT: 1 << 15, //! Privileged Intents
|
19
|
+
GUILD_SCHEDULED_EVENTS: 1 << 16,
|
20
|
+
AUTO_MODERATION_CONFIGURATION: 1 << 20,
|
21
|
+
AUTO_MODERATION_EXECUTION: 1 << 21
|
22
|
+
};
|
23
|
+
|
24
|
+
module.exports = Intents;
|
package/vcord/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* text=auto eol=lf
|
@@ -0,0 +1,52 @@
|
|
1
|
+
name: Bug report
|
2
|
+
description: Create a bug report
|
3
|
+
body:
|
4
|
+
- type: markdown
|
5
|
+
attributes:
|
6
|
+
value: |
|
7
|
+
Thank you for reporting an issue.
|
8
|
+
|
9
|
+
This issue tracker is for bugs and issues found in ws.
|
10
|
+
General support questions should be raised on a channel like Stack Overflow.
|
11
|
+
|
12
|
+
Please fill in as much of the template below as you're able.
|
13
|
+
- type: checkboxes
|
14
|
+
attributes:
|
15
|
+
label: Is there an existing issue for this?
|
16
|
+
description:
|
17
|
+
Please search to see if an issue already exists for the bug you
|
18
|
+
encountered.
|
19
|
+
options:
|
20
|
+
- label:
|
21
|
+
I've searched for any related issues and avoided creating a
|
22
|
+
duplicate issue.
|
23
|
+
required: true
|
24
|
+
- type: textarea
|
25
|
+
attributes:
|
26
|
+
label: Description
|
27
|
+
description:
|
28
|
+
Description of the bug or feature, preferably a simple code snippet that
|
29
|
+
can be run directly without installing third-party dependencies.
|
30
|
+
- type: input
|
31
|
+
attributes:
|
32
|
+
label: ws version
|
33
|
+
- type: input
|
34
|
+
attributes:
|
35
|
+
label: Node.js Version
|
36
|
+
description: Output of `node -v`.
|
37
|
+
- type: textarea
|
38
|
+
attributes:
|
39
|
+
label: System
|
40
|
+
description: Output of `npx envinfo --system`.
|
41
|
+
- type: textarea
|
42
|
+
attributes:
|
43
|
+
label: Expected result
|
44
|
+
description: What you expected to happen.
|
45
|
+
- type: textarea
|
46
|
+
attributes:
|
47
|
+
label: Actual result
|
48
|
+
description: What actually happened.
|
49
|
+
- type: textarea
|
50
|
+
attributes:
|
51
|
+
label: Attachments
|
52
|
+
description: Logs, screenshots, screencast, etc.
|
@@ -0,0 +1 @@
|
|
1
|
+
blank_issues_enabled: false
|
@@ -0,0 +1,82 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
6
|
+
|
7
|
+
permissions: {}
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
arch:
|
15
|
+
- x64
|
16
|
+
node:
|
17
|
+
- 10
|
18
|
+
- 12
|
19
|
+
- 14
|
20
|
+
- 16
|
21
|
+
- 18
|
22
|
+
- 20
|
23
|
+
- 22
|
24
|
+
- 23
|
25
|
+
os:
|
26
|
+
- macOS-latest
|
27
|
+
- ubuntu-latest
|
28
|
+
- windows-latest
|
29
|
+
include:
|
30
|
+
- arch: x86
|
31
|
+
node: 10
|
32
|
+
os: windows-latest
|
33
|
+
- arch: x86
|
34
|
+
node: 12
|
35
|
+
os: windows-latest
|
36
|
+
- arch: x86
|
37
|
+
node: 14
|
38
|
+
os: windows-latest
|
39
|
+
- arch: x86
|
40
|
+
node: 16
|
41
|
+
os: windows-latest
|
42
|
+
- arch: x86
|
43
|
+
node: 20
|
44
|
+
os: windows-latest
|
45
|
+
- arch: x86
|
46
|
+
node: 22
|
47
|
+
os: windows-latest
|
48
|
+
steps:
|
49
|
+
- uses: actions/checkout@v4
|
50
|
+
- uses: actions/setup-node@v4
|
51
|
+
with:
|
52
|
+
node-version: ${{ matrix.node }}
|
53
|
+
architecture: ${{ matrix.arch }}
|
54
|
+
cache: npm
|
55
|
+
cache-dependency-path: ./package.json
|
56
|
+
- run: npm install
|
57
|
+
- run: npm run lint
|
58
|
+
if:
|
59
|
+
matrix.os == 'ubuntu-latest' && matrix.node == 20 && matrix.arch ==
|
60
|
+
'x64'
|
61
|
+
- run: npm test
|
62
|
+
- run: |
|
63
|
+
id=$(node -e "console.log(crypto.randomBytes(16).toString('hex'))")
|
64
|
+
|
65
|
+
echo "job_id=$id" >> $GITHUB_OUTPUT
|
66
|
+
id: get_job_id
|
67
|
+
shell: bash
|
68
|
+
- uses: coverallsapp/github-action@v2
|
69
|
+
with:
|
70
|
+
flag-name:
|
71
|
+
${{ steps.get_job_id.outputs.job_id }} (Node.js ${{ matrix.node }}
|
72
|
+
${{ matrix.arch }} on ${{ matrix.os }})
|
73
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
74
|
+
parallel: true
|
75
|
+
coverage:
|
76
|
+
needs: test
|
77
|
+
runs-on: ubuntu-latest
|
78
|
+
steps:
|
79
|
+
- uses: coverallsapp/github-action@v2
|
80
|
+
with:
|
81
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
82
|
+
parallel-finished: true
|
package/ws/FUNDING.json
ADDED
package/ws/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
2
|
+
Copyright (c) 2013 Arnout Kazemier and contributors
|
3
|
+
Copyright (c) 2016 Luigi Pinca and contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|