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,687 @@
|
|
|
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
|
+
const buffer_1 = require("buffer");
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const ChatNotDefinedError_1 = __importDefault(require("../errors/ChatNotDefinedError"));
|
|
42
|
+
const Defaults_1 = require("../configs/Defaults");
|
|
43
|
+
const Message_1 = __importStar(require("../messages/Message"));
|
|
44
|
+
const ErrorMessage_1 = __importDefault(require("../messages/ErrorMessage"));
|
|
45
|
+
const ReactionMessage_1 = __importDefault(require("../messages/ReactionMessage"));
|
|
46
|
+
const QuickResponseController_1 = __importDefault(require("../modules/quickResponse/QuickResponseController"));
|
|
47
|
+
const ChatStatus_1 = __importDefault(require("../modules/chat/ChatStatus"));
|
|
48
|
+
const Chat_1 = __importDefault(require("../modules/chat/Chat"));
|
|
49
|
+
const User_1 = __importDefault(require("../modules/user/User"));
|
|
50
|
+
const CommandEnums_1 = require("../modules/command/CommandEnums");
|
|
51
|
+
const CommandController_1 = __importDefault(require("../modules/command/CommandController"));
|
|
52
|
+
const ClientEvents_1 = __importDefault(require("./ClientEvents"));
|
|
53
|
+
const ClientCluster_1 = __importDefault(require("../cluster/ClientCluster"));
|
|
54
|
+
const ClientFunctionHandler_1 = __importDefault(require("./ClientFunctionHandler"));
|
|
55
|
+
const BotStatus_1 = require("../bot/BotStatus");
|
|
56
|
+
const BotBase_1 = __importDefault(require("../bot/BotBase"));
|
|
57
|
+
const Generic_1 = require("../utils/Generic");
|
|
58
|
+
const MessageHandler_1 = __importDefault(require("../utils/MessageHandler"));
|
|
59
|
+
const QuickResponse_1 = __importDefault(require("../modules/quickResponse/QuickResponse"));
|
|
60
|
+
const AdvancedCommandController_1 = __importDefault(require("../modules/command/advanced/AdvancedCommandController"));
|
|
61
|
+
const Call_1 = __importDefault(require("../models/Call"));
|
|
62
|
+
class Client extends ClientEvents_1.default {
|
|
63
|
+
constructor(bot, config = {}) {
|
|
64
|
+
super();
|
|
65
|
+
this.funcHandler = new ClientFunctionHandler_1.default(this, {
|
|
66
|
+
bot: [],
|
|
67
|
+
chat: [],
|
|
68
|
+
user: [],
|
|
69
|
+
message: [],
|
|
70
|
+
sendMessage: [],
|
|
71
|
+
sendMediaMessage: [],
|
|
72
|
+
downloadMedia: [],
|
|
73
|
+
});
|
|
74
|
+
this.commandController = new CommandController_1.default();
|
|
75
|
+
this.quickResponseController = new QuickResponseController_1.default();
|
|
76
|
+
this.messageHandler = new MessageHandler_1.default();
|
|
77
|
+
this.reconnectTimes = 0;
|
|
78
|
+
this.config = { ...Defaults_1.DEFAULT_CONNECTION_CONFIG, ...config };
|
|
79
|
+
this.id = Client.generateId();
|
|
80
|
+
this.bot = bot;
|
|
81
|
+
this.advancedCommandController = new AdvancedCommandController_1.default(this.id);
|
|
82
|
+
this.configEvents();
|
|
83
|
+
Client.saveClient(this);
|
|
84
|
+
}
|
|
85
|
+
configEvents() {
|
|
86
|
+
this.bot.on('message', async (message) => {
|
|
87
|
+
try {
|
|
88
|
+
message.inject({ clientId: this.id, botId: this.bot.id });
|
|
89
|
+
if (!message.fromMe && !this.config.disableAutoRead) {
|
|
90
|
+
if (!message.isDeleted && !message.isUpdate) {
|
|
91
|
+
await message.read();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
message.user = (await this.getUser(message.user)) || message.user;
|
|
95
|
+
message.chat = (await this.getChat(message.chat)) || message.chat;
|
|
96
|
+
if (!message.chat.timestamp ||
|
|
97
|
+
message.timestamp > message.chat.timestamp) {
|
|
98
|
+
message.chat.timestamp = message.timestamp;
|
|
99
|
+
}
|
|
100
|
+
if (message.mention) {
|
|
101
|
+
if (message.mention.chat.id != message.chat.id) {
|
|
102
|
+
message.mention.chat =
|
|
103
|
+
(await this.getChat(message.mention.chat)) ||
|
|
104
|
+
message.mention.chat;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
message.mention.chat = message.chat;
|
|
108
|
+
}
|
|
109
|
+
if (message.mention.user.id != message.user.id) {
|
|
110
|
+
message.mention.user =
|
|
111
|
+
(await this.getUser(message.mention.user)) ||
|
|
112
|
+
message.mention.user;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
message.mention.user = message.user;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (this.messageHandler.resolveMessage(message))
|
|
119
|
+
return;
|
|
120
|
+
this.emit('message', message);
|
|
121
|
+
if (this.config.disableAutoCommand)
|
|
122
|
+
return;
|
|
123
|
+
if (this.config.disableAutoCommandForOldMessage && message.isOld)
|
|
124
|
+
return;
|
|
125
|
+
if (this.config.disableAutoCommandForUnofficialMessage &&
|
|
126
|
+
message.isUnofficial)
|
|
127
|
+
return;
|
|
128
|
+
await this.quickResponseController.searchAndExecute(message);
|
|
129
|
+
const command = this.searchCommand(message.text);
|
|
130
|
+
if (command != null) {
|
|
131
|
+
this.runCommand(command, message, CommandEnums_1.CMDRunType.Exec);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
this.emit('message', new ErrorMessage_1.default(message.chat, err));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.bot.on('open', (update) => {
|
|
139
|
+
try {
|
|
140
|
+
this.reconnectTimes = 0;
|
|
141
|
+
this.emit('open', update);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
this.bot.on('reconnecting', (update) => {
|
|
148
|
+
try {
|
|
149
|
+
this.emit('reconnecting', update);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
this.bot.on('connecting', (update) => {
|
|
156
|
+
try {
|
|
157
|
+
this.emit('connecting', update);
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
this.bot.on('close', async (update) => {
|
|
164
|
+
try {
|
|
165
|
+
this.emit('close', update);
|
|
166
|
+
if (this.reconnectTimes < this.config.maxReconnectTimes) {
|
|
167
|
+
this.reconnectTimes++;
|
|
168
|
+
await (0, Generic_1.sleep)(this.config.reconnectTimeout);
|
|
169
|
+
this.reconnect();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
this.bot.on('stop', async (update) => {
|
|
177
|
+
try {
|
|
178
|
+
this.emit('stop', update);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
this.bot.on('qr', (qr) => {
|
|
185
|
+
try {
|
|
186
|
+
this.emit('qr', qr);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
this.bot.on('code', (code) => {
|
|
193
|
+
try {
|
|
194
|
+
this.emit('code', code);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
this.bot.on('chat', (update) => {
|
|
201
|
+
this.emit('chat', {
|
|
202
|
+
...update,
|
|
203
|
+
chat: { ...update.chat, clientId: this.id, botId: this.bot.id },
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
this.bot.on('user', (update) => {
|
|
207
|
+
try {
|
|
208
|
+
this.emit('user', {
|
|
209
|
+
event: update.event,
|
|
210
|
+
action: update.action,
|
|
211
|
+
chat: Chat_1.default.apply(update.chat, {
|
|
212
|
+
clientId: this.id,
|
|
213
|
+
botId: this.bot.id,
|
|
214
|
+
}),
|
|
215
|
+
user: User_1.default.apply(update.user, {
|
|
216
|
+
clientId: this.id,
|
|
217
|
+
botId: this.bot.id,
|
|
218
|
+
}),
|
|
219
|
+
fromUser: User_1.default.apply(update.fromUser, {
|
|
220
|
+
clientId: this.id,
|
|
221
|
+
botId: this.bot.id,
|
|
222
|
+
}),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
this.bot.on('call', (call) => {
|
|
230
|
+
this.emit('call', Call_1.default.apply(call, { clientId: this.id, botId: this.bot.id }));
|
|
231
|
+
});
|
|
232
|
+
this.bot.on('error', (err) => {
|
|
233
|
+
try {
|
|
234
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
this.emit('error', (0, Generic_1.getError)(err));
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async connect(auth) {
|
|
242
|
+
await this.bot.connect(auth);
|
|
243
|
+
}
|
|
244
|
+
async reconnect(alert) {
|
|
245
|
+
await this.bot.reconnect(alert);
|
|
246
|
+
}
|
|
247
|
+
async stop(reason) {
|
|
248
|
+
await this.bot.stop(reason);
|
|
249
|
+
}
|
|
250
|
+
async logout() {
|
|
251
|
+
await this.bot.logout();
|
|
252
|
+
}
|
|
253
|
+
async awaitEvent(eventName, maxTimeout) {
|
|
254
|
+
return new Promise((res, rej) => {
|
|
255
|
+
let timeout;
|
|
256
|
+
if (maxTimeout) {
|
|
257
|
+
timeout = setTimeout(() => {
|
|
258
|
+
rej('Wait event time out');
|
|
259
|
+
}, maxTimeout);
|
|
260
|
+
}
|
|
261
|
+
const listener = (arg) => {
|
|
262
|
+
if (timeout) {
|
|
263
|
+
clearTimeout(timeout);
|
|
264
|
+
}
|
|
265
|
+
this.ev.removeListener(eventName, listener);
|
|
266
|
+
res(arg);
|
|
267
|
+
};
|
|
268
|
+
this.ev.on(eventName, listener);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async awaitConnectionOpen() {
|
|
272
|
+
if (this.bot.status != BotStatus_1.BotStatus.Online) {
|
|
273
|
+
await this.awaitEvent('open', this.config.maxTimeout);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
getCommandController() {
|
|
277
|
+
if (this.commandController.clientId != this.id) {
|
|
278
|
+
this.commandController.clientId = this.id;
|
|
279
|
+
}
|
|
280
|
+
if (this.commandController.botId != this.bot.id) {
|
|
281
|
+
this.commandController.botId = this.bot.id;
|
|
282
|
+
}
|
|
283
|
+
return this.commandController;
|
|
284
|
+
}
|
|
285
|
+
setCommandController(controller) {
|
|
286
|
+
controller.botId = this.bot.id;
|
|
287
|
+
controller.clientId = this.id;
|
|
288
|
+
this.commandController = controller;
|
|
289
|
+
}
|
|
290
|
+
setCommands(commands) {
|
|
291
|
+
this.commandController.setCommands(commands);
|
|
292
|
+
}
|
|
293
|
+
getCommands() {
|
|
294
|
+
return this.commandController.getCommands();
|
|
295
|
+
}
|
|
296
|
+
addCommand(command) {
|
|
297
|
+
this.commandController.addCommand(command);
|
|
298
|
+
}
|
|
299
|
+
removeCommand(command) {
|
|
300
|
+
return this.commandController.removeCommand(command);
|
|
301
|
+
}
|
|
302
|
+
searchCommand(text) {
|
|
303
|
+
const command = this.commandController.searchCommand(text);
|
|
304
|
+
if (command == null)
|
|
305
|
+
return null;
|
|
306
|
+
command.clientId = this.id;
|
|
307
|
+
command.botId = this.bot.id;
|
|
308
|
+
return command;
|
|
309
|
+
}
|
|
310
|
+
runCommand(command, message, type) {
|
|
311
|
+
return this.commandController.runCommand(command, message, type);
|
|
312
|
+
}
|
|
313
|
+
setAdvancedCommandController(advancedCommandController) {
|
|
314
|
+
advancedCommandController.clientId = this.id;
|
|
315
|
+
this.advancedCommandController = advancedCommandController;
|
|
316
|
+
}
|
|
317
|
+
getAdvancedCommandController() {
|
|
318
|
+
return this.advancedCommandController;
|
|
319
|
+
}
|
|
320
|
+
setAdvancedCommands(commands) {
|
|
321
|
+
this.advancedCommandController.setCommands(...commands);
|
|
322
|
+
}
|
|
323
|
+
getAdvancedCommands() {
|
|
324
|
+
return this.advancedCommandController.getCommands();
|
|
325
|
+
}
|
|
326
|
+
createAdvancedCommand(id, context) {
|
|
327
|
+
return this.advancedCommandController.createCommand({ id, context });
|
|
328
|
+
}
|
|
329
|
+
addAdvancedCommand(command) {
|
|
330
|
+
this.advancedCommandController.addCommand(command);
|
|
331
|
+
}
|
|
332
|
+
removeAdvancedCommand(command) {
|
|
333
|
+
return this.advancedCommandController.removeCommand(command);
|
|
334
|
+
}
|
|
335
|
+
execAdvancedCommand(command, message) {
|
|
336
|
+
if (typeof command == 'string') {
|
|
337
|
+
const cmd = this.advancedCommandController.getCommand(command);
|
|
338
|
+
if (!cmd) {
|
|
339
|
+
throw new Error('Command not found');
|
|
340
|
+
}
|
|
341
|
+
command = cmd;
|
|
342
|
+
}
|
|
343
|
+
const options = {
|
|
344
|
+
chatId: message.chat.id,
|
|
345
|
+
context: {
|
|
346
|
+
...command.initialContext,
|
|
347
|
+
chatId: message.chat.id,
|
|
348
|
+
clientId: this.id,
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
return this.advancedCommandController.execCommand(command.id, message, options);
|
|
352
|
+
}
|
|
353
|
+
addQuickResponse(content, reply, options) {
|
|
354
|
+
if (content instanceof QuickResponse_1.default) {
|
|
355
|
+
this.quickResponseController.add(content);
|
|
356
|
+
return content;
|
|
357
|
+
}
|
|
358
|
+
//@ts-ignore
|
|
359
|
+
const quickResponse = new QuickResponse_1.default(content, reply, options);
|
|
360
|
+
this.quickResponseController.add(quickResponse);
|
|
361
|
+
return quickResponse;
|
|
362
|
+
}
|
|
363
|
+
removeQuickResponse(quickResponse) {
|
|
364
|
+
this.quickResponseController.remove(quickResponse);
|
|
365
|
+
}
|
|
366
|
+
deleteMessage(message) {
|
|
367
|
+
return this.funcHandler.exec('message', this.bot.deleteMessage, message);
|
|
368
|
+
}
|
|
369
|
+
removeMessage(message) {
|
|
370
|
+
return this.funcHandler.exec('message', this.bot.removeMessage, message);
|
|
371
|
+
}
|
|
372
|
+
async readMessage(message) {
|
|
373
|
+
await this.funcHandler.exec('message', this.bot.readMessage, message);
|
|
374
|
+
if (message.status == Message_1.MessageStatus.Sending ||
|
|
375
|
+
message.status == Message_1.MessageStatus.Sended ||
|
|
376
|
+
message.status == Message_1.MessageStatus.Received) {
|
|
377
|
+
if (message.type == Message_1.MessageType.Audio) {
|
|
378
|
+
message.status = Message_1.MessageStatus.Played;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
message.status = Message_1.MessageStatus.Readed;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (message.timestamp == message.chat.timestamp) {
|
|
385
|
+
message.chat.unreadCount = (message.chat.unreadCount || 0) - 1 || 0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
editMessage(message, text) {
|
|
389
|
+
message.text = text;
|
|
390
|
+
message.isEdited = true;
|
|
391
|
+
return this.funcHandler.exec('message', this.bot.editMessage, message);
|
|
392
|
+
}
|
|
393
|
+
addReaction(message, reaction) {
|
|
394
|
+
return this.funcHandler.exec('message', this.bot.addReaction, new ReactionMessage_1.default(message.chat, reaction, message, {
|
|
395
|
+
user: message.user,
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
removeReaction(message) {
|
|
399
|
+
return this.funcHandler.exec('message', this.bot.removeReaction, new ReactionMessage_1.default(message.chat, '', message, { user: message.user }));
|
|
400
|
+
}
|
|
401
|
+
addAnimatedReaction(message, reactions, interval = 2000, maxTimeout = 60000) {
|
|
402
|
+
let isStoped = false;
|
|
403
|
+
const now = Date.now();
|
|
404
|
+
const stop = async (reactionStop) => {
|
|
405
|
+
if (isStoped)
|
|
406
|
+
return;
|
|
407
|
+
isStoped = true;
|
|
408
|
+
if (!reactionStop) {
|
|
409
|
+
await this.removeReaction(message);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
await this.addReaction(message, reactionStop);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const addReaction = async (index) => {
|
|
416
|
+
if (isStoped || now + maxTimeout < Date.now()) {
|
|
417
|
+
return stop();
|
|
418
|
+
}
|
|
419
|
+
if (reactions[index]) {
|
|
420
|
+
await this.addReaction(message, reactions[index]);
|
|
421
|
+
}
|
|
422
|
+
await (0, Generic_1.sleep)(interval);
|
|
423
|
+
addReaction(index + 1 >= reactions.length ? 0 : index + 1);
|
|
424
|
+
};
|
|
425
|
+
addReaction(0);
|
|
426
|
+
return stop;
|
|
427
|
+
}
|
|
428
|
+
async send(message) {
|
|
429
|
+
message = Message_1.default.apply(message, { clientId: this.id, botId: this.bot.id });
|
|
430
|
+
if (!this.config.disableAutoTyping) {
|
|
431
|
+
await this.changeChatStatus(message.chat, message.type == 'audio' ? ChatStatus_1.default.Recording : ChatStatus_1.default.Typing);
|
|
432
|
+
}
|
|
433
|
+
if ('file' in message) {
|
|
434
|
+
return Message_1.default.apply(await this.funcHandler.exec('sendMediaMessage', this.bot.send, message), { clientId: this.id, botId: this.bot.id });
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
return Message_1.default.apply(await this.funcHandler.exec('sendMessage', this.bot.send, message), { clientId: this.id, botId: this.bot.id });
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async sendMessage(chat, message, mention) {
|
|
441
|
+
if (Message_1.default.isValid(message)) {
|
|
442
|
+
message = Message_1.default.apply(message, {
|
|
443
|
+
clientId: this.id,
|
|
444
|
+
botId: this.bot.id,
|
|
445
|
+
});
|
|
446
|
+
message.chat = Chat_1.default.apply(chat, {
|
|
447
|
+
clientId: this.id,
|
|
448
|
+
botId: this.bot.id,
|
|
449
|
+
});
|
|
450
|
+
message.mention = mention;
|
|
451
|
+
return await this.send(message);
|
|
452
|
+
}
|
|
453
|
+
return await this.send(new Message_1.default(chat, message, { mention }));
|
|
454
|
+
}
|
|
455
|
+
async awaitMessage(chat, config = {}) {
|
|
456
|
+
const chatId = Chat_1.default.getId(chat);
|
|
457
|
+
if (!chatId) {
|
|
458
|
+
throw new ChatNotDefinedError_1.default();
|
|
459
|
+
}
|
|
460
|
+
const message = await this.messageHandler.addMessage(chatId, config);
|
|
461
|
+
return Message_1.default.apply(message, {
|
|
462
|
+
clientId: this.id,
|
|
463
|
+
botId: this.bot.id,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
async downloadStreamMessage(message) {
|
|
467
|
+
if (!message.file)
|
|
468
|
+
return buffer_1.Buffer.from('');
|
|
469
|
+
if (buffer_1.Buffer.isBuffer(message.file))
|
|
470
|
+
return message.file;
|
|
471
|
+
if (typeof message.file == 'string') {
|
|
472
|
+
return (0, fs_1.readFileSync)(message.file);
|
|
473
|
+
}
|
|
474
|
+
return this.funcHandler.exec('downloadMedia', this.bot.downloadStreamMessage, message.file);
|
|
475
|
+
}
|
|
476
|
+
getBotName() {
|
|
477
|
+
return this.funcHandler.exec('bot', this.bot.getBotName);
|
|
478
|
+
}
|
|
479
|
+
setBotName(name) {
|
|
480
|
+
return this.funcHandler.exec('bot', this.bot.setBotName, name);
|
|
481
|
+
}
|
|
482
|
+
getBotDescription() {
|
|
483
|
+
return this.funcHandler.exec('bot', this.bot.getBotDescription);
|
|
484
|
+
}
|
|
485
|
+
setBotDescription(description) {
|
|
486
|
+
return this.funcHandler.exec('bot', this.bot.setBotDescription, description);
|
|
487
|
+
}
|
|
488
|
+
getBotProfile(lowQuality) {
|
|
489
|
+
return this.funcHandler.exec('bot', this.bot.getBotProfile, lowQuality);
|
|
490
|
+
}
|
|
491
|
+
setBotProfile(profile) {
|
|
492
|
+
return this.funcHandler.exec('bot', this.bot.setBotProfile, profile);
|
|
493
|
+
}
|
|
494
|
+
async getChat(chat) {
|
|
495
|
+
const chatData = await this.funcHandler.exec('chat', this.bot.getChat, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
496
|
+
if (chatData == null)
|
|
497
|
+
return null;
|
|
498
|
+
return Chat_1.default.apply(chatData, { clientId: this.id, botId: this.bot.id });
|
|
499
|
+
}
|
|
500
|
+
updateChat(id, chat) {
|
|
501
|
+
return this.funcHandler.exec('chat', this.bot.updateChat, { ...chat, id });
|
|
502
|
+
}
|
|
503
|
+
async getChats() {
|
|
504
|
+
const ids = await this.funcHandler.exec('chat', this.bot.getChats);
|
|
505
|
+
const chats = [];
|
|
506
|
+
await Promise.all(ids.map(async (id) => {
|
|
507
|
+
const chat = await this.funcHandler.exec('chat', this.bot.getChat, new Chat_1.default(id));
|
|
508
|
+
if (chat == null)
|
|
509
|
+
return;
|
|
510
|
+
chats.push(Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
511
|
+
}));
|
|
512
|
+
return chats;
|
|
513
|
+
}
|
|
514
|
+
setChats(chats) {
|
|
515
|
+
return this.funcHandler.exec('chat', this.bot.setChats, chats);
|
|
516
|
+
}
|
|
517
|
+
removeChat(chat) {
|
|
518
|
+
return this.funcHandler.exec('chat', this.bot.removeChat, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
519
|
+
}
|
|
520
|
+
createChat(chat) {
|
|
521
|
+
return this.funcHandler.exec('chat', this.bot.createChat, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
522
|
+
}
|
|
523
|
+
leaveChat(chat) {
|
|
524
|
+
return this.funcHandler.exec('chat', this.bot.leaveChat, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
525
|
+
}
|
|
526
|
+
getChatName(chat) {
|
|
527
|
+
return this.funcHandler.exec('chat', this.bot.getChatName, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
528
|
+
}
|
|
529
|
+
setChatName(chat, name) {
|
|
530
|
+
return this.funcHandler.exec('chat', this.bot.setChatName, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), name);
|
|
531
|
+
}
|
|
532
|
+
getChatDescription(chat) {
|
|
533
|
+
return this.funcHandler.exec('chat', this.bot.getChatDescription, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
534
|
+
}
|
|
535
|
+
setChatDescription(chat, description) {
|
|
536
|
+
return this.funcHandler.exec('chat', this.bot.setChatDescription, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), description);
|
|
537
|
+
}
|
|
538
|
+
getChatProfile(chat, lowQuality) {
|
|
539
|
+
return this.funcHandler.exec('chat', this.bot.getChatProfile, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), lowQuality);
|
|
540
|
+
}
|
|
541
|
+
setChatProfile(chat, profile) {
|
|
542
|
+
return this.funcHandler.exec('chat', this.bot.setChatProfile, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), profile);
|
|
543
|
+
}
|
|
544
|
+
async getChatLeader(chat) {
|
|
545
|
+
return User_1.default.apply(await this.funcHandler.exec('chat', this.bot.getChatLeader, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id })), { clientId: this.id, botId: this.bot.id });
|
|
546
|
+
}
|
|
547
|
+
async getChatUsers(chat) {
|
|
548
|
+
return await this.funcHandler.exec('chat', this.bot.getChatUsers, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
549
|
+
}
|
|
550
|
+
async getChatAdmins(chat) {
|
|
551
|
+
return await this.funcHandler.exec('chat', this.bot.getChatAdmins, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
552
|
+
}
|
|
553
|
+
addUserInChat(chat, user) {
|
|
554
|
+
return this.funcHandler.exec('chat', 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 }));
|
|
555
|
+
}
|
|
556
|
+
removeUserInChat(chat, user) {
|
|
557
|
+
return this.funcHandler.exec('chat', 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 }));
|
|
558
|
+
}
|
|
559
|
+
promoteUserInChat(chat, user) {
|
|
560
|
+
return this.funcHandler.exec('chat', 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 }));
|
|
561
|
+
}
|
|
562
|
+
demoteUserInChat(chat, user) {
|
|
563
|
+
return this.funcHandler.exec('chat', 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 }));
|
|
564
|
+
}
|
|
565
|
+
changeChatStatus(chat, status) {
|
|
566
|
+
return this.funcHandler.exec('chat', this.bot.changeChatStatus, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }), status);
|
|
567
|
+
}
|
|
568
|
+
joinChat(code) {
|
|
569
|
+
return this.funcHandler.exec('chat', this.bot.joinChat, code);
|
|
570
|
+
}
|
|
571
|
+
getChatInvite(chat) {
|
|
572
|
+
return this.funcHandler.exec('chat', this.bot.getChatInvite, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
573
|
+
}
|
|
574
|
+
revokeChatInvite(chat) {
|
|
575
|
+
return this.funcHandler.exec('chat', this.bot.revokeChatInvite, Chat_1.default.apply(chat, { clientId: this.id, botId: this.bot.id }));
|
|
576
|
+
}
|
|
577
|
+
rejectCall(call) {
|
|
578
|
+
return this.funcHandler.exec('chat', this.bot.rejectCall, Call_1.default.apply(call));
|
|
579
|
+
}
|
|
580
|
+
async getUsers() {
|
|
581
|
+
const ids = await this.funcHandler.exec('user', this.bot.getUsers);
|
|
582
|
+
const users = [];
|
|
583
|
+
await Promise.all(ids.map(async (id) => {
|
|
584
|
+
const user = await this.funcHandler.exec('user', this.bot.getUser, new User_1.default(id));
|
|
585
|
+
if (user == null)
|
|
586
|
+
return;
|
|
587
|
+
users.push(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
588
|
+
}));
|
|
589
|
+
return users;
|
|
590
|
+
}
|
|
591
|
+
async getSavedUsers() {
|
|
592
|
+
const ids = await this.funcHandler.exec('user', this.bot.getUsers);
|
|
593
|
+
const users = [];
|
|
594
|
+
await Promise.all(ids.map(async (id) => {
|
|
595
|
+
const user = await this.funcHandler.exec('user', this.bot.getUser, new User_1.default(id));
|
|
596
|
+
if (user == null || !user.savedName)
|
|
597
|
+
return;
|
|
598
|
+
users.push(User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
599
|
+
}));
|
|
600
|
+
return users;
|
|
601
|
+
}
|
|
602
|
+
setUsers(users) {
|
|
603
|
+
return this.funcHandler.exec('user', this.bot.setUsers, users);
|
|
604
|
+
}
|
|
605
|
+
async getUser(user) {
|
|
606
|
+
const userData = await this.funcHandler.exec('user', this.bot.getUser, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
607
|
+
if (userData == null)
|
|
608
|
+
return null;
|
|
609
|
+
return User_1.default.apply(userData, { clientId: this.id, botId: this.bot.id });
|
|
610
|
+
}
|
|
611
|
+
updateUser(id, user) {
|
|
612
|
+
return this.funcHandler.exec('user', this.bot.updateUser, { ...user, id });
|
|
613
|
+
}
|
|
614
|
+
removeUser(user) {
|
|
615
|
+
return this.funcHandler.exec('user', this.bot.removeUser, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
616
|
+
}
|
|
617
|
+
getUserName(user) {
|
|
618
|
+
if (User_1.default.getId(user) == this.id)
|
|
619
|
+
return this.getBotName();
|
|
620
|
+
return this.funcHandler.exec('user', this.bot.getUserName, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
621
|
+
}
|
|
622
|
+
setUserName(user, name) {
|
|
623
|
+
if (User_1.default.getId(user) == this.id)
|
|
624
|
+
return this.setBotName(name);
|
|
625
|
+
return this.funcHandler.exec('user', this.bot.setUserName, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), name);
|
|
626
|
+
}
|
|
627
|
+
getUserDescription(user) {
|
|
628
|
+
if (User_1.default.getId(user) == this.id)
|
|
629
|
+
return this.getBotDescription();
|
|
630
|
+
return this.funcHandler.exec('user', this.bot.getUserDescription, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
631
|
+
}
|
|
632
|
+
setUserDescription(user, description) {
|
|
633
|
+
if (User_1.default.getId(user) == this.id)
|
|
634
|
+
return this.setBotDescription(description);
|
|
635
|
+
return this.funcHandler.exec('user', this.bot.setUserDescription, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), description);
|
|
636
|
+
}
|
|
637
|
+
getUserProfile(user, lowQuality) {
|
|
638
|
+
if (User_1.default.getId(user) == this.id)
|
|
639
|
+
return this.getBotProfile(lowQuality);
|
|
640
|
+
return this.funcHandler.exec('user', this.bot.getUserProfile, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), lowQuality);
|
|
641
|
+
}
|
|
642
|
+
setUserProfile(user, profile) {
|
|
643
|
+
if (User_1.default.getId(user) == this.id)
|
|
644
|
+
return this.setBotProfile(profile);
|
|
645
|
+
return this.funcHandler.exec('user', this.bot.setUserProfile, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }), profile);
|
|
646
|
+
}
|
|
647
|
+
unblockUser(user) {
|
|
648
|
+
return this.funcHandler.exec('user', this.bot.unblockUser, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
649
|
+
}
|
|
650
|
+
blockUser(user) {
|
|
651
|
+
return this.funcHandler.exec('user', this.bot.blockUser, User_1.default.apply(user, { clientId: this.id, botId: this.bot.id }));
|
|
652
|
+
}
|
|
653
|
+
static getClients() {
|
|
654
|
+
if (!('trompot-clients' in global) ||
|
|
655
|
+
typeof global['trompot-clients'] != 'object') {
|
|
656
|
+
global['trompot-clients'] = {};
|
|
657
|
+
}
|
|
658
|
+
return global['trompot-clients'];
|
|
659
|
+
}
|
|
660
|
+
static saveClients(clients) {
|
|
661
|
+
global['trompot-clients'] = clients;
|
|
662
|
+
}
|
|
663
|
+
static getClient(id) {
|
|
664
|
+
var _a;
|
|
665
|
+
const clients = Client.getClients();
|
|
666
|
+
if (id in clients && typeof clients[id] == 'object') {
|
|
667
|
+
return clients[id];
|
|
668
|
+
}
|
|
669
|
+
if (global['default-trompot-worker'] ||
|
|
670
|
+
((_a = global['trompot-cluster-save']) === null || _a === void 0 ? void 0 : _a.worker)) {
|
|
671
|
+
return ClientCluster_1.default.getClient(id);
|
|
672
|
+
}
|
|
673
|
+
return new Client(new BotBase_1.default());
|
|
674
|
+
}
|
|
675
|
+
static saveClient(client) {
|
|
676
|
+
if (!('trompot-clients' in global) ||
|
|
677
|
+
typeof global['trompot-clients'] != 'object') {
|
|
678
|
+
global['trompot-clients'] = {};
|
|
679
|
+
}
|
|
680
|
+
global['trompot-clients'][client.id] = client;
|
|
681
|
+
}
|
|
682
|
+
static generateId() {
|
|
683
|
+
return `${process.pid}-${Date.now()}-${Object.keys(Client.getClients()).length}`;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
exports.default = Client;
|
|
687
|
+
//# sourceMappingURL=Client.js.map
|