@deffa5556/bail 1.0.6 → 1.0.9

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 (316) hide show
  1. package/cjs/WAProto/index.cjs +106053 -0
  2. package/cjs/deffa/config.cjs +14 -0
  3. package/cjs/deffa/plugins/ai/deepseekr1.cjs +35 -0
  4. package/cjs/deffa/plugins/ai/gita.cjs +26 -0
  5. package/cjs/deffa/plugins/ai/glm47flash.cjs +35 -0
  6. package/cjs/deffa/plugins/ai/gptoss120b.cjs +35 -0
  7. package/cjs/deffa/plugins/ai/qwq32b.cjs +35 -0
  8. package/cjs/deffa/plugins/berita/antara.cjs +25 -0
  9. package/cjs/deffa/plugins/berita/cnbcindonesia.cjs +25 -0
  10. package/cjs/deffa/plugins/berita/cnn.cjs +25 -0
  11. package/cjs/deffa/plugins/berita/kompas.cjs +25 -0
  12. package/cjs/deffa/plugins/berita/liputan6.cjs +25 -0
  13. package/cjs/deffa/plugins/berita/merdeka.cjs +25 -0
  14. package/cjs/deffa/plugins/berita/sindonews.cjs +25 -0
  15. package/cjs/deffa/plugins/berita/tribunnews.cjs +25 -0
  16. package/cjs/deffa/plugins/downloader/douyin.cjs +30 -0
  17. package/cjs/deffa/plugins/downloader/facebook.cjs +30 -0
  18. package/cjs/deffa/plugins/downloader/github.cjs +35 -0
  19. package/cjs/deffa/plugins/downloader/lahelu.cjs +30 -0
  20. package/cjs/deffa/plugins/downloader/snackvideo.cjs +30 -0
  21. package/cjs/deffa/plugins/downloader/soundcloud.cjs +30 -0
  22. package/cjs/deffa/plugins/downloader/tiktok.cjs +30 -0
  23. package/cjs/deffa/plugins/downloader/tiktokhd.cjs +30 -0
  24. package/cjs/deffa/plugins/downloader/twitter.cjs +30 -0
  25. package/cjs/deffa/plugins/downloader/ummy.cjs +36 -0
  26. package/cjs/deffa/plugins/index.cjs +213 -0
  27. package/cjs/deffa/plugins/info/bmkg.cjs +34 -0
  28. package/cjs/deffa/plugins/info/cuaca.cjs +31 -0
  29. package/cjs/deffa/plugins/info/jadwaltv.cjs +29 -0
  30. package/cjs/deffa/plugins/maker/brat.cjs +45 -0
  31. package/cjs/deffa/plugins/maker/bratvid.cjs +52 -0
  32. package/cjs/deffa/plugins/search/8font.cjs +28 -0
  33. package/cjs/deffa/plugins/search/applemusic.cjs +28 -0
  34. package/cjs/deffa/plugins/search/bimg.cjs +30 -0
  35. package/cjs/deffa/plugins/search/brave.cjs +34 -0
  36. package/cjs/deffa/plugins/search/duckduckgo.cjs +28 -0
  37. package/cjs/deffa/plugins/search/lahelu.cjs +28 -0
  38. package/cjs/deffa/plugins/search/mangatoon.cjs +28 -0
  39. package/cjs/deffa/plugins/search/mcpedl.cjs +28 -0
  40. package/cjs/deffa/plugins/search/myinstants.cjs +28 -0
  41. package/cjs/deffa/plugins/search/otakotaku.cjs +28 -0
  42. package/cjs/deffa/plugins/search/pinterest.cjs +30 -0
  43. package/cjs/deffa/plugins/search/resep.cjs +28 -0
  44. package/cjs/deffa/plugins/search/seegore.cjs +30 -0
  45. package/cjs/deffa/plugins/search/soundcloud.cjs +28 -0
  46. package/cjs/deffa/plugins/search/youtube.cjs +28 -0
  47. package/cjs/deffa/plugins/stalk/github.cjs +38 -0
  48. package/cjs/deffa/plugins/stalk/pinterest.cjs +37 -0
  49. package/cjs/deffa/plugins/stalk/threads.cjs +34 -0
  50. package/cjs/deffa/plugins/stalk/tiktok.cjs +37 -0
  51. package/cjs/deffa/plugins/stalk/twitter.cjs +37 -0
  52. package/cjs/deffa/plugins/stalk/youtube.cjs +37 -0
  53. package/cjs/lib/Defaults/index.cjs +158 -0
  54. package/cjs/lib/Discord/Client.cjs +263 -0
  55. package/cjs/lib/Discord/Constants.cjs +1842 -0
  56. package/cjs/lib/Discord/connect-dc.cjs +11 -0
  57. package/cjs/lib/Discord/esm-bridge.cjs +136 -0
  58. package/cjs/lib/Discord/gateway/Dispatcher.cjs +93 -0
  59. package/cjs/lib/Discord/gateway/Shard.cjs +695 -0
  60. package/cjs/lib/Discord/gateway/ShardManager.cjs +344 -0
  61. package/cjs/lib/Discord/gateway/compression/base.cjs +13 -0
  62. package/cjs/lib/Discord/gateway/compression/config.cjs +47 -0
  63. package/cjs/lib/Discord/gateway/compression/pako.cjs +44 -0
  64. package/cjs/lib/Discord/gateway/compression/zlib-native.cjs +47 -0
  65. package/cjs/lib/Discord/gateway/compression/zlib-sync.cjs +31 -0
  66. package/cjs/lib/Discord/gateway/compression/zstd-napi.cjs +80 -0
  67. package/cjs/lib/Discord/gateway/compression/zstd-native.cjs +46 -0
  68. package/cjs/lib/Discord/gateway/events.cjs +956 -0
  69. package/cjs/lib/Discord/index.cjs +238 -0
  70. package/cjs/lib/Discord/rest/Bucket.cjs +69 -0
  71. package/cjs/lib/Discord/rest/DiscordHTTPError.cjs +63 -0
  72. package/cjs/lib/Discord/rest/DiscordRESTError.cjs +84 -0
  73. package/cjs/lib/Discord/rest/OAuthHelper.cjs +226 -0
  74. package/cjs/lib/Discord/rest/RESTManager.cjs +116 -0
  75. package/cjs/lib/Discord/rest/RequestHandler.cjs +320 -0
  76. package/cjs/lib/Discord/rest/SequentialBucket.cjs +69 -0
  77. package/cjs/lib/Discord/routes/Applications.cjs +625 -0
  78. package/cjs/lib/Discord/routes/Channels.cjs +1199 -0
  79. package/cjs/lib/Discord/routes/Guilds.cjs +1792 -0
  80. package/cjs/lib/Discord/routes/Interactions.cjs +212 -0
  81. package/cjs/lib/Discord/routes/Lobbies.cjs +197 -0
  82. package/cjs/lib/Discord/routes/Miscellaneous.cjs +120 -0
  83. package/cjs/lib/Discord/routes/OAuth.cjs +350 -0
  84. package/cjs/lib/Discord/routes/Users.cjs +107 -0
  85. package/cjs/lib/Discord/routes/Webhooks.cjs +308 -0
  86. package/cjs/lib/Discord/structures/AnnouncementChannel.cjs +46 -0
  87. package/cjs/lib/Discord/structures/AnnouncementThreadChannel.cjs +28 -0
  88. package/cjs/lib/Discord/structures/Application.cjs +345 -0
  89. package/cjs/lib/Discord/structures/ApplicationCommand.cjs +109 -0
  90. package/cjs/lib/Discord/structures/Attachment.cjs +46 -0
  91. package/cjs/lib/Discord/structures/AuditLogEntry.cjs +41 -0
  92. package/cjs/lib/Discord/structures/AutoModerationRule.cjs +117 -0
  93. package/cjs/lib/Discord/structures/AutocompleteInteraction.cjs +90 -0
  94. package/cjs/lib/Discord/structures/Base.cjs +56 -0
  95. package/cjs/lib/Discord/structures/BaseEntitlement.cjs +40 -0
  96. package/cjs/lib/Discord/structures/CategoryChannel.cjs +102 -0
  97. package/cjs/lib/Discord/structures/Channel.cjs +89 -0
  98. package/cjs/lib/Discord/structures/ClientApplication.cjs +269 -0
  99. package/cjs/lib/Discord/structures/CommandInteraction.cjs +294 -0
  100. package/cjs/lib/Discord/structures/ComponentInteraction.cjs +306 -0
  101. package/cjs/lib/Discord/structures/Entitlement.cjs +24 -0
  102. package/cjs/lib/Discord/structures/ExtendedUser.cjs +48 -0
  103. package/cjs/lib/Discord/structures/ForumChannel.cjs +20 -0
  104. package/cjs/lib/Discord/structures/GroupChannel.cjs +160 -0
  105. package/cjs/lib/Discord/structures/Guild.cjs +1289 -0
  106. package/cjs/lib/Discord/structures/GuildChannel.cjs +82 -0
  107. package/cjs/lib/Discord/structures/GuildPreview.cjs +141 -0
  108. package/cjs/lib/Discord/structures/GuildScheduledEvent.cjs +166 -0
  109. package/cjs/lib/Discord/structures/GuildTemplate.cjs +96 -0
  110. package/cjs/lib/Discord/structures/Integration.cjs +123 -0
  111. package/cjs/lib/Discord/structures/Interaction.cjs +78 -0
  112. package/cjs/lib/Discord/structures/InteractionResolvedChannel.cjs +36 -0
  113. package/cjs/lib/Discord/structures/Invite.cjs +196 -0
  114. package/cjs/lib/Discord/structures/InviteGuild.cjs +117 -0
  115. package/cjs/lib/Discord/structures/InviteRole.cjs +88 -0
  116. package/cjs/lib/Discord/structures/Lobby.cjs +84 -0
  117. package/cjs/lib/Discord/structures/LobbyMember.cjs +30 -0
  118. package/cjs/lib/Discord/structures/MediaChannel.cjs +20 -0
  119. package/cjs/lib/Discord/structures/Member.cjs +300 -0
  120. package/cjs/lib/Discord/structures/Message.cjs +553 -0
  121. package/cjs/lib/Discord/structures/ModalSubmitInteraction.cjs +263 -0
  122. package/cjs/lib/Discord/structures/OAuthApplication.cjs +203 -0
  123. package/cjs/lib/Discord/structures/OAuthGuild.cjs +98 -0
  124. package/cjs/lib/Discord/structures/PartialApplication.cjs +97 -0
  125. package/cjs/lib/Discord/structures/Permission.cjs +61 -0
  126. package/cjs/lib/Discord/structures/PermissionOverwrite.cjs +46 -0
  127. package/cjs/lib/Discord/structures/PingInteraction.cjs +27 -0
  128. package/cjs/lib/Discord/structures/Poll.cjs +69 -0
  129. package/cjs/lib/Discord/structures/PrimaryGuild.cjs +93 -0
  130. package/cjs/lib/Discord/structures/PrivateChannel.cjs +131 -0
  131. package/cjs/lib/Discord/structures/PrivateThreadChannel.cjs +28 -0
  132. package/cjs/lib/Discord/structures/PublicThreadChannel.cjs +36 -0
  133. package/cjs/lib/Discord/structures/Role.cjs +126 -0
  134. package/cjs/lib/Discord/structures/SKU.cjs +58 -0
  135. package/cjs/lib/Discord/structures/Soundboard.cjs +58 -0
  136. package/cjs/lib/Discord/structures/StageChannel.cjs +45 -0
  137. package/cjs/lib/Discord/structures/StageInstance.cjs +80 -0
  138. package/cjs/lib/Discord/structures/Subscription.cjs +21 -0
  139. package/cjs/lib/Discord/structures/Team.cjs +70 -0
  140. package/cjs/lib/Discord/structures/TestEntitlement.cjs +22 -0
  141. package/cjs/lib/Discord/structures/TextChannel.cjs +48 -0
  142. package/cjs/lib/Discord/structures/TextableChannel.cjs +265 -0
  143. package/cjs/lib/Discord/structures/TextableVoiceChannel.cjs +70 -0
  144. package/cjs/lib/Discord/structures/ThreadChannel.cjs +276 -0
  145. package/cjs/lib/Discord/structures/ThreadOnlyChannel.cjs +205 -0
  146. package/cjs/lib/Discord/structures/ThreadableChannel.cjs +57 -0
  147. package/cjs/lib/Discord/structures/UnavailableGuild.cjs +21 -0
  148. package/cjs/lib/Discord/structures/User.cjs +223 -0
  149. package/cjs/lib/Discord/structures/VoiceChannel.cjs +34 -0
  150. package/cjs/lib/Discord/structures/VoiceState.cjs +113 -0
  151. package/cjs/lib/Discord/structures/Webhook.cjs +224 -0
  152. package/cjs/lib/Discord/util/Collection.cjs +77 -0
  153. package/cjs/lib/Discord/util/Errors.cjs +81 -0
  154. package/cjs/lib/Discord/util/QueryBuilder.cjs +20 -0
  155. package/cjs/lib/Discord/util/Routes.cjs +293 -0
  156. package/cjs/lib/Discord/util/SimpleCollection.cjs +78 -0
  157. package/cjs/lib/Discord/util/Time.cjs +92 -0
  158. package/cjs/lib/Discord/util/TypedCollection.cjs +78 -0
  159. package/cjs/lib/Discord/util/TypedEmitter.cjs +20 -0
  160. package/cjs/lib/Discord/util/Util.cjs +906 -0
  161. package/cjs/lib/Discord/util/interactions/InteractionOptionsWrapper.cjs +207 -0
  162. package/cjs/lib/Discord/util/interactions/MessageInteractionResponse.cjs +26 -0
  163. package/cjs/lib/Discord/util/interactions/ModalSubmitInteractionComponentsWrapper.cjs +98 -0
  164. package/cjs/lib/Discord/util/interactions/SelectMenuValuesWrapper.cjs +77 -0
  165. package/cjs/lib/Discord/util/interactions/shared.cjs +20 -0
  166. package/cjs/lib/Discord/util/warning.cjs +34 -0
  167. package/cjs/lib/Signal/Group/ciphertext-message.cjs +16 -0
  168. package/cjs/lib/Signal/Group/group-session-builder.cjs +67 -0
  169. package/cjs/lib/Signal/Group/group_cipher.cjs +86 -0
  170. package/cjs/lib/Signal/Group/index.cjs +58 -0
  171. package/cjs/lib/Signal/Group/keyhelper.cjs +56 -0
  172. package/cjs/lib/Signal/Group/sender-chain-key.cjs +30 -0
  173. package/cjs/lib/Signal/Group/sender-key-distribution-message.cjs +67 -0
  174. package/cjs/lib/Signal/Group/sender-key-message.cjs +70 -0
  175. package/cjs/lib/Signal/Group/sender-key-name.cjs +52 -0
  176. package/cjs/lib/Signal/Group/sender-key-record.cjs +45 -0
  177. package/cjs/lib/Signal/Group/sender-key-state.cjs +88 -0
  178. package/cjs/lib/Signal/Group/sender-message-key.cjs +30 -0
  179. package/cjs/lib/Signal/libsignal.cjs +467 -0
  180. package/cjs/lib/Signal/lid-mapping.cjs +281 -0
  181. package/cjs/lib/Socket/Client/index.cjs +19 -0
  182. package/cjs/lib/Socket/Client/types.cjs +15 -0
  183. package/cjs/lib/Socket/Client/websocket.cjs +61 -0
  184. package/cjs/lib/Socket/business.cjs +384 -0
  185. package/cjs/lib/Socket/chats.cjs +1221 -0
  186. package/cjs/lib/Socket/communities.cjs +440 -0
  187. package/cjs/lib/Socket/groups.cjs +353 -0
  188. package/cjs/lib/Socket/index.cjs +14 -0
  189. package/cjs/lib/Socket/messages-recv.cjs +1772 -0
  190. package/cjs/lib/Socket/messages-send.cjs +1376 -0
  191. package/cjs/lib/Socket/mex.cjs +46 -0
  192. package/cjs/lib/Socket/newsletter.cjs +230 -0
  193. package/cjs/lib/Socket/socket.cjs +976 -0
  194. package/cjs/lib/Store/index.cjs +20 -0
  195. package/cjs/lib/Store/make-in-memory-store.cjs +470 -0
  196. package/cjs/lib/Store/make-ordered-dictionary.cjs +82 -0
  197. package/cjs/lib/Store/object-repository.cjs +28 -0
  198. package/cjs/lib/Telegram/button.cjs +147 -0
  199. package/cjs/lib/Telegram/composer.cjs +582 -0
  200. package/cjs/lib/Telegram/context.cjs +853 -0
  201. package/cjs/lib/Telegram/core/helpers/args.cjs +57 -0
  202. package/cjs/lib/Telegram/core/helpers/check.cjs +55 -0
  203. package/cjs/lib/Telegram/core/helpers/compact.cjs +16 -0
  204. package/cjs/lib/Telegram/core/helpers/deunionize.cjs +12 -0
  205. package/cjs/lib/Telegram/core/helpers/formatting.cjs +91 -0
  206. package/cjs/lib/Telegram/core/helpers/util.cjs +50 -0
  207. package/cjs/lib/Telegram/core/network/client.cjs +338 -0
  208. package/cjs/lib/Telegram/core/network/error.cjs +21 -0
  209. package/cjs/lib/Telegram/core/network/multipart-stream.cjs +79 -0
  210. package/cjs/lib/Telegram/core/network/polling.cjs +87 -0
  211. package/cjs/lib/Telegram/core/network/webhook.cjs +54 -0
  212. package/cjs/lib/Telegram/core/types/typegram.cjs +31 -0
  213. package/cjs/lib/Telegram/deffa-telegraf.cjs +264 -0
  214. package/cjs/lib/Telegram/esm-bridge.cjs +20 -0
  215. package/cjs/lib/Telegram/filters.cjs +69 -0
  216. package/cjs/lib/Telegram/format.cjs +58 -0
  217. package/cjs/lib/Telegram/future.cjs +140 -0
  218. package/cjs/lib/Telegram/index.cjs +67 -0
  219. package/cjs/lib/Telegram/input.cjs +61 -0
  220. package/cjs/lib/Telegram/markup.cjs +129 -0
  221. package/cjs/lib/Telegram/middleware.cjs +2 -0
  222. package/cjs/lib/Telegram/reactions.cjs +84 -0
  223. package/cjs/lib/Telegram/router.cjs +46 -0
  224. package/cjs/lib/Telegram/scenes/base.cjs +39 -0
  225. package/cjs/lib/Telegram/scenes/context.cjs +104 -0
  226. package/cjs/lib/Telegram/scenes/index.cjs +21 -0
  227. package/cjs/lib/Telegram/scenes/stage.cjs +49 -0
  228. package/cjs/lib/Telegram/scenes/wizard/context.cjs +31 -0
  229. package/cjs/lib/Telegram/scenes/wizard/index.cjs +45 -0
  230. package/cjs/lib/Telegram/scenes.cjs +21 -0
  231. package/cjs/lib/Telegram/session.cjs +166 -0
  232. package/cjs/lib/Telegram/telegram-types.cjs +6 -0
  233. package/cjs/lib/Telegram/telegram.cjs +945 -0
  234. package/cjs/lib/Telegram/types.cjs +2 -0
  235. package/cjs/lib/Telegram/utils.cjs +5 -0
  236. package/cjs/lib/Types/Auth.cjs +3 -0
  237. package/cjs/lib/Types/Bussines.cjs +3 -0
  238. package/cjs/lib/Types/Call.cjs +3 -0
  239. package/cjs/lib/Types/Chat.cjs +11 -0
  240. package/cjs/lib/Types/Contact.cjs +3 -0
  241. package/cjs/lib/Types/Events.cjs +4 -0
  242. package/cjs/lib/Types/GroupMetadata.cjs +3 -0
  243. package/cjs/lib/Types/Label.cjs +26 -0
  244. package/cjs/lib/Types/LabelAssociation.cjs +8 -0
  245. package/cjs/lib/Types/Message.cjs +19 -0
  246. package/cjs/lib/Types/Mex.cjs +40 -0
  247. package/cjs/lib/Types/Product.cjs +3 -0
  248. package/cjs/lib/Types/RichType.cjs +24 -0
  249. package/cjs/lib/Types/Signal.cjs +4 -0
  250. package/cjs/lib/Types/Socket.cjs +4 -0
  251. package/cjs/lib/Types/State.cjs +54 -0
  252. package/cjs/lib/Types/USync.cjs +4 -0
  253. package/cjs/lib/Types/index.cjs +42 -0
  254. package/cjs/lib/Utils/auth-utils.cjs +312 -0
  255. package/cjs/lib/Utils/browser-utils.cjs +39 -0
  256. package/cjs/lib/Utils/business.cjs +241 -0
  257. package/cjs/lib/Utils/chat-utils.cjs +890 -0
  258. package/cjs/lib/Utils/companion-reg-client-utils.cjs +51 -0
  259. package/cjs/lib/Utils/crypto.cjs +170 -0
  260. package/cjs/lib/Utils/decode-wa-message.cjs +330 -0
  261. package/cjs/lib/Utils/event-buffer.cjs +629 -0
  262. package/cjs/lib/Utils/generics.cjs +427 -0
  263. package/cjs/lib/Utils/history.cjs +141 -0
  264. package/cjs/lib/Utils/identity-change-handler.cjs +56 -0
  265. package/cjs/lib/Utils/index.cjs +43 -0
  266. package/cjs/lib/Utils/link-preview.cjs +122 -0
  267. package/cjs/lib/Utils/logger.cjs +8 -0
  268. package/cjs/lib/Utils/lt-hash.cjs +11 -0
  269. package/cjs/lib/Utils/make-mutex.cjs +38 -0
  270. package/cjs/lib/Utils/message-retry-manager.cjs +267 -0
  271. package/cjs/lib/Utils/messages-media.cjs +906 -0
  272. package/cjs/lib/Utils/messages.cjs +1909 -0
  273. package/cjs/lib/Utils/noise-handler.cjs +205 -0
  274. package/cjs/lib/Utils/offline-node-processor.cjs +43 -0
  275. package/cjs/lib/Utils/pre-key-manager.cjs +113 -0
  276. package/cjs/lib/Utils/process-message.cjs +755 -0
  277. package/cjs/lib/Utils/reporting-utils.cjs +263 -0
  278. package/cjs/lib/Utils/rich-message-utils.cjs +434 -0
  279. package/cjs/lib/Utils/session-guard.cjs +163 -0
  280. package/cjs/lib/Utils/signal.cjs +214 -0
  281. package/cjs/lib/Utils/stanza-ack.cjs +41 -0
  282. package/cjs/lib/Utils/sync-action-utils.cjs +54 -0
  283. package/cjs/lib/Utils/tc-token-utils.cjs +174 -0
  284. package/cjs/lib/Utils/text-sticker.cjs +174 -0
  285. package/cjs/lib/Utils/use-multi-file-auth-state.cjs +125 -0
  286. package/cjs/lib/Utils/use-single-file-auth-state.cjs +113 -0
  287. package/cjs/lib/Utils/use-sqlite-auth-state.cjs +145 -0
  288. package/cjs/lib/Utils/validate-connection.cjs +210 -0
  289. package/cjs/lib/WABinary/constants.cjs +1470 -0
  290. package/cjs/lib/WABinary/decode.cjs +301 -0
  291. package/cjs/lib/WABinary/encode.cjs +257 -0
  292. package/cjs/lib/WABinary/generic-utils.cjs +240 -0
  293. package/cjs/lib/WABinary/index.cjs +22 -0
  294. package/cjs/lib/WABinary/jid-utils.cjs +114 -0
  295. package/cjs/lib/WABinary/types.cjs +37 -0
  296. package/cjs/lib/WAM/BinaryInfo.cjs +14 -0
  297. package/cjs/lib/WAM/constants.cjs +22856 -0
  298. package/cjs/lib/WAM/encode.cjs +154 -0
  299. package/cjs/lib/WAM/index.cjs +20 -0
  300. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.cjs +56 -0
  301. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.cjs +58 -0
  302. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.cjs +31 -0
  303. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.cjs +42 -0
  304. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.cjs +29 -0
  305. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.cjs +55 -0
  306. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.cjs +33 -0
  307. package/cjs/lib/WAUSync/Protocols/index.cjs +22 -0
  308. package/cjs/lib/WAUSync/USyncQuery.cjs +102 -0
  309. package/cjs/lib/WAUSync/USyncUser.cjs +35 -0
  310. package/cjs/lib/WAUSync/index.cjs +20 -0
  311. package/cjs/lib/index.cjs +372 -0
  312. package/cjs/lib/plugins/loader.cjs +117 -0
  313. package/lib/Defaults/index.js +1 -1
  314. package/lib/Socket/socket.js +3 -3
  315. package/lib/Telegram/esm-bridge.mjs +1 -1
  316. package/package.json +11 -6
@@ -0,0 +1,695 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const config_1 = __importDefault(require("./compression/config.cjs"));
7
+ const TypedEmitter_1 = __importDefault(require("../util/TypedEmitter.cjs"));
8
+ const Bucket_1 = __importDefault(require("../rest/Bucket.cjs"));
9
+ const Constants_1 = require("../Constants.cjs");
10
+ const Base_1 = __importDefault(require("../structures/Base.cjs"));
11
+ const ExtendedUser_1 = __importDefault(require("../structures/ExtendedUser.cjs"));
12
+ const Errors_1 = require("../util/Errors.cjs");
13
+ const ClientApplication_1 = __importDefault(require("../structures/ClientApplication.cjs"));
14
+ const ws_1 = __importDefault(require("ws"));
15
+ const node_crypto_1 = require("node:crypto");
16
+ const node_util_1 = require("node:util");
17
+ /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, unicorn/prefer-module, @typescript-eslint/no-unsafe-member-access */
18
+ // @ts-ignore
19
+ let Erlpack;
20
+ try {
21
+ Erlpack = require("erlpack");
22
+ }
23
+ catch { }
24
+ /* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, unicorn/prefer-module */
25
+ /** Represents a gateway connection to Discord. See {@link Types.Events.ShardEvents | Shard Events} for a list of events. */
26
+ class Shard extends TypedEmitter_1.default {
27
+ constructor(id, manager) {
28
+ super();
29
+ Object.defineProperties(this, {
30
+ client: {
31
+ value: manager.client,
32
+ enumerable: false,
33
+ writable: false,
34
+ configurable: false
35
+ },
36
+ manager: {
37
+ value: manager,
38
+ enumerable: false,
39
+ writable: true,
40
+ configurable: false
41
+ },
42
+ ws: {
43
+ value: null,
44
+ enumerable: false,
45
+ writable: true,
46
+ configurable: false
47
+ }
48
+ });
49
+ this.onPacket = this.onPacket.bind(this);
50
+ this.onWSClose = this.onWSClose.bind(this);
51
+ this.onWSError = this.onWSError.bind(this);
52
+ this.onWSMessage = this.onWSMessage.bind(this);
53
+ this.onWSOpen = this.onWSOpen.bind(this);
54
+ this.connectAttempts = 0;
55
+ this._connectTimeout = null;
56
+ this.connecting = false;
57
+ this._getAllUsersCount = {};
58
+ this._getAllUsersQueue = [];
59
+ this._guildCreateTimeout = null;
60
+ this._heartbeatInterval = null;
61
+ this.id = id;
62
+ this.lastHeartbeatAck = true;
63
+ this.lastHeartbeatReceived = 0;
64
+ this.lastHeartbeatSent = 0;
65
+ this.latency = Infinity;
66
+ this.preReady = false;
67
+ this.ready = false;
68
+ this.reconnectInterval = 1000;
69
+ this._requestMembersPromise = {};
70
+ this._requestSoundboardSoundsPromise = {};
71
+ this.resumeURL = null;
72
+ this.sequence = 0;
73
+ this.sessionID = null;
74
+ this.status = "disconnected";
75
+ this.hardReset();
76
+ }
77
+ _ready(data) {
78
+ this.connectAttempts = 0;
79
+ this.reconnectInterval = 1000;
80
+ this.connecting = false;
81
+ if (this._connectTimeout) {
82
+ clearTimeout(this._connectTimeout);
83
+ }
84
+ this.status = "ready";
85
+ this.client.shards["_ready"](this.id);
86
+ this.client["_application"] = new ClientApplication_1.default(data.application, this.client);
87
+ if (this.client["_user"]) {
88
+ this.client.users.update(data.user);
89
+ }
90
+ else {
91
+ this.client["_user"] = this.client.users.add(new ExtendedUser_1.default(data.user, this.client));
92
+ }
93
+ let url = data.resume_gateway_url;
94
+ if (url.includes("?")) {
95
+ url = url.slice(0, url.indexOf("?"));
96
+ }
97
+ if (!url.endsWith("/")) {
98
+ url += "/";
99
+ }
100
+ this.resumeURL = `${url}?v=${Constants_1.GATEWAY_VERSION}&encoding=${Erlpack ? "etf" : "json"}`;
101
+ if (this.client.shards.options.compress) {
102
+ const type = this.client.shards.options.compress === "zstd-stream" ? "zstd-stream" : "zlib-stream";
103
+ this.resumeURL += `&compress=${type}`;
104
+ }
105
+ this.sessionID = data.session_id;
106
+ for (const guild of data.guilds) {
107
+ this.client.guilds.delete(guild.id);
108
+ this.client.unavailableGuilds.update(guild);
109
+ }
110
+ this.preReady = true;
111
+ this.emit("preReady");
112
+ if (this.client.unavailableGuilds.size !== 0 && data.guilds.length !== 0) {
113
+ void this.restartGuildCreateTimeout();
114
+ }
115
+ else {
116
+ void this.checkReady();
117
+ }
118
+ }
119
+ _resume() {
120
+ this.connectAttempts = 0;
121
+ this.reconnectInterval = 1000;
122
+ this.connecting = false;
123
+ if (this._connectTimeout) {
124
+ clearTimeout(this._connectTimeout);
125
+ }
126
+ this.status = "ready";
127
+ this.client.shards["_ready"](this.id);
128
+ void this.checkReady();
129
+ this.emit("resume");
130
+ }
131
+ async checkReady() {
132
+ if (!this.ready) {
133
+ if (this._getAllUsersQueue.length !== 0) {
134
+ const id = this._getAllUsersQueue.shift();
135
+ await this.requestGuildMembers(id);
136
+ return;
137
+ }
138
+ if (Object.keys(this._getAllUsersCount).length === 0) {
139
+ this.ready = true;
140
+ this.emit("ready");
141
+ }
142
+ }
143
+ }
144
+ createGuild(data) {
145
+ this.client.guildShardMap.set(data.id, this.id);
146
+ const guild = this.client.guilds.update(data);
147
+ if (this.client.shards.options.getAllUsers && guild.members.size < guild.memberCount) {
148
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
149
+ void this.requestGuildMembers(guild.id, { presences: (this.client.shards.options.intents & Constants_1.Intents.GUILD_PRESENCES) === Constants_1.Intents.GUILD_PRESENCES });
150
+ }
151
+ return guild;
152
+ }
153
+ async initialize() {
154
+ if (!this._token) {
155
+ return this.disconnect(false, new TypeError("Invalid Token."));
156
+ }
157
+ this.status = "connecting";
158
+ if (this.client.shards.options.compress) {
159
+ const type = this.client.shards.options.compress;
160
+ const library = this.client.shards.options.compressLibrary;
161
+ const config = config_1.default[type]?.find(cnf => cnf.name === library);
162
+ if (!config) {
163
+ throw new Error("Invalid compression config");
164
+ }
165
+ this.client.emit("debug", `Initializing ${type} compression with ${library}.`);
166
+ this._compressor = new (config.getClass())(this);
167
+ }
168
+ if (!this.client.shards.options.override.gatewayURLIsResumeURL && this.sessionID) {
169
+ if (this.resumeURL === null) {
170
+ this.client.emit("warn", "Resume url is not currently present. Discord may disconnect you quicker.", this.id);
171
+ }
172
+ this.ws = new ws_1.default(this.resumeURL ?? await this.client.shards["_gatewayURLForShard"](this), this.client.shards.options.ws);
173
+ }
174
+ else {
175
+ this.ws = new ws_1.default(await this.client.shards["_gatewayURLForShard"](this), this.client.shards.options.ws);
176
+ }
177
+ /* eslint-disable @typescript-eslint/unbound-method */
178
+ this.ws.on("close", this.onWSClose);
179
+ this.ws.on("error", this.onWSError);
180
+ this.ws.on("message", this.onWSMessage);
181
+ this.ws.on("open", this.onWSOpen);
182
+ /* eslint-enable @typescript-eslint/unbound-method */
183
+ this._connectTimeout = setTimeout(() => {
184
+ if (this.connecting) {
185
+ this.disconnect(undefined, new Error("Connection timeout."));
186
+ }
187
+ }, this.client.shards.options.connectionTimeout);
188
+ }
189
+ onPacket(packet) {
190
+ if ("s" in packet && packet.s) {
191
+ if (packet.s > this.sequence + 1 && this.ws && this.status !== "resuming") {
192
+ this.client.emit("warn", `Non-consecutive sequence (${this.sequence} -> ${packet.s})`, this.id);
193
+ }
194
+ this.sequence = packet.s;
195
+ }
196
+ switch (packet.op) {
197
+ case Constants_1.GatewayOPCodes.DISPATCH: {
198
+ this.client.emit("packet", packet, this.id);
199
+ this.manager.dispatcher["handle"](packet, this);
200
+ break;
201
+ }
202
+ case Constants_1.GatewayOPCodes.HEARTBEAT: {
203
+ this.heartbeat(true);
204
+ break;
205
+ }
206
+ case Constants_1.GatewayOPCodes.INVALID_SESSION: {
207
+ if (packet.d) {
208
+ this.client.emit("warn", "Session Invalidated. Session may be resumable, attempting to resume..", this.id);
209
+ this.resume();
210
+ }
211
+ else {
212
+ this.sequence = 0;
213
+ this.sessionID = null;
214
+ this.client.emit("warn", "Session Invalidated. Session is not resumable, requesting a new session..", this.id);
215
+ this.identify();
216
+ }
217
+ break;
218
+ }
219
+ case Constants_1.GatewayOPCodes.RECONNECT: {
220
+ this.client.emit("debug", "Reconnect requested by Discord.", this.id);
221
+ this.disconnect(true);
222
+ break;
223
+ }
224
+ case Constants_1.GatewayOPCodes.HELLO: {
225
+ if (this._heartbeatInterval) {
226
+ clearInterval(this._heartbeatInterval);
227
+ }
228
+ this._heartbeatInterval = setInterval(() => this.heartbeat(false), packet.d.heartbeat_interval);
229
+ this.connecting = false;
230
+ if (this._connectTimeout) {
231
+ clearTimeout(this._connectTimeout);
232
+ }
233
+ this._connectTimeout = null;
234
+ if (this.sessionID) {
235
+ this.resume();
236
+ }
237
+ else {
238
+ this.identify();
239
+ this.heartbeat();
240
+ }
241
+ this.client.emit("hello", packet.d.heartbeat_interval, this.id);
242
+ break;
243
+ }
244
+ case Constants_1.GatewayOPCodes.HEARTBEAT_ACK: {
245
+ this.lastHeartbeatAck = true;
246
+ this.lastHeartbeatReceived = Date.now();
247
+ this.latency = this.lastHeartbeatReceived - this.lastHeartbeatSent;
248
+ if (isNaN(this.latency)) {
249
+ this.latency = Infinity;
250
+ }
251
+ break;
252
+ }
253
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
254
+ default: {
255
+ this.client.emit("warn", `Unrecognized gateway packet: ${packet}`, this.id);
256
+ }
257
+ }
258
+ }
259
+ async onWSClose(code, r) {
260
+ const reason = r.toString();
261
+ let err;
262
+ let reconnect;
263
+ if (code) {
264
+ this.client.emit("debug", `${code === 1000 ? "Clean" : "Unclean"} WS close: ${code}: ${reason}`, this.id);
265
+ switch (code) {
266
+ case 1001: {
267
+ err = new Errors_1.GatewayError("CloudFlare WebSocket proxy restarting.", code);
268
+ break;
269
+ }
270
+ case 1006: {
271
+ err = new Errors_1.GatewayError("Connection reset by peer. This is a network issue. If you are concerned, talk to your ISP or host.", code);
272
+ break;
273
+ }
274
+ case Constants_1.GatewayCloseCodes.UNKNOWN_OPCODE: {
275
+ err = new Errors_1.GatewayError("Gateway received an unknown opcode.", code);
276
+ break;
277
+ }
278
+ case Constants_1.GatewayCloseCodes.DECODE_ERROR: {
279
+ err = new Errors_1.GatewayError("Gateway received an improperly encoded packet.", code);
280
+ break;
281
+ }
282
+ case Constants_1.GatewayCloseCodes.NOT_AUTHENTICATED: {
283
+ err = new Errors_1.GatewayError("Gateway received a packet before authentication.", code);
284
+ this.sessionID = null;
285
+ break;
286
+ }
287
+ case Constants_1.GatewayCloseCodes.AUTHENTICATION_FAILED: {
288
+ err = new Errors_1.GatewayError("Authentication failed.", code);
289
+ this.sessionID = null;
290
+ reconnect = false;
291
+ this.client.emit("error", new Error(`Invalid Token: ${this._token}`));
292
+ break;
293
+ }
294
+ case Constants_1.GatewayCloseCodes.ALREADY_AUTHENTICATED: {
295
+ err = new Errors_1.GatewayError("Gateway received an authentication attempt while already authenticated.", code);
296
+ break;
297
+ }
298
+ case Constants_1.GatewayCloseCodes.INVALID_SEQUENCE: {
299
+ err = new Errors_1.GatewayError("Gateway received an invalid sequence.", code);
300
+ this.sequence = 0;
301
+ break;
302
+ }
303
+ case Constants_1.GatewayCloseCodes.RATE_LIMITED: {
304
+ err = new Errors_1.GatewayError("Gateway connection was ratelimited.", code);
305
+ break;
306
+ }
307
+ case Constants_1.GatewayCloseCodes.INVALID_SHARD: {
308
+ err = new Errors_1.GatewayError("Invalid sharding specified.", code);
309
+ this.sessionID = null;
310
+ reconnect = false;
311
+ break;
312
+ }
313
+ case Constants_1.GatewayCloseCodes.SHARDING_REQUIRED: {
314
+ err = new Errors_1.GatewayError("Shard would handle too many guilds (>2500 each).", code);
315
+ this.sessionID = null;
316
+ reconnect = false;
317
+ break;
318
+ }
319
+ case Constants_1.GatewayCloseCodes.INVALID_API_VERSION: {
320
+ err = new Errors_1.GatewayError("Invalid API version.", code);
321
+ this.sessionID = null;
322
+ reconnect = false;
323
+ break;
324
+ }
325
+ case Constants_1.GatewayCloseCodes.INVALID_INTENTS: {
326
+ err = new Errors_1.GatewayError("Invalid intents specified.", code);
327
+ this.sessionID = null;
328
+ reconnect = false;
329
+ break;
330
+ }
331
+ case Constants_1.GatewayCloseCodes.DISALLOWED_INTENTS: {
332
+ const disallowed = this.client.shards.options.lookupDisallowedIntents ? await this.client.util.detectMissingPrivilegedIntents() : [];
333
+ let message = "Disallowed intents specified. Make sure any privileged intents you're trying to access have been enabled in the developer portal.";
334
+ if (disallowed.length !== 0) {
335
+ // application should always be present after the call to detectMissingPrivilegedIntents, but just in case it isn't, we don't want to swallow this disallowed intents error with a lib error
336
+ message = `Disallowed intents specified. You are missing: ${disallowed.join(", ")}. Make sure they are enabled here: https://discord.com/developers/applications/${this.client["_application"]?.id || "unknown"}/bot`;
337
+ }
338
+ err = new Errors_1.GatewayError(message, code);
339
+ this.sessionID = null;
340
+ reconnect = false;
341
+ break;
342
+ }
343
+ default: {
344
+ err = new Errors_1.GatewayError(`Unknown close: ${code}: ${reason}`, code);
345
+ break;
346
+ }
347
+ }
348
+ this.disconnect(reconnect, err);
349
+ }
350
+ }
351
+ onWSError(err) {
352
+ this.client.emit("error", err, this.id);
353
+ }
354
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-argument */
355
+ async onWSMessage(data) {
356
+ if (typeof data === "string") {
357
+ data = Buffer.from(data);
358
+ }
359
+ try {
360
+ if (data instanceof ArrayBuffer) {
361
+ if (this.client.shards.options.compress || Erlpack) {
362
+ data = Buffer.from(data);
363
+ }
364
+ }
365
+ else if (Array.isArray(data)) {
366
+ data = Buffer.concat(data);
367
+ }
368
+ const buf = data;
369
+ if (this.client.shards.options.compress) {
370
+ let result = await this._compressor.decompress(buf);
371
+ if (result === null) {
372
+ return;
373
+ }
374
+ if (Erlpack) {
375
+ return this.onPacket(Erlpack.unpack(result));
376
+ }
377
+ else {
378
+ // After the valid data, all the remaining octets are filled with zero, so remove them.
379
+ let last = result.length - 1;
380
+ if (result[last] === 0) {
381
+ while (result[last - 1] === 0 && last > 0)
382
+ last--;
383
+ result = result.subarray(0, last);
384
+ }
385
+ return this.onPacket(JSON.parse(String(result)));
386
+ }
387
+ }
388
+ else if (Erlpack) {
389
+ return this.onPacket(Erlpack.unpack(buf));
390
+ }
391
+ else {
392
+ return this.onPacket(JSON.parse(String(buf)));
393
+ }
394
+ }
395
+ catch (err) {
396
+ this.client.emit("error", err, this.id);
397
+ }
398
+ }
399
+ /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-argument */
400
+ onWSOpen() {
401
+ this.status = "handshaking";
402
+ this.client.emit("connect", this.id);
403
+ this.lastHeartbeatAck = true;
404
+ }
405
+ async restartGuildCreateTimeout() {
406
+ if (this._guildCreateTimeout) {
407
+ clearTimeout(this._guildCreateTimeout);
408
+ this._guildCreateTimeout = null;
409
+ }
410
+ if (!this.ready) {
411
+ if (this.client.unavailableGuilds.size === 0) {
412
+ return this.checkReady();
413
+ }
414
+ this._guildCreateTimeout = setTimeout(this.checkReady.bind(this), this.client.shards.options.guildCreateTimeout);
415
+ }
416
+ }
417
+ sendPresenceUpdate() {
418
+ this.send(Constants_1.GatewayOPCodes.PRESENCE_UPDATE, {
419
+ activities: this.presence.activities,
420
+ afk: !!this.presence.afk,
421
+ since: this.presence.status === "idle" ? Date.now() : null,
422
+ status: this.presence.status
423
+ });
424
+ }
425
+ get _token() {
426
+ return this.client.options.auth;
427
+ }
428
+ /** Connect this shard. */
429
+ async connect() {
430
+ if (this.ws && this.ws.readyState !== ws_1.default.CLOSED) {
431
+ this.client.emit("error", new Error("Shard#connect called while existing connection is established."), this.id);
432
+ return;
433
+ }
434
+ ++this.connectAttempts;
435
+ this.connecting = true;
436
+ await this.initialize();
437
+ }
438
+ disconnect(reconnect = this.client.shards.options.autoReconnect, error) {
439
+ if (!this.ws) {
440
+ return;
441
+ }
442
+ if (this._heartbeatInterval) {
443
+ clearInterval(this._heartbeatInterval);
444
+ this._heartbeatInterval = null;
445
+ }
446
+ if (this.ws.readyState !== ws_1.default.CLOSED) {
447
+ this.ws.removeAllListeners();
448
+ try {
449
+ if (reconnect && this.sessionID) {
450
+ if (this.ws.readyState === ws_1.default.OPEN) {
451
+ this.client.emit("debug", `Closing websocket (state: ${this.ws.readyState})`, this.id);
452
+ this.ws.terminate();
453
+ }
454
+ else {
455
+ this.ws.close(4999, "Reconnect");
456
+ }
457
+ }
458
+ else {
459
+ this.ws.close(1000, "Normal Close");
460
+ }
461
+ }
462
+ catch (err) {
463
+ this.client.emit("error", err, this.id);
464
+ }
465
+ }
466
+ this.ws = null;
467
+ this.reset();
468
+ if (error) {
469
+ if (error instanceof Errors_1.GatewayError && [1001, 1006].includes(error.code)) {
470
+ this.client.emit("debug", error.message, this.id);
471
+ }
472
+ else {
473
+ this.client.emit("error", error, this.id);
474
+ }
475
+ }
476
+ this.emit("disconnect", error);
477
+ if (this.sessionID && this.connectAttempts >= this.client.shards.options.maxReconnectAttempts) {
478
+ this.client.emit("debug", `Automatically invalidating session due to excessive resume attempts | Attempt ${this.connectAttempts}`, this.id);
479
+ this.sessionID = null;
480
+ }
481
+ if (reconnect) {
482
+ if (this.sessionID) {
483
+ this.client.emit("debug", `Immediately reconnecting for potential resume | Attempt ${this.connectAttempts}`, this.id);
484
+ void this.client.shards["_connect"](this);
485
+ }
486
+ else {
487
+ this.client.emit("debug", `Queueing reconnect in ${this.reconnectInterval}ms | Attempt ${this.connectAttempts}`, this.id);
488
+ setTimeout(() => {
489
+ void this.client.shards["_connect"](this);
490
+ }, this.reconnectInterval);
491
+ this.reconnectInterval = Math.min(Math.round(this.reconnectInterval * (Math.random() * 2 + 1)), 30000);
492
+ }
493
+ }
494
+ else {
495
+ this.hardReset();
496
+ }
497
+ }
498
+ /**
499
+ * Edit this shard's status.
500
+ * @param status The status.
501
+ * @param activities An array of activities.
502
+ */
503
+ async editStatus(status, activities = []) {
504
+ this.presence.status = status;
505
+ this.presence.activities = activities;
506
+ return this.sendPresenceUpdate();
507
+ }
508
+ hardReset() {
509
+ this.reset();
510
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
511
+ for (const [, voiceAdapter] of this.client.voiceAdapters)
512
+ voiceAdapter.destroy();
513
+ this.sequence = 0;
514
+ this.sessionID = null;
515
+ this.reconnectInterval = 1000;
516
+ this.connectAttempts = 0;
517
+ this.ws = null;
518
+ this._heartbeatInterval = null;
519
+ this._guildCreateTimeout = null;
520
+ this.globalBucket = new Bucket_1.default(120, 60000, { reservedTokens: 5 });
521
+ this.presence = structuredClone(this.client.shards.options.presence);
522
+ this.presenceUpdateBucket = new Bucket_1.default(5, 20000);
523
+ this.resumeURL = null;
524
+ }
525
+ heartbeat(requested = false) {
526
+ // discord/discord-api-docs#1619
527
+ if (this.status === "resuming" || this.status === "identifying") {
528
+ return;
529
+ }
530
+ if (!requested) {
531
+ if (!this.lastHeartbeatAck) {
532
+ this.client.emit("debug", "Heartbeat timeout; " + JSON.stringify({
533
+ lastReceived: this.lastHeartbeatReceived,
534
+ lastSent: this.lastHeartbeatSent,
535
+ interval: this._heartbeatInterval,
536
+ status: this.status,
537
+ timestamp: Date.now()
538
+ }));
539
+ return this.disconnect(undefined, new Error("Server didn't acknowledge previous heartbeat, possible lost connection."));
540
+ }
541
+ this.lastHeartbeatAck = false;
542
+ }
543
+ this.lastHeartbeatSent = Date.now();
544
+ this.send(Constants_1.GatewayOPCodes.HEARTBEAT, this.sequence, true);
545
+ }
546
+ identify() {
547
+ const data = {
548
+ token: this._token,
549
+ properties: this.client.shards.options.connectionProperties,
550
+ compress: this.client.shards.options.compress,
551
+ large_threshold: this.client.shards.options.largeThreshold,
552
+ shard: [this.id, this.client.shards.options.maxShards],
553
+ presence: this.presence,
554
+ intents: this.client.shards.options.intents
555
+ };
556
+ this.send(Constants_1.GatewayOPCodes.IDENTIFY, data);
557
+ }
558
+ [node_util_1.inspect.custom]() {
559
+ return Base_1.default.prototype[node_util_1.inspect.custom].call(this);
560
+ }
561
+ /**
562
+ * Request the members of a guild.
563
+ * @param guildID The ID of the guild to request the members of.
564
+ * @param options The options for requesting the members.
565
+ */
566
+ async requestGuildMembers(guildID, options) {
567
+ const opts = {
568
+ guild_id: guildID,
569
+ limit: options?.limit ?? 0,
570
+ user_ids: options?.userIDs,
571
+ query: options?.query,
572
+ nonce: (0, node_crypto_1.randomBytes)(16).toString("hex"),
573
+ presences: options?.presences ?? false
574
+ };
575
+ if (!opts.user_ids && !opts.query) {
576
+ opts.query = "";
577
+ }
578
+ if (!opts.query && !opts.user_ids) {
579
+ if (!(this.client.shards.options.intents & Constants_1.Intents.GUILD_MEMBERS)) {
580
+ throw new TypeError("Cannot request all members without the GUILD_MEMBERS intent.");
581
+ }
582
+ const guild = this.client.guilds.get(guildID);
583
+ if (guild) {
584
+ guild["updateMemberLimit"](true);
585
+ }
586
+ }
587
+ if (opts.presences && (!(this.client.shards.options.intents & Constants_1.Intents.GUILD_PRESENCES))) {
588
+ throw new TypeError("Cannot request presences without the GUILD_PRESENCES intent.");
589
+ }
590
+ if (opts.user_ids && opts.user_ids.length > 100) {
591
+ throw new TypeError("Cannot request more than 100 users at once.");
592
+ }
593
+ this.send(Constants_1.GatewayOPCodes.REQUEST_GUILD_MEMBERS, opts);
594
+ return new Promise((resolve, reject) => this._requestMembersPromise[opts.nonce] = {
595
+ members: [],
596
+ received: 0,
597
+ timeout: setTimeout(() => {
598
+ resolve(this._requestMembersPromise[opts.nonce].members);
599
+ delete this._requestMembersPromise[opts.nonce];
600
+ }, options?.timeout ?? this.client.rest.options.requestTimeout),
601
+ resolve,
602
+ reject
603
+ });
604
+ }
605
+ async requestSoundboardSounds(guildID, options) {
606
+ const opts = {
607
+ guild_ids: [guildID],
608
+ nonce: (0, node_crypto_1.randomBytes)(16).toString("hex")
609
+ };
610
+ this.send(Constants_1.GatewayOPCodes.REQUEST_SOUNDBOARD_SOUNDS, opts);
611
+ return new Promise((resolve, reject) => this._requestSoundboardSoundsPromise[opts.nonce] = {
612
+ guildID,
613
+ soundboardSounds: [],
614
+ timeout: setTimeout(() => {
615
+ resolve(this._requestSoundboardSoundsPromise[opts.nonce].soundboardSounds);
616
+ delete this._requestSoundboardSoundsPromise[opts.nonce];
617
+ }, options?.timeout ?? this.client.rest.options.requestTimeout),
618
+ resolve,
619
+ reject
620
+ });
621
+ }
622
+ reset() {
623
+ this.connecting = false;
624
+ this.ready = false;
625
+ this.preReady = false;
626
+ if (this._requestMembersPromise !== undefined) {
627
+ for (const guildID in this._requestMembersPromise) {
628
+ if (!this._requestMembersPromise[guildID]) {
629
+ continue;
630
+ }
631
+ clearTimeout(this._requestMembersPromise[guildID].timeout);
632
+ this._requestMembersPromise[guildID].resolve(this._requestMembersPromise[guildID].received);
633
+ }
634
+ }
635
+ this._requestMembersPromise = {};
636
+ this._getAllUsersCount = {};
637
+ this._getAllUsersQueue = [];
638
+ this.latency = Infinity;
639
+ this.lastHeartbeatAck = true;
640
+ this.lastHeartbeatReceived = 0;
641
+ this.lastHeartbeatSent = 0;
642
+ this.status = "disconnected";
643
+ if (this._connectTimeout) {
644
+ clearTimeout(this._connectTimeout);
645
+ }
646
+ this._connectTimeout = null;
647
+ }
648
+ resume() {
649
+ this.status = "resuming";
650
+ this.send(Constants_1.GatewayOPCodes.RESUME, {
651
+ token: this._token,
652
+ session_id: this.sessionID,
653
+ seq: this.sequence
654
+ });
655
+ }
656
+ send(op, data, priority = false) {
657
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
658
+ let i = 0, waitFor = 1;
659
+ const func = () => {
660
+ if (++i >= waitFor && this.ws && this.ws.readyState === ws_1.default.OPEN) {
661
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
662
+ const d = Erlpack ? Erlpack.pack({ op, d: data }) : JSON.stringify({ op, d: data });
663
+ this.ws.send(d);
664
+ if (typeof data === "object" && data && "token" in data) {
665
+ data.token = "[REMOVED]";
666
+ }
667
+ this.client.emit("debug", JSON.stringify({ op, d: data }), this.id);
668
+ }
669
+ };
670
+ if (op === Constants_1.GatewayOPCodes.PRESENCE_UPDATE) {
671
+ ++waitFor;
672
+ this.presenceUpdateBucket.queue(func, priority);
673
+ }
674
+ this.globalBucket.queue(func, priority);
675
+ }
676
+ }
677
+ toString() {
678
+ return Base_1.default.prototype.toString.call(this);
679
+ }
680
+ /**
681
+ * Update the voice state of this shard.
682
+ * @param guildID The ID of the guild to update the voice state of.
683
+ * @param channelID The ID of the voice channel to join. Null to disconnect.
684
+ * @param options The options for updating the voice state.
685
+ */
686
+ updateVoiceState(guildID, channelID, options) {
687
+ this.send(Constants_1.GatewayOPCodes.VOICE_STATE_UPDATE, {
688
+ channel_id: channelID,
689
+ guild_id: guildID,
690
+ self_deaf: options?.selfDeaf ?? false,
691
+ self_mute: options?.selfMute ?? false
692
+ });
693
+ }
694
+ }
695
+ exports.default = Shard;