@badgerclaw/connect 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -92,9 +92,9 @@ export async function handleBotCommand(params: {
|
|
|
92
92
|
" Works in: Any room or DM",
|
|
93
93
|
"",
|
|
94
94
|
"/bot add <botname>",
|
|
95
|
-
" Invite a bot to the current room.
|
|
96
|
-
" will be @<botname>_bot on this server.",
|
|
95
|
+
" Invite a bot to the current room.",
|
|
97
96
|
" Example: /bot add jarvis → invites @jarvis_bot",
|
|
97
|
+
" Also accepts: /bot add @jarvis_bot",
|
|
98
98
|
" Works in: Any room",
|
|
99
99
|
"",
|
|
100
100
|
"━━━ BotBadger DM Only ━━━",
|
|
@@ -116,9 +116,8 @@ export async function handleBotCommand(params: {
|
|
|
116
116
|
" Works in: Direct message with BotBadger only",
|
|
117
117
|
"",
|
|
118
118
|
"/bot list",
|
|
119
|
-
" List all
|
|
120
|
-
" 🟢
|
|
121
|
-
" 🔴 Not connected — bot needs pairing",
|
|
119
|
+
" List all bots in this room.",
|
|
120
|
+
" 🟢 = this bot 🤖 = other bots",
|
|
122
121
|
" Works in: Any room or DM",
|
|
123
122
|
].join("\n"),
|
|
124
123
|
});
|
|
@@ -158,7 +157,8 @@ export async function handleBotCommand(params: {
|
|
|
158
157
|
if (arg === "on") {
|
|
159
158
|
// Multiple bots + no specific mention → ask which bot
|
|
160
159
|
if (multipleBots && !mentionedBot) {
|
|
161
|
-
const
|
|
160
|
+
const allBots = [selfUserId, ...roomBots];
|
|
161
|
+
const botList = allBots
|
|
162
162
|
.map((b, i) => ` ${i + 1}. ${b.split(":")[0]}`)
|
|
163
163
|
.join("\n");
|
|
164
164
|
await client.sendMessage(roomId, {
|
|
@@ -209,31 +209,75 @@ export async function handleBotCommand(params: {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
case "add": {
|
|
212
|
-
|
|
213
|
-
if (!
|
|
212
|
+
let rawName = parts.slice(2).join(" ").trim();
|
|
213
|
+
if (!rawName) {
|
|
214
214
|
await client.sendMessage(roomId, {
|
|
215
215
|
msgtype: "m.text",
|
|
216
|
-
body: "Usage: /bot add <botname
|
|
216
|
+
body: "Usage: /bot add <botname>\nExample: /bot add jarvis or /bot add @jarvis_bot",
|
|
217
217
|
});
|
|
218
218
|
return true;
|
|
219
219
|
}
|
|
220
|
-
|
|
220
|
+
// Normalize: strip @, strip _bot suffix, strip :server
|
|
221
|
+
rawName = rawName.replace(/^@/, "").split(":")[0].replace(/_bot$/i, "").toLowerCase();
|
|
222
|
+
const addBotUserId = `@${rawName}_bot:badger.signout.io`;
|
|
223
|
+
const addBotDisplay = `@${rawName}_bot`;
|
|
221
224
|
try {
|
|
222
|
-
await client.inviteUser(
|
|
225
|
+
await client.inviteUser(addBotUserId, roomId);
|
|
223
226
|
await client.sendMessage(roomId, {
|
|
224
227
|
msgtype: "m.text",
|
|
225
|
-
body: `✅ Invited ${
|
|
228
|
+
body: `✅ Invited ${addBotDisplay} to this room.`,
|
|
226
229
|
});
|
|
227
230
|
} catch (err) {
|
|
228
231
|
const msg = err instanceof Error ? err.message : String(err);
|
|
232
|
+
// Strip homeserver from error messages too
|
|
233
|
+
const cleanMsg = msg.replace(/:badger\.signout\.io/g, "");
|
|
229
234
|
await client.sendMessage(roomId, {
|
|
230
235
|
msgtype: "m.text",
|
|
231
|
-
body: `❌ Failed to invite ${
|
|
236
|
+
body: `❌ Failed to invite ${addBotDisplay}: ${cleanMsg}`,
|
|
232
237
|
});
|
|
233
238
|
}
|
|
234
239
|
return true;
|
|
235
240
|
}
|
|
236
241
|
|
|
242
|
+
case "list": {
|
|
243
|
+
const botSuffix2 = "_bot:badger.signout.io";
|
|
244
|
+
let botsInRoom: string[] = [];
|
|
245
|
+
try {
|
|
246
|
+
const members = await client.getJoinedRoomMembers(roomId);
|
|
247
|
+
botsInRoom = members.filter((m: string) => m.includes(botSuffix2));
|
|
248
|
+
} catch {
|
|
249
|
+
botsInRoom = [selfUserId]; // At minimum, we know we're here
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (botsInRoom.length === 0) {
|
|
253
|
+
await client.sendMessage(roomId, {
|
|
254
|
+
msgtype: "m.text",
|
|
255
|
+
body: "No bots in this room.",
|
|
256
|
+
});
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const botList = botsInRoom
|
|
261
|
+
.map((b) => {
|
|
262
|
+
const displayName = b.split(":")[0];
|
|
263
|
+
const isMe = b === selfUserId;
|
|
264
|
+
return ` ${isMe ? "🟢" : "🤖"} ${displayName}${isMe ? " (me)" : ""}`;
|
|
265
|
+
})
|
|
266
|
+
.join("\n");
|
|
267
|
+
|
|
268
|
+
await client.sendMessage(roomId, {
|
|
269
|
+
msgtype: "m.text",
|
|
270
|
+
body: [
|
|
271
|
+
"🦡 Bots in this room:",
|
|
272
|
+
"",
|
|
273
|
+
botList,
|
|
274
|
+
"",
|
|
275
|
+
`${botsInRoom.length} bot${botsInRoom.length === 1 ? "" : "s"} total`,
|
|
276
|
+
].join("\n"),
|
|
277
|
+
});
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
237
281
|
default: {
|
|
238
282
|
// Unknown /bot command — show help hint
|
|
239
283
|
await client.sendMessage(roomId, {
|