@ebowwa/channel-telegram 1.12.5 → 1.13.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.
- package/README.md +78 -44
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/restart.d.ts +7 -0
- package/dist/commands/restart.d.ts.map +1 -0
- package/dist/commands/restart.js +29 -0
- package/dist/commands/restart.js.map +1 -0
- package/dist/commands/settings.d.ts +8 -0
- package/dist/commands/settings.d.ts.map +1 -0
- package/dist/commands/settings.js +16 -0
- package/dist/commands/settings.js.map +1 -0
- package/dist/index.d.ts +83 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +350 -712
- package/dist/index.js.map +1 -1
- package/package.json +9 -13
- package/src/commands/index.ts +3 -0
- package/src/commands/restart.ts +41 -0
- package/src/commands/settings.ts +24 -0
- package/src/index.ts +415 -823
- package/dist/mcp/client.d.ts +0 -50
- package/dist/mcp/client.d.ts.map +0 -1
- package/dist/mcp/client.js +0 -150
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -5
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -5
- package/dist/mcp/index.js.map +0 -1
- package/src/api/fetch-retry.js +0 -96
- package/src/api/keys.js +0 -25
- package/src/commands/cancel.js +0 -120
- package/src/commands/clear.js +0 -59
- package/src/commands/doppler.js +0 -118
- package/src/commands/git.js +0 -126
- package/src/commands/help.js +0 -74
- package/src/commands/index.js +0 -65
- package/src/commands/logs.js +0 -81
- package/src/commands/pause.js +0 -133
- package/src/commands/resources.js +0 -87
- package/src/commands/resume.js +0 -95
- package/src/commands/start.js +0 -68
- package/src/commands/status.js +0 -62
- package/src/commands/tools.js +0 -67
- package/src/commands/toolsoutput.js +0 -85
- package/src/commands/types.js +0 -5
- package/src/mcp/client.ts +0 -188
- package/src/mcp/index.ts +0 -5
package/src/commands/git.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /git command - Check git status & GitHub auth
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerGitCommand = registerGitCommand;
|
|
43
|
-
var child_process_1 = require("child_process");
|
|
44
|
-
function registerGitCommand(bot, _memory, _tools) {
|
|
45
|
-
var _this = this;
|
|
46
|
-
bot.onText(/\/git(?:\s+(.+))?/, function (msg, match) { return __awaiter(_this, void 0, void 0, function () {
|
|
47
|
-
var chatId, subCommand, statusMsg, deviceResp, codeMatch, urlMatch, statusMsg, authStatus, loggedIn, accountMatch, branch, ahead, dirty, error_1;
|
|
48
|
-
var _a;
|
|
49
|
-
return __generator(this, function (_b) {
|
|
50
|
-
switch (_b.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
chatId = msg.chat.id;
|
|
53
|
-
subCommand = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
54
|
-
_b.label = 1;
|
|
55
|
-
case 1:
|
|
56
|
-
_b.trys.push([1, 6, , 8]);
|
|
57
|
-
if (!(subCommand === 'auth')) return [3 /*break*/, 3];
|
|
58
|
-
statusMsg = 'GitHub Auth\n\n';
|
|
59
|
-
try {
|
|
60
|
-
deviceResp = (0, child_process_1.execSync)('gh auth login --web --git-protocol https 2>&1 | head -20', {
|
|
61
|
-
encoding: 'utf-8',
|
|
62
|
-
timeout: 8000,
|
|
63
|
-
cwd: '/root'
|
|
64
|
-
});
|
|
65
|
-
codeMatch = deviceResp.match(/verification code:\s*([A-Z0-9-]+)/i);
|
|
66
|
-
urlMatch = deviceResp.match(/https:\/\/github\.com\/login\/device[^\s]*/);
|
|
67
|
-
if (codeMatch && urlMatch) {
|
|
68
|
-
statusMsg += "Code: ".concat(codeMatch[1], "\n");
|
|
69
|
-
statusMsg += "URL: ".concat(urlMatch[0], "\n\n");
|
|
70
|
-
statusMsg += "Open URL and enter code to authenticate.";
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
statusMsg += deviceResp.slice(0, 500);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
statusMsg += "Error: ".concat(e.message);
|
|
78
|
-
}
|
|
79
|
-
return [4 /*yield*/, bot.sendMessage(chatId, statusMsg)];
|
|
80
|
-
case 2:
|
|
81
|
-
_b.sent();
|
|
82
|
-
return [3 /*break*/, 5];
|
|
83
|
-
case 3:
|
|
84
|
-
statusMsg = 'Git Status\n\n';
|
|
85
|
-
try {
|
|
86
|
-
authStatus = (0, child_process_1.execSync)('gh auth status 2>&1', { encoding: 'utf-8', cwd: '/root' });
|
|
87
|
-
loggedIn = authStatus.includes('Logged in');
|
|
88
|
-
accountMatch = authStatus.match(/account\s+(\w+)/i);
|
|
89
|
-
statusMsg += "GitHub: ".concat(loggedIn ? 'Connected' : 'Not logged in', "\n");
|
|
90
|
-
if (accountMatch)
|
|
91
|
-
statusMsg += "Account: ".concat(accountMatch[1], "\n");
|
|
92
|
-
if (!loggedIn)
|
|
93
|
-
statusMsg += "\nUse /git auth to authenticate";
|
|
94
|
-
}
|
|
95
|
-
catch (_c) {
|
|
96
|
-
statusMsg += "GitHub: Not authenticated\n";
|
|
97
|
-
statusMsg += "Use /git auth to login\n";
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
branch = (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD 2>/dev/null', { encoding: 'utf-8', cwd: '/root' }).trim();
|
|
101
|
-
ahead = (0, child_process_1.execSync)('git rev-list --count @{upstream}..HEAD 2>/dev/null || echo 0', { encoding: 'utf-8', cwd: '/root' }).trim();
|
|
102
|
-
dirty = (0, child_process_1.execSync)('git status --porcelain 2>/dev/null | wc -l', { encoding: 'utf-8', cwd: '/root' }).trim();
|
|
103
|
-
statusMsg += "\nRepo:\n";
|
|
104
|
-
statusMsg += "Branch: ".concat(branch, "\n");
|
|
105
|
-
statusMsg += "Ahead: ".concat(ahead, " commits\n");
|
|
106
|
-
statusMsg += "Modified: ".concat(dirty, " files");
|
|
107
|
-
}
|
|
108
|
-
catch (_d) {
|
|
109
|
-
statusMsg += "\nRepo: Not a git repo or error";
|
|
110
|
-
}
|
|
111
|
-
return [4 /*yield*/, bot.sendMessage(chatId, statusMsg)];
|
|
112
|
-
case 4:
|
|
113
|
-
_b.sent();
|
|
114
|
-
_b.label = 5;
|
|
115
|
-
case 5: return [3 /*break*/, 8];
|
|
116
|
-
case 6:
|
|
117
|
-
error_1 = _b.sent();
|
|
118
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "Error: ".concat(error_1.message))];
|
|
119
|
-
case 7:
|
|
120
|
-
_b.sent();
|
|
121
|
-
return [3 /*break*/, 8];
|
|
122
|
-
case 8: return [2 /*return*/];
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}); });
|
|
126
|
-
}
|
package/src/commands/help.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /help command - Show help message
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerHelpCommand = registerHelpCommand;
|
|
43
|
-
function registerHelpCommand(bot, _memory, _tools) {
|
|
44
|
-
var _this = this;
|
|
45
|
-
bot.onText(/\/help/, function (msg) { return __awaiter(_this, void 0, void 0, function () {
|
|
46
|
-
var chatId;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
chatId = msg.chat.id;
|
|
51
|
-
return [4 /*yield*/, bot.sendMessage(chatId, '📚 *GLM Daemon Bot Help*\n\n' +
|
|
52
|
-
'🧠 Powered by GLM-4.7 via Z.AI API\n\n' +
|
|
53
|
-
'*Commands:*\n' +
|
|
54
|
-
'/start - Show welcome message\n' +
|
|
55
|
-
'/status - Check API status\n' +
|
|
56
|
-
'/git - Check git status & GitHub auth\n' +
|
|
57
|
-
'/git auth - Start GitHub auth flow\n' +
|
|
58
|
-
'/doppler - Check Doppler config\n' +
|
|
59
|
-
'/doppler secrets - List secret names\n' +
|
|
60
|
-
'/tools - Show available AI tools\n' +
|
|
61
|
-
'/clear - Clear conversation memory\n' +
|
|
62
|
-
'/resources - Show system resources\n' +
|
|
63
|
-
'/logs [n] - Show last n log lines\n' +
|
|
64
|
-
'/toolsoutput [on|off] - Toggle tool output messages\n' +
|
|
65
|
-
'/help - Show this help\n\n' +
|
|
66
|
-
'*Usage:*\n' +
|
|
67
|
-
'Just send any message and I\\\'ll respond with AI assistance!', { parse_mode: 'Markdown' })];
|
|
68
|
-
case 1:
|
|
69
|
-
_a.sent();
|
|
70
|
-
return [2 /*return*/];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}); });
|
|
74
|
-
}
|
package/src/commands/index.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Command index - Exports all command registrars
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.registerResumeCommand = exports.clearPause = exports.waitWhilePaused = exports.isPaused = exports.registerPauseCommand = exports.clearCancel = exports.isCancelled = exports.registerCancelCommand = exports.registerResourcesCommand = exports.registerToolsCommand = exports.registerClearCommand = exports.registerLogsCommand = exports.registerDopplerCommand = exports.registerGitCommand = exports.registerHelpCommand = exports.registerStatusCommand = exports.registerStartCommand = void 0;
|
|
7
|
-
exports.registerAllCommands = registerAllCommands;
|
|
8
|
-
var start_1 = require("./start");
|
|
9
|
-
Object.defineProperty(exports, "registerStartCommand", { enumerable: true, get: function () { return start_1.registerStartCommand; } });
|
|
10
|
-
var status_1 = require("./status");
|
|
11
|
-
Object.defineProperty(exports, "registerStatusCommand", { enumerable: true, get: function () { return status_1.registerStatusCommand; } });
|
|
12
|
-
var help_1 = require("./help");
|
|
13
|
-
Object.defineProperty(exports, "registerHelpCommand", { enumerable: true, get: function () { return help_1.registerHelpCommand; } });
|
|
14
|
-
var git_1 = require("./git");
|
|
15
|
-
Object.defineProperty(exports, "registerGitCommand", { enumerable: true, get: function () { return git_1.registerGitCommand; } });
|
|
16
|
-
var doppler_1 = require("./doppler");
|
|
17
|
-
Object.defineProperty(exports, "registerDopplerCommand", { enumerable: true, get: function () { return doppler_1.registerDopplerCommand; } });
|
|
18
|
-
var logs_1 = require("./logs");
|
|
19
|
-
Object.defineProperty(exports, "registerLogsCommand", { enumerable: true, get: function () { return logs_1.registerLogsCommand; } });
|
|
20
|
-
var clear_1 = require("./clear");
|
|
21
|
-
Object.defineProperty(exports, "registerClearCommand", { enumerable: true, get: function () { return clear_1.registerClearCommand; } });
|
|
22
|
-
var tools_1 = require("./tools");
|
|
23
|
-
Object.defineProperty(exports, "registerToolsCommand", { enumerable: true, get: function () { return tools_1.registerToolsCommand; } });
|
|
24
|
-
var resources_1 = require("./resources");
|
|
25
|
-
Object.defineProperty(exports, "registerResourcesCommand", { enumerable: true, get: function () { return resources_1.registerResourcesCommand; } });
|
|
26
|
-
var cancel_1 = require("./cancel");
|
|
27
|
-
Object.defineProperty(exports, "registerCancelCommand", { enumerable: true, get: function () { return cancel_1.registerCancelCommand; } });
|
|
28
|
-
Object.defineProperty(exports, "isCancelled", { enumerable: true, get: function () { return cancel_1.isCancelled; } });
|
|
29
|
-
Object.defineProperty(exports, "clearCancel", { enumerable: true, get: function () { return cancel_1.clearCancel; } });
|
|
30
|
-
var pause_1 = require("./pause");
|
|
31
|
-
Object.defineProperty(exports, "registerPauseCommand", { enumerable: true, get: function () { return pause_1.registerPauseCommand; } });
|
|
32
|
-
Object.defineProperty(exports, "isPaused", { enumerable: true, get: function () { return pause_1.isPaused; } });
|
|
33
|
-
Object.defineProperty(exports, "waitWhilePaused", { enumerable: true, get: function () { return pause_1.waitWhilePaused; } });
|
|
34
|
-
Object.defineProperty(exports, "clearPause", { enumerable: true, get: function () { return pause_1.clearPause; } });
|
|
35
|
-
var resume_1 = require("./resume");
|
|
36
|
-
Object.defineProperty(exports, "registerResumeCommand", { enumerable: true, get: function () { return resume_1.registerResumeCommand; } });
|
|
37
|
-
var start_2 = require("./start");
|
|
38
|
-
var status_2 = require("./status");
|
|
39
|
-
var help_2 = require("./help");
|
|
40
|
-
var git_2 = require("./git");
|
|
41
|
-
var doppler_2 = require("./doppler");
|
|
42
|
-
var logs_2 = require("./logs");
|
|
43
|
-
var clear_2 = require("./clear");
|
|
44
|
-
var tools_2 = require("./tools");
|
|
45
|
-
var resources_2 = require("./resources");
|
|
46
|
-
var cancel_2 = require("./cancel");
|
|
47
|
-
var pause_2 = require("./pause");
|
|
48
|
-
var resume_2 = require("./resume");
|
|
49
|
-
/**
|
|
50
|
-
* Register all commands with the bot
|
|
51
|
-
*/
|
|
52
|
-
function registerAllCommands(bot, memory, tools) {
|
|
53
|
-
(0, start_2.registerStartCommand)(bot, memory, tools);
|
|
54
|
-
(0, status_2.registerStatusCommand)(bot, memory, tools);
|
|
55
|
-
(0, help_2.registerHelpCommand)(bot, memory, tools);
|
|
56
|
-
(0, git_2.registerGitCommand)(bot, memory, tools);
|
|
57
|
-
(0, doppler_2.registerDopplerCommand)(bot, memory, tools);
|
|
58
|
-
(0, logs_2.registerLogsCommand)(bot, memory, tools);
|
|
59
|
-
(0, clear_2.registerClearCommand)(bot, memory, tools);
|
|
60
|
-
(0, tools_2.registerToolsCommand)(bot, memory, tools);
|
|
61
|
-
(0, resources_2.registerResourcesCommand)(bot, memory, tools);
|
|
62
|
-
(0, cancel_2.registerCancelCommand)(bot, memory, tools);
|
|
63
|
-
(0, pause_2.registerPauseCommand)(bot, memory, tools);
|
|
64
|
-
(0, resume_2.registerResumeCommand)(bot, memory, tools);
|
|
65
|
-
}
|
package/src/commands/logs.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /logs command - Show systemd journal logs
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerLogsCommand = registerLogsCommand;
|
|
43
|
-
var child_process_1 = require("child_process");
|
|
44
|
-
function registerLogsCommand(bot, _memory, _tools) {
|
|
45
|
-
var _this = this;
|
|
46
|
-
bot.onText(/\/logs(?:\s+(\d+))?/, function (msg, match) { return __awaiter(_this, void 0, void 0, function () {
|
|
47
|
-
var chatId, lines, logs, maxLen, output, error_1;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
chatId = msg.chat.id;
|
|
52
|
-
lines = (match === null || match === void 0 ? void 0 : match[1]) ? parseInt(match[1]) : 20;
|
|
53
|
-
_a.label = 1;
|
|
54
|
-
case 1:
|
|
55
|
-
_a.trys.push([1, 3, , 5]);
|
|
56
|
-
logs = (0, child_process_1.execSync)("journalctl -u telegram-bot -n ".concat(Math.min(lines, 100), " --no-pager 2>&1"), {
|
|
57
|
-
encoding: 'utf-8',
|
|
58
|
-
cwd: '/root'
|
|
59
|
-
});
|
|
60
|
-
maxLen = 4000;
|
|
61
|
-
output = logs.trim();
|
|
62
|
-
if (output.length > maxLen) {
|
|
63
|
-
output = '...\n' + output.slice(-maxLen);
|
|
64
|
-
}
|
|
65
|
-
// Send without Markdown to avoid parsing errors with log content
|
|
66
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "System Logs (last ".concat(lines, " lines)\n\n").concat(output))];
|
|
67
|
-
case 2:
|
|
68
|
-
// Send without Markdown to avoid parsing errors with log content
|
|
69
|
-
_a.sent();
|
|
70
|
-
return [3 /*break*/, 5];
|
|
71
|
-
case 3:
|
|
72
|
-
error_1 = _a.sent();
|
|
73
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "Error reading logs: ".concat(error_1.message))];
|
|
74
|
-
case 4:
|
|
75
|
-
_a.sent();
|
|
76
|
-
return [3 /*break*/, 5];
|
|
77
|
-
case 5: return [2 /*return*/];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}); });
|
|
81
|
-
}
|
package/src/commands/pause.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /pause command - Pause current execution
|
|
4
|
-
*
|
|
5
|
-
* Sets a pause flag that the daemon checks during execution.
|
|
6
|
-
* Use /resume to continue.
|
|
7
|
-
*/
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
19
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.registerPauseCommand = registerPauseCommand;
|
|
46
|
-
exports.isPaused = isPaused;
|
|
47
|
-
exports.waitWhilePaused = waitWhilePaused;
|
|
48
|
-
exports.clearPause = clearPause;
|
|
49
|
-
var fs_1 = require("fs");
|
|
50
|
-
var STATE_DIR = '/root/seed/state';
|
|
51
|
-
var PAUSE_FLAG = "".concat(STATE_DIR, "/.pause");
|
|
52
|
-
function registerPauseCommand(bot, _memory, _tools) {
|
|
53
|
-
var _this = this;
|
|
54
|
-
bot.onText(/\/pause/, function (msg) { return __awaiter(_this, void 0, void 0, function () {
|
|
55
|
-
var chatId, error_1;
|
|
56
|
-
return __generator(this, function (_a) {
|
|
57
|
-
switch (_a.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
chatId = msg.chat.id;
|
|
60
|
-
_a.label = 1;
|
|
61
|
-
case 1:
|
|
62
|
-
_a.trys.push([1, 3, , 5]);
|
|
63
|
-
// Ensure state directory exists
|
|
64
|
-
if (!(0, fs_1.existsSync)(STATE_DIR)) {
|
|
65
|
-
(0, fs_1.mkdirSync)(STATE_DIR, { recursive: true });
|
|
66
|
-
}
|
|
67
|
-
// Set pause flag
|
|
68
|
-
(0, fs_1.writeFileSync)(PAUSE_FLAG, Date.now().toString());
|
|
69
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "\u23F8\uFE0F *PAUSED*\n\n" +
|
|
70
|
-
"Pause flag set. Daemon will wait.\n" +
|
|
71
|
-
"Use /resume to continue.", { parse_mode: 'Markdown' })];
|
|
72
|
-
case 2:
|
|
73
|
-
_a.sent();
|
|
74
|
-
console.log("[PAUSE] Pause requested by chat ".concat(chatId, " at ").concat(new Date().toISOString()));
|
|
75
|
-
return [3 /*break*/, 5];
|
|
76
|
-
case 3:
|
|
77
|
-
error_1 = _a.sent();
|
|
78
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "\u274C Error setting pause flag: ".concat(error_1), { parse_mode: 'Markdown' })];
|
|
79
|
-
case 4:
|
|
80
|
-
_a.sent();
|
|
81
|
-
return [3 /*break*/, 5];
|
|
82
|
-
case 5: return [2 /*return*/];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}); });
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check if paused
|
|
89
|
-
*/
|
|
90
|
-
function isPaused() {
|
|
91
|
-
return (0, fs_1.existsSync)(PAUSE_FLAG);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Wait while paused (with optional timeout)
|
|
95
|
-
*/
|
|
96
|
-
function waitWhilePaused() {
|
|
97
|
-
return __awaiter(this, arguments, void 0, function (timeoutMs) {
|
|
98
|
-
var startTime, isCancelled;
|
|
99
|
-
if (timeoutMs === void 0) { timeoutMs = 0; }
|
|
100
|
-
return __generator(this, function (_a) {
|
|
101
|
-
switch (_a.label) {
|
|
102
|
-
case 0:
|
|
103
|
-
if (!isPaused())
|
|
104
|
-
return [2 /*return*/, false];
|
|
105
|
-
startTime = Date.now();
|
|
106
|
-
_a.label = 1;
|
|
107
|
-
case 1:
|
|
108
|
-
if (!isPaused()) return [3 /*break*/, 3];
|
|
109
|
-
return [4 /*yield*/, new Promise(function (r) { return setTimeout(r, 1000); })];
|
|
110
|
-
case 2:
|
|
111
|
-
_a.sent();
|
|
112
|
-
// Check timeout
|
|
113
|
-
if (timeoutMs > 0 && Date.now() - startTime > timeoutMs) {
|
|
114
|
-
return [2 /*return*/, true]; // Timed out
|
|
115
|
-
}
|
|
116
|
-
isCancelled = require('./cancel').isCancelled;
|
|
117
|
-
if (isCancelled()) {
|
|
118
|
-
return [2 /*return*/, false]; // Cancelled
|
|
119
|
-
}
|
|
120
|
-
return [3 /*break*/, 1];
|
|
121
|
-
case 3: return [2 /*return*/, false];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Clear pause flag
|
|
128
|
-
*/
|
|
129
|
-
function clearPause() {
|
|
130
|
-
if ((0, fs_1.existsSync)(PAUSE_FLAG)) {
|
|
131
|
-
(0, fs_1.unlinkSync)(PAUSE_FLAG);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /resources command - Show system resources
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerResourcesCommand = void 0;
|
|
43
|
-
var child_process_1 = require("child_process");
|
|
44
|
-
var registerResourcesCommand = function (bot) {
|
|
45
|
-
bot.onText(/\/resources/, function (msg) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
var chatId, loadAvg, cpuCount, memInfo, memMatch, memTotal, memUsed, memPercent, diskInfo, diskMatch, diskUsed, diskTotal, diskPercent, uptime, error_1;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
chatId = msg.chat.id;
|
|
51
|
-
_a.label = 1;
|
|
52
|
-
case 1:
|
|
53
|
-
_a.trys.push([1, 3, , 5]);
|
|
54
|
-
loadAvg = (0, child_process_1.execSync)('cat /proc/loadavg', { encoding: 'utf-8' }).trim().split(' ').slice(0, 3).join(', ');
|
|
55
|
-
cpuCount = (0, child_process_1.execSync)('nproc', { encoding: 'utf-8' }).trim();
|
|
56
|
-
memInfo = (0, child_process_1.execSync)('free -m | grep Mem', { encoding: 'utf-8' });
|
|
57
|
-
memMatch = memInfo.match(/Mem:\s+(\d+)\s+(\d+)\s+(\d+)/);
|
|
58
|
-
memTotal = memMatch ? Math.round(parseInt(memMatch[1]) / 1024) : 0;
|
|
59
|
-
memUsed = memMatch ? Math.round(parseInt(memMatch[2]) / 1024) : 0;
|
|
60
|
-
memPercent = memMatch ? Math.round((parseInt(memMatch[2]) / parseInt(memMatch[1])) * 100) : 0;
|
|
61
|
-
diskInfo = (0, child_process_1.execSync)('df -h / | tail -1', { encoding: 'utf-8' });
|
|
62
|
-
diskMatch = diskInfo.match(/\S+\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+%)/);
|
|
63
|
-
diskUsed = diskMatch ? diskMatch[2] : '?';
|
|
64
|
-
diskTotal = diskMatch ? diskMatch[1] : '?';
|
|
65
|
-
diskPercent = diskMatch ? diskMatch[4] : '?';
|
|
66
|
-
uptime = (0, child_process_1.execSync)('uptime -p 2>/dev/null || uptime', { encoding: 'utf-8' }).trim().replace('up ', '');
|
|
67
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "*System Resources*\n\n" +
|
|
68
|
-
"*CPU:* ".concat(cpuCount, " cores\n") +
|
|
69
|
-
"*Load:* ".concat(loadAvg, "\n\n") +
|
|
70
|
-
"*Memory:* ".concat(memUsed, "/").concat(memTotal, "GB (").concat(memPercent, "%)\n") +
|
|
71
|
-
"*Disk:* ".concat(diskUsed, "/").concat(diskTotal, " (").concat(diskPercent, ")\n\n") +
|
|
72
|
-
"*Uptime:* ".concat(uptime), { parse_mode: 'Markdown' })];
|
|
73
|
-
case 2:
|
|
74
|
-
_a.sent();
|
|
75
|
-
return [3 /*break*/, 5];
|
|
76
|
-
case 3:
|
|
77
|
-
error_1 = _a.sent();
|
|
78
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "Error reading resources: ".concat(error_1.message))];
|
|
79
|
-
case 4:
|
|
80
|
-
_a.sent();
|
|
81
|
-
return [3 /*break*/, 5];
|
|
82
|
-
case 5: return [2 /*return*/];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}); });
|
|
86
|
-
};
|
|
87
|
-
exports.registerResourcesCommand = registerResourcesCommand;
|