nestwhats 1.0.3 → 1.1.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/CHANGELOG.md +12 -0
- package/README.md +3 -2
- package/dist/commands/command.discovery.d.ts +2 -0
- package/dist/commands/command.discovery.js +4 -0
- package/dist/commands/commands.service.d.ts +1 -1
- package/dist/commands/commands.service.js +15 -3
- package/dist/commands/decorators/arg-index.decorator.d.ts +10 -0
- package/dist/commands/decorators/arg-index.decorator.js +12 -0
- package/dist/commands/decorators/arguments.decorator.d.ts +4 -2
- package/dist/commands/decorators/arguments.decorator.js +8 -3
- package/dist/commands/decorators/author.decorator.d.ts +1 -0
- package/dist/commands/decorators/author.decorator.js +20 -0
- package/dist/commands/decorators/chat.decorator.d.ts +1 -0
- package/dist/commands/decorators/chat.decorator.js +20 -0
- package/dist/commands/decorators/index.d.ts +4 -0
- package/dist/commands/decorators/index.js +4 -0
- package/dist/commands/decorators/message.decorator.d.ts +2 -0
- package/dist/commands/decorators/message.decorator.js +11 -0
- package/dist/commands/exceptions/command-args.exception.d.ts +5 -0
- package/dist/commands/exceptions/command-args.exception.js +12 -0
- package/dist/commands/exceptions/index.d.ts +1 -0
- package/dist/commands/exceptions/index.js +17 -0
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/pipes/index.d.ts +1 -0
- package/dist/commands/pipes/index.js +17 -0
- package/dist/commands/pipes/parse-args.pipe.d.ts +6 -0
- package/dist/commands/pipes/parse-args.pipe.js +58 -0
- package/dist/filters/index.d.ts +1 -0
- package/dist/filters/index.js +17 -0
- package/dist/filters/nestwhats-exception-filter.interface.d.ts +3 -0
- package/dist/filters/nestwhats-exception-filter.interface.js +2 -0
- package/dist/guards/dm-only.guard.d.ts +5 -0
- package/dist/guards/dm-only.guard.js +34 -0
- package/dist/guards/from-me.guard.d.ts +5 -0
- package/dist/guards/from-me.guard.js +22 -0
- package/dist/guards/group-only.guard.d.ts +5 -0
- package/dist/guards/group-only.guard.js +34 -0
- package/dist/guards/index.d.ts +5 -0
- package/dist/guards/index.js +21 -0
- package/dist/guards/is-admin.guard.d.ts +5 -0
- package/dist/guards/is-admin.guard.js +39 -0
- package/dist/guards/nestwhats-guard.interface.d.ts +3 -0
- package/dist/guards/nestwhats-guard.interface.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/listeners/decorators/on.decorator.d.ts +1 -1
- package/dist/listeners/decorators/once.decorator.d.ts +1 -1
- package/dist/listeners/listener.interface.d.ts +12 -3
- package/package.json +27 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
# [v1.0.3](https://github.com/NedcloarBR/NestWhats/compare/v1.0.2...v1.0.3) - (2025-02-01)
|
|
5
|
+
|
|
6
|
+
## Bug Fixes
|
|
7
|
+
|
|
8
|
+
- Build script ([8193216](https://github.com/NedcloarBR/NestWhats/commit/8193216d55b50280de54b36e05fa17e86b7c86d9))
|
|
9
|
+
|
|
10
|
+
# [v1.0.2](https://github.com/NedcloarBR/NestWhats/compare/v1.0.1...v1.0.2) - (2025-02-01)
|
|
11
|
+
|
|
12
|
+
## Bug Fixes
|
|
13
|
+
|
|
14
|
+
- Move husky from postinstall to prepare
|
|
15
|
+
|
|
4
16
|
# [v1.0.1](https://github.com/NedcloarBR/NestWhats/commits/v1.0.0...v1.0.1) - (2025-02-01)
|
|
5
17
|
|
|
6
18
|
## Bug Fixes
|
package/README.md
CHANGED
|
@@ -72,9 +72,10 @@ export class AppUpdate {
|
|
|
72
72
|
public constructor(private readonly client: Client) {}
|
|
73
73
|
|
|
74
74
|
@Once("ready")
|
|
75
|
-
public onReady(
|
|
76
|
-
this.logger.log(`Bot logged in as ${client.info.pushname}`);
|
|
75
|
+
public onReady() {
|
|
76
|
+
this.logger.log(`Bot logged in as ${this.client.info.pushname}`);
|
|
77
77
|
}
|
|
78
|
+
|
|
78
79
|
@On("message_create")
|
|
79
80
|
public onWarn(@Context() [message]: ContextOf<'message_create'>) {
|
|
80
81
|
this.logger.log(message);
|
|
@@ -2,10 +2,12 @@ import { NestWhatsBaseDiscovery } from "../context";
|
|
|
2
2
|
export interface CommandMeta {
|
|
3
3
|
name: string;
|
|
4
4
|
description: string;
|
|
5
|
+
aliases?: string[];
|
|
5
6
|
}
|
|
6
7
|
export declare class CommandDiscovery extends NestWhatsBaseDiscovery<CommandMeta> {
|
|
7
8
|
getName(): string;
|
|
8
9
|
getDescription(): string;
|
|
10
|
+
getAliases(): string[];
|
|
9
11
|
isCommand(): this is CommandDiscovery;
|
|
10
12
|
toJSON(): Record<string, any>;
|
|
11
13
|
}
|
|
@@ -9,6 +9,10 @@ class CommandDiscovery extends context_1.NestWhatsBaseDiscovery {
|
|
|
9
9
|
getDescription() {
|
|
10
10
|
return this.meta.description;
|
|
11
11
|
}
|
|
12
|
+
getAliases() {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = this.meta.aliases) !== null && _a !== void 0 ? _a : [];
|
|
15
|
+
}
|
|
12
16
|
isCommand() {
|
|
13
17
|
return true;
|
|
14
18
|
}
|
|
@@ -2,7 +2,7 @@ import { CommandDiscovery } from "./command.discovery";
|
|
|
2
2
|
export declare class CommandsService {
|
|
3
3
|
private readonly logger;
|
|
4
4
|
readonly cache: Map<string, CommandDiscovery>;
|
|
5
|
-
add(
|
|
5
|
+
add(command: CommandDiscovery): void;
|
|
6
6
|
get(name: string): CommandDiscovery;
|
|
7
7
|
remove(name: string): void;
|
|
8
8
|
}
|
|
@@ -14,18 +14,30 @@ let CommandsService = CommandsService_1 = class CommandsService {
|
|
|
14
14
|
this.logger = new common_1.Logger(CommandsService_1.name);
|
|
15
15
|
this.cache = new Map();
|
|
16
16
|
}
|
|
17
|
-
add(
|
|
18
|
-
const name =
|
|
17
|
+
add(command) {
|
|
18
|
+
const name = command.getName();
|
|
19
19
|
if (this.cache.has(name)) {
|
|
20
20
|
this.logger.warn(`Command : ${name} already exists`);
|
|
21
21
|
}
|
|
22
|
-
this.cache.set(name,
|
|
22
|
+
this.cache.set(name, command);
|
|
23
|
+
for (const alias of command.getAliases()) {
|
|
24
|
+
if (this.cache.has(alias)) {
|
|
25
|
+
this.logger.warn(`Command alias: ${alias} already exists`);
|
|
26
|
+
}
|
|
27
|
+
this.cache.set(alias, command);
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
get(name) {
|
|
25
31
|
return this.cache.get(name);
|
|
26
32
|
}
|
|
27
33
|
remove(name) {
|
|
34
|
+
const command = this.cache.get(name);
|
|
35
|
+
if (!command)
|
|
36
|
+
return;
|
|
28
37
|
this.cache.delete(name);
|
|
38
|
+
for (const alias of command.getAliases()) {
|
|
39
|
+
this.cache.delete(alias);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
42
|
};
|
|
31
43
|
exports.CommandsService = CommandsService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const ARG_INDEX_METADATA: unique symbol;
|
|
2
|
+
export interface ArgIndexOptions {
|
|
3
|
+
rest?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ArgIndexMeta {
|
|
6
|
+
propertyKey: string;
|
|
7
|
+
index: number;
|
|
8
|
+
options?: ArgIndexOptions;
|
|
9
|
+
}
|
|
10
|
+
export declare function ArgIndex(index: number, options?: ArgIndexOptions): PropertyDecorator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARG_INDEX_METADATA = void 0;
|
|
4
|
+
exports.ArgIndex = ArgIndex;
|
|
5
|
+
exports.ARG_INDEX_METADATA = Symbol("nestwhats::arg_index");
|
|
6
|
+
function ArgIndex(index, options) {
|
|
7
|
+
return (target, propertyKey) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const existing = (_a = Reflect.getMetadata(exports.ARG_INDEX_METADATA, target)) !== null && _a !== void 0 ? _a : [];
|
|
10
|
+
Reflect.defineMetadata(exports.ARG_INDEX_METADATA, [...existing, { propertyKey: String(propertyKey), index, options }], target);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import { Type } from "@nestjs/common";
|
|
2
|
+
export declare const Arguments: (...dataOrPipes: (number | import("@nestjs/common").PipeTransform<any, any> | Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
3
|
+
export declare const Args: (...dataOrPipes: (number | import("@nestjs/common").PipeTransform<any, any> | Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
4
|
+
export declare const ParseArgs: <T extends object>(dto: Type<T>) => ParameterDecorator;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Args = exports.Arguments = void 0;
|
|
3
|
+
exports.ParseArgs = exports.Args = exports.Arguments = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const context_1 = require("../../context");
|
|
6
|
-
|
|
6
|
+
const parse_args_pipe_1 = require("../pipes/parse-args.pipe");
|
|
7
|
+
exports.Arguments = (0, common_1.createParamDecorator)((index, context) => {
|
|
8
|
+
var _a;
|
|
7
9
|
const moduleContext = context_1.NestWhatsExecutionContext.create(context);
|
|
8
10
|
const [message] = moduleContext.getContext();
|
|
9
11
|
const discovery = moduleContext.getDiscovery();
|
|
10
12
|
if (!discovery.isCommand())
|
|
11
13
|
return null;
|
|
12
|
-
|
|
14
|
+
const args = message.body.split(/ +/g).slice(1);
|
|
15
|
+
return index !== undefined ? ((_a = args[index]) !== null && _a !== void 0 ? _a : null) : args;
|
|
13
16
|
});
|
|
14
17
|
exports.Args = exports.Arguments;
|
|
18
|
+
const ParseArgs = (dto) => (0, exports.Args)(new parse_args_pipe_1.ParseArgsPipe(dto));
|
|
19
|
+
exports.ParseArgs = ParseArgs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Author: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Author = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const context_1 = require("../../context");
|
|
15
|
+
exports.Author = (0, common_1.createParamDecorator)((_, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
17
|
+
const ctx = context_1.NestWhatsExecutionContext.create(context);
|
|
18
|
+
const [message] = ctx.getContext();
|
|
19
|
+
return (_a = message === null || message === void 0 ? void 0 : message.getContact()) !== null && _a !== void 0 ? _a : null;
|
|
20
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Chat: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Chat = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const context_1 = require("../../context");
|
|
15
|
+
exports.Chat = (0, common_1.createParamDecorator)((_, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
17
|
+
const ctx = context_1.NestWhatsExecutionContext.create(context);
|
|
18
|
+
const [message] = ctx.getContext();
|
|
19
|
+
return (_a = message === null || message === void 0 ? void 0 : message.getChat()) !== null && _a !== void 0 ? _a : null;
|
|
20
|
+
}));
|
|
@@ -14,5 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./arg-index.decorator"), exports);
|
|
17
18
|
__exportStar(require("./arguments.decorator"), exports);
|
|
19
|
+
__exportStar(require("./author.decorator"), exports);
|
|
20
|
+
__exportStar(require("./chat.decorator"), exports);
|
|
18
21
|
__exportStar(require("./command.decorator"), exports);
|
|
22
|
+
__exportStar(require("./message.decorator"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Msg = exports.Message = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const context_1 = require("../../context");
|
|
6
|
+
exports.Message = (0, common_1.createParamDecorator)((_, context) => {
|
|
7
|
+
const ctx = context_1.NestWhatsExecutionContext.create(context);
|
|
8
|
+
const [message] = ctx.getContext();
|
|
9
|
+
return message !== null && message !== void 0 ? message : null;
|
|
10
|
+
});
|
|
11
|
+
exports.Msg = exports.Message;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandArgsException = void 0;
|
|
4
|
+
class CommandArgsException extends Error {
|
|
5
|
+
constructor(errors) {
|
|
6
|
+
const messages = errors.flatMap((e) => { var _a; return Object.values((_a = e.constraints) !== null && _a !== void 0 ? _a : {}); });
|
|
7
|
+
super(messages.join("; "));
|
|
8
|
+
this.name = "CommandArgsException";
|
|
9
|
+
this.errors = errors;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.CommandArgsException = CommandArgsException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./command-args.exception";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./command-args.exception"), exports);
|
package/dist/commands/index.d.ts
CHANGED
package/dist/commands/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./decorators"), exports);
|
|
18
|
+
__exportStar(require("./exceptions"), exports);
|
|
19
|
+
__exportStar(require("./pipes"), exports);
|
|
18
20
|
__exportStar(require("./command.discovery"), exports);
|
|
19
21
|
__exportStar(require("./commands.module"), exports);
|
|
20
22
|
__exportStar(require("./commands.service"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parse-args.pipe";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./parse-args.pipe"), exports);
|
|
@@ -0,0 +1,58 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.ParseArgsPipe = void 0;
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const class_transformer_1 = require("class-transformer");
|
|
24
|
+
const class_validator_1 = require("class-validator");
|
|
25
|
+
const arg_index_decorator_1 = require("../decorators/arg-index.decorator");
|
|
26
|
+
const command_args_exception_1 = require("../exceptions/command-args.exception");
|
|
27
|
+
let ParseArgsPipe = class ParseArgsPipe {
|
|
28
|
+
constructor(dto) {
|
|
29
|
+
this.dto = dto;
|
|
30
|
+
}
|
|
31
|
+
transform(args) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
var _a;
|
|
34
|
+
const metas = (_a = Reflect.getMetadata(arg_index_decorator_1.ARG_INDEX_METADATA, this.dto.prototype)) !== null && _a !== void 0 ? _a : [];
|
|
35
|
+
const plain = {};
|
|
36
|
+
for (const { propertyKey, index, options } of metas) {
|
|
37
|
+
if (options === null || options === void 0 ? void 0 : options.rest) {
|
|
38
|
+
const joined = args.slice(index).join(" ");
|
|
39
|
+
plain[propertyKey] = joined.length ? joined : undefined;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
plain[propertyKey] = args[index];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const instance = (0, class_transformer_1.plainToInstance)(this.dto, plain);
|
|
46
|
+
const errors = yield (0, class_validator_1.validate)(instance);
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
throw new command_args_exception_1.CommandArgsException(errors);
|
|
49
|
+
}
|
|
50
|
+
return instance;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.ParseArgsPipe = ParseArgsPipe;
|
|
55
|
+
exports.ParseArgsPipe = ParseArgsPipe = __decorate([
|
|
56
|
+
(0, common_1.Injectable)(),
|
|
57
|
+
__metadata("design:paramtypes", [Object])
|
|
58
|
+
], ParseArgsPipe);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./nestwhats-exception-filter.interface";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./nestwhats-exception-filter.interface"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.DmOnlyGuard = void 0;
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const context_1 = require("../context");
|
|
21
|
+
let DmOnlyGuard = class DmOnlyGuard {
|
|
22
|
+
canActivate(rawCtx) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const ctx = context_1.NestWhatsExecutionContext.create(rawCtx);
|
|
25
|
+
const [message] = ctx.getContext();
|
|
26
|
+
const chat = yield message.getChat();
|
|
27
|
+
return !chat.isGroup;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.DmOnlyGuard = DmOnlyGuard;
|
|
32
|
+
exports.DmOnlyGuard = DmOnlyGuard = __decorate([
|
|
33
|
+
(0, common_1.Injectable)()
|
|
34
|
+
], DmOnlyGuard);
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FromMeGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const context_1 = require("../context");
|
|
12
|
+
let FromMeGuard = class FromMeGuard {
|
|
13
|
+
canActivate(rawCtx) {
|
|
14
|
+
const ctx = context_1.NestWhatsExecutionContext.create(rawCtx);
|
|
15
|
+
const [message] = ctx.getContext();
|
|
16
|
+
return message.fromMe;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.FromMeGuard = FromMeGuard;
|
|
20
|
+
exports.FromMeGuard = FromMeGuard = __decorate([
|
|
21
|
+
(0, common_1.Injectable)()
|
|
22
|
+
], FromMeGuard);
|
|
@@ -0,0 +1,34 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.GroupOnlyGuard = void 0;
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const context_1 = require("../context");
|
|
21
|
+
let GroupOnlyGuard = class GroupOnlyGuard {
|
|
22
|
+
canActivate(rawCtx) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const ctx = context_1.NestWhatsExecutionContext.create(rawCtx);
|
|
25
|
+
const [message] = ctx.getContext();
|
|
26
|
+
const chat = yield message.getChat();
|
|
27
|
+
return chat.isGroup;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.GroupOnlyGuard = GroupOnlyGuard;
|
|
32
|
+
exports.GroupOnlyGuard = GroupOnlyGuard = __decorate([
|
|
33
|
+
(0, common_1.Injectable)()
|
|
34
|
+
], GroupOnlyGuard);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./dm-only.guard"), exports);
|
|
18
|
+
__exportStar(require("./from-me.guard"), exports);
|
|
19
|
+
__exportStar(require("./group-only.guard"), exports);
|
|
20
|
+
__exportStar(require("./is-admin.guard"), exports);
|
|
21
|
+
__exportStar(require("./nestwhats-guard.interface"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.IsAdminGuard = void 0;
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const context_1 = require("../context");
|
|
21
|
+
let IsAdminGuard = class IsAdminGuard {
|
|
22
|
+
canActivate(rawCtx) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
25
|
+
const ctx = context_1.NestWhatsExecutionContext.create(rawCtx);
|
|
26
|
+
const [message] = ctx.getContext();
|
|
27
|
+
const chat = yield message.getChat();
|
|
28
|
+
if (!chat.isGroup)
|
|
29
|
+
return false;
|
|
30
|
+
const contact = yield message.getContact();
|
|
31
|
+
const participant = chat.participants.find((p) => p.id._serialized === contact.id._serialized);
|
|
32
|
+
return (_a = participant === null || participant === void 0 ? void 0 : participant.isAdmin) !== null && _a !== void 0 ? _a : false;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.IsAdminGuard = IsAdminGuard;
|
|
37
|
+
exports.IsAdminGuard = IsAdminGuard = __decorate([
|
|
38
|
+
(0, common_1.Injectable)()
|
|
39
|
+
], IsAdminGuard);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,6 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./commands"), exports);
|
|
18
18
|
__exportStar(require("./context"), exports);
|
|
19
|
+
__exportStar(require("./filters"), exports);
|
|
20
|
+
__exportStar(require("./guards"), exports);
|
|
19
21
|
__exportStar(require("./listeners"), exports);
|
|
20
22
|
__exportStar(require("./providers"), exports);
|
|
21
23
|
__exportStar(require("./nestwhats-explorer.service"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { NestWhatsEvents } from "../listener.interface";
|
|
2
|
-
export declare const On: <K extends keyof E, E =
|
|
2
|
+
export declare const On: <K extends keyof E, E = NestWhatsEvents>(event: K) => import("@nestjs/common").CustomDecorator;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { NestWhatsEvents } from "../listener.interface";
|
|
2
|
-
export declare const Once: <K extends keyof E, E =
|
|
2
|
+
export declare const Once: <K extends keyof E, E = NestWhatsEvents>(event: K) => import("@nestjs/common").CustomDecorator;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { BatteryInfo, Call, GroupNotification, Message, MessageAck, WAState } from "whatsapp-web.js";
|
|
1
|
+
import { BatteryInfo, Call, Chat, GroupNotification, Message, MessageAck, PollVote, Reaction, WAState } from "whatsapp-web.js";
|
|
2
2
|
export interface ClientEvents {
|
|
3
3
|
auth_failure: [message: string];
|
|
4
4
|
authenticated: any;
|
|
5
|
+
/** @deprecated Battery status events are no longer supported by WhatsApp */
|
|
5
6
|
change_battery: [batteryInfo: BatteryInfo];
|
|
7
|
+
change_state: [state: WAState];
|
|
6
8
|
call: [call: Call];
|
|
9
|
+
chat_archived: [chat: Chat, currState: boolean, prevState: boolean];
|
|
10
|
+
chat_removed: [chat: Chat];
|
|
11
|
+
code: [code: string];
|
|
7
12
|
contact_changed: [
|
|
8
13
|
message: Message,
|
|
9
14
|
oldId: string,
|
|
@@ -16,17 +21,21 @@ export interface ClientEvents {
|
|
|
16
21
|
group_leave: [notification: GroupNotification];
|
|
17
22
|
group_membership_request: [notification: GroupNotification];
|
|
18
23
|
group_update: [notification: GroupNotification];
|
|
19
|
-
loading_screen:
|
|
24
|
+
loading_screen: [percent: string, message: string];
|
|
20
25
|
media_uploaded: [message: Message];
|
|
21
26
|
message_ack: [message: Message, ack: MessageAck];
|
|
22
27
|
message_ciphertext: [message: Message];
|
|
28
|
+
message_ciphertext_failed: [message: Message];
|
|
23
29
|
message_create: [message: Message];
|
|
24
30
|
message_edit: [message: Message, newBody: string, prevBody: string];
|
|
25
31
|
message: [message: Message];
|
|
26
|
-
|
|
32
|
+
message_reaction: [reaction: Reaction];
|
|
33
|
+
message_revoke_everyone: [message: Message, revoked_msg: Message | null];
|
|
27
34
|
message_revoke_me: [message: Message];
|
|
28
35
|
qr: [qr: string];
|
|
29
36
|
ready: any;
|
|
30
37
|
remote_session_saved: any;
|
|
38
|
+
unread_count: [chat: Chat];
|
|
39
|
+
vote_update: [vote: PollVote];
|
|
31
40
|
}
|
|
32
41
|
export type NestWhatsEvents = ClientEvents;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestwhats",
|
|
3
3
|
"description": "A whatsapp-web.js wrapper for NestJS to create WhatsApp bots",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Miguel Alexandre Uhlein",
|
|
7
7
|
"email": "nedcloar1@hotmail.com"
|
|
@@ -46,34 +46,45 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"path-to-regexp": "8.2.0",
|
|
49
|
-
"qrcode": "^1.5.
|
|
49
|
+
"qrcode": "^1.5.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@biomejs/biome": "^1.9.4",
|
|
53
|
-
"@commitlint/cli": "19.
|
|
54
|
-
"@commitlint/config-angular": "19.
|
|
55
|
-
"@nedcloarbr/biome-config": "^1.
|
|
56
|
-
"@nestjs/common": "11.0
|
|
57
|
-
"@nestjs/core": "11.0
|
|
58
|
-
"@types/node": "22.
|
|
53
|
+
"@commitlint/cli": "19.8.0",
|
|
54
|
+
"@commitlint/config-angular": "19.8.0",
|
|
55
|
+
"@nedcloarbr/biome-config": "^1.9.1",
|
|
56
|
+
"@nestjs/common": "11.1.0",
|
|
57
|
+
"@nestjs/core": "11.1.0",
|
|
58
|
+
"@types/node": "22.15.2",
|
|
59
59
|
"@types/qrcode": "^1.5.5",
|
|
60
|
-
"
|
|
60
|
+
"class-transformer": "^0.5.1",
|
|
61
|
+
"class-validator": "^0.15.1",
|
|
62
|
+
"globals": "^16.0.0",
|
|
61
63
|
"husky": "^9.1.7",
|
|
62
|
-
"lint-staged": "15.
|
|
63
|
-
"prettier": "3.4.2",
|
|
64
|
+
"lint-staged": "15.5.1",
|
|
64
65
|
"reflect-metadata": "0.2.2",
|
|
65
|
-
"release-it": "
|
|
66
|
+
"release-it": "19.0.1",
|
|
66
67
|
"rimraf": "6.0.1",
|
|
67
|
-
"rxjs": "7.8.
|
|
68
|
+
"rxjs": "7.8.2",
|
|
68
69
|
"ts-node": "10.9.2",
|
|
69
|
-
"typescript": "5.
|
|
70
|
-
"whatsapp-web.js": "^1.
|
|
70
|
+
"typescript": "5.8.3",
|
|
71
|
+
"whatsapp-web.js": "^1.34.7"
|
|
71
72
|
},
|
|
72
73
|
"peerDependencies": {
|
|
73
74
|
"@nestjs/common": "^10.2.0 || ^11.0.0",
|
|
74
75
|
"@nestjs/core": "^10.2.0 || ^11.0.0",
|
|
76
|
+
"class-transformer": ">=0.5.0",
|
|
77
|
+
"class-validator": ">=0.14.0",
|
|
75
78
|
"reflect-metadata": "^0.2.1",
|
|
76
79
|
"rxjs": "^7.2.0",
|
|
77
|
-
"whatsapp-web.js": "^1.
|
|
80
|
+
"whatsapp-web.js": "^1.34.0"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"class-transformer": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"class-validator": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
78
89
|
}
|
|
79
90
|
}
|