@metatell/bot-cli 0.0.6 → 0.0.8
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/README.md +52 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +19 -13
- package/dist/commands/connect.js +31 -86
- package/dist/commands/inspect.js +51 -108
- package/dist/commands/interactive.js +105 -185
- package/dist/index.js +3 -9
- package/dist/types.js +1 -2
- package/dist/utils/commands.js +216 -359
- package/dist/utils/url.js +13 -17
- package/package.json +9 -9
|
@@ -1,192 +1,112 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Interactive mode command with rich commands support
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
_.trys.pop(); continue;
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import { createMetatellClient } from '@metatell/bot-sdk';
|
|
6
|
+
import { CommandParser } from '../utils/commands.js';
|
|
7
|
+
import { parseUrl } from '../utils/url.js';
|
|
8
|
+
export async function startInteractiveMode(url, options) {
|
|
9
|
+
console.log('Starting interactive mode...');
|
|
10
|
+
try {
|
|
11
|
+
const { serverUrl, roomId } = parseUrl(url);
|
|
12
|
+
const client = createMetatellClient({
|
|
13
|
+
serverUrl,
|
|
14
|
+
roomId,
|
|
15
|
+
token: options.token || process.env.METATELL_TOKEN || '',
|
|
16
|
+
username: options.name || 'MetatellCLI',
|
|
17
|
+
debug: options.debug,
|
|
18
|
+
});
|
|
19
|
+
// Event handlers
|
|
20
|
+
client.on('connected', () => {
|
|
21
|
+
console.log('[Connected]');
|
|
22
|
+
});
|
|
23
|
+
client.on('disconnected', (reason) => {
|
|
24
|
+
console.log('[Disconnected]', reason || 'Connection closed');
|
|
25
|
+
});
|
|
26
|
+
// chat-messageイベントを使用して、より詳細なメッセージ情報を取得
|
|
27
|
+
client.on('chat-message', (message) => {
|
|
28
|
+
const mentionInfo = message.mention ? ` (mentions @${message.mention.name})` : '';
|
|
29
|
+
console.log(`[Chat] ${message.from.name}: ${message.text}${mentionInfo}`);
|
|
30
|
+
// デバッグ情報
|
|
31
|
+
if (options.debug) {
|
|
32
|
+
console.log(`[Debug] Sender ID: ${message.from.id}`);
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
}); });
|
|
97
|
-
client_1.on('user-join', function (user) {
|
|
98
|
-
console.log('[User joined]', user.name || 'Anonymous', "(".concat(user.id, ")"));
|
|
99
|
-
});
|
|
100
|
-
client_1.on('user-leave', function (user) {
|
|
101
|
-
console.log('[User left]', user.name || 'Anonymous', "(".concat(user.id, ")"));
|
|
102
|
-
});
|
|
103
|
-
return [4 /*yield*/, client_1.connect()];
|
|
104
|
-
case 3:
|
|
105
|
-
_b.sent();
|
|
106
|
-
console.log('Connected to room:', roomId);
|
|
107
|
-
console.log('Session ID:', client_1.getSessionId());
|
|
108
|
-
console.log('Commands: /help for list of commands');
|
|
109
|
-
console.log('Type messages to send, or "quit" to exit\n');
|
|
110
|
-
rl_1 = (0, node_readline_1.createInterface)({
|
|
111
|
-
input: process.stdin,
|
|
112
|
-
output: process.stdout,
|
|
113
|
-
prompt: '> ',
|
|
114
|
-
});
|
|
115
|
-
parser_1 = new commands_js_1.CommandParser();
|
|
116
|
-
rl_1.on('line', function (line) { return __awaiter(_this, void 0, void 0, function () {
|
|
117
|
-
var input, result, error_2, error_3;
|
|
118
|
-
return __generator(this, function (_a) {
|
|
119
|
-
switch (_a.label) {
|
|
120
|
-
case 0:
|
|
121
|
-
input = line.trim();
|
|
122
|
-
// 特殊なキーワードのみ特別扱い
|
|
123
|
-
if (input === 'quit' || input === 'exit') {
|
|
124
|
-
rl_1.close();
|
|
125
|
-
return [2 /*return*/];
|
|
126
|
-
}
|
|
127
|
-
if (!input.startsWith('/')) return [3 /*break*/, 5];
|
|
128
|
-
_a.label = 1;
|
|
129
|
-
case 1:
|
|
130
|
-
_a.trys.push([1, 3, , 4]);
|
|
131
|
-
return [4 /*yield*/, parser_1.execute(input, client_1)];
|
|
132
|
-
case 2:
|
|
133
|
-
result = _a.sent();
|
|
134
|
-
if (!result.success) {
|
|
135
|
-
console.error('[Error]', result.message);
|
|
136
|
-
}
|
|
137
|
-
return [3 /*break*/, 4];
|
|
138
|
-
case 3:
|
|
139
|
-
error_2 = _a.sent();
|
|
140
|
-
console.error('[Error]', error_2 instanceof Error ? error_2.message : 'Command failed');
|
|
141
|
-
return [3 /*break*/, 4];
|
|
142
|
-
case 4: return [3 /*break*/, 9];
|
|
143
|
-
case 5:
|
|
144
|
-
if (!input) return [3 /*break*/, 9];
|
|
145
|
-
_a.label = 6;
|
|
146
|
-
case 6:
|
|
147
|
-
_a.trys.push([6, 8, , 9]);
|
|
148
|
-
return [4 /*yield*/, client_1.chat.send(input)];
|
|
149
|
-
case 7:
|
|
150
|
-
_a.sent();
|
|
151
|
-
console.log("[Sent] ".concat(input));
|
|
152
|
-
return [3 /*break*/, 9];
|
|
153
|
-
case 8:
|
|
154
|
-
error_3 = _a.sent();
|
|
155
|
-
console.error('[Error sending message]', error_3);
|
|
156
|
-
return [3 /*break*/, 9];
|
|
157
|
-
case 9:
|
|
158
|
-
rl_1.prompt();
|
|
159
|
-
return [2 /*return*/];
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}); });
|
|
163
|
-
rl_1.on('close', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
164
|
-
return __generator(this, function (_a) {
|
|
165
|
-
switch (_a.label) {
|
|
166
|
-
case 0:
|
|
167
|
-
console.log('\nShutting down...');
|
|
168
|
-
return [4 /*yield*/, client_1.disconnect()];
|
|
169
|
-
case 1:
|
|
170
|
-
_a.sent();
|
|
171
|
-
process.exit(0);
|
|
172
|
-
return [2 /*return*/];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}); });
|
|
176
|
-
// Show initial prompt
|
|
177
|
-
rl_1.prompt();
|
|
178
|
-
// Handle process termination
|
|
179
|
-
process.on('SIGINT', function () {
|
|
180
|
-
rl_1.close();
|
|
181
|
-
});
|
|
182
|
-
return [3 /*break*/, 5];
|
|
183
|
-
case 4:
|
|
184
|
-
error_1 = _b.sent();
|
|
185
|
-
console.error('Failed to start interactive mode:', error_1);
|
|
186
|
-
process.exit(1);
|
|
187
|
-
return [3 /*break*/, 5];
|
|
188
|
-
case 5: return [2 /*return*/];
|
|
34
|
+
});
|
|
35
|
+
// メッセージハンドラーを設定(メンションのみ反応)
|
|
36
|
+
const botInfo = await client.getInfo();
|
|
37
|
+
client.chat.onMessage(async (event) => {
|
|
38
|
+
if (event.mention && event.mention.sessionId === botInfo.sessionId) {
|
|
39
|
+
console.log(`[Mentioned by ${event.from.name}] ${event.text}`);
|
|
40
|
+
// 自動的に返信
|
|
41
|
+
event.reply(`Hello ${event.from.name}! You said: "${event.text}"`).catch((err) => {
|
|
42
|
+
console.error('[Error replying]', err);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
client.on('user-join', (user) => {
|
|
47
|
+
console.log('[User joined]', user.name || 'Anonymous', `(${user.id})`);
|
|
48
|
+
});
|
|
49
|
+
client.on('user-leave', (user) => {
|
|
50
|
+
console.log('[User left]', user.name || 'Anonymous', `(${user.id})`);
|
|
51
|
+
});
|
|
52
|
+
await client.connect();
|
|
53
|
+
console.log('Connected to room:', roomId);
|
|
54
|
+
console.log('Session ID:', client.getSessionId());
|
|
55
|
+
console.log('Commands: /help for list of commands');
|
|
56
|
+
console.log('Type messages to send, or "quit" to exit\n');
|
|
57
|
+
// Setup readline interface
|
|
58
|
+
const rl = createInterface({
|
|
59
|
+
input: process.stdin,
|
|
60
|
+
output: process.stdout,
|
|
61
|
+
prompt: '> ',
|
|
62
|
+
});
|
|
63
|
+
// Command parser
|
|
64
|
+
const parser = new CommandParser();
|
|
65
|
+
rl.on('line', async (line) => {
|
|
66
|
+
const input = line.trim();
|
|
67
|
+
// 特殊なキーワードのみ特別扱い
|
|
68
|
+
if (input === 'quit' || input === 'exit') {
|
|
69
|
+
rl.close();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// /で始まる場合のみコマンドとして処理
|
|
73
|
+
if (input.startsWith('/')) {
|
|
74
|
+
try {
|
|
75
|
+
const result = await parser.execute(input, client);
|
|
76
|
+
if (!result.success) {
|
|
77
|
+
console.error('[Error]', result.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error('[Error]', error instanceof Error ? error.message : 'Command failed');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (input) {
|
|
85
|
+
// それ以外はすべてメッセージとして送信
|
|
86
|
+
try {
|
|
87
|
+
await client.chat.send(input);
|
|
88
|
+
console.log(`[Sent] ${input}`);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('[Error sending message]', error);
|
|
92
|
+
}
|
|
189
93
|
}
|
|
94
|
+
rl.prompt();
|
|
190
95
|
});
|
|
191
|
-
|
|
96
|
+
rl.on('close', async () => {
|
|
97
|
+
console.log('\nShutting down...');
|
|
98
|
+
await client.disconnect();
|
|
99
|
+
process.exit(0);
|
|
100
|
+
});
|
|
101
|
+
// Show initial prompt
|
|
102
|
+
rl.prompt();
|
|
103
|
+
// Handle process termination
|
|
104
|
+
process.on('SIGINT', () => {
|
|
105
|
+
rl.close();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error('Failed to start interactive mode:', error);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
192
112
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Main exports for @metatell/cli
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "connectCommand", { enumerable: true, get: function () { return connect_js_1.connectCommand; } });
|
|
9
|
-
var inspect_js_1 = require("./commands/inspect.js");
|
|
10
|
-
Object.defineProperty(exports, "inspectCommand", { enumerable: true, get: function () { return inspect_js_1.inspectCommand; } });
|
|
11
|
-
var interactive_js_1 = require("./commands/interactive.js");
|
|
12
|
-
Object.defineProperty(exports, "startInteractiveMode", { enumerable: true, get: function () { return interactive_js_1.startInteractiveMode; } });
|
|
4
|
+
export { connectCommand } from './commands/connect.js';
|
|
5
|
+
export { inspectCommand } from './commands/inspect.js';
|
|
6
|
+
export { startInteractiveMode } from './commands/interactive.js';
|
package/dist/types.js
CHANGED