botify-wa 0.2.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 +23 -0
- package/README.md +101 -0
- package/bin/botify.js +198 -0
- package/package.json +61 -0
- package/src/Bot.js +327 -0
- package/src/Context.js +185 -0
- package/src/PluginManager.js +131 -0
- package/src/config/index.js +2 -0
- package/src/config/parser.js +114 -0
- package/src/config/schema.js +106 -0
- package/src/index.js +18 -0
- package/src/loader.js +87 -0
- package/src/middlewares/antiSpam.js +75 -0
- package/src/middlewares/cooldown.js +81 -0
- package/src/middlewares/index.js +4 -0
- package/src/middlewares/logger.js +47 -0
- package/src/middlewares/permission.js +60 -0
- package/src/templates/config.bt +37 -0
- package/src/templates/index.js +34 -0
- package/src/templates/plugins/info.js +25 -0
- package/src/templates/plugins/menu.js +30 -0
- package/src/templates/plugins/ping.js +13 -0
- package/vendor/core/WAProto/GenerateStatics.sh +3 -0
- package/vendor/core/WAProto/WAProto.proto +6035 -0
- package/vendor/core/WAProto/fix-imports.js +81 -0
- package/vendor/core/WAProto/index.d.ts +2 -0
- package/vendor/core/WAProto/index.js +132326 -0
- package/vendor/core/lib/Defaults/index.d.ts +74 -0
- package/vendor/core/lib/Defaults/index.d.ts.map +1 -0
- package/vendor/core/lib/Defaults/index.js +140 -0
- package/vendor/core/lib/Defaults/index.js.map +1 -0
- package/vendor/core/lib/Modded/message_builder.js +2330 -0
- package/vendor/core/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/vendor/core/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/ciphertext-message.js +12 -0
- package/vendor/core/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/vendor/core/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/vendor/core/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/group-session-builder.js +30 -0
- package/vendor/core/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/vendor/core/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/vendor/core/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/group_cipher.js +82 -0
- package/vendor/core/lib/Signal/Group/group_cipher.js.map +1 -0
- package/vendor/core/lib/Signal/Group/index.d.ts +12 -0
- package/vendor/core/lib/Signal/Group/index.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/index.js +12 -0
- package/vendor/core/lib/Signal/Group/index.js.map +1 -0
- package/vendor/core/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/vendor/core/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/keyhelper.js +18 -0
- package/vendor/core/lib/Signal/Group/keyhelper.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/vendor/core/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-chain-key.js +26 -0
- package/vendor/core/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/vendor/core/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/vendor/core/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/vendor/core/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-message.js +66 -0
- package/vendor/core/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/vendor/core/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-name.js +48 -0
- package/vendor/core/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/vendor/core/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-record.js +41 -0
- package/vendor/core/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/vendor/core/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-key-state.js +84 -0
- package/vendor/core/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/vendor/core/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/vendor/core/lib/Signal/Group/sender-message-key.js +26 -0
- package/vendor/core/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/vendor/core/lib/Signal/libsignal.d.ts +5 -0
- package/vendor/core/lib/Signal/libsignal.d.ts.map +1 -0
- package/vendor/core/lib/Signal/libsignal.js +403 -0
- package/vendor/core/lib/Signal/libsignal.js.map +1 -0
- package/vendor/core/lib/Signal/lid-mapping.d.ts +19 -0
- package/vendor/core/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/vendor/core/lib/Signal/lid-mapping.js +271 -0
- package/vendor/core/lib/Signal/lid-mapping.js.map +1 -0
- package/vendor/core/lib/Socket/Client/index.d.ts +3 -0
- package/vendor/core/lib/Socket/Client/index.d.ts.map +1 -0
- package/vendor/core/lib/Socket/Client/index.js +3 -0
- package/vendor/core/lib/Socket/Client/index.js.map +1 -0
- package/vendor/core/lib/Socket/Client/types.d.ts +16 -0
- package/vendor/core/lib/Socket/Client/types.d.ts.map +1 -0
- package/vendor/core/lib/Socket/Client/types.js +11 -0
- package/vendor/core/lib/Socket/Client/types.js.map +1 -0
- package/vendor/core/lib/Socket/Client/websocket.d.ts +13 -0
- package/vendor/core/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/vendor/core/lib/Socket/Client/websocket.js +54 -0
- package/vendor/core/lib/Socket/Client/websocket.js.map +1 -0
- package/vendor/core/lib/Socket/business.d.ts +536 -0
- package/vendor/core/lib/Socket/business.d.ts.map +1 -0
- package/vendor/core/lib/Socket/business.js +422 -0
- package/vendor/core/lib/Socket/business.js.map +1 -0
- package/vendor/core/lib/Socket/chats.d.ts +111 -0
- package/vendor/core/lib/Socket/chats.d.ts.map +1 -0
- package/vendor/core/lib/Socket/chats.js +991 -0
- package/vendor/core/lib/Socket/chats.js.map +1 -0
- package/vendor/core/lib/Socket/communities.d.ts +645 -0
- package/vendor/core/lib/Socket/communities.d.ts.map +1 -0
- package/vendor/core/lib/Socket/communities.js +431 -0
- package/vendor/core/lib/Socket/communities.js.map +1 -0
- package/vendor/core/lib/Socket/dugong.d.ts +130 -0
- package/vendor/core/lib/Socket/dugong.d.ts.map +1 -0
- package/vendor/core/lib/Socket/dugong.js +768 -0
- package/vendor/core/lib/Socket/dugong.js.map +1 -0
- package/vendor/core/lib/Socket/groups.d.ts +150 -0
- package/vendor/core/lib/Socket/groups.d.ts.map +1 -0
- package/vendor/core/lib/Socket/groups.js +327 -0
- package/vendor/core/lib/Socket/groups.js.map +1 -0
- package/vendor/core/lib/Socket/index.d.ts +636 -0
- package/vendor/core/lib/Socket/index.d.ts.map +1 -0
- package/vendor/core/lib/Socket/index.js +15 -0
- package/vendor/core/lib/Socket/index.js.map +1 -0
- package/vendor/core/lib/Socket/messages-recv.d.ts +238 -0
- package/vendor/core/lib/Socket/messages-recv.d.ts.map +1 -0
- package/vendor/core/lib/Socket/messages-recv.js +1308 -0
- package/vendor/core/lib/Socket/messages-recv.js.map +1 -0
- package/vendor/core/lib/Socket/messages-send.d.ts +579 -0
- package/vendor/core/lib/Socket/messages-send.d.ts.map +1 -0
- package/vendor/core/lib/Socket/messages-send.js +1595 -0
- package/vendor/core/lib/Socket/messages-send.js.map +1 -0
- package/vendor/core/lib/Socket/mex.d.ts +3 -0
- package/vendor/core/lib/Socket/mex.d.ts.map +1 -0
- package/vendor/core/lib/Socket/mex.js +48 -0
- package/vendor/core/lib/Socket/mex.js.map +1 -0
- package/vendor/core/lib/Socket/newsletter.d.ts +177 -0
- package/vendor/core/lib/Socket/newsletter.d.ts.map +1 -0
- package/vendor/core/lib/Socket/newsletter.js +456 -0
- package/vendor/core/lib/Socket/newsletter.js.map +1 -0
- package/vendor/core/lib/Socket/socket.d.ts +55 -0
- package/vendor/core/lib/Socket/socket.d.ts.map +1 -0
- package/vendor/core/lib/Socket/socket.js +936 -0
- package/vendor/core/lib/Socket/socket.js.map +1 -0
- package/vendor/core/lib/Types/Auth.d.ts +116 -0
- package/vendor/core/lib/Types/Auth.d.ts.map +1 -0
- package/vendor/core/lib/Types/Auth.js +2 -0
- package/vendor/core/lib/Types/Auth.js.map +1 -0
- package/vendor/core/lib/Types/Bussines.d.ts +37 -0
- package/vendor/core/lib/Types/Bussines.d.ts.map +1 -0
- package/vendor/core/lib/Types/Bussines.js +2 -0
- package/vendor/core/lib/Types/Bussines.js.map +1 -0
- package/vendor/core/lib/Types/Call.d.ts +15 -0
- package/vendor/core/lib/Types/Call.d.ts.map +1 -0
- package/vendor/core/lib/Types/Call.js +2 -0
- package/vendor/core/lib/Types/Call.js.map +1 -0
- package/vendor/core/lib/Types/Chat.d.ts +123 -0
- package/vendor/core/lib/Types/Chat.d.ts.map +1 -0
- package/vendor/core/lib/Types/Chat.js +8 -0
- package/vendor/core/lib/Types/Chat.js.map +1 -0
- package/vendor/core/lib/Types/Contact.d.ts +24 -0
- package/vendor/core/lib/Types/Contact.d.ts.map +1 -0
- package/vendor/core/lib/Types/Contact.js +2 -0
- package/vendor/core/lib/Types/Contact.js.map +1 -0
- package/vendor/core/lib/Types/Events.d.ts +237 -0
- package/vendor/core/lib/Types/Events.d.ts.map +1 -0
- package/vendor/core/lib/Types/Events.js +2 -0
- package/vendor/core/lib/Types/Events.js.map +1 -0
- package/vendor/core/lib/Types/GroupMetadata.d.ts +68 -0
- package/vendor/core/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/vendor/core/lib/Types/GroupMetadata.js +2 -0
- package/vendor/core/lib/Types/GroupMetadata.js.map +1 -0
- package/vendor/core/lib/Types/Label.d.ts +47 -0
- package/vendor/core/lib/Types/Label.d.ts.map +1 -0
- package/vendor/core/lib/Types/Label.js +25 -0
- package/vendor/core/lib/Types/Label.js.map +1 -0
- package/vendor/core/lib/Types/LabelAssociation.d.ts +30 -0
- package/vendor/core/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/vendor/core/lib/Types/LabelAssociation.js +7 -0
- package/vendor/core/lib/Types/LabelAssociation.js.map +1 -0
- package/vendor/core/lib/Types/Message.d.ts +422 -0
- package/vendor/core/lib/Types/Message.d.ts.map +1 -0
- package/vendor/core/lib/Types/Message.js +11 -0
- package/vendor/core/lib/Types/Message.js.map +1 -0
- package/vendor/core/lib/Types/Newsletter.d.ts +135 -0
- package/vendor/core/lib/Types/Newsletter.d.ts.map +1 -0
- package/vendor/core/lib/Types/Newsletter.js +31 -0
- package/vendor/core/lib/Types/Newsletter.js.map +1 -0
- package/vendor/core/lib/Types/Product.d.ts +79 -0
- package/vendor/core/lib/Types/Product.d.ts.map +1 -0
- package/vendor/core/lib/Types/Product.js +2 -0
- package/vendor/core/lib/Types/Product.js.map +1 -0
- package/vendor/core/lib/Types/Signal.d.ts +76 -0
- package/vendor/core/lib/Types/Signal.d.ts.map +1 -0
- package/vendor/core/lib/Types/Signal.js +2 -0
- package/vendor/core/lib/Types/Signal.js.map +1 -0
- package/vendor/core/lib/Types/Socket.d.ts +158 -0
- package/vendor/core/lib/Types/Socket.d.ts.map +1 -0
- package/vendor/core/lib/Types/Socket.js +3 -0
- package/vendor/core/lib/Types/Socket.js.map +1 -0
- package/vendor/core/lib/Types/State.d.ts +39 -0
- package/vendor/core/lib/Types/State.d.ts.map +1 -0
- package/vendor/core/lib/Types/State.js +13 -0
- package/vendor/core/lib/Types/State.js.map +1 -0
- package/vendor/core/lib/Types/USync.d.ts +26 -0
- package/vendor/core/lib/Types/USync.d.ts.map +1 -0
- package/vendor/core/lib/Types/USync.js +2 -0
- package/vendor/core/lib/Types/USync.js.map +1 -0
- package/vendor/core/lib/Types/index.d.ts +66 -0
- package/vendor/core/lib/Types/index.d.ts.map +1 -0
- package/vendor/core/lib/Types/index.js +33 -0
- package/vendor/core/lib/Types/index.js.map +1 -0
- package/vendor/core/lib/Utils/auth-utils.d.ts +19 -0
- package/vendor/core/lib/Utils/auth-utils.d.ts.map +1 -0
- package/vendor/core/lib/Utils/auth-utils.js +290 -0
- package/vendor/core/lib/Utils/auth-utils.js.map +1 -0
- package/vendor/core/lib/Utils/browser-utils.d.ts +4 -0
- package/vendor/core/lib/Utils/browser-utils.d.ts.map +1 -0
- package/vendor/core/lib/Utils/browser-utils.js +28 -0
- package/vendor/core/lib/Utils/browser-utils.js.map +1 -0
- package/vendor/core/lib/Utils/business.d.ts +23 -0
- package/vendor/core/lib/Utils/business.d.ts.map +1 -0
- package/vendor/core/lib/Utils/business.js +231 -0
- package/vendor/core/lib/Utils/business.js.map +1 -0
- package/vendor/core/lib/Utils/chat-utils.d.ts +70 -0
- package/vendor/core/lib/Utils/chat-utils.d.ts.map +1 -0
- package/vendor/core/lib/Utils/chat-utils.js +812 -0
- package/vendor/core/lib/Utils/chat-utils.js.map +1 -0
- package/vendor/core/lib/Utils/crypto.d.ts +37 -0
- package/vendor/core/lib/Utils/crypto.d.ts.map +1 -0
- package/vendor/core/lib/Utils/crypto.js +118 -0
- package/vendor/core/lib/Utils/crypto.js.map +1 -0
- package/vendor/core/lib/Utils/decode-wa-message.d.ts +48 -0
- package/vendor/core/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/vendor/core/lib/Utils/decode-wa-message.js +283 -0
- package/vendor/core/lib/Utils/decode-wa-message.js.map +1 -0
- package/vendor/core/lib/Utils/event-buffer.d.ts +34 -0
- package/vendor/core/lib/Utils/event-buffer.d.ts.map +1 -0
- package/vendor/core/lib/Utils/event-buffer.js +574 -0
- package/vendor/core/lib/Utils/event-buffer.js.map +1 -0
- package/vendor/core/lib/Utils/generics.d.ts +91 -0
- package/vendor/core/lib/Utils/generics.d.ts.map +1 -0
- package/vendor/core/lib/Utils/generics.js +384 -0
- package/vendor/core/lib/Utils/generics.js.map +1 -0
- package/vendor/core/lib/Utils/history.d.ts +22 -0
- package/vendor/core/lib/Utils/history.d.ts.map +1 -0
- package/vendor/core/lib/Utils/history.js +131 -0
- package/vendor/core/lib/Utils/history.js.map +1 -0
- package/vendor/core/lib/Utils/identity-change-handler.d.ts +37 -0
- package/vendor/core/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/vendor/core/lib/Utils/identity-change-handler.js +49 -0
- package/vendor/core/lib/Utils/identity-change-handler.js.map +1 -0
- package/vendor/core/lib/Utils/index.d.ts +23 -0
- package/vendor/core/lib/Utils/index.d.ts.map +1 -0
- package/vendor/core/lib/Utils/index.js +23 -0
- package/vendor/core/lib/Utils/index.js.map +1 -0
- package/vendor/core/lib/Utils/link-preview.d.ts +21 -0
- package/vendor/core/lib/Utils/link-preview.d.ts.map +1 -0
- package/vendor/core/lib/Utils/link-preview.js +85 -0
- package/vendor/core/lib/Utils/link-preview.js.map +1 -0
- package/vendor/core/lib/Utils/logger.d.ts +13 -0
- package/vendor/core/lib/Utils/logger.d.ts.map +1 -0
- package/vendor/core/lib/Utils/logger.js +3 -0
- package/vendor/core/lib/Utils/logger.js.map +1 -0
- package/vendor/core/lib/Utils/lt-hash.d.ts +8 -0
- package/vendor/core/lib/Utils/lt-hash.d.ts.map +1 -0
- package/vendor/core/lib/Utils/lt-hash.js +8 -0
- package/vendor/core/lib/Utils/lt-hash.js.map +1 -0
- package/vendor/core/lib/Utils/make-mutex.d.ts +9 -0
- package/vendor/core/lib/Utils/make-mutex.d.ts.map +1 -0
- package/vendor/core/lib/Utils/make-mutex.js +33 -0
- package/vendor/core/lib/Utils/make-mutex.js.map +1 -0
- package/vendor/core/lib/Utils/message-retry-manager.d.ts +110 -0
- package/vendor/core/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/vendor/core/lib/Utils/message-retry-manager.js +225 -0
- package/vendor/core/lib/Utils/message-retry-manager.js.map +1 -0
- package/vendor/core/lib/Utils/messages-media.d.ts +130 -0
- package/vendor/core/lib/Utils/messages-media.d.ts.map +1 -0
- package/vendor/core/lib/Utils/messages-media.js +782 -0
- package/vendor/core/lib/Utils/messages-media.js.map +1 -0
- package/vendor/core/lib/Utils/messages.d.ts +91 -0
- package/vendor/core/lib/Utils/messages.d.ts.map +1 -0
- package/vendor/core/lib/Utils/messages.js +1240 -0
- package/vendor/core/lib/Utils/messages.js.map +1 -0
- package/vendor/core/lib/Utils/noise-handler.d.ts +20 -0
- package/vendor/core/lib/Utils/noise-handler.d.ts.map +1 -0
- package/vendor/core/lib/Utils/noise-handler.js +201 -0
- package/vendor/core/lib/Utils/noise-handler.js.map +1 -0
- package/vendor/core/lib/Utils/offline-node-processor.d.ts +17 -0
- package/vendor/core/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/vendor/core/lib/Utils/offline-node-processor.js +40 -0
- package/vendor/core/lib/Utils/offline-node-processor.js.map +1 -0
- package/vendor/core/lib/Utils/pre-key-manager.d.ts +28 -0
- package/vendor/core/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/vendor/core/lib/Utils/pre-key-manager.js +106 -0
- package/vendor/core/lib/Utils/pre-key-manager.js.map +1 -0
- package/vendor/core/lib/Utils/process-message.d.ts +60 -0
- package/vendor/core/lib/Utils/process-message.d.ts.map +1 -0
- package/vendor/core/lib/Utils/process-message.js +528 -0
- package/vendor/core/lib/Utils/process-message.js.map +1 -0
- package/vendor/core/lib/Utils/reporting-utils.d.ts +11 -0
- package/vendor/core/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/vendor/core/lib/Utils/reporting-utils.js +258 -0
- package/vendor/core/lib/Utils/reporting-utils.js.map +1 -0
- package/vendor/core/lib/Utils/rich-messages.d.ts +277 -0
- package/vendor/core/lib/Utils/rich-messages.d.ts.map +1 -0
- package/vendor/core/lib/Utils/rich-messages.js +1144 -0
- package/vendor/core/lib/Utils/rich-messages.js.map +1 -0
- package/vendor/core/lib/Utils/signal.d.ts +34 -0
- package/vendor/core/lib/Utils/signal.d.ts.map +1 -0
- package/vendor/core/lib/Utils/signal.js +159 -0
- package/vendor/core/lib/Utils/signal.js.map +1 -0
- package/vendor/core/lib/Utils/stanza-ack.d.ts +11 -0
- package/vendor/core/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/vendor/core/lib/Utils/stanza-ack.js +38 -0
- package/vendor/core/lib/Utils/stanza-ack.js.map +1 -0
- package/vendor/core/lib/Utils/sticker-pack.d.ts +10 -0
- package/vendor/core/lib/Utils/sticker-pack.js +111 -0
- package/vendor/core/lib/Utils/sync-action-utils.d.ts +19 -0
- package/vendor/core/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/vendor/core/lib/Utils/sync-action-utils.js +48 -0
- package/vendor/core/lib/Utils/sync-action-utils.js.map +1 -0
- package/vendor/core/lib/Utils/tc-token-utils.d.ts +12 -0
- package/vendor/core/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/vendor/core/lib/Utils/tc-token-utils.js +18 -0
- package/vendor/core/lib/Utils/tc-token-utils.js.map +1 -0
- package/vendor/core/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/vendor/core/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/vendor/core/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/vendor/core/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/vendor/core/lib/Utils/validate-connection.d.ts +11 -0
- package/vendor/core/lib/Utils/validate-connection.d.ts.map +1 -0
- package/vendor/core/lib/Utils/validate-connection.js +200 -0
- package/vendor/core/lib/Utils/validate-connection.js.map +1 -0
- package/vendor/core/lib/WABinary/constants.d.ts +28 -0
- package/vendor/core/lib/WABinary/constants.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/constants.js +1301 -0
- package/vendor/core/lib/WABinary/constants.js.map +1 -0
- package/vendor/core/lib/WABinary/decode.d.ts +7 -0
- package/vendor/core/lib/WABinary/decode.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/decode.js +262 -0
- package/vendor/core/lib/WABinary/decode.js.map +1 -0
- package/vendor/core/lib/WABinary/encode.d.ts +3 -0
- package/vendor/core/lib/WABinary/encode.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/encode.js +220 -0
- package/vendor/core/lib/WABinary/encode.js.map +1 -0
- package/vendor/core/lib/WABinary/generic-utils.d.ts +17 -0
- package/vendor/core/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/generic-utils.js +191 -0
- package/vendor/core/lib/WABinary/generic-utils.js.map +1 -0
- package/vendor/core/lib/WABinary/index.d.ts +6 -0
- package/vendor/core/lib/WABinary/index.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/index.js +6 -0
- package/vendor/core/lib/WABinary/index.js.map +1 -0
- package/vendor/core/lib/WABinary/jid-utils.d.ts +48 -0
- package/vendor/core/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/jid-utils.js +96 -0
- package/vendor/core/lib/WABinary/jid-utils.js.map +1 -0
- package/vendor/core/lib/WABinary/types.d.ts +19 -0
- package/vendor/core/lib/WABinary/types.d.ts.map +1 -0
- package/vendor/core/lib/WABinary/types.js +2 -0
- package/vendor/core/lib/WABinary/types.js.map +1 -0
- package/vendor/core/lib/WAM/BinaryInfo.d.ts +9 -0
- package/vendor/core/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/vendor/core/lib/WAM/BinaryInfo.js +10 -0
- package/vendor/core/lib/WAM/BinaryInfo.js.map +1 -0
- package/vendor/core/lib/WAM/constants.d.ts +40 -0
- package/vendor/core/lib/WAM/constants.d.ts.map +1 -0
- package/vendor/core/lib/WAM/constants.js +22853 -0
- package/vendor/core/lib/WAM/constants.js.map +1 -0
- package/vendor/core/lib/WAM/encode.d.ts +3 -0
- package/vendor/core/lib/WAM/encode.d.ts.map +1 -0
- package/vendor/core/lib/WAM/encode.js +150 -0
- package/vendor/core/lib/WAM/encode.js.map +1 -0
- package/vendor/core/lib/WAM/index.d.ts +4 -0
- package/vendor/core/lib/WAM/index.d.ts.map +1 -0
- package/vendor/core/lib/WAM/index.js +4 -0
- package/vendor/core/lib/WAM/index.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/vendor/core/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/Protocols/index.js +5 -0
- package/vendor/core/lib/WAUSync/Protocols/index.js.map +1 -0
- package/vendor/core/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/vendor/core/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/USyncQuery.js +94 -0
- package/vendor/core/lib/WAUSync/USyncQuery.js.map +1 -0
- package/vendor/core/lib/WAUSync/USyncUser.d.ts +13 -0
- package/vendor/core/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/USyncUser.js +23 -0
- package/vendor/core/lib/WAUSync/USyncUser.js.map +1 -0
- package/vendor/core/lib/WAUSync/index.d.ts +4 -0
- package/vendor/core/lib/WAUSync/index.d.ts.map +1 -0
- package/vendor/core/lib/WAUSync/index.js +4 -0
- package/vendor/core/lib/WAUSync/index.js.map +1 -0
- package/vendor/core/lib/index.d.ts +13 -0
- package/vendor/core/lib/index.d.ts.map +1 -0
- package/vendor/core/lib/index.js +13 -0
- package/vendor/core/lib/index.js.map +1 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config.bt parser
|
|
3
|
+
* ----------------
|
|
4
|
+
* Parses Botify's TOML-style config file (.bt extension).
|
|
5
|
+
*
|
|
6
|
+
* Supported syntax:
|
|
7
|
+
* # comment
|
|
8
|
+
* key = value
|
|
9
|
+
* key = "string value"
|
|
10
|
+
* key = true / false
|
|
11
|
+
* key = 1234
|
|
12
|
+
* key = ["a", "b", "c"] (inline arrays)
|
|
13
|
+
*
|
|
14
|
+
* [section]
|
|
15
|
+
* key = value
|
|
16
|
+
*
|
|
17
|
+
* Section keys are returned as nested objects:
|
|
18
|
+
* { section: { key: value } }
|
|
19
|
+
*
|
|
20
|
+
* Top-level keys (before any section header) go into the root object.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { readFileSync, existsSync } from "fs";
|
|
24
|
+
import { resolve } from "path";
|
|
25
|
+
|
|
26
|
+
// ─── value coercions ────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
function coerce(raw) {
|
|
29
|
+
const s = raw.trim();
|
|
30
|
+
|
|
31
|
+
// boolean
|
|
32
|
+
if (s === "true") return true;
|
|
33
|
+
if (s === "false") return false;
|
|
34
|
+
|
|
35
|
+
// inline array ["a", 1, true]
|
|
36
|
+
if (s.startsWith("[") && s.endsWith("]")) {
|
|
37
|
+
const inner = s.slice(1, -1).trim();
|
|
38
|
+
if (inner === "") return [];
|
|
39
|
+
return inner.split(",").map((item) => coerce(item.trim()));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// quoted string "hello world"
|
|
43
|
+
if (
|
|
44
|
+
(s.startsWith('"') && s.endsWith('"')) ||
|
|
45
|
+
(s.startsWith("'") && s.endsWith("'"))
|
|
46
|
+
) {
|
|
47
|
+
return s.slice(1, -1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// number
|
|
51
|
+
const n = Number(s);
|
|
52
|
+
if (!Number.isNaN(n) && s !== "") return n;
|
|
53
|
+
|
|
54
|
+
// bare string (unquoted)
|
|
55
|
+
return s;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ─── parser ─────────────────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parse a .bt config string into a plain object.
|
|
62
|
+
* @param {string} src Raw file contents.
|
|
63
|
+
* @returns {Record<string, any>}
|
|
64
|
+
*/
|
|
65
|
+
export function parse(src) {
|
|
66
|
+
const result = {};
|
|
67
|
+
let section = null; // current [section], null = root
|
|
68
|
+
|
|
69
|
+
for (const raw of src.split(/\r?\n/)) {
|
|
70
|
+
const line = raw.trim();
|
|
71
|
+
|
|
72
|
+
// blank line or comment
|
|
73
|
+
if (!line || line.startsWith("#")) continue;
|
|
74
|
+
|
|
75
|
+
// section header [name]
|
|
76
|
+
if (line.startsWith("[") && line.endsWith("]")) {
|
|
77
|
+
section = line.slice(1, -1).trim();
|
|
78
|
+
if (!result[section]) result[section] = {};
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// key = value
|
|
83
|
+
const eqIdx = line.indexOf("=");
|
|
84
|
+
if (eqIdx === -1) continue; // malformed line — skip silently
|
|
85
|
+
|
|
86
|
+
const key = line.slice(0, eqIdx).trim();
|
|
87
|
+
const value = coerce(line.slice(eqIdx + 1));
|
|
88
|
+
|
|
89
|
+
if (section) {
|
|
90
|
+
result[section][key] = value;
|
|
91
|
+
} else {
|
|
92
|
+
result[key] = value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ─── loader ─────────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Load and parse a config.bt file from the given directory.
|
|
103
|
+
* Returns an empty object if the file doesn't exist (config is optional).
|
|
104
|
+
*
|
|
105
|
+
* @param {string} [dir=process.cwd()] Directory to look in.
|
|
106
|
+
* @returns {Record<string, any>}
|
|
107
|
+
*/
|
|
108
|
+
export function loadConfig(dir = process.cwd()) {
|
|
109
|
+
const filePath = resolve(dir, "config.bt");
|
|
110
|
+
if (!existsSync(filePath)) return {};
|
|
111
|
+
|
|
112
|
+
const src = readFileSync(filePath, "utf8");
|
|
113
|
+
return parse(src);
|
|
114
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config.bt schema + merger
|
|
3
|
+
* --------------------------
|
|
4
|
+
* Defines which config.bt keys map to which Bot options, handles type
|
|
5
|
+
* validation with friendly error messages, and merges file config with
|
|
6
|
+
* programmatic options (code always wins on conflict).
|
|
7
|
+
*
|
|
8
|
+
* config.bt keys → Bot option
|
|
9
|
+
* ─────────────────────────────────────────
|
|
10
|
+
* [bot]
|
|
11
|
+
* prefix = "!" → prefix
|
|
12
|
+
* session_path = "./session" → sessionPath
|
|
13
|
+
* log_level = "error" → logLevel
|
|
14
|
+
* print_qr = true → printQR
|
|
15
|
+
* owners = ["628...@s.whatsapp.net"] → owners
|
|
16
|
+
*
|
|
17
|
+
* [reconnect]
|
|
18
|
+
* base_delay = 1000 → reconnectBaseDelay
|
|
19
|
+
* max_delay = 30000 → reconnectMaxDelay
|
|
20
|
+
*
|
|
21
|
+
* [cooldown]
|
|
22
|
+
* default = 0 → defaultCooldown (ms, applied when command omits cooldown)
|
|
23
|
+
* message = "..." → cooldownMessage
|
|
24
|
+
*
|
|
25
|
+
* [anti_spam]
|
|
26
|
+
* enabled = true → antiSpam.enabled
|
|
27
|
+
* window_ms = 5000 → antiSpam.windowMs
|
|
28
|
+
* max_messages = 5 → antiSpam.maxMessages
|
|
29
|
+
* message = "..." → antiSpam.message
|
|
30
|
+
*
|
|
31
|
+
* [permission]
|
|
32
|
+
* owner_message = "..." → permissionMessages.owner
|
|
33
|
+
* admin_message = "..." → permissionMessages.admin
|
|
34
|
+
*
|
|
35
|
+
* [logger]
|
|
36
|
+
* enabled = true → logger.enabled
|
|
37
|
+
* show_pn = true → logger.showPn
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Merge file config (from config.bt) with programmatic options.
|
|
42
|
+
* Programmatic options take priority on every key.
|
|
43
|
+
*
|
|
44
|
+
* @param {Record<string, any>} fileConfig Parsed config.bt output.
|
|
45
|
+
* @param {Record<string, any>} codeOptions Options passed to `new Bot(options)`.
|
|
46
|
+
* @returns {Record<string, any>} Merged, normalised options.
|
|
47
|
+
*/
|
|
48
|
+
export function mergeConfig(fileConfig, codeOptions) {
|
|
49
|
+
const bot = fileConfig.bot ?? {};
|
|
50
|
+
const reconnect = fileConfig.reconnect ?? {};
|
|
51
|
+
const cooldown = fileConfig.cooldown ?? {};
|
|
52
|
+
const antiSpam = fileConfig.anti_spam ?? {};
|
|
53
|
+
const permission = fileConfig.permission ?? {};
|
|
54
|
+
const loggerCfg = fileConfig.logger ?? {};
|
|
55
|
+
|
|
56
|
+
// Build the "file defaults" object using config.bt values.
|
|
57
|
+
const fileDefaults = {
|
|
58
|
+
prefix: bot.prefix,
|
|
59
|
+
sessionPath: bot.session_path,
|
|
60
|
+
logLevel: bot.log_level,
|
|
61
|
+
printQR: bot.print_qr,
|
|
62
|
+
owners: bot.owners,
|
|
63
|
+
reconnectBaseDelay: reconnect.base_delay,
|
|
64
|
+
reconnectMaxDelay: reconnect.max_delay,
|
|
65
|
+
|
|
66
|
+
defaultCooldown: cooldown.default,
|
|
67
|
+
cooldownMessage: cooldown.message,
|
|
68
|
+
|
|
69
|
+
antiSpam: {
|
|
70
|
+
enabled: antiSpam.enabled ?? false,
|
|
71
|
+
windowMs: antiSpam.window_ms,
|
|
72
|
+
maxMessages: antiSpam.max_messages,
|
|
73
|
+
message: antiSpam.message,
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
permissionMessages: {
|
|
77
|
+
owner: permission.owner_message,
|
|
78
|
+
admin: permission.admin_message,
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
logger: {
|
|
82
|
+
enabled: loggerCfg.enabled ?? true,
|
|
83
|
+
showPn: loggerCfg.show_pn,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Code options override file defaults — strip undefined so Object.assign
|
|
88
|
+
// doesn't accidentally overwrite a file value with undefined.
|
|
89
|
+
const clean = (obj) =>
|
|
90
|
+
Object.fromEntries(
|
|
91
|
+
Object.entries(obj).filter(([, v]) => v !== undefined)
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// For nested objects (antiSpam, permissionMessages, logger) we merge one
|
|
95
|
+
// level deep so a partial code override doesn't wipe the file's sub-keys.
|
|
96
|
+
const merged = { ...fileDefaults, ...clean(codeOptions) };
|
|
97
|
+
|
|
98
|
+
for (const nested of ["antiSpam", "permissionMessages", "logger"]) {
|
|
99
|
+
merged[nested] = {
|
|
100
|
+
...fileDefaults[nested],
|
|
101
|
+
...clean(codeOptions[nested] ?? {}),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return merged;
|
|
106
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { Bot } from "./Bot.js";
|
|
2
|
+
export { Context } from "./Context.js";
|
|
3
|
+
export { PluginManager } from "./PluginManager.js";
|
|
4
|
+
export { loadPlugins } from "./loader.js";
|
|
5
|
+
|
|
6
|
+
// Built-in middlewares (auto-registered by Bot).
|
|
7
|
+
// Exported here for advanced users who need manual composition.
|
|
8
|
+
export * as middlewares from "./middlewares/index.js";
|
|
9
|
+
|
|
10
|
+
// Config utilities.
|
|
11
|
+
export { loadConfig, parse as parseConfig } from "./config/parser.js";
|
|
12
|
+
|
|
13
|
+
// Low-level core re-exports for dropping down to raw connection API.
|
|
14
|
+
export {
|
|
15
|
+
DisconnectReason,
|
|
16
|
+
useMultiFileAuthState,
|
|
17
|
+
Dugong,
|
|
18
|
+
} from "../vendor/core/lib/index.js";
|
package/src/loader.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadPlugins
|
|
3
|
+
* -----------
|
|
4
|
+
* Auto-scans a directory and dynamically imports every `.js` file as a
|
|
5
|
+
* plugin. Each plugin file must export a default function that receives
|
|
6
|
+
* the Bot instance and registers its commands/middlewares on it.
|
|
7
|
+
*
|
|
8
|
+
* Plugin file shape:
|
|
9
|
+
*
|
|
10
|
+
* // plugins/ping.js
|
|
11
|
+
* export default function (bot) {
|
|
12
|
+
* bot.command("ping", async (ctx) => {
|
|
13
|
+
* await ctx.reply("pong 🏓");
|
|
14
|
+
* });
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
*
|
|
19
|
+
* import { Bot, loadPlugins } from "botify-wa";
|
|
20
|
+
* const bot = new Bot();
|
|
21
|
+
* await loadPlugins(bot, "./plugins");
|
|
22
|
+
* await bot.start();
|
|
23
|
+
*
|
|
24
|
+
* Files are loaded in alphabetical order so the load sequence is
|
|
25
|
+
* predictable. Subdirectories are ignored — only the top-level `.js`
|
|
26
|
+
* files are loaded. If the directory doesn't exist the function logs a
|
|
27
|
+
* warning and returns without throwing.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { readdirSync, existsSync, statSync } from "fs";
|
|
31
|
+
import { resolve, join, extname } from "path";
|
|
32
|
+
import { pathToFileURL } from "url";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {import('./Bot.js').Bot} bot
|
|
36
|
+
* @param {string} [pluginsDir="./plugins"] Path to the plugins directory,
|
|
37
|
+
* relative to process.cwd() or absolute.
|
|
38
|
+
* @returns {Promise<{ loaded: string[], failed: Array<{ file: string, error: unknown }> }>}
|
|
39
|
+
* Summary of what was loaded and what failed (individual plugin errors
|
|
40
|
+
* never abort the whole scan).
|
|
41
|
+
*/
|
|
42
|
+
export async function loadPlugins(bot, pluginsDir = "./plugins") {
|
|
43
|
+
const dir = resolve(process.cwd(), pluginsDir);
|
|
44
|
+
|
|
45
|
+
if (!existsSync(dir)) {
|
|
46
|
+
console.warn(`[botify] plugins directory not found: ${dir}`);
|
|
47
|
+
return { loaded: [], failed: [] };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Read only top-level .js files, sorted alphabetically.
|
|
51
|
+
const files = readdirSync(dir)
|
|
52
|
+
.filter((f) => extname(f) === ".js" && statSync(join(dir, f)).isFile())
|
|
53
|
+
.sort();
|
|
54
|
+
|
|
55
|
+
if (files.length === 0) {
|
|
56
|
+
console.warn(`[botify] no plugins found in: ${dir}`);
|
|
57
|
+
return { loaded: [], failed: [] };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const loaded = [];
|
|
61
|
+
const failed = [];
|
|
62
|
+
|
|
63
|
+
for (const file of files) {
|
|
64
|
+
const filePath = join(dir, file);
|
|
65
|
+
try {
|
|
66
|
+
const mod = await import(pathToFileURL(filePath).href);
|
|
67
|
+
|
|
68
|
+
if (typeof mod.default !== "function") {
|
|
69
|
+
throw new TypeError(
|
|
70
|
+
`Plugin must export a default function — got ${typeof mod.default}`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
await mod.default(bot);
|
|
75
|
+
loaded.push(file);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`[botify] failed to load plugin "${file}":`, error);
|
|
78
|
+
failed.push({ file, error });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
console.log(
|
|
83
|
+
`[botify] loaded ${loaded.length} plugin(s): ${loaded.join(", ")}`
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return { loaded, failed };
|
|
87
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* antiSpam middleware
|
|
3
|
+
* -------------------
|
|
4
|
+
* Global rate limiter: limits how many commands a single sender can trigger
|
|
5
|
+
* within a rolling time window, regardless of which command they used.
|
|
6
|
+
*
|
|
7
|
+
* Algorithm: sliding window counter per sender.
|
|
8
|
+
* - Each sender gets a bucket: { count, windowStart }.
|
|
9
|
+
* - On every command: if now - windowStart >= windowMs, reset the bucket.
|
|
10
|
+
* - If count >= maxMessages after the reset check, deny and return false.
|
|
11
|
+
* - Otherwise increment count and continue.
|
|
12
|
+
*
|
|
13
|
+
* This is intentionally coarser than the per-command cooldown: it's a
|
|
14
|
+
* last-resort spam brake, not a gameplay mechanic.
|
|
15
|
+
*
|
|
16
|
+
* Stale buckets (senders who haven't sent anything in > windowMs) are
|
|
17
|
+
* pruned lazily on lookup and periodically via a background sweep.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {{
|
|
22
|
+
* windowMs?: number, // rolling window size in ms (default: 5000)
|
|
23
|
+
* maxMessages?: number, // max commands per sender per window (default: 5)
|
|
24
|
+
* message?: string | ((ctx) => string),
|
|
25
|
+
* sweepIntervalMs?: number, // cleanup interval (default: 60_000)
|
|
26
|
+
* }} [opts]
|
|
27
|
+
* @returns {(ctx: import('../Context.js').Context) => false | void}
|
|
28
|
+
*/
|
|
29
|
+
export function antiSpam(opts = {}) {
|
|
30
|
+
const windowMs = opts.windowMs ?? 5_000;
|
|
31
|
+
const maxMessages = opts.maxMessages ?? 5;
|
|
32
|
+
const sweepMs = opts.sweepIntervalMs ?? 60_000;
|
|
33
|
+
|
|
34
|
+
const defaultMsg = `🚫 Slow down! You're sending commands too fast.`;
|
|
35
|
+
|
|
36
|
+
/** @type {Map<string, { count: number, windowStart: number }>} */
|
|
37
|
+
const buckets = new Map();
|
|
38
|
+
|
|
39
|
+
const sweepTimer = setInterval(() => {
|
|
40
|
+
const cutoff = Date.now() - windowMs;
|
|
41
|
+
for (const [k, bucket] of buckets) {
|
|
42
|
+
if (bucket.windowStart < cutoff) buckets.delete(k);
|
|
43
|
+
}
|
|
44
|
+
}, sweepMs);
|
|
45
|
+
|
|
46
|
+
if (sweepTimer.unref) sweepTimer.unref();
|
|
47
|
+
|
|
48
|
+
return (ctx) => {
|
|
49
|
+
if (!ctx.command) return;
|
|
50
|
+
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
const key = ctx.sender;
|
|
53
|
+
let bucket = buckets.get(key);
|
|
54
|
+
|
|
55
|
+
// New sender or expired window — reset.
|
|
56
|
+
if (!bucket || now - bucket.windowStart >= windowMs) {
|
|
57
|
+
bucket = { count: 0, windowStart: now };
|
|
58
|
+
buckets.set(key, bucket);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
bucket.count++;
|
|
62
|
+
|
|
63
|
+
if (bucket.count > maxMessages) {
|
|
64
|
+
const text =
|
|
65
|
+
typeof opts.message === "function"
|
|
66
|
+
? opts.message(ctx)
|
|
67
|
+
: (opts.message ?? defaultMsg);
|
|
68
|
+
|
|
69
|
+
// Fire-and-forget — we don't await here so the chain stops
|
|
70
|
+
// immediately without waiting for the WA send round-trip.
|
|
71
|
+
ctx.reply(text).catch(() => {});
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cooldown middleware
|
|
3
|
+
* -------------------
|
|
4
|
+
* Enforces a per-user, per-command cooldown.
|
|
5
|
+
*
|
|
6
|
+
* Priority order (highest to lowest):
|
|
7
|
+
* 1. opts.cooldown passed to bot.command() — per-command override
|
|
8
|
+
* 2. defaultCooldown from config.bt / Bot() — global default
|
|
9
|
+
* 3. 0 (no cooldown)
|
|
10
|
+
*
|
|
11
|
+
* When a user triggers a cooldown the middleware emits the "cooldown" event
|
|
12
|
+
* on the Bot instance and returns `false` to stop the middleware chain —
|
|
13
|
+
* the command handler is never reached.
|
|
14
|
+
*
|
|
15
|
+
* The store is an in-memory Map keyed "commandName:senderJID". It never
|
|
16
|
+
* grows unboundedly: entries are pruned lazily on each lookup once they've
|
|
17
|
+
* expired, and a periodic sweep cleans up any remaining stale entries every
|
|
18
|
+
* `sweepIntervalMs` milliseconds (default: 5 min).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{
|
|
23
|
+
* defaultCooldown?: number, // ms; 0 = disabled (default)
|
|
24
|
+
* message?: string | ((ctx, remainingMs: number) => string),
|
|
25
|
+
* sweepIntervalMs?: number, // how often to prune expired entries (default: 300_000)
|
|
26
|
+
* emitEvent?: (ctx, remainingMs: number) => void, // hook so Bot can emit "cooldown"
|
|
27
|
+
* }} [opts]
|
|
28
|
+
* @returns {(ctx: import('../Context.js').Context) => Promise<false | void>}
|
|
29
|
+
*/
|
|
30
|
+
export function cooldown(opts = {}) {
|
|
31
|
+
const defaultMs = opts.defaultCooldown ?? 0;
|
|
32
|
+
const sweepMs = opts.sweepIntervalMs ?? 300_000;
|
|
33
|
+
const emitEvent = opts.emitEvent ?? (() => {});
|
|
34
|
+
|
|
35
|
+
/** @type {Map<string, number>} key → expiry timestamp */
|
|
36
|
+
const store = new Map();
|
|
37
|
+
|
|
38
|
+
// Periodic sweep — remove entries whose cooldown has already expired.
|
|
39
|
+
const sweepTimer = setInterval(() => {
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
for (const [k, expiry] of store) {
|
|
42
|
+
if (expiry <= now) store.delete(k);
|
|
43
|
+
}
|
|
44
|
+
}, sweepMs);
|
|
45
|
+
|
|
46
|
+
// Don't keep the process alive just for cleanup.
|
|
47
|
+
if (sweepTimer.unref) sweepTimer.unref();
|
|
48
|
+
|
|
49
|
+
return async (ctx) => {
|
|
50
|
+
if (!ctx.command) return;
|
|
51
|
+
|
|
52
|
+
// Resolve cooldown duration for this command.
|
|
53
|
+
// ctx._commandEntry is attached by PluginManager before running middlewares.
|
|
54
|
+
const commandMs = ctx._commandEntry?.cooldown ?? 0;
|
|
55
|
+
const ms = commandMs > 0 ? commandMs : defaultMs;
|
|
56
|
+
if (ms <= 0) return;
|
|
57
|
+
|
|
58
|
+
const key = `${ctx.command}:${ctx.sender}`;
|
|
59
|
+
const expiry = store.get(key) ?? 0;
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
|
|
62
|
+
if (now < expiry) {
|
|
63
|
+
const remainingMs = expiry - now;
|
|
64
|
+
emitEvent(ctx, remainingMs);
|
|
65
|
+
|
|
66
|
+
if (opts.message) {
|
|
67
|
+
const text =
|
|
68
|
+
typeof opts.message === "function"
|
|
69
|
+
? opts.message(ctx, remainingMs)
|
|
70
|
+
: opts.message;
|
|
71
|
+
await ctx.reply(text);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return false; // stop chain
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Record new expiry — set BEFORE running the handler so concurrent
|
|
78
|
+
// messages from the same user don't both slip through.
|
|
79
|
+
store.set(key, now + ms);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logger middleware
|
|
3
|
+
* ------------------
|
|
4
|
+
* A ready-to-use command logger: who sent it, what chat it came from
|
|
5
|
+
* (private / which group), and what command+args they ran. Built in so
|
|
6
|
+
* production bots don't need to hand-roll this — just `bot.use(logger())`.
|
|
7
|
+
*
|
|
8
|
+
* Handles WhatsApp's LID (Linked ID, @lid) addressing automatically: it
|
|
9
|
+
* always has *a* sender identifier to log (LID or phone-number JID,
|
|
10
|
+
* whichever WhatsApp gave us), and optionally shows the real phone number
|
|
11
|
+
* alongside it when available.
|
|
12
|
+
*
|
|
13
|
+
* Can be disabled via config.bt:
|
|
14
|
+
* [logger]
|
|
15
|
+
* enabled = false
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {{
|
|
20
|
+
* enabled?: boolean, // set false to disable entirely (default: true)
|
|
21
|
+
* logFn?: (line: string) => void, // defaults to console.log
|
|
22
|
+
* showPn?: boolean, // show phone number next to LID when known (default: true)
|
|
23
|
+
* format?: (ctx: import('../Context.js').Context) => string | Promise<string>
|
|
24
|
+
* }} [opts]
|
|
25
|
+
* @returns {(ctx: import('../Context.js').Context) => Promise<void>}
|
|
26
|
+
*/
|
|
27
|
+
export function logger(opts = {}) {
|
|
28
|
+
if (opts.enabled === false) return () => {};
|
|
29
|
+
|
|
30
|
+
const logFn = opts.logFn ?? console.log;
|
|
31
|
+
const showPn = opts.showPn ?? true;
|
|
32
|
+
const format = opts.format ?? ((ctx) => defaultFormat(ctx, showPn));
|
|
33
|
+
|
|
34
|
+
return async (ctx) => {
|
|
35
|
+
if (!ctx.command) return;
|
|
36
|
+
logFn(await format(ctx));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function defaultFormat(ctx, showPn) {
|
|
41
|
+
const chat = await ctx.describeChat();
|
|
42
|
+
const senderLabel = showPn
|
|
43
|
+
? `${ctx.sender}, pn: ${ctx.senderPn ? ctx.senderPn.split("@")[0] : "unknown"}`
|
|
44
|
+
: ctx.sender;
|
|
45
|
+
|
|
46
|
+
return `[cmd] ${ctx.pushName} (${senderLabel}) via ${chat} -> ${ctx.botConfig.prefix}${ctx.command} ${ctx.args.join(" ")}`.trimEnd();
|
|
47
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* permission middleware
|
|
3
|
+
* ---------------------
|
|
4
|
+
* Enforces owner-only and group-admin-only gates for commands that declare
|
|
5
|
+
* `{ owner: true }` or `{ admin: true }` in their options.
|
|
6
|
+
*
|
|
7
|
+
* The command metadata is attached to ctx._commandEntry by PluginManager
|
|
8
|
+
* before the middleware chain runs, so this middleware can read it without
|
|
9
|
+
* needing a reference to the command registry.
|
|
10
|
+
*
|
|
11
|
+
* When access is denied:
|
|
12
|
+
* - The "noPermission" event is emitted on the Bot instance.
|
|
13
|
+
* - An optional message is sent to the chat.
|
|
14
|
+
* - `false` is returned to stop the middleware chain.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {{
|
|
19
|
+
* ownerMessage?: string | ((ctx) => string),
|
|
20
|
+
* adminMessage?: string | ((ctx) => string),
|
|
21
|
+
* emitEvent?: (ctx, reason: "owner" | "admin") => void,
|
|
22
|
+
* }} [opts]
|
|
23
|
+
* @returns {(ctx: import('../Context.js').Context) => Promise<false | void>}
|
|
24
|
+
*/
|
|
25
|
+
export function permission(opts = {}) {
|
|
26
|
+
const emitEvent = opts.emitEvent ?? (() => {});
|
|
27
|
+
|
|
28
|
+
const ownerMsg =
|
|
29
|
+
opts.ownerMessage ?? "🚫 This command is owner-only.";
|
|
30
|
+
const adminMsg =
|
|
31
|
+
opts.adminMessage ?? "🚫 This command is for group admins only.";
|
|
32
|
+
|
|
33
|
+
return async (ctx) => {
|
|
34
|
+
if (!ctx.command) return;
|
|
35
|
+
|
|
36
|
+
const entry = ctx._commandEntry;
|
|
37
|
+
if (!entry) return;
|
|
38
|
+
|
|
39
|
+
// ── owner gate ──────────────────────────────────────────────────────────
|
|
40
|
+
if (entry.owner && !ctx.isOwner) {
|
|
41
|
+
emitEvent(ctx, "owner");
|
|
42
|
+
const text =
|
|
43
|
+
typeof ownerMsg === "function" ? ownerMsg(ctx) : ownerMsg;
|
|
44
|
+
await ctx.reply(text);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ── admin gate ──────────────────────────────────────────────────────────
|
|
49
|
+
if (entry.admin) {
|
|
50
|
+
const isAdmin = await ctx.isGroupAdmin();
|
|
51
|
+
if (!isAdmin) {
|
|
52
|
+
emitEvent(ctx, "admin");
|
|
53
|
+
const text =
|
|
54
|
+
typeof adminMsg === "function" ? adminMsg(ctx) : adminMsg;
|
|
55
|
+
await ctx.reply(text);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# ──────────────────────────────────────────────
|
|
2
|
+
# config.bt — Botify configuration
|
|
3
|
+
# ──────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
[bot]
|
|
6
|
+
prefix = "!"
|
|
7
|
+
session_path = "./session"
|
|
8
|
+
log_level = "error"
|
|
9
|
+
print_qr = true
|
|
10
|
+
# owners = ["628XXXXXXXXXX@s.whatsapp.net"]
|
|
11
|
+
|
|
12
|
+
[reconnect]
|
|
13
|
+
base_delay = 1000
|
|
14
|
+
max_delay = 30000
|
|
15
|
+
|
|
16
|
+
[cooldown]
|
|
17
|
+
default = 0
|
|
18
|
+
# message = "⏳ Tunggu {remaining}s lagi."
|
|
19
|
+
|
|
20
|
+
[anti_spam]
|
|
21
|
+
enabled = false
|
|
22
|
+
window_ms = 5000
|
|
23
|
+
max_messages = 5
|
|
24
|
+
# message = "🚫 Terlalu cepat! Tunggu sebentar."
|
|
25
|
+
|
|
26
|
+
[permission]
|
|
27
|
+
# owner_message = "🚫 Command ini khusus owner bot."
|
|
28
|
+
# admin_message = "🚫 Command ini khusus admin grup."
|
|
29
|
+
|
|
30
|
+
[logger]
|
|
31
|
+
enabled = true
|
|
32
|
+
show_pn = true
|
|
33
|
+
|
|
34
|
+
[plugins]
|
|
35
|
+
# Folder tempat command disimpan (relatif dari root bot).
|
|
36
|
+
# Semua file .js di dalamnya di-load otomatis saat startup.
|
|
37
|
+
dir = "./plugins"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Bot, loadPlugins } from "botify-wa";
|
|
2
|
+
|
|
3
|
+
const bot = new Bot();
|
|
4
|
+
// config.bt di folder ini dibaca otomatis.
|
|
5
|
+
// Kalau mau override satu opsi: new Bot({ prefix: "?" })
|
|
6
|
+
|
|
7
|
+
// Load semua command dari folder plugins/ secara otomatis.
|
|
8
|
+
await loadPlugins(bot, "./plugins");
|
|
9
|
+
|
|
10
|
+
// ── Framework events ─────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
bot.on("ready", () => {
|
|
13
|
+
console.log("✅ Bot online!");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
bot.on("disconnect", ({ willReconnect, reconnectDelayMs, attempt }) => {
|
|
17
|
+
if (willReconnect) {
|
|
18
|
+
console.log(`⚠️ Terputus. Reconnect dalam ${reconnectDelayMs}ms (percobaan #${attempt})...`);
|
|
19
|
+
} else {
|
|
20
|
+
console.log("⚠️ Terputus. Sesi habis — tidak reconnect.");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
bot.on("unknownCommand", (ctx) => {
|
|
25
|
+
// Hapus baris ini kalau tidak mau balas command yang tidak dikenal.
|
|
26
|
+
ctx.reply(`❓ Command tidak ditemukan. Ketik ${bot.options.prefix}menu untuk daftar command.`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
bot.onError(async (error, ctx) => {
|
|
30
|
+
console.error(`[error] command "${ctx.command}" gagal:`, error);
|
|
31
|
+
await ctx.reply("⚠️ Terjadi kesalahan saat menjalankan command ini.");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await bot.start();
|