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.
Files changed (422) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +101 -0
  3. package/bin/botify.js +198 -0
  4. package/package.json +61 -0
  5. package/src/Bot.js +327 -0
  6. package/src/Context.js +185 -0
  7. package/src/PluginManager.js +131 -0
  8. package/src/config/index.js +2 -0
  9. package/src/config/parser.js +114 -0
  10. package/src/config/schema.js +106 -0
  11. package/src/index.js +18 -0
  12. package/src/loader.js +87 -0
  13. package/src/middlewares/antiSpam.js +75 -0
  14. package/src/middlewares/cooldown.js +81 -0
  15. package/src/middlewares/index.js +4 -0
  16. package/src/middlewares/logger.js +47 -0
  17. package/src/middlewares/permission.js +60 -0
  18. package/src/templates/config.bt +37 -0
  19. package/src/templates/index.js +34 -0
  20. package/src/templates/plugins/info.js +25 -0
  21. package/src/templates/plugins/menu.js +30 -0
  22. package/src/templates/plugins/ping.js +13 -0
  23. package/vendor/core/WAProto/GenerateStatics.sh +3 -0
  24. package/vendor/core/WAProto/WAProto.proto +6035 -0
  25. package/vendor/core/WAProto/fix-imports.js +81 -0
  26. package/vendor/core/WAProto/index.d.ts +2 -0
  27. package/vendor/core/WAProto/index.js +132326 -0
  28. package/vendor/core/lib/Defaults/index.d.ts +74 -0
  29. package/vendor/core/lib/Defaults/index.d.ts.map +1 -0
  30. package/vendor/core/lib/Defaults/index.js +140 -0
  31. package/vendor/core/lib/Defaults/index.js.map +1 -0
  32. package/vendor/core/lib/Modded/message_builder.js +2330 -0
  33. package/vendor/core/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  34. package/vendor/core/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  35. package/vendor/core/lib/Signal/Group/ciphertext-message.js +12 -0
  36. package/vendor/core/lib/Signal/Group/ciphertext-message.js.map +1 -0
  37. package/vendor/core/lib/Signal/Group/group-session-builder.d.ts +15 -0
  38. package/vendor/core/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  39. package/vendor/core/lib/Signal/Group/group-session-builder.js +30 -0
  40. package/vendor/core/lib/Signal/Group/group-session-builder.js.map +1 -0
  41. package/vendor/core/lib/Signal/Group/group_cipher.d.ts +17 -0
  42. package/vendor/core/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  43. package/vendor/core/lib/Signal/Group/group_cipher.js +82 -0
  44. package/vendor/core/lib/Signal/Group/group_cipher.js.map +1 -0
  45. package/vendor/core/lib/Signal/Group/index.d.ts +12 -0
  46. package/vendor/core/lib/Signal/Group/index.d.ts.map +1 -0
  47. package/vendor/core/lib/Signal/Group/index.js +12 -0
  48. package/vendor/core/lib/Signal/Group/index.js.map +1 -0
  49. package/vendor/core/lib/Signal/Group/keyhelper.d.ts +11 -0
  50. package/vendor/core/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  51. package/vendor/core/lib/Signal/Group/keyhelper.js +18 -0
  52. package/vendor/core/lib/Signal/Group/keyhelper.js.map +1 -0
  53. package/vendor/core/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  54. package/vendor/core/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  55. package/vendor/core/lib/Signal/Group/sender-chain-key.js +26 -0
  56. package/vendor/core/lib/Signal/Group/sender-chain-key.js.map +1 -0
  57. package/vendor/core/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  58. package/vendor/core/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  59. package/vendor/core/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  60. package/vendor/core/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  61. package/vendor/core/lib/Signal/Group/sender-key-message.d.ts +19 -0
  62. package/vendor/core/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  63. package/vendor/core/lib/Signal/Group/sender-key-message.js +66 -0
  64. package/vendor/core/lib/Signal/Group/sender-key-message.js.map +1 -0
  65. package/vendor/core/lib/Signal/Group/sender-key-name.d.ts +18 -0
  66. package/vendor/core/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  67. package/vendor/core/lib/Signal/Group/sender-key-name.js +48 -0
  68. package/vendor/core/lib/Signal/Group/sender-key-name.js.map +1 -0
  69. package/vendor/core/lib/Signal/Group/sender-key-record.d.ts +31 -0
  70. package/vendor/core/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  71. package/vendor/core/lib/Signal/Group/sender-key-record.js +41 -0
  72. package/vendor/core/lib/Signal/Group/sender-key-record.js.map +1 -0
  73. package/vendor/core/lib/Signal/Group/sender-key-state.d.ts +39 -0
  74. package/vendor/core/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  75. package/vendor/core/lib/Signal/Group/sender-key-state.js +84 -0
  76. package/vendor/core/lib/Signal/Group/sender-key-state.js.map +1 -0
  77. package/vendor/core/lib/Signal/Group/sender-message-key.d.ts +12 -0
  78. package/vendor/core/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  79. package/vendor/core/lib/Signal/Group/sender-message-key.js +26 -0
  80. package/vendor/core/lib/Signal/Group/sender-message-key.js.map +1 -0
  81. package/vendor/core/lib/Signal/libsignal.d.ts +5 -0
  82. package/vendor/core/lib/Signal/libsignal.d.ts.map +1 -0
  83. package/vendor/core/lib/Signal/libsignal.js +403 -0
  84. package/vendor/core/lib/Signal/libsignal.js.map +1 -0
  85. package/vendor/core/lib/Signal/lid-mapping.d.ts +19 -0
  86. package/vendor/core/lib/Signal/lid-mapping.d.ts.map +1 -0
  87. package/vendor/core/lib/Signal/lid-mapping.js +271 -0
  88. package/vendor/core/lib/Signal/lid-mapping.js.map +1 -0
  89. package/vendor/core/lib/Socket/Client/index.d.ts +3 -0
  90. package/vendor/core/lib/Socket/Client/index.d.ts.map +1 -0
  91. package/vendor/core/lib/Socket/Client/index.js +3 -0
  92. package/vendor/core/lib/Socket/Client/index.js.map +1 -0
  93. package/vendor/core/lib/Socket/Client/types.d.ts +16 -0
  94. package/vendor/core/lib/Socket/Client/types.d.ts.map +1 -0
  95. package/vendor/core/lib/Socket/Client/types.js +11 -0
  96. package/vendor/core/lib/Socket/Client/types.js.map +1 -0
  97. package/vendor/core/lib/Socket/Client/websocket.d.ts +13 -0
  98. package/vendor/core/lib/Socket/Client/websocket.d.ts.map +1 -0
  99. package/vendor/core/lib/Socket/Client/websocket.js +54 -0
  100. package/vendor/core/lib/Socket/Client/websocket.js.map +1 -0
  101. package/vendor/core/lib/Socket/business.d.ts +536 -0
  102. package/vendor/core/lib/Socket/business.d.ts.map +1 -0
  103. package/vendor/core/lib/Socket/business.js +422 -0
  104. package/vendor/core/lib/Socket/business.js.map +1 -0
  105. package/vendor/core/lib/Socket/chats.d.ts +111 -0
  106. package/vendor/core/lib/Socket/chats.d.ts.map +1 -0
  107. package/vendor/core/lib/Socket/chats.js +991 -0
  108. package/vendor/core/lib/Socket/chats.js.map +1 -0
  109. package/vendor/core/lib/Socket/communities.d.ts +645 -0
  110. package/vendor/core/lib/Socket/communities.d.ts.map +1 -0
  111. package/vendor/core/lib/Socket/communities.js +431 -0
  112. package/vendor/core/lib/Socket/communities.js.map +1 -0
  113. package/vendor/core/lib/Socket/dugong.d.ts +130 -0
  114. package/vendor/core/lib/Socket/dugong.d.ts.map +1 -0
  115. package/vendor/core/lib/Socket/dugong.js +768 -0
  116. package/vendor/core/lib/Socket/dugong.js.map +1 -0
  117. package/vendor/core/lib/Socket/groups.d.ts +150 -0
  118. package/vendor/core/lib/Socket/groups.d.ts.map +1 -0
  119. package/vendor/core/lib/Socket/groups.js +327 -0
  120. package/vendor/core/lib/Socket/groups.js.map +1 -0
  121. package/vendor/core/lib/Socket/index.d.ts +636 -0
  122. package/vendor/core/lib/Socket/index.d.ts.map +1 -0
  123. package/vendor/core/lib/Socket/index.js +15 -0
  124. package/vendor/core/lib/Socket/index.js.map +1 -0
  125. package/vendor/core/lib/Socket/messages-recv.d.ts +238 -0
  126. package/vendor/core/lib/Socket/messages-recv.d.ts.map +1 -0
  127. package/vendor/core/lib/Socket/messages-recv.js +1308 -0
  128. package/vendor/core/lib/Socket/messages-recv.js.map +1 -0
  129. package/vendor/core/lib/Socket/messages-send.d.ts +579 -0
  130. package/vendor/core/lib/Socket/messages-send.d.ts.map +1 -0
  131. package/vendor/core/lib/Socket/messages-send.js +1595 -0
  132. package/vendor/core/lib/Socket/messages-send.js.map +1 -0
  133. package/vendor/core/lib/Socket/mex.d.ts +3 -0
  134. package/vendor/core/lib/Socket/mex.d.ts.map +1 -0
  135. package/vendor/core/lib/Socket/mex.js +48 -0
  136. package/vendor/core/lib/Socket/mex.js.map +1 -0
  137. package/vendor/core/lib/Socket/newsletter.d.ts +177 -0
  138. package/vendor/core/lib/Socket/newsletter.d.ts.map +1 -0
  139. package/vendor/core/lib/Socket/newsletter.js +456 -0
  140. package/vendor/core/lib/Socket/newsletter.js.map +1 -0
  141. package/vendor/core/lib/Socket/socket.d.ts +55 -0
  142. package/vendor/core/lib/Socket/socket.d.ts.map +1 -0
  143. package/vendor/core/lib/Socket/socket.js +936 -0
  144. package/vendor/core/lib/Socket/socket.js.map +1 -0
  145. package/vendor/core/lib/Types/Auth.d.ts +116 -0
  146. package/vendor/core/lib/Types/Auth.d.ts.map +1 -0
  147. package/vendor/core/lib/Types/Auth.js +2 -0
  148. package/vendor/core/lib/Types/Auth.js.map +1 -0
  149. package/vendor/core/lib/Types/Bussines.d.ts +37 -0
  150. package/vendor/core/lib/Types/Bussines.d.ts.map +1 -0
  151. package/vendor/core/lib/Types/Bussines.js +2 -0
  152. package/vendor/core/lib/Types/Bussines.js.map +1 -0
  153. package/vendor/core/lib/Types/Call.d.ts +15 -0
  154. package/vendor/core/lib/Types/Call.d.ts.map +1 -0
  155. package/vendor/core/lib/Types/Call.js +2 -0
  156. package/vendor/core/lib/Types/Call.js.map +1 -0
  157. package/vendor/core/lib/Types/Chat.d.ts +123 -0
  158. package/vendor/core/lib/Types/Chat.d.ts.map +1 -0
  159. package/vendor/core/lib/Types/Chat.js +8 -0
  160. package/vendor/core/lib/Types/Chat.js.map +1 -0
  161. package/vendor/core/lib/Types/Contact.d.ts +24 -0
  162. package/vendor/core/lib/Types/Contact.d.ts.map +1 -0
  163. package/vendor/core/lib/Types/Contact.js +2 -0
  164. package/vendor/core/lib/Types/Contact.js.map +1 -0
  165. package/vendor/core/lib/Types/Events.d.ts +237 -0
  166. package/vendor/core/lib/Types/Events.d.ts.map +1 -0
  167. package/vendor/core/lib/Types/Events.js +2 -0
  168. package/vendor/core/lib/Types/Events.js.map +1 -0
  169. package/vendor/core/lib/Types/GroupMetadata.d.ts +68 -0
  170. package/vendor/core/lib/Types/GroupMetadata.d.ts.map +1 -0
  171. package/vendor/core/lib/Types/GroupMetadata.js +2 -0
  172. package/vendor/core/lib/Types/GroupMetadata.js.map +1 -0
  173. package/vendor/core/lib/Types/Label.d.ts +47 -0
  174. package/vendor/core/lib/Types/Label.d.ts.map +1 -0
  175. package/vendor/core/lib/Types/Label.js +25 -0
  176. package/vendor/core/lib/Types/Label.js.map +1 -0
  177. package/vendor/core/lib/Types/LabelAssociation.d.ts +30 -0
  178. package/vendor/core/lib/Types/LabelAssociation.d.ts.map +1 -0
  179. package/vendor/core/lib/Types/LabelAssociation.js +7 -0
  180. package/vendor/core/lib/Types/LabelAssociation.js.map +1 -0
  181. package/vendor/core/lib/Types/Message.d.ts +422 -0
  182. package/vendor/core/lib/Types/Message.d.ts.map +1 -0
  183. package/vendor/core/lib/Types/Message.js +11 -0
  184. package/vendor/core/lib/Types/Message.js.map +1 -0
  185. package/vendor/core/lib/Types/Newsletter.d.ts +135 -0
  186. package/vendor/core/lib/Types/Newsletter.d.ts.map +1 -0
  187. package/vendor/core/lib/Types/Newsletter.js +31 -0
  188. package/vendor/core/lib/Types/Newsletter.js.map +1 -0
  189. package/vendor/core/lib/Types/Product.d.ts +79 -0
  190. package/vendor/core/lib/Types/Product.d.ts.map +1 -0
  191. package/vendor/core/lib/Types/Product.js +2 -0
  192. package/vendor/core/lib/Types/Product.js.map +1 -0
  193. package/vendor/core/lib/Types/Signal.d.ts +76 -0
  194. package/vendor/core/lib/Types/Signal.d.ts.map +1 -0
  195. package/vendor/core/lib/Types/Signal.js +2 -0
  196. package/vendor/core/lib/Types/Signal.js.map +1 -0
  197. package/vendor/core/lib/Types/Socket.d.ts +158 -0
  198. package/vendor/core/lib/Types/Socket.d.ts.map +1 -0
  199. package/vendor/core/lib/Types/Socket.js +3 -0
  200. package/vendor/core/lib/Types/Socket.js.map +1 -0
  201. package/vendor/core/lib/Types/State.d.ts +39 -0
  202. package/vendor/core/lib/Types/State.d.ts.map +1 -0
  203. package/vendor/core/lib/Types/State.js +13 -0
  204. package/vendor/core/lib/Types/State.js.map +1 -0
  205. package/vendor/core/lib/Types/USync.d.ts +26 -0
  206. package/vendor/core/lib/Types/USync.d.ts.map +1 -0
  207. package/vendor/core/lib/Types/USync.js +2 -0
  208. package/vendor/core/lib/Types/USync.js.map +1 -0
  209. package/vendor/core/lib/Types/index.d.ts +66 -0
  210. package/vendor/core/lib/Types/index.d.ts.map +1 -0
  211. package/vendor/core/lib/Types/index.js +33 -0
  212. package/vendor/core/lib/Types/index.js.map +1 -0
  213. package/vendor/core/lib/Utils/auth-utils.d.ts +19 -0
  214. package/vendor/core/lib/Utils/auth-utils.d.ts.map +1 -0
  215. package/vendor/core/lib/Utils/auth-utils.js +290 -0
  216. package/vendor/core/lib/Utils/auth-utils.js.map +1 -0
  217. package/vendor/core/lib/Utils/browser-utils.d.ts +4 -0
  218. package/vendor/core/lib/Utils/browser-utils.d.ts.map +1 -0
  219. package/vendor/core/lib/Utils/browser-utils.js +28 -0
  220. package/vendor/core/lib/Utils/browser-utils.js.map +1 -0
  221. package/vendor/core/lib/Utils/business.d.ts +23 -0
  222. package/vendor/core/lib/Utils/business.d.ts.map +1 -0
  223. package/vendor/core/lib/Utils/business.js +231 -0
  224. package/vendor/core/lib/Utils/business.js.map +1 -0
  225. package/vendor/core/lib/Utils/chat-utils.d.ts +70 -0
  226. package/vendor/core/lib/Utils/chat-utils.d.ts.map +1 -0
  227. package/vendor/core/lib/Utils/chat-utils.js +812 -0
  228. package/vendor/core/lib/Utils/chat-utils.js.map +1 -0
  229. package/vendor/core/lib/Utils/crypto.d.ts +37 -0
  230. package/vendor/core/lib/Utils/crypto.d.ts.map +1 -0
  231. package/vendor/core/lib/Utils/crypto.js +118 -0
  232. package/vendor/core/lib/Utils/crypto.js.map +1 -0
  233. package/vendor/core/lib/Utils/decode-wa-message.d.ts +48 -0
  234. package/vendor/core/lib/Utils/decode-wa-message.d.ts.map +1 -0
  235. package/vendor/core/lib/Utils/decode-wa-message.js +283 -0
  236. package/vendor/core/lib/Utils/decode-wa-message.js.map +1 -0
  237. package/vendor/core/lib/Utils/event-buffer.d.ts +34 -0
  238. package/vendor/core/lib/Utils/event-buffer.d.ts.map +1 -0
  239. package/vendor/core/lib/Utils/event-buffer.js +574 -0
  240. package/vendor/core/lib/Utils/event-buffer.js.map +1 -0
  241. package/vendor/core/lib/Utils/generics.d.ts +91 -0
  242. package/vendor/core/lib/Utils/generics.d.ts.map +1 -0
  243. package/vendor/core/lib/Utils/generics.js +384 -0
  244. package/vendor/core/lib/Utils/generics.js.map +1 -0
  245. package/vendor/core/lib/Utils/history.d.ts +22 -0
  246. package/vendor/core/lib/Utils/history.d.ts.map +1 -0
  247. package/vendor/core/lib/Utils/history.js +131 -0
  248. package/vendor/core/lib/Utils/history.js.map +1 -0
  249. package/vendor/core/lib/Utils/identity-change-handler.d.ts +37 -0
  250. package/vendor/core/lib/Utils/identity-change-handler.d.ts.map +1 -0
  251. package/vendor/core/lib/Utils/identity-change-handler.js +49 -0
  252. package/vendor/core/lib/Utils/identity-change-handler.js.map +1 -0
  253. package/vendor/core/lib/Utils/index.d.ts +23 -0
  254. package/vendor/core/lib/Utils/index.d.ts.map +1 -0
  255. package/vendor/core/lib/Utils/index.js +23 -0
  256. package/vendor/core/lib/Utils/index.js.map +1 -0
  257. package/vendor/core/lib/Utils/link-preview.d.ts +21 -0
  258. package/vendor/core/lib/Utils/link-preview.d.ts.map +1 -0
  259. package/vendor/core/lib/Utils/link-preview.js +85 -0
  260. package/vendor/core/lib/Utils/link-preview.js.map +1 -0
  261. package/vendor/core/lib/Utils/logger.d.ts +13 -0
  262. package/vendor/core/lib/Utils/logger.d.ts.map +1 -0
  263. package/vendor/core/lib/Utils/logger.js +3 -0
  264. package/vendor/core/lib/Utils/logger.js.map +1 -0
  265. package/vendor/core/lib/Utils/lt-hash.d.ts +8 -0
  266. package/vendor/core/lib/Utils/lt-hash.d.ts.map +1 -0
  267. package/vendor/core/lib/Utils/lt-hash.js +8 -0
  268. package/vendor/core/lib/Utils/lt-hash.js.map +1 -0
  269. package/vendor/core/lib/Utils/make-mutex.d.ts +9 -0
  270. package/vendor/core/lib/Utils/make-mutex.d.ts.map +1 -0
  271. package/vendor/core/lib/Utils/make-mutex.js +33 -0
  272. package/vendor/core/lib/Utils/make-mutex.js.map +1 -0
  273. package/vendor/core/lib/Utils/message-retry-manager.d.ts +110 -0
  274. package/vendor/core/lib/Utils/message-retry-manager.d.ts.map +1 -0
  275. package/vendor/core/lib/Utils/message-retry-manager.js +225 -0
  276. package/vendor/core/lib/Utils/message-retry-manager.js.map +1 -0
  277. package/vendor/core/lib/Utils/messages-media.d.ts +130 -0
  278. package/vendor/core/lib/Utils/messages-media.d.ts.map +1 -0
  279. package/vendor/core/lib/Utils/messages-media.js +782 -0
  280. package/vendor/core/lib/Utils/messages-media.js.map +1 -0
  281. package/vendor/core/lib/Utils/messages.d.ts +91 -0
  282. package/vendor/core/lib/Utils/messages.d.ts.map +1 -0
  283. package/vendor/core/lib/Utils/messages.js +1240 -0
  284. package/vendor/core/lib/Utils/messages.js.map +1 -0
  285. package/vendor/core/lib/Utils/noise-handler.d.ts +20 -0
  286. package/vendor/core/lib/Utils/noise-handler.d.ts.map +1 -0
  287. package/vendor/core/lib/Utils/noise-handler.js +201 -0
  288. package/vendor/core/lib/Utils/noise-handler.js.map +1 -0
  289. package/vendor/core/lib/Utils/offline-node-processor.d.ts +17 -0
  290. package/vendor/core/lib/Utils/offline-node-processor.d.ts.map +1 -0
  291. package/vendor/core/lib/Utils/offline-node-processor.js +40 -0
  292. package/vendor/core/lib/Utils/offline-node-processor.js.map +1 -0
  293. package/vendor/core/lib/Utils/pre-key-manager.d.ts +28 -0
  294. package/vendor/core/lib/Utils/pre-key-manager.d.ts.map +1 -0
  295. package/vendor/core/lib/Utils/pre-key-manager.js +106 -0
  296. package/vendor/core/lib/Utils/pre-key-manager.js.map +1 -0
  297. package/vendor/core/lib/Utils/process-message.d.ts +60 -0
  298. package/vendor/core/lib/Utils/process-message.d.ts.map +1 -0
  299. package/vendor/core/lib/Utils/process-message.js +528 -0
  300. package/vendor/core/lib/Utils/process-message.js.map +1 -0
  301. package/vendor/core/lib/Utils/reporting-utils.d.ts +11 -0
  302. package/vendor/core/lib/Utils/reporting-utils.d.ts.map +1 -0
  303. package/vendor/core/lib/Utils/reporting-utils.js +258 -0
  304. package/vendor/core/lib/Utils/reporting-utils.js.map +1 -0
  305. package/vendor/core/lib/Utils/rich-messages.d.ts +277 -0
  306. package/vendor/core/lib/Utils/rich-messages.d.ts.map +1 -0
  307. package/vendor/core/lib/Utils/rich-messages.js +1144 -0
  308. package/vendor/core/lib/Utils/rich-messages.js.map +1 -0
  309. package/vendor/core/lib/Utils/signal.d.ts +34 -0
  310. package/vendor/core/lib/Utils/signal.d.ts.map +1 -0
  311. package/vendor/core/lib/Utils/signal.js +159 -0
  312. package/vendor/core/lib/Utils/signal.js.map +1 -0
  313. package/vendor/core/lib/Utils/stanza-ack.d.ts +11 -0
  314. package/vendor/core/lib/Utils/stanza-ack.d.ts.map +1 -0
  315. package/vendor/core/lib/Utils/stanza-ack.js +38 -0
  316. package/vendor/core/lib/Utils/stanza-ack.js.map +1 -0
  317. package/vendor/core/lib/Utils/sticker-pack.d.ts +10 -0
  318. package/vendor/core/lib/Utils/sticker-pack.js +111 -0
  319. package/vendor/core/lib/Utils/sync-action-utils.d.ts +19 -0
  320. package/vendor/core/lib/Utils/sync-action-utils.d.ts.map +1 -0
  321. package/vendor/core/lib/Utils/sync-action-utils.js +48 -0
  322. package/vendor/core/lib/Utils/sync-action-utils.js.map +1 -0
  323. package/vendor/core/lib/Utils/tc-token-utils.d.ts +12 -0
  324. package/vendor/core/lib/Utils/tc-token-utils.d.ts.map +1 -0
  325. package/vendor/core/lib/Utils/tc-token-utils.js +18 -0
  326. package/vendor/core/lib/Utils/tc-token-utils.js.map +1 -0
  327. package/vendor/core/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  328. package/vendor/core/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  329. package/vendor/core/lib/Utils/use-multi-file-auth-state.js +121 -0
  330. package/vendor/core/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  331. package/vendor/core/lib/Utils/validate-connection.d.ts +11 -0
  332. package/vendor/core/lib/Utils/validate-connection.d.ts.map +1 -0
  333. package/vendor/core/lib/Utils/validate-connection.js +200 -0
  334. package/vendor/core/lib/Utils/validate-connection.js.map +1 -0
  335. package/vendor/core/lib/WABinary/constants.d.ts +28 -0
  336. package/vendor/core/lib/WABinary/constants.d.ts.map +1 -0
  337. package/vendor/core/lib/WABinary/constants.js +1301 -0
  338. package/vendor/core/lib/WABinary/constants.js.map +1 -0
  339. package/vendor/core/lib/WABinary/decode.d.ts +7 -0
  340. package/vendor/core/lib/WABinary/decode.d.ts.map +1 -0
  341. package/vendor/core/lib/WABinary/decode.js +262 -0
  342. package/vendor/core/lib/WABinary/decode.js.map +1 -0
  343. package/vendor/core/lib/WABinary/encode.d.ts +3 -0
  344. package/vendor/core/lib/WABinary/encode.d.ts.map +1 -0
  345. package/vendor/core/lib/WABinary/encode.js +220 -0
  346. package/vendor/core/lib/WABinary/encode.js.map +1 -0
  347. package/vendor/core/lib/WABinary/generic-utils.d.ts +17 -0
  348. package/vendor/core/lib/WABinary/generic-utils.d.ts.map +1 -0
  349. package/vendor/core/lib/WABinary/generic-utils.js +191 -0
  350. package/vendor/core/lib/WABinary/generic-utils.js.map +1 -0
  351. package/vendor/core/lib/WABinary/index.d.ts +6 -0
  352. package/vendor/core/lib/WABinary/index.d.ts.map +1 -0
  353. package/vendor/core/lib/WABinary/index.js +6 -0
  354. package/vendor/core/lib/WABinary/index.js.map +1 -0
  355. package/vendor/core/lib/WABinary/jid-utils.d.ts +48 -0
  356. package/vendor/core/lib/WABinary/jid-utils.d.ts.map +1 -0
  357. package/vendor/core/lib/WABinary/jid-utils.js +96 -0
  358. package/vendor/core/lib/WABinary/jid-utils.js.map +1 -0
  359. package/vendor/core/lib/WABinary/types.d.ts +19 -0
  360. package/vendor/core/lib/WABinary/types.d.ts.map +1 -0
  361. package/vendor/core/lib/WABinary/types.js +2 -0
  362. package/vendor/core/lib/WABinary/types.js.map +1 -0
  363. package/vendor/core/lib/WAM/BinaryInfo.d.ts +9 -0
  364. package/vendor/core/lib/WAM/BinaryInfo.d.ts.map +1 -0
  365. package/vendor/core/lib/WAM/BinaryInfo.js +10 -0
  366. package/vendor/core/lib/WAM/BinaryInfo.js.map +1 -0
  367. package/vendor/core/lib/WAM/constants.d.ts +40 -0
  368. package/vendor/core/lib/WAM/constants.d.ts.map +1 -0
  369. package/vendor/core/lib/WAM/constants.js +22853 -0
  370. package/vendor/core/lib/WAM/constants.js.map +1 -0
  371. package/vendor/core/lib/WAM/encode.d.ts +3 -0
  372. package/vendor/core/lib/WAM/encode.d.ts.map +1 -0
  373. package/vendor/core/lib/WAM/encode.js +150 -0
  374. package/vendor/core/lib/WAM/encode.js.map +1 -0
  375. package/vendor/core/lib/WAM/index.d.ts +4 -0
  376. package/vendor/core/lib/WAM/index.d.ts.map +1 -0
  377. package/vendor/core/lib/WAM/index.js +4 -0
  378. package/vendor/core/lib/WAM/index.js.map +1 -0
  379. package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  380. package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  381. package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  382. package/vendor/core/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  383. package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  384. package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  385. package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  386. package/vendor/core/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  387. package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  388. package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  389. package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  390. package/vendor/core/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  391. package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  392. package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  393. package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  394. package/vendor/core/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  395. package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  396. package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  397. package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  398. package/vendor/core/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  399. package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  400. package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  401. package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  402. package/vendor/core/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  403. package/vendor/core/lib/WAUSync/Protocols/index.d.ts +5 -0
  404. package/vendor/core/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  405. package/vendor/core/lib/WAUSync/Protocols/index.js +5 -0
  406. package/vendor/core/lib/WAUSync/Protocols/index.js.map +1 -0
  407. package/vendor/core/lib/WAUSync/USyncQuery.d.ts +29 -0
  408. package/vendor/core/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  409. package/vendor/core/lib/WAUSync/USyncQuery.js +94 -0
  410. package/vendor/core/lib/WAUSync/USyncQuery.js.map +1 -0
  411. package/vendor/core/lib/WAUSync/USyncUser.d.ts +13 -0
  412. package/vendor/core/lib/WAUSync/USyncUser.d.ts.map +1 -0
  413. package/vendor/core/lib/WAUSync/USyncUser.js +23 -0
  414. package/vendor/core/lib/WAUSync/USyncUser.js.map +1 -0
  415. package/vendor/core/lib/WAUSync/index.d.ts +4 -0
  416. package/vendor/core/lib/WAUSync/index.d.ts.map +1 -0
  417. package/vendor/core/lib/WAUSync/index.js +4 -0
  418. package/vendor/core/lib/WAUSync/index.js.map +1 -0
  419. package/vendor/core/lib/index.d.ts +13 -0
  420. package/vendor/core/lib/index.d.ts.map +1 -0
  421. package/vendor/core/lib/index.js +13 -0
  422. 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,4 @@
1
+ export { logger } from "./logger.js";
2
+ export { cooldown } from "./cooldown.js";
3
+ export { permission } from "./permission.js";
4
+ export { antiSpam } from "./antiSpam.js";
@@ -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();