@globalart/nestcord 2.2.1 → 2.3.0
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/dist/core/src/nestcord-options.interface.d.ts +11 -0
- package/dist/core/src/nestcord.module.d.ts +1 -1
- package/dist/core/src/nestcord.module.js +3 -3
- package/dist/core/src/nestcord.service.d.ts +13 -1
- package/dist/core/src/nestcord.service.js +41 -1
- package/dist/core/src/providers/client.provider.js +17 -1
- package/dist/core/src/services/proxy.service.d.ts +19 -0
- package/dist/core/src/services/proxy.service.js +69 -0
- package/package.json +6 -6
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { ClientOptions as DiscordClientOptions, Snowflake } from 'discord.js';
|
|
2
|
+
export interface NestCordProxyOptions {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
auth?: {
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
};
|
|
9
|
+
protocol?: 'http' | 'https';
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* The NestCord module options.
|
|
4
13
|
*/
|
|
@@ -27,4 +36,6 @@ export interface NestCordModuleOptions extends DiscordClientOptions {
|
|
|
27
36
|
* If true, the bot won't fetch data from the Discord API, and discordResponse in the commandDiscovery will be null."
|
|
28
37
|
*/
|
|
29
38
|
skipGetCommandInfoFromDiscord?: boolean;
|
|
39
|
+
proxyPath?: string;
|
|
40
|
+
proxy?: NestCordProxyOptions;
|
|
30
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { Client } from 'discord.js';
|
|
3
|
-
import { ConfigurableModuleClass } from './nestcord.module-definition';
|
|
4
3
|
import { NestCordModuleOptions } from './nestcord-options.interface';
|
|
4
|
+
import { ConfigurableModuleClass } from './nestcord.module-definition';
|
|
5
5
|
export declare class NestCordModule extends ConfigurableModuleClass implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
6
6
|
private readonly client;
|
|
7
7
|
private readonly options;
|
|
@@ -14,17 +14,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.NestCordModule = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@nestjs/core");
|
|
17
18
|
const discord_js_1 = require("discord.js");
|
|
18
|
-
const nestcord_module_definition_1 = require("./nestcord.module-definition");
|
|
19
19
|
const commands_1 = require("./commands");
|
|
20
20
|
const listeners_1 = require("./listeners");
|
|
21
21
|
const message_components_1 = require("./message-components");
|
|
22
22
|
const modals_1 = require("./modals");
|
|
23
23
|
const nestcord_explorer_service_1 = require("./nestcord-explorer.service");
|
|
24
|
-
const
|
|
25
|
-
const core_1 = require("@nestjs/core");
|
|
24
|
+
const nestcord_module_definition_1 = require("./nestcord.module-definition");
|
|
26
25
|
const nestcord_service_1 = require("./nestcord.service");
|
|
27
26
|
const ProvidersMap = require("./providers");
|
|
27
|
+
const text_commands_1 = require("./text-commands");
|
|
28
28
|
const Providers = Object.values(ProvidersMap);
|
|
29
29
|
let NestCordModule = class NestCordModule extends nestcord_module_definition_1.ConfigurableModuleClass {
|
|
30
30
|
constructor(client, options) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
2
2
|
import { ApplicationEmoji, Client } from 'discord.js';
|
|
3
|
-
import { NestCordModuleOptions } from './nestcord-options.interface';
|
|
4
3
|
import { DiscordApplicationAsset } from './interfaces';
|
|
4
|
+
import { NestCordModuleOptions } from './nestcord-options.interface';
|
|
5
5
|
export declare class NestCordService implements OnApplicationBootstrap {
|
|
6
6
|
private readonly options;
|
|
7
7
|
private readonly discordClient;
|
|
@@ -9,8 +9,20 @@ export declare class NestCordService implements OnApplicationBootstrap {
|
|
|
9
9
|
private readonly logger;
|
|
10
10
|
private assetsMap;
|
|
11
11
|
private emojisMap;
|
|
12
|
+
private proxyConfig?;
|
|
12
13
|
constructor(options: NestCordModuleOptions, discordClient: Client);
|
|
13
14
|
onApplicationBootstrap(): void;
|
|
15
|
+
private setupProxy;
|
|
16
|
+
private maskProxyUrl;
|
|
17
|
+
private maskString;
|
|
18
|
+
getProxyConfig(): string | {
|
|
19
|
+
host: string;
|
|
20
|
+
port: number;
|
|
21
|
+
auth?: {
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
};
|
|
25
|
+
} | undefined;
|
|
14
26
|
getApplicationEmoji(name: string): ApplicationEmoji | null;
|
|
15
27
|
getApplicationAsset(name: string): DiscordApplicationAsset | null;
|
|
16
28
|
getApplicationEmojiPlain(name: string): string;
|
|
@@ -25,8 +25,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.NestCordService = void 0;
|
|
26
26
|
const common_1 = require("@nestjs/common");
|
|
27
27
|
const discord_js_1 = require("discord.js");
|
|
28
|
-
const nestcord_module_definition_1 = require("./nestcord.module-definition");
|
|
29
28
|
const nestcord_consts_1 = require("./nestcord.consts");
|
|
29
|
+
const nestcord_module_definition_1 = require("./nestcord.module-definition");
|
|
30
30
|
let NestCordService = NestCordService_1 = class NestCordService {
|
|
31
31
|
constructor(options, discordClient) {
|
|
32
32
|
this.options = options;
|
|
@@ -35,6 +35,7 @@ let NestCordService = NestCordService_1 = class NestCordService {
|
|
|
35
35
|
this.logger = new common_1.Logger(NestCordService_1.name);
|
|
36
36
|
this.assetsMap = new Map();
|
|
37
37
|
this.emojisMap = new Map();
|
|
38
|
+
this.setupProxy();
|
|
38
39
|
}
|
|
39
40
|
onApplicationBootstrap() {
|
|
40
41
|
this.discordClient.once('ready', () => {
|
|
@@ -42,6 +43,45 @@ let NestCordService = NestCordService_1 = class NestCordService {
|
|
|
42
43
|
setInterval(() => this.updateData(), this.dataFetchInterval);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
46
|
+
setupProxy() {
|
|
47
|
+
if (this.options.proxyPath) {
|
|
48
|
+
this.proxyConfig = this.options.proxyPath;
|
|
49
|
+
const maskedPath = this.maskProxyUrl(this.options.proxyPath);
|
|
50
|
+
this.logger.log(`Proxy path configured: ${maskedPath}`);
|
|
51
|
+
process.env.HTTPS_PROXY = this.options.proxyPath;
|
|
52
|
+
process.env.HTTP_PROXY = this.options.proxyPath;
|
|
53
|
+
}
|
|
54
|
+
else if (this.options.proxy) {
|
|
55
|
+
const { host, port, auth, protocol = 'http' } = this.options.proxy;
|
|
56
|
+
const authString = auth ? `${auth.username}:${auth.password}@` : '';
|
|
57
|
+
const proxyUrl = `${protocol}://${authString}${host}:${port}`;
|
|
58
|
+
this.proxyConfig = this.options.proxy;
|
|
59
|
+
const maskedHost = this.maskString(host);
|
|
60
|
+
this.logger.log(`Proxy configured: ${protocol}://${maskedHost}:${port}`);
|
|
61
|
+
process.env.HTTPS_PROXY = proxyUrl;
|
|
62
|
+
process.env.HTTP_PROXY = proxyUrl;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
maskProxyUrl(url) {
|
|
66
|
+
try {
|
|
67
|
+
const proxyUrl = new URL(url);
|
|
68
|
+
const maskedHost = this.maskString(proxyUrl.hostname);
|
|
69
|
+
return `${proxyUrl.protocol}//${proxyUrl.username ? '****:****@' : ''}${maskedHost}:${proxyUrl.port}`;
|
|
70
|
+
}
|
|
71
|
+
catch (_a) {
|
|
72
|
+
return '****';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
maskString(str) {
|
|
76
|
+
if (!str)
|
|
77
|
+
return '';
|
|
78
|
+
const visibleChars = 2;
|
|
79
|
+
const start = str.slice(0, visibleChars);
|
|
80
|
+
return start + '*'.repeat(Math.max(str.length - visibleChars, 3));
|
|
81
|
+
}
|
|
82
|
+
getProxyConfig() {
|
|
83
|
+
return this.proxyConfig;
|
|
84
|
+
}
|
|
45
85
|
getApplicationEmoji(name) {
|
|
46
86
|
return this.emojisMap.get(name) || null;
|
|
47
87
|
}
|
|
@@ -5,6 +5,22 @@ const discord_js_1 = require("discord.js");
|
|
|
5
5
|
const nestcord_module_definition_1 = require("../nestcord.module-definition");
|
|
6
6
|
exports.ClientProvider = {
|
|
7
7
|
provide: discord_js_1.Client,
|
|
8
|
-
useFactory: (options) =>
|
|
8
|
+
useFactory: (options) => {
|
|
9
|
+
const clientOptions = Object.assign({}, options);
|
|
10
|
+
if (options.proxyPath) {
|
|
11
|
+
process.env.HTTPS_PROXY = options.proxyPath;
|
|
12
|
+
process.env.HTTP_PROXY = options.proxyPath;
|
|
13
|
+
}
|
|
14
|
+
else if (options.proxy) {
|
|
15
|
+
const { host, port, auth, protocol = 'http' } = options.proxy;
|
|
16
|
+
const authString = auth ? `${auth.username}:${auth.password}@` : '';
|
|
17
|
+
const proxyUrl = `${protocol}://${authString}${host}:${port}`;
|
|
18
|
+
process.env.HTTPS_PROXY = proxyUrl;
|
|
19
|
+
process.env.HTTP_PROXY = proxyUrl;
|
|
20
|
+
}
|
|
21
|
+
delete clientOptions.proxyPath;
|
|
22
|
+
delete clientOptions.proxy;
|
|
23
|
+
return new discord_js_1.Client(clientOptions);
|
|
24
|
+
},
|
|
9
25
|
inject: [nestcord_module_definition_1.NESTCORD_MODULE_OPTIONS],
|
|
10
26
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NestCordModuleOptions } from '../nestcord-options.interface';
|
|
2
|
+
export declare class ProxyService {
|
|
3
|
+
private readonly logger;
|
|
4
|
+
private proxyConfig?;
|
|
5
|
+
configure(options: NestCordModuleOptions): void;
|
|
6
|
+
getConfig(): string | {
|
|
7
|
+
host: string;
|
|
8
|
+
port: number;
|
|
9
|
+
auth?: {
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
private setupProxyPath;
|
|
15
|
+
private setupProxyObject;
|
|
16
|
+
private setEnvVariables;
|
|
17
|
+
private maskProxyUrl;
|
|
18
|
+
private maskString;
|
|
19
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var ProxyService_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ProxyService = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
let ProxyService = ProxyService_1 = class ProxyService {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.logger = new common_1.Logger(ProxyService_1.name);
|
|
15
|
+
}
|
|
16
|
+
configure(options) {
|
|
17
|
+
if (options.proxyPath) {
|
|
18
|
+
this.setupProxyPath(options.proxyPath);
|
|
19
|
+
}
|
|
20
|
+
else if (options.proxy) {
|
|
21
|
+
this.setupProxyObject(options.proxy);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getConfig() {
|
|
25
|
+
return this.proxyConfig;
|
|
26
|
+
}
|
|
27
|
+
setupProxyPath(proxyPath) {
|
|
28
|
+
this.proxyConfig = proxyPath;
|
|
29
|
+
const maskedPath = this.maskProxyUrl(proxyPath);
|
|
30
|
+
this.logger.log(`Proxy path configured: ${maskedPath}`);
|
|
31
|
+
this.setEnvVariables(proxyPath);
|
|
32
|
+
}
|
|
33
|
+
setupProxyObject(proxy) {
|
|
34
|
+
if (!proxy)
|
|
35
|
+
return;
|
|
36
|
+
const { host, port, auth, protocol = 'http' } = proxy;
|
|
37
|
+
const authString = auth ? `${auth.username}:${auth.password}@` : '';
|
|
38
|
+
const proxyUrl = `${protocol}://${authString}${host}:${port}`;
|
|
39
|
+
this.proxyConfig = proxy;
|
|
40
|
+
const maskedHost = this.maskString(host);
|
|
41
|
+
this.logger.log(`Proxy configured: ${protocol}://${maskedHost}:${port}`);
|
|
42
|
+
this.setEnvVariables(proxyUrl);
|
|
43
|
+
}
|
|
44
|
+
setEnvVariables(proxyUrl) {
|
|
45
|
+
process.env.HTTPS_PROXY = proxyUrl;
|
|
46
|
+
process.env.HTTP_PROXY = proxyUrl;
|
|
47
|
+
}
|
|
48
|
+
maskProxyUrl(url) {
|
|
49
|
+
try {
|
|
50
|
+
const proxyUrl = new URL(url);
|
|
51
|
+
const maskedHost = this.maskString(proxyUrl.hostname);
|
|
52
|
+
return `${proxyUrl.protocol}//${proxyUrl.username ? '****:****@' : ''}${maskedHost}:${proxyUrl.port}`;
|
|
53
|
+
}
|
|
54
|
+
catch (_a) {
|
|
55
|
+
return '****';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
maskString(str) {
|
|
59
|
+
if (!str)
|
|
60
|
+
return '';
|
|
61
|
+
const visibleChars = 2;
|
|
62
|
+
const start = str.slice(0, visibleChars);
|
|
63
|
+
return start + '*'.repeat(Math.max(str.length - visibleChars, 3));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.ProxyService = ProxyService;
|
|
67
|
+
exports.ProxyService = ProxyService = ProxyService_1 = __decorate([
|
|
68
|
+
(0, common_1.Injectable)()
|
|
69
|
+
], ProxyService);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalart/nestcord",
|
|
3
3
|
"description": "A module for creating Discord bots using NestJS, based on Discord.js",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@nestjs/axios": "^4.0.0",
|
|
51
51
|
"@nestjs/schedule": "^6.0.0",
|
|
52
52
|
"axios": "^1.9.0",
|
|
53
|
-
"cron": "
|
|
53
|
+
"cron": "4.3.0",
|
|
54
54
|
"deepmerge": "^4.3.1",
|
|
55
55
|
"lavalink-client": "^2.5.3",
|
|
56
56
|
"path-to-regexp": "^8.0.0"
|
|
@@ -62,19 +62,19 @@
|
|
|
62
62
|
"@nestjs/common": "11.1.2",
|
|
63
63
|
"@nestjs/core": "11.1.2",
|
|
64
64
|
"@nestjs/platform-express": "^11.1.1",
|
|
65
|
-
"@types/node": "22.15.
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
65
|
+
"@types/node": "22.15.27",
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "8.33.0",
|
|
67
67
|
"@typescript-eslint/parser": "8.33.0",
|
|
68
68
|
"discord-api-types": "0.38.8",
|
|
69
69
|
"discord.js": "14.19.3",
|
|
70
70
|
"eslint": "9.27.0",
|
|
71
71
|
"eslint-config-prettier": "10.1.5",
|
|
72
|
-
"eslint-plugin-prettier": "5.4.
|
|
72
|
+
"eslint-plugin-prettier": "5.4.1",
|
|
73
73
|
"husky": "9.1.7",
|
|
74
74
|
"lint-staged": "16.1.0",
|
|
75
75
|
"prettier": "3.5.3",
|
|
76
76
|
"reflect-metadata": "0.2.2",
|
|
77
|
-
"release-it": "19.0.
|
|
77
|
+
"release-it": "19.0.3",
|
|
78
78
|
"rimraf": "6.0.1",
|
|
79
79
|
"rxjs": "7.8.2",
|
|
80
80
|
"ts-node": "10.9.2",
|