@manybot/manybot 5.7.0 → 5.9.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 (81) hide show
  1. package/README.md +28 -3
  2. package/dist/client/banner.js +10 -0
  3. package/dist/client/banner.test.js +31 -0
  4. package/dist/client/store.js +91 -6
  5. package/dist/client/store.test.js +170 -0
  6. package/dist/config.js +28 -44
  7. package/dist/config.test.js +26 -0
  8. package/dist/download/queue.js +13 -4
  9. package/dist/drivers/baileys/adapter.js +133 -15
  10. package/dist/drivers/baileys/api/contacts.integration.test.js +261 -0
  11. package/dist/drivers/baileys/api/groupMeta.test.js +235 -0
  12. package/dist/drivers/baileys/api/index.js +384 -62
  13. package/dist/drivers/baileys/index.js +92 -36
  14. package/dist/drivers/baileys/loginPrompt.js +0 -2
  15. package/dist/drivers/baileys/messageHandler.js +344 -4
  16. package/dist/drivers/baileys/messageHandler.test.js +445 -0
  17. package/dist/drivers/baileysAdapter.test.js +378 -0
  18. package/dist/drivers/jid.js +26 -0
  19. package/dist/drivers/jid.test.js +74 -0
  20. package/dist/drivers/types.js +5 -5
  21. package/dist/i18n/index.js +20 -24
  22. package/dist/kernel/activeDriverSend.js +21 -0
  23. package/dist/kernel/activeDriverSend.test.js +89 -0
  24. package/dist/kernel/alerts.js +3 -9
  25. package/dist/kernel/chatOverrides.js +46 -0
  26. package/dist/kernel/chatOverrides.test.js +59 -0
  27. package/dist/kernel/chatSession.js +65 -0
  28. package/dist/kernel/chatSession.test.js +46 -0
  29. package/dist/kernel/commandAccess.js +66 -0
  30. package/dist/kernel/commandAccess.test.js +74 -0
  31. package/dist/kernel/commandDeprecation.js +170 -0
  32. package/dist/kernel/commandDeprecation.test.js +114 -0
  33. package/dist/kernel/commandMenu.js +357 -0
  34. package/dist/kernel/commandMenu.test.js +363 -0
  35. package/dist/kernel/commandPermissions.js +171 -0
  36. package/dist/kernel/commandPermissions.test.js +227 -0
  37. package/dist/kernel/commandRegistry.js +583 -0
  38. package/dist/kernel/commandRegistry.test.js +158 -0
  39. package/dist/kernel/commandsConfig.js +949 -0
  40. package/dist/kernel/commandsConfig.test.js +482 -0
  41. package/dist/kernel/contactAutoSave.js +6 -6
  42. package/dist/kernel/contactAutoSave.test.js +87 -0
  43. package/dist/kernel/coreCommands.js +62 -0
  44. package/dist/kernel/driverManager.js +10 -6
  45. package/dist/kernel/driverManager.test.js +90 -0
  46. package/dist/kernel/integrationMode.js +88 -0
  47. package/dist/kernel/integrationMode.test.js +95 -0
  48. package/dist/kernel/loadIntegrationPlugin.test.js +67 -0
  49. package/dist/kernel/pluginApi.test.js +600 -0
  50. package/dist/kernel/pluginGuard.js +18 -13
  51. package/dist/kernel/pluginGuard.test.js +39 -0
  52. package/dist/kernel/pluginLoader.js +169 -11
  53. package/dist/kernel/pluginLoader.test.js +190 -0
  54. package/dist/kernel/runCommand.js +284 -0
  55. package/dist/kernel/runCommand.test.js +497 -0
  56. package/dist/kernel/sendFallbackGuard.js +19 -48
  57. package/dist/kernel/sendFallbackGuard.test.js +80 -0
  58. package/dist/kernel/sendGuard.js +38 -42
  59. package/dist/kernel/sendGuard.test.js +102 -0
  60. package/dist/kernel/settingsDb.js +19 -5
  61. package/dist/kernel/statusServer.js +9 -2
  62. package/dist/kernel/statusServer.test.js +70 -0
  63. package/dist/kernel/testConfig.js +192 -0
  64. package/dist/kernel/testConfig.test.js +181 -0
  65. package/dist/kernel/updateCheck.js +33 -10
  66. package/dist/locales/en.json +77 -13
  67. package/dist/locales/es.json +77 -13
  68. package/dist/locales/pt.json +77 -13
  69. package/dist/logger/logger.js +23 -3
  70. package/dist/logger/logger.test.js +45 -0
  71. package/dist/main.js +5 -76
  72. package/dist/plugins/__manybot_integration__/index.js +184 -0
  73. package/dist/plugins/__manybot_integration__/index.test.js +218 -0
  74. package/dist/utils/phoneNumber.js +83 -0
  75. package/dist/utils/phoneNumber.test.js +53 -0
  76. package/package.json +76 -18
  77. package/dist/drivers/whatsmeow/client.js +0 -252
  78. package/dist/drivers/whatsmeow/index.js +0 -79
  79. package/dist/drivers/whatsmeow/installer.js +0 -86
  80. package/dist/drivers/whatsmeow/supervisor.js +0 -328
  81. package/dist/drivers/whatsmeow/whatsmeow.proto +0 -64
@@ -0,0 +1,158 @@
1
+ import test, { describe } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { buildCommandRegistry } from "#kernel/commandRegistry.js";
4
+ function createMockPluginRegistry(plugins) {
5
+ const map = new Map();
6
+ for (const p of plugins) {
7
+ map.set(p.name, {
8
+ name: p.name,
9
+ status: p.status ?? "active",
10
+ manifest: { name: p.name, version: "1.0.0" },
11
+ commands: p.commands ?? {},
12
+ });
13
+ }
14
+ return map;
15
+ }
16
+ describe("kernel/commandRegistry", () => {
17
+ test("builds registry from active plugin defaults", () => {
18
+ const plugins = createMockPluginRegistry([
19
+ {
20
+ name: "pingPlugin",
21
+ commands: {
22
+ pingFn: {
23
+ cmd: "ping",
24
+ aliases: ["p"],
25
+ desc: "Pong command",
26
+ handler: async () => "pong",
27
+ },
28
+ },
29
+ },
30
+ ]);
31
+ const registry = buildCommandRegistry(null, plugins);
32
+ assert.equal(registry.byId.size, 1);
33
+ const entry = registry.byId.get("pingPlugin::pingFn");
34
+ assert.ok(entry);
35
+ assert.equal(entry?.cmd, "ping");
36
+ assert.deepEqual(entry?.aliases, ["p"]);
37
+ assert.equal(entry?.source, "plugin");
38
+ assert.equal(registry.byInvocation.get("ping"), "pingPlugin::pingFn");
39
+ assert.equal(registry.byInvocation.get("p"), "pingPlugin::pingFn");
40
+ });
41
+ test("skips plugin commands with a non-string cmd instead of throwing", () => {
42
+ const plugins = createMockPluginRegistry([
43
+ {
44
+ name: "brokenPlugin",
45
+ commands: {
46
+ badFn: {
47
+ cmd: true,
48
+ handler: async () => "x",
49
+ },
50
+ goodFn: {
51
+ cmd: "ok",
52
+ aliases: [1, "valid", null],
53
+ handler: async () => "x",
54
+ },
55
+ },
56
+ },
57
+ ]);
58
+ assert.doesNotThrow(() => buildCommandRegistry(null, plugins));
59
+ const registry = buildCommandRegistry(null, plugins);
60
+ assert.equal(registry.byId.has("brokenPlugin::badFn"), false);
61
+ const good = registry.byId.get("brokenPlugin::goodFn");
62
+ assert.ok(good);
63
+ assert.equal(good?.cmd, "ok");
64
+ assert.deepEqual(good?.aliases, ["valid"]);
65
+ });
66
+ test("applies spec overrides to plugin commands", () => {
67
+ const plugins = createMockPluginRegistry([
68
+ {
69
+ name: "funPlugin",
70
+ commands: {
71
+ jokeFn: {
72
+ cmd: "joke",
73
+ aliases: ["j"],
74
+ desc: "Original desc",
75
+ },
76
+ },
77
+ },
78
+ ]);
79
+ const specs = [
80
+ {
81
+ id: "funPlugin::jokeFn",
82
+ plugin: "funPlugin",
83
+ functions: ["jokeFn"],
84
+ loading: null,
85
+ cmd: "telljoke",
86
+ aliases: ["tj"],
87
+ desc: "Overridden desc",
88
+ category: "Fun",
89
+ group: null,
90
+ manual: null,
91
+ text: null,
92
+ deprecatedMessage: null,
93
+ notifyChanges: null,
94
+ permissions: { admin: true },
95
+ messages: null,
96
+ arguments: [],
97
+ subcommands: [],
98
+ },
99
+ ];
100
+ const registry = buildCommandRegistry(specs, plugins);
101
+ const entry = registry.byId.get("funPlugin::jokeFn");
102
+ assert.ok(entry);
103
+ assert.equal(entry?.cmd, "telljoke");
104
+ assert.deepEqual(entry?.aliases, ["tj"]);
105
+ assert.equal(entry?.desc, "Overridden desc");
106
+ assert.equal(entry?.category, "Fun");
107
+ assert.equal(entry?.permissions.admin, true);
108
+ // Old invocation "joke" should no longer map to entry if overridden by new cmd/aliases
109
+ assert.equal(registry.byInvocation.get("telljoke"), "funPlugin::jokeFn");
110
+ assert.equal(registry.byInvocation.get("tj"), "funPlugin::jokeFn");
111
+ });
112
+ test("registers text-only command specs", () => {
113
+ const plugins = createMockPluginRegistry([]);
114
+ const specs = [
115
+ {
116
+ id: "custom_hello",
117
+ plugin: null,
118
+ functions: [],
119
+ loading: null,
120
+ cmd: "hello",
121
+ aliases: ["hi"],
122
+ desc: "Says hello",
123
+ category: "General",
124
+ group: null,
125
+ manual: null,
126
+ text: "Hello World!",
127
+ deprecatedMessage: null,
128
+ notifyChanges: null,
129
+ permissions: null,
130
+ messages: null,
131
+ arguments: [],
132
+ subcommands: [],
133
+ },
134
+ ];
135
+ const registry = buildCommandRegistry(specs, plugins);
136
+ assert.equal(registry.byId.size, 1);
137
+ const entry = registry.byId.get("text::custom_hello");
138
+ assert.ok(entry);
139
+ assert.equal(entry?.source, "text");
140
+ assert.equal(entry?.text, "Hello World!");
141
+ assert.equal(registry.byInvocation.get("hello"), "text::custom_hello");
142
+ assert.equal(registry.byInvocation.get("hi"), "text::custom_hello");
143
+ });
144
+ test("ignores inactive plugin commands", () => {
145
+ const plugins = createMockPluginRegistry([
146
+ {
147
+ name: "disabledPlugin",
148
+ status: "inactive",
149
+ commands: {
150
+ testFn: { cmd: "disabledCmd" },
151
+ },
152
+ },
153
+ ]);
154
+ const registry = buildCommandRegistry(null, plugins);
155
+ assert.equal(registry.byId.size, 0);
156
+ assert.equal(registry.byInvocation.has("disabledCmd"), false);
157
+ });
158
+ });