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,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const BotStatus_1 = require("./BotStatus");
|
|
7
|
+
const BotEvents_1 = __importDefault(require("./BotEvents"));
|
|
8
|
+
class BotBase extends BotEvents_1.default {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.id = '';
|
|
12
|
+
this.status = BotStatus_1.BotStatus.Offline;
|
|
13
|
+
this.phoneNumber = '';
|
|
14
|
+
this.name = '';
|
|
15
|
+
this.profileUrl = '';
|
|
16
|
+
}
|
|
17
|
+
//! #################################################################
|
|
18
|
+
//! ########## MÉTODOS DE CONEXÃO
|
|
19
|
+
//! #################################################################
|
|
20
|
+
async connect(auth) { }
|
|
21
|
+
async reconnect(alert) { }
|
|
22
|
+
async stop(reason) { }
|
|
23
|
+
async logout() { }
|
|
24
|
+
//! #################################################################
|
|
25
|
+
//! ########## MÉTODOS DE MENSAGEM
|
|
26
|
+
//! #################################################################
|
|
27
|
+
async send(message) {
|
|
28
|
+
return message;
|
|
29
|
+
}
|
|
30
|
+
async sendMessage(chat, message, mention) {
|
|
31
|
+
return new Promise(() => { });
|
|
32
|
+
}
|
|
33
|
+
async editMessage(message) { }
|
|
34
|
+
async addReaction(message) { }
|
|
35
|
+
async removeReaction(message) { }
|
|
36
|
+
async readMessage(message) { }
|
|
37
|
+
async removeMessage(message) { }
|
|
38
|
+
async deleteMessage(message) { }
|
|
39
|
+
async downloadStreamMessage(media) {
|
|
40
|
+
return Buffer.from('');
|
|
41
|
+
}
|
|
42
|
+
//! #################################################################
|
|
43
|
+
//! ########## MÉTODOS DO BOT
|
|
44
|
+
//! #################################################################
|
|
45
|
+
async getBotName() {
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
async setBotName(name) { }
|
|
49
|
+
async getBotDescription() {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
async setBotDescription(description) { }
|
|
53
|
+
async getBotProfile(lowQuality) {
|
|
54
|
+
return Buffer.from('');
|
|
55
|
+
}
|
|
56
|
+
async getBotProfileUrl(lowQuality) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
async setBotProfile(image) { }
|
|
60
|
+
//! #################################################################
|
|
61
|
+
//! ########## MÉTODOS DO CHAT
|
|
62
|
+
//! #################################################################
|
|
63
|
+
async getChats() {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
async setChats(chats) { }
|
|
67
|
+
async getChat(chat) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
async updateChat(chat) { }
|
|
71
|
+
async removeChat(chat) { }
|
|
72
|
+
async createChat(chat) { }
|
|
73
|
+
async leaveChat(chat) { }
|
|
74
|
+
async addUserInChat(chat, user) { }
|
|
75
|
+
async removeUserInChat(chat, user) { }
|
|
76
|
+
async promoteUserInChat(chat, user) { }
|
|
77
|
+
async demoteUserInChat(chat, user) { }
|
|
78
|
+
async changeChatStatus(chat, status) { }
|
|
79
|
+
async getChatUsers(chat) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
async getChatAdmins(chat) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
async getChatLeader(chat) {
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
async getChatName(chat) {
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
async setChatName(chat, name) { }
|
|
92
|
+
async getChatDescription(chat) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
async setChatDescription(chat, description) { }
|
|
96
|
+
async getChatProfile(chat, lowQuality) {
|
|
97
|
+
return Buffer.from('');
|
|
98
|
+
}
|
|
99
|
+
async getChatProfileUrl(chat, lowQuality) {
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
102
|
+
async setChatProfile(chat, profile) { }
|
|
103
|
+
async joinChat(code) { }
|
|
104
|
+
async getChatInvite(chat) {
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
async revokeChatInvite(chat) {
|
|
108
|
+
return '';
|
|
109
|
+
}
|
|
110
|
+
async rejectCall(call) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
//! #################################################################
|
|
114
|
+
//! ########## MÉTODOS DO USUÁRIO
|
|
115
|
+
//! #################################################################
|
|
116
|
+
async getUsers() {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
async setUsers(users) { }
|
|
120
|
+
async getUser(user) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
async updateUser(user) { }
|
|
124
|
+
async removeUser(user) { }
|
|
125
|
+
async unblockUser(user) { }
|
|
126
|
+
async blockUser(user) { }
|
|
127
|
+
async getUserName(user) {
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
async setUserName(user, name) { }
|
|
131
|
+
async getUserDescription(user) {
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
async setUserDescription(user, description) { }
|
|
135
|
+
async getUserProfile(user) {
|
|
136
|
+
return Buffer.from('');
|
|
137
|
+
}
|
|
138
|
+
async getUserProfileUrl(user, lowQuality) {
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
async setUserProfile(user, profile) { }
|
|
142
|
+
}
|
|
143
|
+
exports.default = BotBase;
|
|
144
|
+
//# sourceMappingURL=BotBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BotBase.js","sourceRoot":"","sources":["../../src/bot/BotBase.ts"],"names":[],"mappings":";;;;;AAIA,2CAAwC;AAExC,4DAAoC;AAMpC,MAAqB,OAAQ,SAAQ,mBAAS;IAA9C;;QACS,OAAE,GAAW,EAAE,CAAC;QAChB,WAAM,GAAc,qBAAS,CAAC,OAAO,CAAC;QACtC,gBAAW,GAAW,EAAE,CAAC;QACzB,S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C,WAAW,CAAC,IAAU;QACjC,OAAO,EAAE,CAAC;IACZ,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,IAAU,EAAE,IAAY,IAAkB,CAAC;IAE7D,KAAK,CAAC,kBAAkB,CAAC,IAAU;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC7B,IAAU,EACV,WAAmB,IACH,CAAC;IAEZ,KAAK,CAAC,cAAc,CAAC,IAAU;QACpC,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAC5B,IAAU,EACV,UAAoB;QAEpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAU,EAAE,OAAe,IAAkB,CAAC;CAC3E;AA9ND,0BA8NC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type UserEvent from '../modules/user/UserEvent';
|
|
2
|
+
import type UserAction from '../modules/user/UserAction';
|
|
3
|
+
import type ChatAction from '../modules/chat/ChatAction';
|
|
4
|
+
import EventEmitter from 'events';
|
|
5
|
+
import Chat from '../modules/chat/Chat';
|
|
6
|
+
import User from '../modules/user/User';
|
|
7
|
+
import Call from '../models/Call';
|
|
8
|
+
import Message from '../messages/Message';
|
|
9
|
+
/**
|
|
10
|
+
* Mapeia os eventos disponíveis para um bot.
|
|
11
|
+
*/
|
|
12
|
+
export type BotEventsMap = {
|
|
13
|
+
/** Ocorre quando o bot é conectado. */
|
|
14
|
+
open: {
|
|
15
|
+
isNewLogin: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** Ocorre quando o bot está reconectando. */
|
|
18
|
+
reconnecting: object;
|
|
19
|
+
/** Ocorre quando o bot está se conectando. */
|
|
20
|
+
connecting: object;
|
|
21
|
+
/** Ocorre quando a conexão com o bot é interrompida. */
|
|
22
|
+
stop: {
|
|
23
|
+
/** O bot se desconectou */
|
|
24
|
+
isLogout: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** Ocorre quando a conexão com o bot é fechada. */
|
|
27
|
+
close: {
|
|
28
|
+
/** Motivo da desconeção */
|
|
29
|
+
reason: any;
|
|
30
|
+
};
|
|
31
|
+
/** Ocorre quando um código QR é gerado para autenticação. */
|
|
32
|
+
qr: string;
|
|
33
|
+
/** Ocorre quando um código de autenticação é gerado. */
|
|
34
|
+
code: string;
|
|
35
|
+
/** Ocorre quando ocorre um evento relacionado a um usuário. */
|
|
36
|
+
user: {
|
|
37
|
+
action: UserAction;
|
|
38
|
+
event: UserEvent;
|
|
39
|
+
chat: Chat;
|
|
40
|
+
user: User;
|
|
41
|
+
fromUser: User;
|
|
42
|
+
};
|
|
43
|
+
/** Ocorre quando ocorre um evento relacionado a uma sala de bate-papo. */
|
|
44
|
+
chat: {
|
|
45
|
+
action: ChatAction;
|
|
46
|
+
chat: {
|
|
47
|
+
id: string;
|
|
48
|
+
} & Partial<Chat>;
|
|
49
|
+
};
|
|
50
|
+
/** Ocorre quando uma nova mensagem é recebida pelo bot. */
|
|
51
|
+
message: Message;
|
|
52
|
+
/** Ocorre ao receber uma atualizaçãod e chamada */
|
|
53
|
+
call: Call;
|
|
54
|
+
/** Ocorre quando um erro é detectado. */
|
|
55
|
+
error: Error;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Classe que lida com os eventos do bot e permite registrar ou remover ouvintes para esses eventos.
|
|
59
|
+
*/
|
|
60
|
+
export default class BotEvents {
|
|
61
|
+
ev: EventEmitter<[never]>;
|
|
62
|
+
eventsIsStoped: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Registra um ouvinte para um evento específico.
|
|
65
|
+
* @param eventName - O nome do evento ao qual o ouvinte será associado.
|
|
66
|
+
* @param listener - A função que será chamada quando o evento ocorrer.
|
|
67
|
+
*/
|
|
68
|
+
on<T extends keyof BotEventsMap>(eventName: T, listener: (arg: BotEventsMap[T]) => void): void;
|
|
69
|
+
/**
|
|
70
|
+
* Remove um ouvinte para um evento específico.
|
|
71
|
+
* @param eventName - O nome do evento do qual o ouvinte será removido.
|
|
72
|
+
* @param listener - A função de ouvinte a ser removida.
|
|
73
|
+
*/
|
|
74
|
+
off<T extends keyof BotEventsMap>(eventName: T, listener: (arg: BotEventsMap[T]) => void): void;
|
|
75
|
+
/**
|
|
76
|
+
* Remove todos os ouvintes associados a um evento específico.
|
|
77
|
+
* @param event - O nome do evento do qual todos os ouvintes serão removidos.
|
|
78
|
+
*/
|
|
79
|
+
removeAllListeners<T extends keyof BotEventsMap>(event: T): void;
|
|
80
|
+
/**
|
|
81
|
+
* Emite um evento e chama todos os ouvintes registrados para esse evento.
|
|
82
|
+
* @param eventName - O nome do evento a ser emitido.
|
|
83
|
+
* @param arg - Os argumentos a serem passados para os ouvintes.
|
|
84
|
+
* @returns Verdadeiro se algum ouvinte for chamado, caso contrário, falso.
|
|
85
|
+
*/
|
|
86
|
+
emit<T extends keyof BotEventsMap>(eventName: T, arg: BotEventsMap[T]): boolean;
|
|
87
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const events_1 = __importDefault(require("events"));
|
|
7
|
+
/**
|
|
8
|
+
* Classe que lida com os eventos do bot e permite registrar ou remover ouvintes para esses eventos.
|
|
9
|
+
*/
|
|
10
|
+
class BotEvents {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.ev = new events_1.default();
|
|
13
|
+
this.eventsIsStoped = false;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registra um ouvinte para um evento específico.
|
|
17
|
+
* @param eventName - O nome do evento ao qual o ouvinte será associado.
|
|
18
|
+
* @param listener - A função que será chamada quando o evento ocorrer.
|
|
19
|
+
*/
|
|
20
|
+
on(eventName, listener) {
|
|
21
|
+
this.ev.on(eventName, listener);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Remove um ouvinte para um evento específico.
|
|
25
|
+
* @param eventName - O nome do evento do qual o ouvinte será removido.
|
|
26
|
+
* @param listener - A função de ouvinte a ser removida.
|
|
27
|
+
*/
|
|
28
|
+
off(eventName, listener) {
|
|
29
|
+
this.ev.off(eventName, listener);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Remove todos os ouvintes associados a um evento específico.
|
|
33
|
+
* @param event - O nome do evento do qual todos os ouvintes serão removidos.
|
|
34
|
+
*/
|
|
35
|
+
removeAllListeners(event) {
|
|
36
|
+
this.ev.removeAllListeners(event);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Emite um evento e chama todos os ouvintes registrados para esse evento.
|
|
40
|
+
* @param eventName - O nome do evento a ser emitido.
|
|
41
|
+
* @param arg - Os argumentos a serem passados para os ouvintes.
|
|
42
|
+
* @returns Verdadeiro se algum ouvinte for chamado, caso contrário, falso.
|
|
43
|
+
*/
|
|
44
|
+
emit(eventName, arg) {
|
|
45
|
+
if (this.eventsIsStoped)
|
|
46
|
+
return false;
|
|
47
|
+
return this.ev.emit(eventName, arg);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = BotEvents;
|
|
51
|
+
//# sourceMappingURL=BotEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BotEvents.js","sourceRoot":"","sources":["../../src/bot/BotEvents.ts"],"names":[],"mappings":";;;;;AAIA,oDAAkC;AAqDlC;;GAEG;AACH,MAAqB,SAAS;IAA9B;QACS,OAAE,GAAG,IAAI,gBAAY,EAAE,CAAC;QACxB,mBAAc,GAAY,KAAK,CAAC;IAgDzC,CAAC;IA9CC;;;;OAIG;IACI,EAAE,CACP,SAAY,EACZ,QAAwC;QAExC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,GAAG,CACR,SAAY,EACZ,QAAwC;QAExC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAA+B,KAAQ;QAC9D,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,IAAI,CACT,SAAY,EACZ,GAAoB;QAEpB,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,KAAK,CAAC;QAEtC,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACtC,CAAC;CACF;AAlDD,4BAkDC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Server } from 'http';
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
|
+
import IBot from './IBot';
|
|
4
|
+
import { ServerRequest } from '../utils/server';
|
|
5
|
+
export type BotServerOptions = {
|
|
6
|
+
serverId: string;
|
|
7
|
+
server: Server;
|
|
8
|
+
port: number;
|
|
9
|
+
disableAutoStart?: boolean;
|
|
10
|
+
pingInterval: number;
|
|
11
|
+
maxPing: number;
|
|
12
|
+
logger: Logger;
|
|
13
|
+
version: 'apiV1';
|
|
14
|
+
};
|
|
15
|
+
export type BotWebhook = {
|
|
16
|
+
id: string;
|
|
17
|
+
url: string;
|
|
18
|
+
ping: number;
|
|
19
|
+
};
|
|
20
|
+
export interface BotServerBase {
|
|
21
|
+
options: BotServerOptions;
|
|
22
|
+
webhooks: Record<string, BotWebhook>;
|
|
23
|
+
sendAll(body: ServerRequest.Body): Promise<void>;
|
|
24
|
+
pingWebhook(id: string): Promise<boolean>;
|
|
25
|
+
registerWebhook(webhook: BotWebhook): void;
|
|
26
|
+
removeWebhook(id: string): boolean;
|
|
27
|
+
}
|
|
28
|
+
export type BotServer<Bot extends IBot = IBot> = Bot & BotServerBase & {
|
|
29
|
+
configEvents(): void;
|
|
30
|
+
configRoutes(): Server;
|
|
31
|
+
};
|
|
32
|
+
export default function BotServer<Bot extends IBot = IBot>(bot: Bot, options?: Partial<BotServerOptions>): BotServer<Bot>;
|
|
33
|
+
export declare function generateBotServerBase(partialOptions?: Partial<BotServerOptions>): BotServerBase;
|
|
34
|
+
export declare function generateBotServerOptions(options: Partial<BotServerOptions>): BotServerOptions;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = BotServer;
|
|
7
|
+
exports.generateBotServerBase = generateBotServerBase;
|
|
8
|
+
exports.generateBotServerOptions = generateBotServerOptions;
|
|
9
|
+
const http_1 = require("http");
|
|
10
|
+
const express_1 = __importDefault(require("express"));
|
|
11
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
12
|
+
const pino_1 = __importDefault(require("pino"));
|
|
13
|
+
const routes_1 = require("../routes/botServer/routes");
|
|
14
|
+
const server_1 = require("../utils/server");
|
|
15
|
+
const nonce_1 = __importDefault(require("../utils/nonce"));
|
|
16
|
+
function BotServer(bot, options = {}) {
|
|
17
|
+
if (!bot || typeof bot !== 'object') {
|
|
18
|
+
throw new Error('Invalid bot');
|
|
19
|
+
}
|
|
20
|
+
const botServer = {
|
|
21
|
+
...bot,
|
|
22
|
+
...generateBotServerBase(options),
|
|
23
|
+
configRoutes() {
|
|
24
|
+
const app = (0, express_1.default)();
|
|
25
|
+
app.use(body_parser_1.default.json({ limit: Infinity }));
|
|
26
|
+
app.use(body_parser_1.default.urlencoded({ extended: true }));
|
|
27
|
+
if (botServer.options.version == 'apiV1') {
|
|
28
|
+
app.use(`/${botServer.options.serverId}`, (0, routes_1.apiV1)(botServer));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
app.use(`/${botServer.options.serverId}`, (0, routes_1.apiV1)(botServer));
|
|
32
|
+
}
|
|
33
|
+
botServer.options.server.on('request', app);
|
|
34
|
+
return botServer.options.server;
|
|
35
|
+
},
|
|
36
|
+
configEvents() {
|
|
37
|
+
const emit = (eventName, arg) => {
|
|
38
|
+
botServer.sendAll(server_1.ServerRequest.generate(server_1.ServerRequest.RequestMethod.EMIT, eventName, arg));
|
|
39
|
+
return bot.ev.emit(eventName, arg);
|
|
40
|
+
};
|
|
41
|
+
bot.emit = emit;
|
|
42
|
+
botServer.emit = emit;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
botServer.configRoutes();
|
|
46
|
+
if (!options.disableAutoStart) {
|
|
47
|
+
botServer.options.server.listen(options.port, () => {
|
|
48
|
+
botServer.options.logger.info(`Bot Server "${botServer.options.serverId}" is running on port ${botServer.options.port}`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return botServer;
|
|
52
|
+
}
|
|
53
|
+
function generateBotServerBase(partialOptions = {}) {
|
|
54
|
+
const options = generateBotServerOptions(partialOptions);
|
|
55
|
+
const webhooks = {};
|
|
56
|
+
return {
|
|
57
|
+
options,
|
|
58
|
+
webhooks,
|
|
59
|
+
async sendAll(body) {
|
|
60
|
+
await Promise.all(Object.values(this.webhooks).map(async (webhook) => {
|
|
61
|
+
try {
|
|
62
|
+
const exists = await this.pingWebhook(webhook.id);
|
|
63
|
+
if (!exists)
|
|
64
|
+
return;
|
|
65
|
+
await server_1.ServerRequest.send(webhook.url, body);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.options.logger.error(JSON.stringify(server_1.ServerResponse.generateError(error), undefined, 2));
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
},
|
|
72
|
+
async pingWebhook(id) {
|
|
73
|
+
try {
|
|
74
|
+
await new Promise((res) => setTimeout(res, this.options.pingInterval));
|
|
75
|
+
const webhook = this.webhooks[id];
|
|
76
|
+
if (!webhook)
|
|
77
|
+
return false;
|
|
78
|
+
if (webhook.ping >= this.options.maxPing) {
|
|
79
|
+
this.removeWebhook(id);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
await server_1.ServerRequest.ping(webhook.url);
|
|
83
|
+
webhook.ping = 0;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const webhook = this.webhooks[id];
|
|
88
|
+
if (!webhook)
|
|
89
|
+
return false;
|
|
90
|
+
webhook.ping += 1;
|
|
91
|
+
}
|
|
92
|
+
return await this.pingWebhook(id);
|
|
93
|
+
},
|
|
94
|
+
registerWebhook(webhook) {
|
|
95
|
+
this.webhooks[webhook.id] = webhook;
|
|
96
|
+
},
|
|
97
|
+
removeWebhook(id) {
|
|
98
|
+
if (!this.webhooks[id])
|
|
99
|
+
return false;
|
|
100
|
+
delete this.webhooks[id];
|
|
101
|
+
return true;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function generateBotServerOptions(options) {
|
|
106
|
+
const botServerOptions = {
|
|
107
|
+
serverId: options.serverId || (0, nonce_1.default)(),
|
|
108
|
+
server: options.server || (0, http_1.createServer)(),
|
|
109
|
+
port: options.port || 8080,
|
|
110
|
+
disableAutoStart: !!options.disableAutoStart,
|
|
111
|
+
pingInterval: options.pingInterval || 10000,
|
|
112
|
+
maxPing: options.maxPing || 6,
|
|
113
|
+
logger: options.logger || (0, pino_1.default)(),
|
|
114
|
+
version: 'apiV1',
|
|
115
|
+
};
|
|
116
|
+
return botServerOptions;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=BotServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BotServer.js","sourceRoot":"","sources":["../../src/bot/BotServer.ts"],"names":[],"mappings":";;;;;AA6CA,4BA4DC;AAED,sDAsEC;AAED,4DAeC;AAlMD,+BAA4C;AAC5C,sDAA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AC,EAAE,CAAC,GAAG,OAAO,CAAC;QACtC,CAAC;QAED,aAAa,CAAC,EAAU;YACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAAE,OAAO,KAAK,CAAC;YAErC,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAEzB,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,wBAAwB,CACtC,OAAkC;IAElC,MAAM,gBAAgB,GAAqB;QACzC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAA,eAAK,GAAE;QACrC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAA,mBAAY,GAAE;QACxC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;QAC1B,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB;QAC5C,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,KAAK;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC;QAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAA,cAAI,GAAE;QAChC,OAAO,EAAE,OAAO;KACjB,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotStatus = void 0;
|
|
4
|
+
var BotStatus;
|
|
5
|
+
(function (BotStatus) {
|
|
6
|
+
BotStatus["Online"] = "online";
|
|
7
|
+
BotStatus["Offline"] = "offline";
|
|
8
|
+
})(BotStatus || (exports.BotStatus = BotStatus = {}));
|
|
9
|
+
//# sourceMappingURL=BotStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BotStatus.js","sourceRoot":"","sources":["../../src/bot/BotStatus.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,gCAAmB,CAAA;AACrB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB"}
|