trompot 1.0.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/LICENSE +21 -0
- package/README.md +560 -0
- package/lib/bot/BotBase.d.ts +82 -0
- package/lib/bot/BotBase.js +144 -0
- package/lib/bot/BotBase.js.map +1 -0
- package/lib/bot/BotEvents.d.ts +87 -0
- package/lib/bot/BotEvents.js +51 -0
- package/lib/bot/BotEvents.js.map +1 -0
- package/lib/bot/BotServer.d.ts +34 -0
- package/lib/bot/BotServer.js +118 -0
- package/lib/bot/BotServer.js.map +1 -0
- package/lib/bot/BotStatus.d.ts +4 -0
- package/lib/bot/BotStatus.js +9 -0
- package/lib/bot/BotStatus.js.map +1 -0
- package/lib/bot/IBot.d.ts +292 -0
- package/lib/bot/IBot.js +3 -0
- package/lib/bot/IBot.js.map +1 -0
- package/lib/bot/index.d.ts +5 -0
- package/lib/bot/index.js +13 -0
- package/lib/bot/index.js.map +1 -0
- package/lib/client/Client.d.ts +120 -0
- package/lib/client/Client.js +687 -0
- package/lib/client/Client.js.map +1 -0
- package/lib/client/ClientEvents.d.ts +147 -0
- package/lib/client/ClientEvents.js +93 -0
- package/lib/client/ClientEvents.js.map +1 -0
- package/lib/client/ClientFunctionHandler.d.ts +15 -0
- package/lib/client/ClientFunctionHandler.js +70 -0
- package/lib/client/ClientFunctionHandler.js.map +1 -0
- package/lib/client/ConnectionType.d.ts +4 -0
- package/lib/client/ConnectionType.js +3 -0
- package/lib/client/ConnectionType.js.map +1 -0
- package/lib/client/IAuth.d.ts +9 -0
- package/lib/client/IAuth.js +3 -0
- package/lib/client/IAuth.js.map +1 -0
- package/lib/client/IClient.d.ts +358 -0
- package/lib/client/IClient.js +3 -0
- package/lib/client/IClient.js.map +1 -0
- package/lib/client/index.d.ts +7 -0
- package/lib/client/index.js +13 -0
- package/lib/client/index.js.map +1 -0
- package/lib/cluster/ClientCluster.d.ts +428 -0
- package/lib/cluster/ClientCluster.js +1746 -0
- package/lib/cluster/ClientCluster.js.map +1 -0
- package/lib/cluster/WorkerMessage.d.ts +99 -0
- package/lib/cluster/WorkerMessage.js +84 -0
- package/lib/cluster/WorkerMessage.js.map +1 -0
- package/lib/cluster/index.d.ts +5 -0
- package/lib/cluster/index.js +27 -0
- package/lib/cluster/index.js.map +1 -0
- package/lib/configs/ConnectionConfig.d.ts +22 -0
- package/lib/configs/ConnectionConfig.js +3 -0
- package/lib/configs/ConnectionConfig.js.map +1 -0
- package/lib/configs/Defaults.d.ts +2 -0
- package/lib/configs/Defaults.js +16 -0
- package/lib/configs/Defaults.js.map +1 -0
- package/lib/configs/WAConfigs.d.ts +1 -0
- package/lib/configs/WAConfigs.js +5 -0
- package/lib/configs/WAConfigs.js.map +1 -0
- package/lib/configs/index.d.ts +3 -0
- package/lib/configs/index.js +18 -0
- package/lib/configs/index.js.map +1 -0
- package/lib/errors/ChatNotDefinedError.d.ts +4 -0
- package/lib/errors/ChatNotDefinedError.js +9 -0
- package/lib/errors/ChatNotDefinedError.js.map +1 -0
- package/lib/errors/ClientNotDefinedError.d.ts +4 -0
- package/lib/errors/ClientNotDefinedError.js +9 -0
- package/lib/errors/ClientNotDefinedError.js.map +1 -0
- package/lib/errors/UserNotDefinedError.d.ts +4 -0
- package/lib/errors/UserNotDefinedError.js +9 -0
- package/lib/errors/UserNotDefinedError.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +60 -0
- package/lib/index.js.map +1 -0
- package/lib/messages/AudioMessage.d.ts +42 -0
- package/lib/messages/AudioMessage.js +66 -0
- package/lib/messages/AudioMessage.js.map +1 -0
- package/lib/messages/ButtonMessage.d.ts +88 -0
- package/lib/messages/ButtonMessage.js +137 -0
- package/lib/messages/ButtonMessage.js.map +1 -0
- package/lib/messages/ContactMessage.d.ts +37 -0
- package/lib/messages/ContactMessage.js +93 -0
- package/lib/messages/ContactMessage.js.map +1 -0
- package/lib/messages/CustomMessage.d.ts +35 -0
- package/lib/messages/CustomMessage.js +88 -0
- package/lib/messages/CustomMessage.js.map +1 -0
- package/lib/messages/EmptyMessage.d.ts +25 -0
- package/lib/messages/EmptyMessage.js +78 -0
- package/lib/messages/EmptyMessage.js.map +1 -0
- package/lib/messages/ErrorMessage.d.ts +35 -0
- package/lib/messages/ErrorMessage.js +86 -0
- package/lib/messages/ErrorMessage.js.map +1 -0
- package/lib/messages/FileMessage.d.ts +36 -0
- package/lib/messages/FileMessage.js +60 -0
- package/lib/messages/FileMessage.js.map +1 -0
- package/lib/messages/ImageMessage.d.ts +41 -0
- package/lib/messages/ImageMessage.js +65 -0
- package/lib/messages/ImageMessage.js.map +1 -0
- package/lib/messages/ListMessage.d.ts +91 -0
- package/lib/messages/ListMessage.js +126 -0
- package/lib/messages/ListMessage.js.map +1 -0
- package/lib/messages/LocationMessage.d.ts +48 -0
- package/lib/messages/LocationMessage.js +107 -0
- package/lib/messages/LocationMessage.js.map +1 -0
- package/lib/messages/MediaMessage.d.ts +54 -0
- package/lib/messages/MediaMessage.js +113 -0
- package/lib/messages/MediaMessage.js.map +1 -0
- package/lib/messages/Message.d.ts +144 -0
- package/lib/messages/Message.js +223 -0
- package/lib/messages/Message.js.map +1 -0
- package/lib/messages/PollMessage.d.ts +87 -0
- package/lib/messages/PollMessage.js +145 -0
- package/lib/messages/PollMessage.js.map +1 -0
- package/lib/messages/PollUpdateMessage.d.ts +40 -0
- package/lib/messages/PollUpdateMessage.js +98 -0
- package/lib/messages/PollUpdateMessage.js.map +1 -0
- package/lib/messages/ReactionMessage.d.ts +36 -0
- package/lib/messages/ReactionMessage.js +91 -0
- package/lib/messages/ReactionMessage.js.map +1 -0
- package/lib/messages/StickerMessage.d.ts +49 -0
- package/lib/messages/StickerMessage.js +73 -0
- package/lib/messages/StickerMessage.js.map +1 -0
- package/lib/messages/TextMessage.d.ts +33 -0
- package/lib/messages/TextMessage.js +84 -0
- package/lib/messages/TextMessage.js.map +1 -0
- package/lib/messages/VideoMessage.d.ts +42 -0
- package/lib/messages/VideoMessage.js +66 -0
- package/lib/messages/VideoMessage.js.map +1 -0
- package/lib/messages/index.d.ts +19 -0
- package/lib/messages/index.js +81 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/models/Address.d.ts +11 -0
- package/lib/models/Address.js +18 -0
- package/lib/models/Address.js.map +1 -0
- package/lib/models/Call.d.ts +68 -0
- package/lib/models/Call.js +127 -0
- package/lib/models/Call.js.map +1 -0
- package/lib/modules/chat/Chat.d.ts +142 -0
- package/lib/modules/chat/Chat.js +246 -0
- package/lib/modules/chat/Chat.js.map +1 -0
- package/lib/modules/chat/ChatAction.d.ts +3 -0
- package/lib/modules/chat/ChatAction.js +3 -0
- package/lib/modules/chat/ChatAction.js.map +1 -0
- package/lib/modules/chat/ChatStatus.d.ts +9 -0
- package/lib/modules/chat/ChatStatus.js +13 -0
- package/lib/modules/chat/ChatStatus.js.map +1 -0
- package/lib/modules/chat/ChatType.d.ts +7 -0
- package/lib/modules/chat/ChatType.js +11 -0
- package/lib/modules/chat/ChatType.js.map +1 -0
- package/lib/modules/chat/index.d.ts +5 -0
- package/lib/modules/chat/index.js +13 -0
- package/lib/modules/chat/index.js.map +1 -0
- package/lib/modules/command/Command.d.ts +67 -0
- package/lib/modules/command/Command.js +139 -0
- package/lib/modules/command/Command.js.map +1 -0
- package/lib/modules/command/CommandController.d.ts +50 -0
- package/lib/modules/command/CommandController.js +119 -0
- package/lib/modules/command/CommandController.js.map +1 -0
- package/lib/modules/command/CommandControllerEvent.d.ts +9 -0
- package/lib/modules/command/CommandControllerEvent.js +25 -0
- package/lib/modules/command/CommandControllerEvent.js.map +1 -0
- package/lib/modules/command/CommandEnums.d.ts +14 -0
- package/lib/modules/command/CommandEnums.js +20 -0
- package/lib/modules/command/CommandEnums.js.map +1 -0
- package/lib/modules/command/CommandKey.d.ts +17 -0
- package/lib/modules/command/CommandKey.js +67 -0
- package/lib/modules/command/CommandKey.js.map +1 -0
- package/lib/modules/command/CommandPermission.d.ts +9 -0
- package/lib/modules/command/CommandPermission.js +35 -0
- package/lib/modules/command/CommandPermission.js.map +1 -0
- package/lib/modules/command/ICommandControllerConfig.d.ts +7 -0
- package/lib/modules/command/ICommandControllerConfig.js +3 -0
- package/lib/modules/command/ICommandControllerConfig.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommand.d.ts +23 -0
- package/lib/modules/command/advanced/AdvancedCommand.js +131 -0
- package/lib/modules/command/advanced/AdvancedCommand.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandContext.d.ts +10 -0
- package/lib/modules/command/advanced/AdvancedCommandContext.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandContext.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandController.d.ts +29 -0
- package/lib/modules/command/advanced/AdvancedCommandController.js +118 -0
- package/lib/modules/command/advanced/AdvancedCommandController.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandData.d.ts +6 -0
- package/lib/modules/command/advanced/AdvancedCommandData.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandData.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandJob.d.ts +12 -0
- package/lib/modules/command/advanced/AdvancedCommandJob.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandJob.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandNext.d.ts +4 -0
- package/lib/modules/command/advanced/AdvancedCommandNext.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandNext.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandOptions.d.ts +8 -0
- package/lib/modules/command/advanced/AdvancedCommandOptions.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandOptions.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandStart.d.ts +11 -0
- package/lib/modules/command/advanced/AdvancedCommandStart.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandStart.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandStop.d.ts +3 -0
- package/lib/modules/command/advanced/AdvancedCommandStop.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandStop.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandTask.d.ts +2 -0
- package/lib/modules/command/advanced/AdvancedCommandTask.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandTask.js.map +1 -0
- package/lib/modules/command/defaults.d.ts +2 -0
- package/lib/modules/command/defaults.js +8 -0
- package/lib/modules/command/defaults.js.map +1 -0
- package/lib/modules/command/index.d.ts +12 -0
- package/lib/modules/command/index.js +36 -0
- package/lib/modules/command/index.js.map +1 -0
- package/lib/modules/command/keys.d.ts +9 -0
- package/lib/modules/command/keys.js +27 -0
- package/lib/modules/command/keys.js.map +1 -0
- package/lib/modules/command/perms.d.ts +2 -0
- package/lib/modules/command/perms.js +11 -0
- package/lib/modules/command/perms.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponse.d.ts +49 -0
- package/lib/modules/quickResponse/QuickResponse.js +64 -0
- package/lib/modules/quickResponse/QuickResponse.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponseController.d.ts +55 -0
- package/lib/modules/quickResponse/QuickResponseController.js +125 -0
- package/lib/modules/quickResponse/QuickResponseController.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponseOptions.d.ts +56 -0
- package/lib/modules/quickResponse/QuickResponseOptions.js +76 -0
- package/lib/modules/quickResponse/QuickResponseOptions.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponsePattern.d.ts +28 -0
- package/lib/modules/quickResponse/QuickResponsePattern.js +3 -0
- package/lib/modules/quickResponse/QuickResponsePattern.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponseReply.d.ts +6 -0
- package/lib/modules/quickResponse/QuickResponseReply.js +3 -0
- package/lib/modules/quickResponse/QuickResponseReply.js.map +1 -0
- package/lib/modules/quickResponse/index.d.ts +6 -0
- package/lib/modules/quickResponse/index.js +13 -0
- package/lib/modules/quickResponse/index.js.map +1 -0
- package/lib/modules/user/User.d.ts +91 -0
- package/lib/modules/user/User.js +173 -0
- package/lib/modules/user/User.js.map +1 -0
- package/lib/modules/user/UserAction.d.ts +4 -0
- package/lib/modules/user/UserAction.js +3 -0
- package/lib/modules/user/UserAction.js.map +1 -0
- package/lib/modules/user/UserEvent.d.ts +3 -0
- package/lib/modules/user/UserEvent.js +3 -0
- package/lib/modules/user/UserEvent.js.map +1 -0
- package/lib/modules/user/index.d.ts +4 -0
- package/lib/modules/user/index.js +9 -0
- package/lib/modules/user/index.js.map +1 -0
- package/lib/routes/botServer/api/v1/emitEvent.d.ts +3 -0
- package/lib/routes/botServer/api/v1/emitEvent.js +17 -0
- package/lib/routes/botServer/api/v1/emitEvent.js.map +1 -0
- package/lib/routes/botServer/api/v1/function.d.ts +3 -0
- package/lib/routes/botServer/api/v1/function.js +22 -0
- package/lib/routes/botServer/api/v1/function.js.map +1 -0
- package/lib/routes/botServer/api/v1/ping.d.ts +3 -0
- package/lib/routes/botServer/api/v1/ping.js +12 -0
- package/lib/routes/botServer/api/v1/ping.js.map +1 -0
- package/lib/routes/botServer/api/v1/register.d.ts +3 -0
- package/lib/routes/botServer/api/v1/register.js +23 -0
- package/lib/routes/botServer/api/v1/register.js.map +1 -0
- package/lib/routes/botServer/api/v1/setValue.d.ts +3 -0
- package/lib/routes/botServer/api/v1/setValue.js +18 -0
- package/lib/routes/botServer/api/v1/setValue.js.map +1 -0
- package/lib/routes/botServer/api/v1/unregister.d.ts +3 -0
- package/lib/routes/botServer/api/v1/unregister.js +22 -0
- package/lib/routes/botServer/api/v1/unregister.js.map +1 -0
- package/lib/routes/botServer/middlewares/setBotServer.d.ts +4 -0
- package/lib/routes/botServer/middlewares/setBotServer.js +16 -0
- package/lib/routes/botServer/middlewares/setBotServer.js.map +1 -0
- package/lib/routes/botServer/routes.d.ts +8 -0
- package/lib/routes/botServer/routes.js +33 -0
- package/lib/routes/botServer/routes.js.map +1 -0
- package/lib/services/AddressService.d.ts +12 -0
- package/lib/services/AddressService.js +51 -0
- package/lib/services/AddressService.js.map +1 -0
- package/lib/services/BaseService.d.ts +5 -0
- package/lib/services/BaseService.js +19 -0
- package/lib/services/BaseService.js.map +1 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +11 -0
- package/lib/services/index.js.map +1 -0
- package/lib/telegram/TelegramAuth.d.ts +17 -0
- package/lib/telegram/TelegramAuth.js +96 -0
- package/lib/telegram/TelegramAuth.js.map +1 -0
- package/lib/telegram/TelegramBot.d.ts +88 -0
- package/lib/telegram/TelegramBot.js +345 -0
- package/lib/telegram/TelegramBot.js.map +1 -0
- package/lib/telegram/TelegramEvents.d.ts +13 -0
- package/lib/telegram/TelegramEvents.js +131 -0
- package/lib/telegram/TelegramEvents.js.map +1 -0
- package/lib/telegram/TelegramSendingController.d.ts +36 -0
- package/lib/telegram/TelegramSendingController.js +213 -0
- package/lib/telegram/TelegramSendingController.js.map +1 -0
- package/lib/telegram/TelegramToRompotConverter.d.ts +22 -0
- package/lib/telegram/TelegramToRompotConverter.js +226 -0
- package/lib/telegram/TelegramToRompotConverter.js.map +1 -0
- package/lib/telegram/TelegramUtils.d.ts +14 -0
- package/lib/telegram/TelegramUtils.js +98 -0
- package/lib/telegram/TelegramUtils.js.map +1 -0
- package/lib/telegram/index.d.ts +7 -0
- package/lib/telegram/index.js +19 -0
- package/lib/telegram/index.js.map +1 -0
- package/lib/utils/ClientUtils.d.ts +27 -0
- package/lib/utils/ClientUtils.js +62 -0
- package/lib/utils/ClientUtils.js.map +1 -0
- package/lib/utils/Generic.d.ts +47 -0
- package/lib/utils/Generic.js +173 -0
- package/lib/utils/Generic.js.map +1 -0
- package/lib/utils/Libs.d.ts +10 -0
- package/lib/utils/Libs.js +55 -0
- package/lib/utils/Libs.js.map +1 -0
- package/lib/utils/MessageHandler.d.ts +54 -0
- package/lib/utils/MessageHandler.js +81 -0
- package/lib/utils/MessageHandler.js.map +1 -0
- package/lib/utils/MessageUtils.d.ts +3 -0
- package/lib/utils/MessageUtils.js +114 -0
- package/lib/utils/MessageUtils.js.map +1 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +27 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/nonce.d.ts +1 -0
- package/lib/utils/nonce.js +16 -0
- package/lib/utils/nonce.js.map +1 -0
- package/lib/utils/server.d.ts +33 -0
- package/lib/utils/server.js +75 -0
- package/lib/utils/server.js.map +1 -0
- package/lib/wa/Auth.d.ts +19 -0
- package/lib/wa/Auth.js +123 -0
- package/lib/wa/Auth.js.map +1 -0
- package/lib/wa/ConfigWAEvents.d.ts +22 -0
- package/lib/wa/ConfigWAEvents.js +526 -0
- package/lib/wa/ConfigWAEvents.js.map +1 -0
- package/lib/wa/ConvertToWAMessage.d.ts +67 -0
- package/lib/wa/ConvertToWAMessage.js +403 -0
- package/lib/wa/ConvertToWAMessage.js.map +1 -0
- package/lib/wa/ConvertWAMessage.d.ts +108 -0
- package/lib/wa/ConvertWAMessage.js +527 -0
- package/lib/wa/ConvertWAMessage.js.map +1 -0
- package/lib/wa/ID.d.ts +4 -0
- package/lib/wa/ID.js +19 -0
- package/lib/wa/ID.js.map +1 -0
- package/lib/wa/WAMessage.d.ts +3 -0
- package/lib/wa/WAMessage.js +8 -0
- package/lib/wa/WAMessage.js.map +1 -0
- package/lib/wa/WAModule.d.ts +3 -0
- package/lib/wa/WAModule.js +3 -0
- package/lib/wa/WAModule.js.map +1 -0
- package/lib/wa/WAStatus.d.ts +3 -0
- package/lib/wa/WAStatus.js +15 -0
- package/lib/wa/WAStatus.js.map +1 -0
- package/lib/wa/WhatsAppBot.d.ts +188 -0
- package/lib/wa/WhatsAppBot.js +980 -0
- package/lib/wa/WhatsAppBot.js.map +1 -0
- package/lib/wa/index.d.ts +12 -0
- package/lib/wa/index.js +37 -0
- package/lib/wa/index.js.map +1 -0
- package/lib/wa/makeInMemoryStore.d.ts +43 -0
- package/lib/wa/makeInMemoryStore.js +430 -0
- package/lib/wa/makeInMemoryStore.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,1746 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.GlobalRompotCluster = void 0;
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const Defaults_1 = require("../configs/Defaults");
|
|
42
|
+
const Message_1 = __importStar(require("../messages/Message"));
|
|
43
|
+
const ReactionMessage_1 = __importDefault(require("../messages/ReactionMessage"));
|
|
44
|
+
const ErrorMessage_1 = __importDefault(require("../messages/ErrorMessage"));
|
|
45
|
+
const ChatStatus_1 = __importDefault(require("../modules/chat/ChatStatus"));
|
|
46
|
+
const Chat_1 = __importDefault(require("../modules/chat/Chat"));
|
|
47
|
+
const User_1 = __importDefault(require("../modules/user/User"));
|
|
48
|
+
const CommandEnums_1 = require("../modules/command/CommandEnums");
|
|
49
|
+
const CommandController_1 = __importDefault(require("../modules/command/CommandController"));
|
|
50
|
+
const AdvancedCommandController_1 = __importDefault(require("../modules/command/advanced/AdvancedCommandController"));
|
|
51
|
+
const QuickResponseController_1 = __importDefault(require("../modules/quickResponse/QuickResponseController"));
|
|
52
|
+
const QuickResponse_1 = __importDefault(require("../modules/quickResponse/QuickResponse"));
|
|
53
|
+
const ClientEvents_1 = __importDefault(require("../client/ClientEvents"));
|
|
54
|
+
const ClientFunctionHandler_1 = __importDefault(require("../client/ClientFunctionHandler"));
|
|
55
|
+
const WorkerMessage_1 = __importStar(require("./WorkerMessage"));
|
|
56
|
+
const BotStatus_1 = require("../bot/BotStatus");
|
|
57
|
+
const BotBase_1 = __importDefault(require("../bot/BotBase"));
|
|
58
|
+
const MessageHandler_1 = __importDefault(require("../utils/MessageHandler"));
|
|
59
|
+
const Generic_1 = require("../utils/Generic");
|
|
60
|
+
const MessageUtils_1 = require("../utils/MessageUtils");
|
|
61
|
+
const Call_1 = __importDefault(require("../models/Call"));
|
|
62
|
+
const ChatNotDefinedError_1 = __importDefault(require("../errors/ChatNotDefinedError"));
|
|
63
|
+
/** ID dos dados globais do cluster gerenciado pelo Rompot */
|
|
64
|
+
exports.GlobalRompotCluster = 'rompot-client-cluster';
|
|
65
|
+
class ClientCluster extends ClientEvents_1.default {
|
|
66
|
+
constructor(id, worker, config = {}, isMain = false) {
|
|
67
|
+
super();
|
|
68
|
+
/** Tratador de mensagens */
|
|
69
|
+
this.messageHandler = new MessageHandler_1.default();
|
|
70
|
+
/** Controlador de comandos */
|
|
71
|
+
this.commandController = new CommandController_1.default();
|
|
72
|
+
this.quickResponseController = new QuickResponseController_1.default();
|
|
73
|
+
/** Bot */
|
|
74
|
+
this.bot = new BotBase_1.default();
|
|
75
|
+
/** Vezes que o bot reconectou */
|
|
76
|
+
this.reconnectTimes = 0;
|
|
77
|
+
/** Autenticação do bot */
|
|
78
|
+
this.auth = './session';
|
|
79
|
+
/** Requisições */
|
|
80
|
+
this.requests = {};
|
|
81
|
+
/** Tratador de funções */
|
|
82
|
+
this.funcHandler = new ClientFunctionHandler_1.default(this, {
|
|
83
|
+
bot: [],
|
|
84
|
+
chat: [],
|
|
85
|
+
user: [],
|
|
86
|
+
message: [],
|
|
87
|
+
sendMessage: [],
|
|
88
|
+
sendMediaMessage: [],
|
|
89
|
+
downloadMedia: [],
|
|
90
|
+
});
|
|
91
|
+
this.id = id;
|
|
92
|
+
this.worker = worker;
|
|
93
|
+
this.isMain = isMain;
|
|
94
|
+
this.config = {
|
|
95
|
+
...Defaults_1.DEFAULT_CONNECTION_CONFIG,
|
|
96
|
+
maxTimeout: 60000,
|
|
97
|
+
...config,
|
|
98
|
+
};
|
|
99
|
+
this.setWorker(worker);
|
|
100
|
+
this.advancedCommandController = new AdvancedCommandController_1.default(this.id);
|
|
101
|
+
if (!isMain) {
|
|
102
|
+
this.configEvents();
|
|
103
|
+
}
|
|
104
|
+
ClientCluster.saveClient(this);
|
|
105
|
+
}
|
|
106
|
+
setWorker(worker) {
|
|
107
|
+
this.worker = worker;
|
|
108
|
+
if (!global['default-rompot-worker'] && worker) {
|
|
109
|
+
global['default-rompot-worker'] = worker;
|
|
110
|
+
}
|
|
111
|
+
this.worker.on('message', async (message) => {
|
|
112
|
+
const workerMessage = WorkerMessage_1.default.fromJSON(message);
|
|
113
|
+
try {
|
|
114
|
+
if (workerMessage.uid != 'rompot')
|
|
115
|
+
return;
|
|
116
|
+
if (workerMessage.clientId != this.id)
|
|
117
|
+
return;
|
|
118
|
+
if (workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Void)
|
|
119
|
+
return;
|
|
120
|
+
if (workerMessage.isMain == this.isMain)
|
|
121
|
+
return;
|
|
122
|
+
const data = workerMessage.getData();
|
|
123
|
+
if (workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Event) {
|
|
124
|
+
this.bot.emit(data.name || '', data.arg);
|
|
125
|
+
}
|
|
126
|
+
else if (workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Patch) {
|
|
127
|
+
(0, Generic_1.injectJSON)(data, this, true);
|
|
128
|
+
}
|
|
129
|
+
else if (workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Func) {
|
|
130
|
+
const clonedMessage = workerMessage.clone({
|
|
131
|
+
tag: WorkerMessage_1.WorkerMessageTag.Result,
|
|
132
|
+
data: { result: await this[data.name](...(data.args || [])) },
|
|
133
|
+
});
|
|
134
|
+
await this.sendWorkerMessage(clonedMessage);
|
|
135
|
+
}
|
|
136
|
+
else if (workerMessage.id in this.requests) {
|
|
137
|
+
this.requests[workerMessage.id](workerMessage);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
await this.sendWorkerMessage(workerMessage.clone({
|
|
142
|
+
tag: WorkerMessage_1.WorkerMessageTag.Error,
|
|
143
|
+
data: { reason: (error === null || error === void 0 ? void 0 : error.message) || 'Internal error' },
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* * Gera um ID combase uma tag.
|
|
150
|
+
* @param tag - Tag que será usada.
|
|
151
|
+
* @returns ID gerado.
|
|
152
|
+
*/
|
|
153
|
+
generateIdByTag(tag) {
|
|
154
|
+
return `${tag}-${Date.now()}-${this.worker.process.pid}-${this.worker.id}-${Object.keys(this.requests).length}`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* * Envia uma mensagem no worker.
|
|
158
|
+
* @param tag - Tag da mensagem.
|
|
159
|
+
* @param data - Data da mensagem.
|
|
160
|
+
* @returns Mensagem de resposta do worker.
|
|
161
|
+
*/
|
|
162
|
+
async sendWorkerMessage(workerMessage) {
|
|
163
|
+
var _a;
|
|
164
|
+
const id = workerMessage.id || this.generateIdByTag(workerMessage.tag);
|
|
165
|
+
const message = await new Promise((resolve) => {
|
|
166
|
+
try {
|
|
167
|
+
this.requests[id] = resolve;
|
|
168
|
+
workerMessage.apply({
|
|
169
|
+
uid: 'rompot',
|
|
170
|
+
clientId: this.id,
|
|
171
|
+
isMain: this.isMain,
|
|
172
|
+
id,
|
|
173
|
+
});
|
|
174
|
+
process.send(workerMessage.toJSON());
|
|
175
|
+
if (workerMessage.isPrimary ||
|
|
176
|
+
workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Event ||
|
|
177
|
+
workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Patch ||
|
|
178
|
+
workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Result ||
|
|
179
|
+
workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Void ||
|
|
180
|
+
workerMessage.tag == WorkerMessage_1.WorkerMessageTag.Error) {
|
|
181
|
+
resolve(workerMessage.clone({
|
|
182
|
+
tag: WorkerMessage_1.WorkerMessageTag.Result,
|
|
183
|
+
data: { result: undefined },
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
else if (workerMessage.autoCancel) {
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
if (!(id in this.requests))
|
|
189
|
+
return;
|
|
190
|
+
resolve(workerMessage.clone({
|
|
191
|
+
tag: WorkerMessage_1.WorkerMessageTag.Error,
|
|
192
|
+
data: { reason: 'Timeout' },
|
|
193
|
+
}));
|
|
194
|
+
}, this.config.maxTimeout);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
resolve(workerMessage.clone({
|
|
199
|
+
tag: WorkerMessage_1.WorkerMessageTag.Error,
|
|
200
|
+
data: { reason: (error === null || error === void 0 ? void 0 : error.message) || 'Internal error' },
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
delete this.requests[id];
|
|
205
|
+
if (message.tag == 'error') {
|
|
206
|
+
throw new Error(((_a = message.data) === null || _a === void 0 ? void 0 : _a.reason) || 'Internal error');
|
|
207
|
+
}
|
|
208
|
+
return message;
|
|
209
|
+
}
|
|
210
|
+
/** Configura os eventos do cliente */
|
|
211
|
+
configEvents() {
|
|
212
|
+
this.bot.on('message', async (message) => {
|
|
213
|
+
try {
|
|
214
|
+
if (this.isMain) {
|
|
215
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
216
|
+
name: 'message',
|
|
217
|
+
arg: message,
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
message = (0, MessageUtils_1.getMessageFromJSON)(message);
|
|
222
|
+
message.inject({ clientId: this.id, botId: this.bot.id });
|
|
223
|
+
if (!message.fromMe && !this.config.disableAutoRead) {
|
|
224
|
+
if (!message.isDeleted && !message.isUpdate) {
|
|
225
|
+
await message.read();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
message.user = (await this.getUser(message.user)) || message.user;
|
|
229
|
+
message.chat = (await this.getChat(message.chat)) || message.chat;
|
|
230
|
+
if (!message.chat.timestamp ||
|
|
231
|
+
message.timestamp > message.chat.timestamp) {
|
|
232
|
+
message.chat.timestamp = message.timestamp;
|
|
233
|
+
}
|
|
234
|
+
if (message.mention) {
|
|
235
|
+
if (message.mention.chat.id != message.chat.id) {
|
|
236
|
+
message.mention.chat =
|
|
237
|
+
(await this.getChat(message.mention.chat)) ||
|
|
238
|
+
message.mention.chat;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
message.mention.chat = message.chat;
|
|
242
|
+
}
|
|
243
|
+
if (message.mention.user.id != message.user.id) {
|
|
244
|
+
message.mention.user =
|
|
245
|
+
(await this.getUser(message.mention.user)) ||
|
|
246
|
+
message.mention.user;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
message.mention.user = message.user;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (this.messageHandler.resolveMessage(message))
|
|
253
|
+
return;
|
|
254
|
+
this.emit('message', message);
|
|
255
|
+
if (this.config.disableAutoCommand)
|
|
256
|
+
return;
|
|
257
|
+
if (this.config.disableAutoCommandForOldMessage && message.isOld)
|
|
258
|
+
return;
|
|
259
|
+
if (this.config.disableAutoCommandForUnofficialMessage &&
|
|
260
|
+
message.isUnofficial)
|
|
261
|
+
return;
|
|
262
|
+
await this.quickResponseController.searchAndExecute(message);
|
|
263
|
+
const command = this.searchCommand(message.text);
|
|
264
|
+
if (command != null) {
|
|
265
|
+
this.runCommand(command, message, CommandEnums_1.CMDRunType.Exec);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
this.emit('message', new ErrorMessage_1.default(message.chat, err));
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
this.on('conn', async (update) => {
|
|
274
|
+
try {
|
|
275
|
+
if (this.isMain) {
|
|
276
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
277
|
+
name: 'conn',
|
|
278
|
+
arg: update,
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
this.on('error', async (update) => {
|
|
287
|
+
try {
|
|
288
|
+
if (this.isMain) {
|
|
289
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
290
|
+
name: 'error',
|
|
291
|
+
arg: update,
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
this.bot.on('open', async (update) => {
|
|
300
|
+
try {
|
|
301
|
+
if (this.isMain) {
|
|
302
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
303
|
+
name: 'open',
|
|
304
|
+
arg: update,
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
this.reconnectTimes = 0;
|
|
309
|
+
this.emit('open', update);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (err) {
|
|
313
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
this.bot.on('reconnecting', async (update) => {
|
|
317
|
+
try {
|
|
318
|
+
if (this.isMain) {
|
|
319
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
320
|
+
name: 'reconnecting',
|
|
321
|
+
arg: update,
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
this.emit('reconnecting', update);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (err) {
|
|
329
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
this.bot.on('connecting', async (update) => {
|
|
333
|
+
try {
|
|
334
|
+
if (this.isMain) {
|
|
335
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
336
|
+
name: 'connecting',
|
|
337
|
+
arg: update,
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
this.emit('connecting', update);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
catch (err) {
|
|
345
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
this.bot.on('close', async (update) => {
|
|
349
|
+
try {
|
|
350
|
+
if (this.isMain) {
|
|
351
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
352
|
+
name: 'close',
|
|
353
|
+
arg: update,
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
this.emit('close', update);
|
|
358
|
+
if (this.reconnectTimes < this.config.maxReconnectTimes) {
|
|
359
|
+
this.reconnectTimes++;
|
|
360
|
+
await (0, Generic_1.sleep)(this.config.reconnectTimeout);
|
|
361
|
+
this.reconnect();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
this.bot.on('stop', async (update) => {
|
|
370
|
+
try {
|
|
371
|
+
if (this.isMain) {
|
|
372
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
373
|
+
name: 'stop',
|
|
374
|
+
arg: update,
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
this.emit('stop', update);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
this.bot.on('qr', async (update) => {
|
|
386
|
+
try {
|
|
387
|
+
if (this.isMain) {
|
|
388
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
389
|
+
name: 'qr',
|
|
390
|
+
arg: update,
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
this.emit('qr', update);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
this.bot.on('code', async (update) => {
|
|
402
|
+
try {
|
|
403
|
+
if (this.isMain) {
|
|
404
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
405
|
+
name: 'code',
|
|
406
|
+
arg: update,
|
|
407
|
+
}));
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
this.emit('code', update);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
catch (err) {
|
|
414
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
this.bot.on('chat', async (update) => {
|
|
418
|
+
try {
|
|
419
|
+
if (this.isMain) {
|
|
420
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
421
|
+
name: 'chat',
|
|
422
|
+
arg: update,
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
this.emit('chat', {
|
|
427
|
+
...update,
|
|
428
|
+
chat: { ...update.chat, clientId: this.id, botId: this.bot.id },
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch (err) {
|
|
433
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
this.bot.on('user', async (update) => {
|
|
437
|
+
try {
|
|
438
|
+
if (this.isMain) {
|
|
439
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
440
|
+
name: 'user',
|
|
441
|
+
arg: update,
|
|
442
|
+
}));
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
this.emit('user', {
|
|
446
|
+
event: update.event,
|
|
447
|
+
action: update.action,
|
|
448
|
+
chat: Chat_1.default.apply(update.chat, {
|
|
449
|
+
clientId: this.id,
|
|
450
|
+
botId: this.bot.id,
|
|
451
|
+
}),
|
|
452
|
+
user: User_1.default.apply(update.user, {
|
|
453
|
+
clientId: this.id,
|
|
454
|
+
botId: this.bot.id,
|
|
455
|
+
}),
|
|
456
|
+
fromUser: User_1.default.apply(update.fromUser, {
|
|
457
|
+
clientId: this.id,
|
|
458
|
+
botId: this.bot.id,
|
|
459
|
+
}),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (err) {
|
|
464
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
this.bot.on('call', async (call) => {
|
|
468
|
+
try {
|
|
469
|
+
if (this.isMain) {
|
|
470
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
471
|
+
name: 'call',
|
|
472
|
+
arg: call,
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
this.emit('call', Call_1.default.apply(call, { clientId: this.id, botId: this.bot.id }));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
this.bot.on('error', async (update) => {
|
|
484
|
+
try {
|
|
485
|
+
if (this.isMain) {
|
|
486
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Event, {
|
|
487
|
+
name: 'error',
|
|
488
|
+
arg: update,
|
|
489
|
+
}));
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
this.emit('error', (0, Generic_1.getError)(update));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
catch (err) {
|
|
496
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
/** Conectar bot
|
|
501
|
+
* @param auth Autenticação do bot
|
|
502
|
+
*/
|
|
503
|
+
async connect(auth) {
|
|
504
|
+
if (this.isMain) {
|
|
505
|
+
await this.bot.connect(typeof auth != 'string' || !auth ? this.auth : auth);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, { name: 'connect', args: [auth] }, false));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/** Reconectar bot
|
|
512
|
+
* @param alert Alerta que está reconectando
|
|
513
|
+
*/
|
|
514
|
+
async reconnect(alert) {
|
|
515
|
+
if (this.isMain) {
|
|
516
|
+
await this.bot.reconnect(alert);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, { name: 'reconnect', args: [alert] }, false));
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/** Parar bot
|
|
523
|
+
* @param reason Razão por parar bot
|
|
524
|
+
*/
|
|
525
|
+
async stop(reason) {
|
|
526
|
+
if (this.isMain) {
|
|
527
|
+
await this.bot.stop(reason);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
531
|
+
name: 'stop',
|
|
532
|
+
args: [reason],
|
|
533
|
+
}));
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Desconecta o bot
|
|
538
|
+
*/
|
|
539
|
+
async logout() {
|
|
540
|
+
if (this.isMain) {
|
|
541
|
+
await this.bot.logout();
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, { name: 'logout', args: [] }));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* * Aguarda um evento ser chamado.
|
|
549
|
+
* @param eventName - Nome do evento que será aguardado.
|
|
550
|
+
* @returns {Promise<ClientEventsMap[T]>} Argumento retornado do evento esperado.
|
|
551
|
+
*/
|
|
552
|
+
async awaitEvent(eventName, maxTimeout) {
|
|
553
|
+
return new Promise((res, rej) => {
|
|
554
|
+
let timeout;
|
|
555
|
+
if (maxTimeout) {
|
|
556
|
+
timeout = setTimeout(() => {
|
|
557
|
+
rej('Wait event time out');
|
|
558
|
+
}, maxTimeout);
|
|
559
|
+
}
|
|
560
|
+
const listener = (arg) => {
|
|
561
|
+
if (timeout) {
|
|
562
|
+
clearTimeout(timeout);
|
|
563
|
+
}
|
|
564
|
+
this.ev.removeListener(eventName, listener);
|
|
565
|
+
res(arg);
|
|
566
|
+
};
|
|
567
|
+
this.ev.on(eventName, listener);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* * Aguarda a conexão for aberta.
|
|
572
|
+
*/
|
|
573
|
+
async awaitConnectionOpen() {
|
|
574
|
+
if (this.bot.status != BotStatus_1.BotStatus.Online) {
|
|
575
|
+
await this.awaitEvent('open');
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/** @returns Controlador de comando do cliente */
|
|
579
|
+
getCommandController() {
|
|
580
|
+
if (this.commandController.clientId != this.id) {
|
|
581
|
+
this.commandController.clientId = this.id;
|
|
582
|
+
}
|
|
583
|
+
if (this.commandController.botId != this.bot.id) {
|
|
584
|
+
this.commandController.botId = this.bot.id;
|
|
585
|
+
}
|
|
586
|
+
return this.commandController;
|
|
587
|
+
}
|
|
588
|
+
/** Define o controlador de comando do cliente */
|
|
589
|
+
setCommandController(controller) {
|
|
590
|
+
controller.botId = this.bot.id;
|
|
591
|
+
controller.clientId = this.id;
|
|
592
|
+
this.commandController = controller;
|
|
593
|
+
}
|
|
594
|
+
/** Define os comandos do bot
|
|
595
|
+
* @param commands Comandos que será injetado
|
|
596
|
+
*/
|
|
597
|
+
setCommands(commands) {
|
|
598
|
+
this.commandController.setCommands(commands);
|
|
599
|
+
}
|
|
600
|
+
/** @returns Retorna os comandos do bot */
|
|
601
|
+
getCommands() {
|
|
602
|
+
return this.commandController.getCommands();
|
|
603
|
+
}
|
|
604
|
+
/** Adiciona um comando na lista de comandos
|
|
605
|
+
* @param command Comando que será adicionado
|
|
606
|
+
*/
|
|
607
|
+
addCommand(command) {
|
|
608
|
+
this.commandController.addCommand(command);
|
|
609
|
+
}
|
|
610
|
+
/** Remove um comando na lista de comandos
|
|
611
|
+
* @param command Comando que será removido
|
|
612
|
+
*/
|
|
613
|
+
removeCommand(command) {
|
|
614
|
+
return this.commandController.removeCommand(command);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Procura um comando no texto.
|
|
618
|
+
* @param text - Texto que contem o comando.
|
|
619
|
+
* */
|
|
620
|
+
searchCommand(text) {
|
|
621
|
+
const command = this.commandController.searchCommand(text);
|
|
622
|
+
if (command == null)
|
|
623
|
+
return null;
|
|
624
|
+
command.clientId = this.id;
|
|
625
|
+
command.botId = this.bot.id;
|
|
626
|
+
return command;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Execução do comando.
|
|
630
|
+
* @param command - Comando que será executado.
|
|
631
|
+
* @param message - Mensagem associada ao comando.
|
|
632
|
+
*/
|
|
633
|
+
runCommand(command, message, type) {
|
|
634
|
+
return this.commandController.runCommand(command, message, type);
|
|
635
|
+
}
|
|
636
|
+
setAdvancedCommandController(advancedCommandController) {
|
|
637
|
+
advancedCommandController.clientId = this.id;
|
|
638
|
+
this.advancedCommandController = advancedCommandController;
|
|
639
|
+
}
|
|
640
|
+
getAdvancedCommandController() {
|
|
641
|
+
return this.advancedCommandController;
|
|
642
|
+
}
|
|
643
|
+
setAdvancedCommands(commands) {
|
|
644
|
+
this.advancedCommandController.setCommands(...commands);
|
|
645
|
+
}
|
|
646
|
+
createAdvancedCommand(id, context) {
|
|
647
|
+
return this.advancedCommandController.createCommand({ id, context });
|
|
648
|
+
}
|
|
649
|
+
getAdvancedCommands() {
|
|
650
|
+
return this.advancedCommandController.getCommands();
|
|
651
|
+
}
|
|
652
|
+
addAdvancedCommand(command) {
|
|
653
|
+
this.advancedCommandController.addCommand(command);
|
|
654
|
+
}
|
|
655
|
+
removeAdvancedCommand(command) {
|
|
656
|
+
return this.advancedCommandController.removeCommand(command);
|
|
657
|
+
}
|
|
658
|
+
execAdvancedCommand(command, message) {
|
|
659
|
+
if (typeof command == 'string') {
|
|
660
|
+
const cmd = this.advancedCommandController.getCommand(command);
|
|
661
|
+
if (!cmd) {
|
|
662
|
+
throw new Error('Command not found');
|
|
663
|
+
}
|
|
664
|
+
command = cmd;
|
|
665
|
+
}
|
|
666
|
+
const options = {
|
|
667
|
+
chatId: message.chat.id,
|
|
668
|
+
context: {
|
|
669
|
+
...command.initialContext,
|
|
670
|
+
chatId: message.chat.id,
|
|
671
|
+
clientId: this.id,
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
return this.advancedCommandController.execCommand(command.id, message, options);
|
|
675
|
+
}
|
|
676
|
+
addQuickResponse(content, reply, options) {
|
|
677
|
+
if (content instanceof QuickResponse_1.default) {
|
|
678
|
+
this.quickResponseController.add(content);
|
|
679
|
+
return content;
|
|
680
|
+
}
|
|
681
|
+
//@ts-ignore
|
|
682
|
+
const quickResponse = new QuickResponse_1.default(content, reply, options);
|
|
683
|
+
this.quickResponseController.add(quickResponse);
|
|
684
|
+
return quickResponse;
|
|
685
|
+
}
|
|
686
|
+
removeQuickResponse(quickResponse) {
|
|
687
|
+
this.quickResponseController.remove(quickResponse);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Deletar mensagem
|
|
691
|
+
* @param message Mensagem que será deletada da sala de bate-papos
|
|
692
|
+
*/
|
|
693
|
+
async deleteMessage(message) {
|
|
694
|
+
if (this.isMain) {
|
|
695
|
+
await this.bot.deleteMessage((0, MessageUtils_1.getMessageFromJSON)(message));
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
699
|
+
name: 'deleteMessage',
|
|
700
|
+
args: [message],
|
|
701
|
+
}));
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/** Remover mensagem
|
|
705
|
+
* @param message Mensagem que será removida da sala de bate-papo
|
|
706
|
+
*/
|
|
707
|
+
async removeMessage(message) {
|
|
708
|
+
if (this.isMain) {
|
|
709
|
+
await this.bot.readMessage((0, MessageUtils_1.getMessageFromJSON)(message));
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
713
|
+
name: 'removeMessage',
|
|
714
|
+
args: [message],
|
|
715
|
+
}));
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
/** Marca uma mensagem como visualizada
|
|
719
|
+
* @param message Mensagem que será visualizada
|
|
720
|
+
*/
|
|
721
|
+
async readMessage(message) {
|
|
722
|
+
if (this.isMain) {
|
|
723
|
+
await this.bot.readMessage((0, MessageUtils_1.getMessageFromJSON)(message));
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
727
|
+
name: 'readMessage',
|
|
728
|
+
args: [message],
|
|
729
|
+
}));
|
|
730
|
+
if (message.status == Message_1.MessageStatus.Sending ||
|
|
731
|
+
message.status == Message_1.MessageStatus.Sended ||
|
|
732
|
+
message.status == Message_1.MessageStatus.Received) {
|
|
733
|
+
if (message.type == Message_1.MessageType.Audio) {
|
|
734
|
+
message.status = Message_1.MessageStatus.Played;
|
|
735
|
+
}
|
|
736
|
+
else {
|
|
737
|
+
message.status = Message_1.MessageStatus.Readed;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
if (message.timestamp == message.chat.timestamp) {
|
|
741
|
+
message.chat.unreadCount = (message.chat.unreadCount || 0) - 1 || 0;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/** Edita o texto de uma mensagem enviada
|
|
746
|
+
* @param message Mensagem que será editada
|
|
747
|
+
* @param text Novo texto da mensagem
|
|
748
|
+
*/
|
|
749
|
+
async editMessage(message, text) {
|
|
750
|
+
if (this.isMain) {
|
|
751
|
+
await this.bot.editMessage((0, MessageUtils_1.getMessageFromJSON)({ ...(message || {}), text, isEdited: true }));
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
message.text = text;
|
|
755
|
+
message.isEdited = true;
|
|
756
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
757
|
+
name: 'editMessage',
|
|
758
|
+
args: [message, text],
|
|
759
|
+
}));
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/** Adiciona uma reação na mensagem
|
|
763
|
+
* @param message Mensagem
|
|
764
|
+
* @param reaction Reação
|
|
765
|
+
*/
|
|
766
|
+
async addReaction(message, reaction) {
|
|
767
|
+
if (this.isMain) {
|
|
768
|
+
message = (0, MessageUtils_1.getMessageFromJSON)(message);
|
|
769
|
+
await this.bot.addReaction(new ReactionMessage_1.default(message.chat, reaction, message, {
|
|
770
|
+
user: message.user,
|
|
771
|
+
}));
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
775
|
+
name: 'addReaction',
|
|
776
|
+
args: [message, reaction],
|
|
777
|
+
}));
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
/** Remove a reação da mensagem
|
|
781
|
+
* @param message Mensagem que terá sua reação removida
|
|
782
|
+
*/
|
|
783
|
+
async removeReaction(message) {
|
|
784
|
+
if (this.isMain) {
|
|
785
|
+
message = (0, MessageUtils_1.getMessageFromJSON)(message);
|
|
786
|
+
await this.bot.removeReaction(new ReactionMessage_1.default(message.chat, '', message, { user: message.user }));
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
790
|
+
name: 'removeReaction',
|
|
791
|
+
args: [message],
|
|
792
|
+
}));
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
/** Adiciona animações na reação da mensagem
|
|
796
|
+
* @param message Mensagem que receberá a animação
|
|
797
|
+
* @param reactions Reações em sequência
|
|
798
|
+
* @param interval Intervalo entre cada reação
|
|
799
|
+
* @param maxTimeout Maximo de tempo reagindo
|
|
800
|
+
*/
|
|
801
|
+
addAnimatedReaction(message, reactions, interval = 2000, maxTimeout = 60000) {
|
|
802
|
+
let isStoped = false;
|
|
803
|
+
const now = Date.now();
|
|
804
|
+
const stop = async (reactionStop) => {
|
|
805
|
+
if (isStoped)
|
|
806
|
+
return;
|
|
807
|
+
isStoped = true;
|
|
808
|
+
if (!reactionStop) {
|
|
809
|
+
await this.removeReaction(message);
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
await this.addReaction(message, reactionStop);
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
const addReaction = async (index) => {
|
|
816
|
+
if (isStoped || now + maxTimeout < Date.now()) {
|
|
817
|
+
return stop();
|
|
818
|
+
}
|
|
819
|
+
if (reactions[index]) {
|
|
820
|
+
await this.addReaction(message, reactions[index]);
|
|
821
|
+
}
|
|
822
|
+
await (0, Generic_1.sleep)(interval);
|
|
823
|
+
addReaction(index + 1 >= reactions.length ? 0 : index + 1);
|
|
824
|
+
};
|
|
825
|
+
addReaction(0);
|
|
826
|
+
return stop;
|
|
827
|
+
}
|
|
828
|
+
/** Envia uma mensagem
|
|
829
|
+
* @param message Menssagem que será enviada
|
|
830
|
+
* @returns Retorna o conteudo enviado
|
|
831
|
+
*/
|
|
832
|
+
async send(message) {
|
|
833
|
+
if (this.isMain) {
|
|
834
|
+
return Message_1.default.apply(await this.bot.send((0, MessageUtils_1.getMessageFromJSON)(message)), {
|
|
835
|
+
clientId: this.id,
|
|
836
|
+
botId: this.bot.id,
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
if (!this.config.disableAutoTyping) {
|
|
841
|
+
await this.changeChatStatus(message.chat, message.type == 'audio' ? ChatStatus_1.default.Recording : ChatStatus_1.default.Typing);
|
|
842
|
+
}
|
|
843
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
844
|
+
name: 'send',
|
|
845
|
+
args: [message],
|
|
846
|
+
}));
|
|
847
|
+
return (0, MessageUtils_1.getMessageFromJSON)(workerMessage.getData().result || message);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
/** Envia uma mensagem
|
|
851
|
+
* @param chat Sala de bate-papo onde irá ser enviado a mensagem
|
|
852
|
+
* @param message Mensagem que será enviada
|
|
853
|
+
* @param mention Mensagem que será mencionada
|
|
854
|
+
*/
|
|
855
|
+
async sendMessage(chat, message, mention) {
|
|
856
|
+
if (Message_1.default.isValid(message)) {
|
|
857
|
+
message = Message_1.default.apply(message, {
|
|
858
|
+
clientId: this.id,
|
|
859
|
+
botId: this.bot.id,
|
|
860
|
+
});
|
|
861
|
+
message.chat = Chat_1.default.apply(chat, {
|
|
862
|
+
clientId: this.id,
|
|
863
|
+
botId: this.bot.id,
|
|
864
|
+
});
|
|
865
|
+
message.mention = mention;
|
|
866
|
+
return await this.send(message);
|
|
867
|
+
}
|
|
868
|
+
return await this.send(new Message_1.default(chat, message, { mention }));
|
|
869
|
+
}
|
|
870
|
+
/** Aguarda uma mensagem ser recebida em uma sala de bate-papo
|
|
871
|
+
* @param chat Sala de bate-papo que irá receber a mensagem
|
|
872
|
+
* @param config Configuração do aguardo da mensagem
|
|
873
|
+
*/
|
|
874
|
+
async awaitMessage(chat, config = {}) {
|
|
875
|
+
const chatId = Chat_1.default.getId(chat);
|
|
876
|
+
if (!chatId) {
|
|
877
|
+
throw new ChatNotDefinedError_1.default();
|
|
878
|
+
}
|
|
879
|
+
const message = await this.messageHandler.addMessage(chatId, config);
|
|
880
|
+
return Message_1.default.apply(message, { clientId: this.id, botId: this.bot.id });
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Retorna a stream da mídia
|
|
884
|
+
* @param message Mídia que será baixada
|
|
885
|
+
* @returns Stream da mídia
|
|
886
|
+
*/
|
|
887
|
+
async downloadStreamMessage(message) {
|
|
888
|
+
if (!message.file)
|
|
889
|
+
return Buffer.from('');
|
|
890
|
+
if (Buffer.isBuffer(message.file))
|
|
891
|
+
return message.file;
|
|
892
|
+
if (typeof message.file == 'string') {
|
|
893
|
+
return (0, fs_1.readFileSync)(message.file);
|
|
894
|
+
}
|
|
895
|
+
if (this.isMain) {
|
|
896
|
+
return await this.bot.downloadStreamMessage(message.file);
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
900
|
+
name: 'downloadStreamMessage',
|
|
901
|
+
args: [message],
|
|
902
|
+
}));
|
|
903
|
+
return workerMessage.getData().result || Buffer.from('');
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
/** @returns Retorna o nome do bot */
|
|
907
|
+
async getBotName() {
|
|
908
|
+
if (this.isMain) {
|
|
909
|
+
return await this.bot.getBotName();
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
913
|
+
name: 'getBotName',
|
|
914
|
+
args: [],
|
|
915
|
+
}));
|
|
916
|
+
return workerMessage.getData().result || '';
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
/** Define o nome do bot
|
|
920
|
+
* @param name Nome do bot
|
|
921
|
+
*/
|
|
922
|
+
async setBotName(name) {
|
|
923
|
+
if (this.isMain) {
|
|
924
|
+
await this.bot.setBotName(name);
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
928
|
+
name: 'setBotName',
|
|
929
|
+
args: [name],
|
|
930
|
+
}));
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
/** @returns Retorna a descrição do bot */
|
|
934
|
+
async getBotDescription() {
|
|
935
|
+
if (this.isMain) {
|
|
936
|
+
return await this.bot.getBotDescription();
|
|
937
|
+
}
|
|
938
|
+
else {
|
|
939
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
940
|
+
name: 'getBotDescription',
|
|
941
|
+
args: [],
|
|
942
|
+
}));
|
|
943
|
+
return workerMessage.getData().result || '';
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
/** Define a descrição do bot
|
|
947
|
+
* @param description Descrição do bot
|
|
948
|
+
*/
|
|
949
|
+
async setBotDescription(description) {
|
|
950
|
+
if (this.isMain) {
|
|
951
|
+
await this.bot.setBotDescription(description);
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
955
|
+
name: 'setBotDescription',
|
|
956
|
+
args: [description],
|
|
957
|
+
}));
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
/** @returns Retorna foto de perfil do bot */
|
|
961
|
+
async getBotProfile(lowQuality) {
|
|
962
|
+
if (this.isMain) {
|
|
963
|
+
return await this.bot.getBotProfile(lowQuality);
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
967
|
+
name: 'getBotProfile',
|
|
968
|
+
args: [lowQuality],
|
|
969
|
+
}));
|
|
970
|
+
return workerMessage.getData().result || Buffer.from('');
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
/** Define a imagem de perfil do bot
|
|
974
|
+
* @param image Imagem de perfil do bot
|
|
975
|
+
*/
|
|
976
|
+
async setBotProfile(profile) {
|
|
977
|
+
if (this.isMain) {
|
|
978
|
+
await this.bot.setBotProfile(profile);
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
982
|
+
name: 'setBotProfile',
|
|
983
|
+
args: [profile],
|
|
984
|
+
}));
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* @param chat Sala de bate-papo
|
|
989
|
+
* @returns Retorna uma sala de bate-papo
|
|
990
|
+
*/
|
|
991
|
+
async getChat(chat) {
|
|
992
|
+
if (this.isMain) {
|
|
993
|
+
const chatData = await this.bot.getChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
994
|
+
if (chatData == null)
|
|
995
|
+
return null;
|
|
996
|
+
return Chat_1.default.apply(chatData, { clientId: this.id, botId: this.bot.id });
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1000
|
+
name: 'getChat',
|
|
1001
|
+
args: [chat],
|
|
1002
|
+
}));
|
|
1003
|
+
const chatData = workerMessage.getData().result || null;
|
|
1004
|
+
if (chatData == null)
|
|
1005
|
+
return null;
|
|
1006
|
+
return Chat_1.default.fromJSON(chatData);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Atualiza os dados de um chat.
|
|
1011
|
+
* @param id - Id do chat que será atualizado.
|
|
1012
|
+
* @param chat - Dados do chat que será atualizado.
|
|
1013
|
+
*/
|
|
1014
|
+
async updateChat(id, chat) {
|
|
1015
|
+
if (this.isMain) {
|
|
1016
|
+
await this.bot.updateChat({ ...chat, id });
|
|
1017
|
+
}
|
|
1018
|
+
else {
|
|
1019
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1020
|
+
name: 'updateChat',
|
|
1021
|
+
args: [id, chat],
|
|
1022
|
+
}));
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
/** @returns Retorna as sala de bate-papo que o bot está */
|
|
1026
|
+
async getChats() {
|
|
1027
|
+
if (this.isMain) {
|
|
1028
|
+
const ids = await this.bot.getChats();
|
|
1029
|
+
const chats = [];
|
|
1030
|
+
await Promise.all(ids.map(async (id) => {
|
|
1031
|
+
const chat = await this.bot.getChat(new Chat_1.default(id));
|
|
1032
|
+
if (chat == null)
|
|
1033
|
+
return;
|
|
1034
|
+
chats.push(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1035
|
+
}));
|
|
1036
|
+
return chats;
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1040
|
+
name: 'getChats',
|
|
1041
|
+
args: [],
|
|
1042
|
+
}));
|
|
1043
|
+
return (workerMessage.getData().result || []).map((chat) => Chat_1.default.fromJSON(chat));
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
/** Define as salas de bate-papo que o bot está
|
|
1047
|
+
* @param chats Salas de bate-papo
|
|
1048
|
+
*/
|
|
1049
|
+
async setChats(chats) {
|
|
1050
|
+
if (this.isMain) {
|
|
1051
|
+
await this.bot.setChats((chats || []).map((chat) => Chat_1.default.fromJSON(chat)));
|
|
1052
|
+
}
|
|
1053
|
+
else {
|
|
1054
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1055
|
+
name: 'setChats',
|
|
1056
|
+
args: [chats],
|
|
1057
|
+
}));
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
/** Remove uma sala de bate-papo
|
|
1061
|
+
* @param chat Sala de bate-papo
|
|
1062
|
+
*/
|
|
1063
|
+
async removeChat(chat) {
|
|
1064
|
+
if (this.isMain) {
|
|
1065
|
+
await this.bot.removeChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1066
|
+
}
|
|
1067
|
+
else {
|
|
1068
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1069
|
+
name: 'removeChat',
|
|
1070
|
+
args: [chat],
|
|
1071
|
+
}));
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
/** Cria uma sala de bate-papo
|
|
1075
|
+
* @param chat Sala de bate-papo
|
|
1076
|
+
*/
|
|
1077
|
+
async createChat(chat) {
|
|
1078
|
+
if (this.isMain) {
|
|
1079
|
+
await this.bot.createChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1083
|
+
name: 'createChat',
|
|
1084
|
+
args: [chat],
|
|
1085
|
+
}));
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
/** Sai de uma sala de bate-papo
|
|
1089
|
+
* @param chat Sala de bate-papo
|
|
1090
|
+
*/
|
|
1091
|
+
async leaveChat(chat) {
|
|
1092
|
+
if (this.isMain) {
|
|
1093
|
+
await this.bot.leaveChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1094
|
+
}
|
|
1095
|
+
else {
|
|
1096
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1097
|
+
name: 'leaveChat',
|
|
1098
|
+
args: [chat],
|
|
1099
|
+
}));
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* @param chat Sala de bate-papo
|
|
1104
|
+
* @returns Retorna o nome da sala de bate-papo
|
|
1105
|
+
*/
|
|
1106
|
+
async getChatName(chat) {
|
|
1107
|
+
if (this.isMain) {
|
|
1108
|
+
return await this.bot.getChatName(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1112
|
+
name: 'getChatName',
|
|
1113
|
+
args: [chat],
|
|
1114
|
+
}));
|
|
1115
|
+
return workerMessage.getData().result || '';
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
/** Define o nome da sala de bate-papo
|
|
1119
|
+
* @param chat Sala de bate-papo
|
|
1120
|
+
* @param name Nome da sala de bate-papo
|
|
1121
|
+
*/
|
|
1122
|
+
async setChatName(chat, name) {
|
|
1123
|
+
if (this.isMain) {
|
|
1124
|
+
await this.bot.setChatName(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), name);
|
|
1125
|
+
}
|
|
1126
|
+
else {
|
|
1127
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1128
|
+
name: 'setChatName',
|
|
1129
|
+
args: [chat, name],
|
|
1130
|
+
}));
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* @param chat Sala de bate-papo
|
|
1135
|
+
* @returns Retorna a descrição da sala de bate-papo
|
|
1136
|
+
*/
|
|
1137
|
+
async getChatDescription(chat) {
|
|
1138
|
+
if (this.isMain) {
|
|
1139
|
+
return await this.bot.getChatDescription(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1140
|
+
}
|
|
1141
|
+
else {
|
|
1142
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1143
|
+
name: 'getChatDescription',
|
|
1144
|
+
args: [chat],
|
|
1145
|
+
}));
|
|
1146
|
+
return workerMessage.getData().result || '';
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
/** Define a descrição da sala de bate-papo
|
|
1150
|
+
* @param chat Sala de bate-papo
|
|
1151
|
+
* @param description Descrição da sala de bate-papo
|
|
1152
|
+
*/
|
|
1153
|
+
async setChatDescription(chat, description) {
|
|
1154
|
+
if (this.isMain) {
|
|
1155
|
+
await this.bot.setChatDescription(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), description);
|
|
1156
|
+
}
|
|
1157
|
+
else {
|
|
1158
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1159
|
+
name: 'setChatDescription',
|
|
1160
|
+
args: [chat, description],
|
|
1161
|
+
}));
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* @param chat Sala de bate-papo
|
|
1166
|
+
* @returns Retorna a imagem de perfil da sala de bate-papo
|
|
1167
|
+
*/
|
|
1168
|
+
async getChatProfile(chat, lowQuality) {
|
|
1169
|
+
if (this.isMain) {
|
|
1170
|
+
return await this.bot.getChatProfile(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), lowQuality);
|
|
1171
|
+
}
|
|
1172
|
+
else {
|
|
1173
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1174
|
+
name: 'getChatProfile',
|
|
1175
|
+
args: [chat, lowQuality],
|
|
1176
|
+
}));
|
|
1177
|
+
return workerMessage.getData().result || Buffer.from('');
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
/** Define a imagem de perfil da sala de bate-papo
|
|
1181
|
+
* @param chat Sala de bate-papo
|
|
1182
|
+
* @param profile Imagem de perfil da sala de bate-papo
|
|
1183
|
+
*/
|
|
1184
|
+
async setChatProfile(chat, profile) {
|
|
1185
|
+
if (this.isMain) {
|
|
1186
|
+
await this.bot.setChatProfile(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), profile);
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1190
|
+
name: 'setChatProfile',
|
|
1191
|
+
args: [chat, profile],
|
|
1192
|
+
}));
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* @param chat Sala de bate-papo
|
|
1197
|
+
* @returns Retorna o lider da sala de bate-papo
|
|
1198
|
+
*/
|
|
1199
|
+
async getChatLeader(chat) {
|
|
1200
|
+
if (this.isMain) {
|
|
1201
|
+
return User_1.default.apply(await this.bot.getChatLeader(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id })), { clientId: this.id, botId: this.bot.id });
|
|
1202
|
+
}
|
|
1203
|
+
else {
|
|
1204
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1205
|
+
name: 'getChatLeader',
|
|
1206
|
+
args: [chat],
|
|
1207
|
+
}));
|
|
1208
|
+
return User_1.default.fromJSON(workerMessage.getData().result || {});
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* @param chat Sala de bate-papo
|
|
1213
|
+
* @returns Retorna os usuários de uma sala de bate-papo
|
|
1214
|
+
*/
|
|
1215
|
+
async getChatUsers(chat) {
|
|
1216
|
+
if (this.isMain) {
|
|
1217
|
+
return await this.bot.getChatUsers(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1218
|
+
}
|
|
1219
|
+
else {
|
|
1220
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1221
|
+
name: 'getChatUsers',
|
|
1222
|
+
args: [chat],
|
|
1223
|
+
}));
|
|
1224
|
+
return workerMessage.getData().result || [];
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* @param chat Sala de bate-papo
|
|
1229
|
+
* @returns Retorna os administradores de uma sala de bate-papo
|
|
1230
|
+
*/
|
|
1231
|
+
async getChatAdmins(chat) {
|
|
1232
|
+
if (this.isMain) {
|
|
1233
|
+
return await this.bot.getChatAdmins(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1234
|
+
}
|
|
1235
|
+
else {
|
|
1236
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1237
|
+
name: 'getChatAdmins',
|
|
1238
|
+
args: [chat],
|
|
1239
|
+
}));
|
|
1240
|
+
return workerMessage.getData().result || [];
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
/** Adiciona um novo usuário a uma sala de bate-papo
|
|
1244
|
+
* @param chat Sala de bate-papo
|
|
1245
|
+
* @param user Usuário
|
|
1246
|
+
*/
|
|
1247
|
+
async addUserInChat(chat, user) {
|
|
1248
|
+
if (this.isMain) {
|
|
1249
|
+
await this.bot.addUserInChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1253
|
+
name: 'addUserInChat',
|
|
1254
|
+
args: [chat, user],
|
|
1255
|
+
}));
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
/** Adiciona um novo usuário a uma sala de bate-papo
|
|
1259
|
+
* @param chat Sala de bate-papo
|
|
1260
|
+
* @param user Usuário
|
|
1261
|
+
*/
|
|
1262
|
+
async removeUserInChat(chat, user) {
|
|
1263
|
+
if (this.isMain) {
|
|
1264
|
+
await this.bot.removeUserInChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1265
|
+
}
|
|
1266
|
+
else {
|
|
1267
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1268
|
+
name: 'removeUserInChat',
|
|
1269
|
+
args: [chat, user],
|
|
1270
|
+
}));
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
/** Promove há administrador um usuário da sala de bate-papo
|
|
1274
|
+
* @param chat Sala de bate-papo
|
|
1275
|
+
* @param user Usuário
|
|
1276
|
+
*/
|
|
1277
|
+
async promoteUserInChat(chat, user) {
|
|
1278
|
+
if (this.isMain) {
|
|
1279
|
+
await this.bot.promoteUserInChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1280
|
+
}
|
|
1281
|
+
else {
|
|
1282
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1283
|
+
name: 'promoteUserInChat',
|
|
1284
|
+
args: [chat, user],
|
|
1285
|
+
}));
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
/** Remove a administração um usuário da sala de bate-papo
|
|
1289
|
+
* @param chat Sala de bate-papo
|
|
1290
|
+
* @param user Usuário
|
|
1291
|
+
*/
|
|
1292
|
+
async demoteUserInChat(chat, user) {
|
|
1293
|
+
if (this.isMain) {
|
|
1294
|
+
await this.bot.demoteUserInChat(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1295
|
+
}
|
|
1296
|
+
else {
|
|
1297
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1298
|
+
name: 'demoteUserInChat',
|
|
1299
|
+
args: [chat, user],
|
|
1300
|
+
}));
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
/** Altera o status da sala de bate-papo
|
|
1304
|
+
* @param chat Sala de bate-papo
|
|
1305
|
+
* @param status Status da sala de bate-papo
|
|
1306
|
+
*/
|
|
1307
|
+
async changeChatStatus(chat, status) {
|
|
1308
|
+
if (this.isMain) {
|
|
1309
|
+
await this.bot.changeChatStatus(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), status);
|
|
1310
|
+
}
|
|
1311
|
+
else {
|
|
1312
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1313
|
+
name: 'changeChatStatus',
|
|
1314
|
+
args: [chat, status],
|
|
1315
|
+
}));
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Entra no chat pelo código de convite.
|
|
1320
|
+
* @param code - Código de convite do chat.
|
|
1321
|
+
*/
|
|
1322
|
+
async joinChat(code) {
|
|
1323
|
+
if (this.isMain) {
|
|
1324
|
+
await this.bot.joinChat(code);
|
|
1325
|
+
}
|
|
1326
|
+
else {
|
|
1327
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1328
|
+
name: 'joinChat',
|
|
1329
|
+
args: [code],
|
|
1330
|
+
}));
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Obtem o código de convite do chat.
|
|
1335
|
+
* @param chat - Chat que será obtido o código de convite.
|
|
1336
|
+
* @returns O código de convite do chat.
|
|
1337
|
+
*/
|
|
1338
|
+
async getChatInvite(chat) {
|
|
1339
|
+
if (this.isMain) {
|
|
1340
|
+
return await this.bot.getChatInvite(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1341
|
+
}
|
|
1342
|
+
else {
|
|
1343
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1344
|
+
name: 'getChatInvite',
|
|
1345
|
+
args: [chat],
|
|
1346
|
+
}));
|
|
1347
|
+
return workerMessage.getData().result || '';
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Revoga o código de convite do chat.
|
|
1352
|
+
* @param chat - Chat que terá seu código de convite revogado.
|
|
1353
|
+
* @returns O novo código de convite do chat.
|
|
1354
|
+
*/
|
|
1355
|
+
async revokeChatInvite(chat) {
|
|
1356
|
+
if (this.isMain) {
|
|
1357
|
+
return await this.bot.revokeChatInvite(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
1358
|
+
}
|
|
1359
|
+
else {
|
|
1360
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1361
|
+
name: 'revokeChatInvite',
|
|
1362
|
+
args: [chat],
|
|
1363
|
+
}));
|
|
1364
|
+
return workerMessage.getData().result || '';
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
async rejectCall(call) {
|
|
1368
|
+
if (this.isMain) {
|
|
1369
|
+
await this.bot.rejectCall(Call_1.default.apply(call, { clientId: this.id, botId: this.bot.id }));
|
|
1370
|
+
}
|
|
1371
|
+
else {
|
|
1372
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1373
|
+
name: 'rejectCall',
|
|
1374
|
+
args: [call],
|
|
1375
|
+
}));
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
/** @returns Retorna a lista de usuários do bot */
|
|
1379
|
+
async getUsers() {
|
|
1380
|
+
if (this.isMain) {
|
|
1381
|
+
const ids = await this.bot.getUsers();
|
|
1382
|
+
const users = [];
|
|
1383
|
+
await Promise.all(ids.map(async (id) => {
|
|
1384
|
+
const user = await this.bot.getUser(new User_1.default(id));
|
|
1385
|
+
if (user == null)
|
|
1386
|
+
return;
|
|
1387
|
+
users.push(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1388
|
+
}));
|
|
1389
|
+
return users;
|
|
1390
|
+
}
|
|
1391
|
+
else {
|
|
1392
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1393
|
+
name: 'getUsers',
|
|
1394
|
+
args: [],
|
|
1395
|
+
}));
|
|
1396
|
+
return (workerMessage.getData().result || []).map((user) => User_1.default.fromJSON(user));
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Obter lista de usuários salvos.
|
|
1401
|
+
* @returns Lista de usuários salvos.
|
|
1402
|
+
*/
|
|
1403
|
+
async getSavedUsers() {
|
|
1404
|
+
if (this.isMain) {
|
|
1405
|
+
const ids = await this.bot.getUsers();
|
|
1406
|
+
const users = [];
|
|
1407
|
+
await Promise.all(ids.map(async (id) => {
|
|
1408
|
+
const user = await this.bot.getUser(new User_1.default(id));
|
|
1409
|
+
if (user == null || !user.savedName)
|
|
1410
|
+
return;
|
|
1411
|
+
users.push(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1412
|
+
}));
|
|
1413
|
+
return users;
|
|
1414
|
+
}
|
|
1415
|
+
else {
|
|
1416
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1417
|
+
name: 'getSavedUsers',
|
|
1418
|
+
args: [],
|
|
1419
|
+
}));
|
|
1420
|
+
return (workerMessage.getData().result || []).map((user) => User_1.default.fromJSON(user));
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
/** Define a lista de usuários do bot
|
|
1424
|
+
* @param users Usuários
|
|
1425
|
+
*/
|
|
1426
|
+
async setUsers(users) {
|
|
1427
|
+
if (this.isMain) {
|
|
1428
|
+
await this.bot.setUsers(users);
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1432
|
+
name: 'setUsers',
|
|
1433
|
+
args: [users],
|
|
1434
|
+
}));
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* @param user Usuário
|
|
1439
|
+
* @returns Retorna um usuário
|
|
1440
|
+
*/
|
|
1441
|
+
async getUser(user) {
|
|
1442
|
+
if (this.isMain) {
|
|
1443
|
+
const userData = await this.bot.getUser(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1444
|
+
if (userData == null)
|
|
1445
|
+
return null;
|
|
1446
|
+
return User_1.default.apply(userData, { clientId: this.id, botId: this.bot.id });
|
|
1447
|
+
}
|
|
1448
|
+
else {
|
|
1449
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1450
|
+
name: 'getUser',
|
|
1451
|
+
args: [user],
|
|
1452
|
+
}));
|
|
1453
|
+
const userData = workerMessage.getData().result || null;
|
|
1454
|
+
if (userData == null)
|
|
1455
|
+
return null;
|
|
1456
|
+
return User_1.default.fromJSON(userData);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Atualiza os dados de um usuário.
|
|
1461
|
+
* @param id - Id do usuário que será atualizado.
|
|
1462
|
+
* @param user - Dados do usuário que será atualizado.
|
|
1463
|
+
*/
|
|
1464
|
+
async updateUser(id, user) {
|
|
1465
|
+
if (this.isMain) {
|
|
1466
|
+
await this.bot.updateUser({ ...user, id });
|
|
1467
|
+
}
|
|
1468
|
+
else {
|
|
1469
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1470
|
+
name: 'updateUser',
|
|
1471
|
+
args: [id, user],
|
|
1472
|
+
}));
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
/** Remove um usuário
|
|
1476
|
+
* @param user Usuário
|
|
1477
|
+
*/
|
|
1478
|
+
async removeUser(user) {
|
|
1479
|
+
if (this.isMain) {
|
|
1480
|
+
await this.bot.removeUser(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1481
|
+
}
|
|
1482
|
+
else {
|
|
1483
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1484
|
+
name: 'removeUser',
|
|
1485
|
+
args: [user],
|
|
1486
|
+
}));
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* @param user Usuário
|
|
1491
|
+
* @returns Retorna o nome do usuário
|
|
1492
|
+
*/
|
|
1493
|
+
async getUserName(user) {
|
|
1494
|
+
if (this.isMain) {
|
|
1495
|
+
if (User_1.default.getId(user) == this.id)
|
|
1496
|
+
return this.getBotName();
|
|
1497
|
+
return await this.bot.getUserName(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1498
|
+
}
|
|
1499
|
+
else {
|
|
1500
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1501
|
+
name: 'getUserName',
|
|
1502
|
+
args: [user],
|
|
1503
|
+
}));
|
|
1504
|
+
return workerMessage.getData().result || '';
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
/** Define o nome do usuário
|
|
1508
|
+
* @param user Usuário
|
|
1509
|
+
* @param name Nome do usuário
|
|
1510
|
+
*/
|
|
1511
|
+
async setUserName(user, name) {
|
|
1512
|
+
if (this.isMain) {
|
|
1513
|
+
if (User_1.default.getId(user) == this.id) {
|
|
1514
|
+
await this.setBotName(name);
|
|
1515
|
+
}
|
|
1516
|
+
await this.bot.setUserName(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), name);
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1520
|
+
name: 'setUserName',
|
|
1521
|
+
args: [user, name],
|
|
1522
|
+
}));
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* @param user Usuário
|
|
1527
|
+
* @returns Retorna a descrição do usuário
|
|
1528
|
+
*/
|
|
1529
|
+
async getUserDescription(user) {
|
|
1530
|
+
if (this.isMain) {
|
|
1531
|
+
if (User_1.default.getId(user) == this.id) {
|
|
1532
|
+
return await this.getBotDescription();
|
|
1533
|
+
}
|
|
1534
|
+
return await this.bot.getUserDescription(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1535
|
+
}
|
|
1536
|
+
else {
|
|
1537
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1538
|
+
name: 'getUserDescription',
|
|
1539
|
+
args: [user],
|
|
1540
|
+
}));
|
|
1541
|
+
return workerMessage.getData().result || '';
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
/** Define a descrição do usuário
|
|
1545
|
+
* @param user Usuário
|
|
1546
|
+
* @param description Descrição do usuário
|
|
1547
|
+
*/
|
|
1548
|
+
async setUserDescription(user, description) {
|
|
1549
|
+
if (this.isMain) {
|
|
1550
|
+
if (User_1.default.getId(user) == this.id) {
|
|
1551
|
+
await this.setBotDescription(description);
|
|
1552
|
+
}
|
|
1553
|
+
await this.bot.setUserDescription(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), description);
|
|
1554
|
+
}
|
|
1555
|
+
else {
|
|
1556
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1557
|
+
name: 'setUserDescription',
|
|
1558
|
+
args: [user, description],
|
|
1559
|
+
}));
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* @param user Usuário
|
|
1564
|
+
* @returns Retorna a foto de perfil do usuário
|
|
1565
|
+
*/
|
|
1566
|
+
async getUserProfile(user, lowQuality) {
|
|
1567
|
+
if (this.isMain) {
|
|
1568
|
+
if (User_1.default.getId(user) == this.id) {
|
|
1569
|
+
return await this.getBotProfile(lowQuality);
|
|
1570
|
+
}
|
|
1571
|
+
return await this.bot.getUserProfile(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), lowQuality);
|
|
1572
|
+
}
|
|
1573
|
+
else {
|
|
1574
|
+
const workerMessage = await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1575
|
+
name: 'getUserProfile',
|
|
1576
|
+
args: [user, lowQuality],
|
|
1577
|
+
}));
|
|
1578
|
+
return workerMessage.getData().result || Buffer.from('');
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
/** Define a imagem de perfil do usuário
|
|
1582
|
+
* @param user Usuário
|
|
1583
|
+
* @param profile Imagem de perfil do usuário
|
|
1584
|
+
*/
|
|
1585
|
+
async setUserProfile(user, profile) {
|
|
1586
|
+
if (this.isMain) {
|
|
1587
|
+
if (User_1.default.getId(user) == this.id) {
|
|
1588
|
+
await this.setBotProfile(profile);
|
|
1589
|
+
}
|
|
1590
|
+
await this.bot.setUserProfile(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), profile);
|
|
1591
|
+
}
|
|
1592
|
+
else {
|
|
1593
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1594
|
+
name: 'setUserProfile',
|
|
1595
|
+
args: [user, profile],
|
|
1596
|
+
}));
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
/** Desbloqueia um usuário
|
|
1600
|
+
* @param user Usuário
|
|
1601
|
+
*/
|
|
1602
|
+
async unblockUser(user) {
|
|
1603
|
+
if (this.isMain) {
|
|
1604
|
+
await this.bot.unblockUser(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1608
|
+
name: 'unblockUser',
|
|
1609
|
+
args: [user],
|
|
1610
|
+
}));
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
/** Bloqueia um usuário
|
|
1614
|
+
* @param user Usuário
|
|
1615
|
+
*/
|
|
1616
|
+
async blockUser(user) {
|
|
1617
|
+
if (this.isMain) {
|
|
1618
|
+
await this.bot.blockUser(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
1619
|
+
}
|
|
1620
|
+
else {
|
|
1621
|
+
await this.sendWorkerMessage(new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Func, {
|
|
1622
|
+
name: 'blockUser',
|
|
1623
|
+
args: [user],
|
|
1624
|
+
}));
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Retorna a lista de clientes diponíveis.
|
|
1629
|
+
* @returns Clientes ordenados pelo ID.
|
|
1630
|
+
*/
|
|
1631
|
+
static getClients() {
|
|
1632
|
+
if (!('rompot-clients-cluster' in global) ||
|
|
1633
|
+
typeof global['rompot-clients-cluster'] != 'object') {
|
|
1634
|
+
global['rompot-clients-cluster'] = {};
|
|
1635
|
+
}
|
|
1636
|
+
return global['rompot-clients-cluster'];
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Define todos os clientes diponíveis.
|
|
1640
|
+
* @param clients - Clientes que serão definidios.
|
|
1641
|
+
*/
|
|
1642
|
+
static saveClients(clients) {
|
|
1643
|
+
global['rompot-clients-cluster'] = clients;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Retorna o cliente pelo seu respectivo ID.
|
|
1647
|
+
* @param id - ID do cliente.
|
|
1648
|
+
* @returns O cliente associado ao ID.
|
|
1649
|
+
*/
|
|
1650
|
+
static getClient(id) {
|
|
1651
|
+
var _a;
|
|
1652
|
+
const clients = ClientCluster.getClients();
|
|
1653
|
+
if (id in clients && typeof clients[id] == 'object') {
|
|
1654
|
+
return clients[id];
|
|
1655
|
+
}
|
|
1656
|
+
return new ClientCluster(id, global['default-rompot-worker'] || ((_a = global['rompot-cluster-save']) === null || _a === void 0 ? void 0 : _a.worker));
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Define um cliente disponível
|
|
1660
|
+
* @param client - Cliente que será definido
|
|
1661
|
+
*/
|
|
1662
|
+
static saveClient(client) {
|
|
1663
|
+
if (!('rompot-clients-cluster' in global) ||
|
|
1664
|
+
typeof global['rompot-clients-cluster'] != 'object') {
|
|
1665
|
+
global['rompot-clients-cluster'] = {};
|
|
1666
|
+
}
|
|
1667
|
+
global['rompot-clients-cluster'][client.id] = client;
|
|
1668
|
+
const workerMessage = new WorkerMessage_1.default(WorkerMessage_1.WorkerMessageTag.Patch, {});
|
|
1669
|
+
workerMessage.id = 'save-client';
|
|
1670
|
+
workerMessage.isPrimary = true;
|
|
1671
|
+
client.sendWorkerMessage(workerMessage);
|
|
1672
|
+
}
|
|
1673
|
+
/** Gera um id único */
|
|
1674
|
+
static generateId() {
|
|
1675
|
+
return `${process.pid}-${Date.now()}-${Object.keys(ClientCluster.getClients()).length}`;
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* * Cria um cliente principal para o bot.
|
|
1679
|
+
* @param id - ID do cliente.
|
|
1680
|
+
* @param worker - Worker do cliente.
|
|
1681
|
+
* @param bot - Bot do cliente.
|
|
1682
|
+
* @param auth - Autenticação do bot.
|
|
1683
|
+
* @returns Instância principal do cliente.
|
|
1684
|
+
*/
|
|
1685
|
+
static createMain(id, worker, bot, auth, config) {
|
|
1686
|
+
const clientMain = new ClientCluster(id, worker, config, true);
|
|
1687
|
+
clientMain.bot = bot;
|
|
1688
|
+
clientMain.auth = auth;
|
|
1689
|
+
clientMain.configEvents();
|
|
1690
|
+
return clientMain;
|
|
1691
|
+
}
|
|
1692
|
+
/** Configura o cluster para o cliente */
|
|
1693
|
+
static configCluster(cluster) {
|
|
1694
|
+
var _a, _b;
|
|
1695
|
+
global['rompot-cluster-save'] = cluster;
|
|
1696
|
+
global[exports.GlobalRompotCluster] = {
|
|
1697
|
+
workers: { ...(((_a = global[exports.GlobalRompotCluster]) === null || _a === void 0 ? void 0 : _a.workers) || {}) },
|
|
1698
|
+
clients: { ...(((_b = global[exports.GlobalRompotCluster]) === null || _b === void 0 ? void 0 : _b.clients) || {}) },
|
|
1699
|
+
};
|
|
1700
|
+
cluster.on('fork', (worker) => {
|
|
1701
|
+
global[exports.GlobalRompotCluster].workers[`${worker.id}`] = worker;
|
|
1702
|
+
});
|
|
1703
|
+
cluster.on('message', (worker, message) => {
|
|
1704
|
+
var _a, _b, _c;
|
|
1705
|
+
const workerMessage = WorkerMessage_1.default.fromJSON(message);
|
|
1706
|
+
try {
|
|
1707
|
+
if (workerMessage.uid != 'rompot')
|
|
1708
|
+
return;
|
|
1709
|
+
if (!((_a = global[exports.GlobalRompotCluster].clients[worker.id]) === null || _a === void 0 ? void 0 : _a.includes(workerMessage.clientId))) {
|
|
1710
|
+
global[exports.GlobalRompotCluster].clients[worker.id] = [
|
|
1711
|
+
...(global[exports.GlobalRompotCluster].clients[worker.id] || []),
|
|
1712
|
+
workerMessage.clientId,
|
|
1713
|
+
];
|
|
1714
|
+
}
|
|
1715
|
+
if (workerMessage.isPrimary)
|
|
1716
|
+
return;
|
|
1717
|
+
for (const workerId of Object.keys(((_b = global[exports.GlobalRompotCluster]) === null || _b === void 0 ? void 0 : _b.clients) || {})) {
|
|
1718
|
+
try {
|
|
1719
|
+
for (const clientId of ((_c = global[exports.GlobalRompotCluster]) === null || _c === void 0 ? void 0 : _c.clients[workerId]) || []) {
|
|
1720
|
+
if (clientId != workerMessage.clientId)
|
|
1721
|
+
continue;
|
|
1722
|
+
const workerReceive = global[exports.GlobalRompotCluster].workers[workerId];
|
|
1723
|
+
if (!workerReceive)
|
|
1724
|
+
continue;
|
|
1725
|
+
workerReceive.send(workerMessage);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
catch (_d) {
|
|
1729
|
+
worker.send(workerMessage.clone({
|
|
1730
|
+
tag: WorkerMessage_1.WorkerMessageTag.Error,
|
|
1731
|
+
data: { reason: 'Error in send message from worker' },
|
|
1732
|
+
}));
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
catch (_e) {
|
|
1737
|
+
worker.send(workerMessage.clone({
|
|
1738
|
+
tag: WorkerMessage_1.WorkerMessageTag.Error,
|
|
1739
|
+
data: { reason: 'Error in receive message from worker' },
|
|
1740
|
+
}));
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
exports.default = ClientCluster;
|
|
1746
|
+
//# sourceMappingURL=ClientCluster.js.map
|