@xbibzlibrary/telebibz 0.4.4 → 3.0.1
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/CHANGELOG.md +35 -138
- package/LICENSE +1 -1
- package/NOTICE.md +9 -4
- package/README.md +173 -242
- package/examples/01-quickstart.js +13 -0
- package/examples/02-menu-tombol.js +22 -0
- package/examples/03-wizard.js +29 -0
- package/examples/04-broadcast.js +25 -0
- package/examples/05-kirim-file.js +19 -0
- package/examples/06-menu.js +35 -0
- package/examples/07-inline-query.js +18 -0
- package/index.d.ts +81 -0
- package/index.js +42 -0
- package/lib/api.js +154 -0
- package/lib/broadcast.js +35 -0
- package/lib/composer.js +174 -0
- package/lib/context.js +190 -0
- package/lib/errors.js +35 -0
- package/lib/file.js +41 -0
- package/lib/inline-query.js +28 -0
- package/lib/keyboard.js +83 -0
- package/lib/logger.js +38 -0
- package/lib/menus.js +90 -0
- package/lib/net.js +115 -0
- package/lib/ratelimit.js +61 -0
- package/lib/runner.js +45 -0
- package/lib/session.js +36 -0
- package/lib/telebibz.js +190 -0
- package/lib/wizard.js +81 -0
- package/package.json +35 -97
- package/test/all.test.js +334 -0
- package/CODE_OF_CONDUCT.md +0 -37
- package/CONTRIBUTING.md +0 -59
- package/CONTRIBUTION_RULES.md +0 -41
- package/GOVERNANCE.md +0 -47
- package/README.id.md +0 -292
- package/README.zh-CN.md +0 -292
- package/RELEASE_AUTOMATION.md +0 -78
- package/RELEASE_POLICY.md +0 -32
- package/SECURITY.md +0 -47
- package/SHOWCASE.md +0 -29
- package/SUPPORT.md +0 -30
- package/assets/readme-preview.html +0 -75
- package/assets/telebibz-logo.png +0 -0
- package/assets/telebibz-readme-preview.png +0 -0
- package/bin/telebibz.mjs +0 -3
- package/dist/generated/api.d.ts +0 -13
- package/dist/generated/api.d.ts.map +0 -1
- package/dist/generated/api.js +0 -192
- package/dist/generated/api.js.map +0 -1
- package/dist/src/api/client.d.ts +0 -62
- package/dist/src/api/client.d.ts.map +0 -1
- package/dist/src/api/client.js +0 -104
- package/dist/src/api/client.js.map +0 -1
- package/dist/src/api/errors.d.ts +0 -45
- package/dist/src/api/errors.d.ts.map +0 -1
- package/dist/src/api/errors.js +0 -65
- package/dist/src/api/errors.js.map +0 -1
- package/dist/src/api/index.d.ts +0 -6
- package/dist/src/api/index.d.ts.map +0 -1
- package/dist/src/api/index.js +0 -6
- package/dist/src/api/index.js.map +0 -1
- package/dist/src/api/telegram-types/LICENSE +0 -21
- package/dist/src/api/telegram-types/api.d.ts +0 -22
- package/dist/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist/src/api/telegram-types/inline.d.ts +0 -692
- package/dist/src/api/telegram-types/langs.d.ts +0 -193
- package/dist/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist/src/api/telegram-types/markup.d.ts +0 -268
- package/dist/src/api/telegram-types/message.d.ts +0 -1537
- package/dist/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist/src/api/telegram-types/mod.d.ts +0 -14
- package/dist/src/api/telegram-types/passport.d.ts +0 -163
- package/dist/src/api/telegram-types/payment.d.ts +0 -570
- package/dist/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist/src/api/telegram-types/settings.d.ts +0 -120
- package/dist/src/api/telegram-types/story.d.ts +0 -89
- package/dist/src/api/telegram-types/update.d.ts +0 -84
- package/dist/src/api/telegram.d.ts +0 -7
- package/dist/src/api/telegram.d.ts.map +0 -1
- package/dist/src/api/telegram.js +0 -2
- package/dist/src/api/telegram.js.map +0 -1
- package/dist/src/api/transport.d.ts +0 -68
- package/dist/src/api/transport.d.ts.map +0 -1
- package/dist/src/api/transport.js +0 -264
- package/dist/src/api/transport.js.map +0 -1
- package/dist/src/api/types.d.ts +0 -466
- package/dist/src/api/types.d.ts.map +0 -1
- package/dist/src/api/types.js +0 -2
- package/dist/src/api/types.js.map +0 -1
- package/dist/src/branding/terminal.d.ts +0 -77
- package/dist/src/branding/terminal.d.ts.map +0 -1
- package/dist/src/branding/terminal.js +0 -328
- package/dist/src/branding/terminal.js.map +0 -1
- package/dist/src/broadcast/broadcast.d.ts +0 -50
- package/dist/src/broadcast/broadcast.d.ts.map +0 -1
- package/dist/src/broadcast/broadcast.js +0 -56
- package/dist/src/broadcast/broadcast.js.map +0 -1
- package/dist/src/cache/cache.d.ts +0 -34
- package/dist/src/cache/cache.d.ts.map +0 -1
- package/dist/src/cache/cache.js +0 -41
- package/dist/src/cache/cache.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -84
- package/dist/src/cli.js.map +0 -1
- package/dist/src/context/context.d.ts +0 -124
- package/dist/src/context/context.d.ts.map +0 -1
- package/dist/src/context/context.js +0 -302
- package/dist/src/context/context.js.map +0 -1
- package/dist/src/core/bot.d.ts +0 -204
- package/dist/src/core/bot.d.ts.map +0 -1
- package/dist/src/core/bot.js +0 -506
- package/dist/src/core/bot.js.map +0 -1
- package/dist/src/core/events.d.ts +0 -75
- package/dist/src/core/events.d.ts.map +0 -1
- package/dist/src/core/events.js +0 -35
- package/dist/src/core/events.js.map +0 -1
- package/dist/src/core/webhook-reply.d.ts +0 -34
- package/dist/src/core/webhook-reply.d.ts.map +0 -1
- package/dist/src/core/webhook-reply.js +0 -37
- package/dist/src/core/webhook-reply.js.map +0 -1
- package/dist/src/index.d.ts +0 -24
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/keyboard/index.d.ts +0 -46
- package/dist/src/keyboard/index.d.ts.map +0 -1
- package/dist/src/keyboard/index.js +0 -55
- package/dist/src/keyboard/index.js.map +0 -1
- package/dist/src/middleware/compose.d.ts +0 -5
- package/dist/src/middleware/compose.d.ts.map +0 -1
- package/dist/src/middleware/compose.js +0 -17
- package/dist/src/middleware/compose.js.map +0 -1
- package/dist/src/observability/logger.d.ts +0 -78
- package/dist/src/observability/logger.d.ts.map +0 -1
- package/dist/src/observability/logger.js +0 -285
- package/dist/src/observability/logger.js.map +0 -1
- package/dist/src/plugins/plugin.d.ts +0 -38
- package/dist/src/plugins/plugin.d.ts.map +0 -1
- package/dist/src/plugins/plugin.js +0 -59
- package/dist/src/plugins/plugin.js.map +0 -1
- package/dist/src/queue/queue.d.ts +0 -77
- package/dist/src/queue/queue.d.ts.map +0 -1
- package/dist/src/queue/queue.js +0 -213
- package/dist/src/queue/queue.js.map +0 -1
- package/dist/src/router/router.d.ts +0 -61
- package/dist/src/router/router.d.ts.map +0 -1
- package/dist/src/router/router.js +0 -183
- package/dist/src/router/router.js.map +0 -1
- package/dist/src/state/conversation.d.ts +0 -56
- package/dist/src/state/conversation.d.ts.map +0 -1
- package/dist/src/state/conversation.js +0 -133
- package/dist/src/state/conversation.js.map +0 -1
- package/dist/src/state/forms.d.ts +0 -34
- package/dist/src/state/forms.d.ts.map +0 -1
- package/dist/src/state/forms.js +0 -44
- package/dist/src/state/forms.js.map +0 -1
- package/dist/src/state/menu.d.ts +0 -78
- package/dist/src/state/menu.d.ts.map +0 -1
- package/dist/src/state/menu.js +0 -127
- package/dist/src/state/menu.js.map +0 -1
- package/dist/src/storage/storage.d.ts +0 -146
- package/dist/src/storage/storage.d.ts.map +0 -1
- package/dist/src/storage/storage.js +0 -195
- package/dist/src/storage/storage.js.map +0 -1
- package/dist/src/telegram-features.d.ts +0 -33
- package/dist/src/telegram-features.d.ts.map +0 -1
- package/dist/src/telegram-features.js +0 -71
- package/dist/src/telegram-features.js.map +0 -1
- package/dist/src/testing.d.ts +0 -24
- package/dist/src/testing.d.ts.map +0 -1
- package/dist/src/testing.js +0 -38
- package/dist/src/testing.js.map +0 -1
- package/dist/src/utils/concurrency.d.ts +0 -25
- package/dist/src/utils/concurrency.d.ts.map +0 -1
- package/dist/src/utils/concurrency.js +0 -52
- package/dist/src/utils/concurrency.js.map +0 -1
- package/dist/src/utils/files.d.ts +0 -45
- package/dist/src/utils/files.d.ts.map +0 -1
- package/dist/src/utils/files.js +0 -53
- package/dist/src/utils/files.js.map +0 -1
- package/dist/src/utils/text.d.ts +0 -39
- package/dist/src/utils/text.d.ts.map +0 -1
- package/dist/src/utils/text.js +0 -56
- package/dist/src/utils/text.js.map +0 -1
- package/dist/src/webhook/handler.d.ts +0 -19
- package/dist/src/webhook/handler.d.ts.map +0 -1
- package/dist/src/webhook/handler.js +0 -141
- package/dist/src/webhook/handler.js.map +0 -1
- package/dist-cjs/generated/api.js +0 -194
- package/dist-cjs/package.json +0 -3
- package/dist-cjs/src/api/client.js +0 -107
- package/dist-cjs/src/api/errors.js +0 -74
- package/dist-cjs/src/api/index.js +0 -21
- package/dist-cjs/src/api/telegram-types/LICENSE +0 -21
- package/dist-cjs/src/api/telegram-types/api.d.ts +0 -22
- package/dist-cjs/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist-cjs/src/api/telegram-types/inline.d.ts +0 -692
- package/dist-cjs/src/api/telegram-types/langs.d.ts +0 -193
- package/dist-cjs/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist-cjs/src/api/telegram-types/markup.d.ts +0 -268
- package/dist-cjs/src/api/telegram-types/message.d.ts +0 -1537
- package/dist-cjs/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist-cjs/src/api/telegram-types/mod.d.ts +0 -14
- package/dist-cjs/src/api/telegram-types/passport.d.ts +0 -163
- package/dist-cjs/src/api/telegram-types/payment.d.ts +0 -570
- package/dist-cjs/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist-cjs/src/api/telegram-types/settings.d.ts +0 -120
- package/dist-cjs/src/api/telegram-types/story.d.ts +0 -89
- package/dist-cjs/src/api/telegram-types/update.d.ts +0 -84
- package/dist-cjs/src/api/telegram.js +0 -2
- package/dist-cjs/src/api/transport.js +0 -267
- package/dist-cjs/src/api/types.js +0 -2
- package/dist-cjs/src/branding/terminal.js +0 -338
- package/dist-cjs/src/broadcast/broadcast.js +0 -58
- package/dist-cjs/src/cache/cache.js +0 -45
- package/dist-cjs/src/cli.js +0 -86
- package/dist-cjs/src/context/context.js +0 -305
- package/dist-cjs/src/core/bot.js +0 -510
- package/dist-cjs/src/core/events.js +0 -38
- package/dist-cjs/src/core/webhook-reply.js +0 -42
- package/dist-cjs/src/index.js +0 -47
- package/dist-cjs/src/keyboard/index.js +0 -61
- package/dist-cjs/src/middleware/compose.js +0 -20
- package/dist-cjs/src/observability/logger.js +0 -293
- package/dist-cjs/src/plugins/plugin.js +0 -63
- package/dist-cjs/src/queue/queue.js +0 -219
- package/dist-cjs/src/router/router.js +0 -186
- package/dist-cjs/src/state/conversation.js +0 -139
- package/dist-cjs/src/state/forms.js +0 -47
- package/dist-cjs/src/state/menu.js +0 -133
- package/dist-cjs/src/storage/storage.js +0 -202
- package/dist-cjs/src/telegram-features.js +0 -76
- package/dist-cjs/src/testing.js +0 -45
- package/dist-cjs/src/utils/concurrency.js +0 -57
- package/dist-cjs/src/utils/files.js +0 -58
- package/dist-cjs/src/utils/text.js +0 -63
- package/dist-cjs/src/webhook/handler.js +0 -144
- package/docs/API.id.md +0 -1935
- package/docs/API.md +0 -1969
- package/docs/API.zh-CN.md +0 -1929
- package/docs/GETTING_STARTED.id.md +0 -85
- package/docs/GETTING_STARTED.md +0 -85
- package/docs/GETTING_STARTED.zh-CN.md +0 -85
- package/docs/GITHUB_PACKAGES.id.md +0 -82
- package/docs/GITHUB_PACKAGES.md +0 -82
- package/docs/GITHUB_PACKAGES.zh-CN.md +0 -82
- package/docs/README.md +0 -48
- package/docs/STORAGE.id.md +0 -105
- package/docs/STORAGE.md +0 -105
- package/docs/STORAGE.zh-CN.md +0 -105
- package/examples/README.md +0 -37
- package/examples/files.ts +0 -35
- package/examples/minimal.ts +0 -12
- package/examples/tsconfig.json +0 -9
- package/examples/webhook.ts +0 -42
- package/examples/wizard-registration.ts +0 -42
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TELE_BIBZ_ASCII = exports.TERMINAL_BRAND_TEXT = void 0;
|
|
4
|
-
exports.paintRainbow = paintRainbow;
|
|
5
|
-
exports.runStartupSequence = runStartupSequence;
|
|
6
|
-
exports.printTeleBibzBanner = printTeleBibzBanner;
|
|
7
|
-
exports.startTeleBibzBanner = startTeleBibzBanner;
|
|
8
|
-
exports.printStatusLine = printStatusLine;
|
|
9
|
-
exports.buildTerminalBranding = buildTerminalBranding;
|
|
10
|
-
exports.printTerminalBranding = printTerminalBranding;
|
|
11
|
-
exports.startTerminalAnimation = startTerminalAnimation;
|
|
12
|
-
exports.TERMINAL_BRAND_TEXT = "Library Bot Telegram By @xbibzofficial";
|
|
13
|
-
/** "Tele Bibz" rendered with the figlet Speed font. */
|
|
14
|
-
exports.TELE_BIBZ_ASCII = [
|
|
15
|
-
"________ ______ ___________________ _______",
|
|
16
|
-
"___ __/_______ /____ ___ __ )__(_)__ /_______",
|
|
17
|
-
"__ / _ _ \\_ /_ _ \\ __ __ |_ /__ __ \\__ /",
|
|
18
|
-
"_ / / __/ / / __/ _ /_/ /_ / _ /_/ /_ /_",
|
|
19
|
-
"/_/ \\___//_/ \\___/ /_____/ /_/ /_.___/_____/",
|
|
20
|
-
];
|
|
21
|
-
const ANSI = {
|
|
22
|
-
reset: "\u001b[0m",
|
|
23
|
-
bold: "\u001b[1m",
|
|
24
|
-
clearLine: "\u001b[2K",
|
|
25
|
-
cursorUp: "\u001b[1A",
|
|
26
|
-
hideCursor: "\u001b[?25l",
|
|
27
|
-
showCursor: "\u001b[?25h",
|
|
28
|
-
blue: "\u001b[34m",
|
|
29
|
-
magenta: "\u001b[35m",
|
|
30
|
-
cyan: "\u001b[36m",
|
|
31
|
-
green: "\u001b[32m",
|
|
32
|
-
yellow: "\u001b[33m",
|
|
33
|
-
red: "\u001b[31m",
|
|
34
|
-
white: "\u001b[97m",
|
|
35
|
-
dim: "\u001b[2m",
|
|
36
|
-
};
|
|
37
|
-
function pad(value, width) {
|
|
38
|
-
return `${value}${" ".repeat(Math.max(0, width - [...value].length))}`;
|
|
39
|
-
}
|
|
40
|
-
function useColor(options, stream) {
|
|
41
|
-
return options.color ?? Boolean(stream.isTTY && !process.env.NO_COLOR);
|
|
42
|
-
}
|
|
43
|
-
function sleep(delayMs) {
|
|
44
|
-
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
45
|
-
}
|
|
46
|
-
function easeInOutCubic(progress) {
|
|
47
|
-
return progress < 0.5 ? 4 * progress ** 3 : 1 - (-2 * progress + 2) ** 3 / 2;
|
|
48
|
-
}
|
|
49
|
-
function hslToRgb(hue, saturation, lightness) {
|
|
50
|
-
const normalizedHue = ((hue % 360) + 360) % 360;
|
|
51
|
-
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
52
|
-
const hueSegment = normalizedHue / 60;
|
|
53
|
-
const secondary = chroma * (1 - Math.abs((hueSegment % 2) - 1));
|
|
54
|
-
let red = 0;
|
|
55
|
-
let green = 0;
|
|
56
|
-
let blue = 0;
|
|
57
|
-
if (hueSegment < 1) {
|
|
58
|
-
red = chroma;
|
|
59
|
-
green = secondary;
|
|
60
|
-
}
|
|
61
|
-
else if (hueSegment < 2) {
|
|
62
|
-
red = secondary;
|
|
63
|
-
green = chroma;
|
|
64
|
-
}
|
|
65
|
-
else if (hueSegment < 3) {
|
|
66
|
-
green = chroma;
|
|
67
|
-
blue = secondary;
|
|
68
|
-
}
|
|
69
|
-
else if (hueSegment < 4) {
|
|
70
|
-
green = secondary;
|
|
71
|
-
blue = chroma;
|
|
72
|
-
}
|
|
73
|
-
else if (hueSegment < 5) {
|
|
74
|
-
red = secondary;
|
|
75
|
-
blue = chroma;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
red = chroma;
|
|
79
|
-
blue = secondary;
|
|
80
|
-
}
|
|
81
|
-
const shift = lightness - chroma / 2;
|
|
82
|
-
return [Math.round((red + shift) * 255), Math.round((green + shift) * 255), Math.round((blue + shift) * 255)];
|
|
83
|
-
}
|
|
84
|
-
function rgbForegroundColor(red, green, blue) {
|
|
85
|
-
return `\u001b[38;2;${red};${green};${blue}m`;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Paints multi-line text with a rainbow gradient across columns (the classic
|
|
89
|
-
* "Rainbow" color filter). Spaces stay unstyled so the art keeps its shape.
|
|
90
|
-
*/
|
|
91
|
-
function paintRainbow(text, options = {}) {
|
|
92
|
-
if (!options.color)
|
|
93
|
-
return text;
|
|
94
|
-
const lines = text.split("\n");
|
|
95
|
-
const width = Math.max(...lines.map((line) => [...line].length), 1);
|
|
96
|
-
const offset = options.offset ?? 0;
|
|
97
|
-
const spread = options.spread ?? 340;
|
|
98
|
-
const saturation = options.saturation ?? 1;
|
|
99
|
-
const lightness = options.lightness ?? 0.58;
|
|
100
|
-
return lines
|
|
101
|
-
.map((line) => {
|
|
102
|
-
const characters = [...line];
|
|
103
|
-
let painted = "";
|
|
104
|
-
for (let index = 0; index < characters.length; index += 1) {
|
|
105
|
-
const character = characters[index];
|
|
106
|
-
if (character === " ") {
|
|
107
|
-
painted += character;
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const hue = offset + (index / width) * spread;
|
|
111
|
-
const [red, green, blue] = hslToRgb(hue, saturation, lightness);
|
|
112
|
-
painted += `${rgbForegroundColor(red, green, blue)}${character}${ANSI.reset}`;
|
|
113
|
-
}
|
|
114
|
-
return painted;
|
|
115
|
-
})
|
|
116
|
-
.join("\n");
|
|
117
|
-
}
|
|
118
|
-
function renderGlassBar(progress, shinePosition, width, colored) {
|
|
119
|
-
const filled = Math.round(progress * width);
|
|
120
|
-
let bar = "";
|
|
121
|
-
for (let index = 0; index < width; index += 1) {
|
|
122
|
-
const isFilled = index < filled;
|
|
123
|
-
const shineDistance = Math.abs(index - shinePosition);
|
|
124
|
-
const isShine = shineDistance <= 1;
|
|
125
|
-
const character = isFilled ? "█" : "░";
|
|
126
|
-
if (!colored) {
|
|
127
|
-
bar += character;
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
if (isShine) {
|
|
131
|
-
bar += `${ANSI.bold}${ANSI.white}${character === "█" ? "█" : "▒"}${ANSI.reset}`;
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (isFilled) {
|
|
135
|
-
const hue = 190 + (index / width) * 150;
|
|
136
|
-
const [red, green, blue] = hslToRgb(hue, 0.85, 0.6);
|
|
137
|
-
bar += `${rgbForegroundColor(red, green, blue)}${character}${ANSI.reset}`;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
bar += `${ANSI.dim}${character}${ANSI.reset}`;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return bar;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Plays the startup sequence on a TTY: a typing effect for the label
|
|
147
|
-
* (default "Installing Dependencies"), a trailing run of dots, and a
|
|
148
|
-
* glass progress bar with a sweeping highlight that fills to 100%.
|
|
149
|
-
* No-ops when the stream is not an interactive TTY.
|
|
150
|
-
*/
|
|
151
|
-
async function runStartupSequence(options = {}) {
|
|
152
|
-
const stream = options.stream ?? process.stdout;
|
|
153
|
-
if (!stream.isTTY)
|
|
154
|
-
return;
|
|
155
|
-
const colored = useColor(options, stream);
|
|
156
|
-
const label = options.label ?? "Installing Dependencies";
|
|
157
|
-
const typeDelayMs = options.typeDelayMs ?? 24;
|
|
158
|
-
const dotDelayMs = options.dotDelayMs ?? 140;
|
|
159
|
-
const dots = options.dots ?? 6;
|
|
160
|
-
const barWidth = Math.max(10, options.barWidth ?? 44);
|
|
161
|
-
const barDurationMs = Math.max(0, options.barDurationMs ?? 1_400);
|
|
162
|
-
const barFrameMs = Math.max(16, options.barFrameMs ?? 40);
|
|
163
|
-
if (colored)
|
|
164
|
-
stream.write(`${ANSI.bold}${ANSI.cyan}`);
|
|
165
|
-
for (const character of label) {
|
|
166
|
-
stream.write(character);
|
|
167
|
-
if (typeDelayMs > 0)
|
|
168
|
-
await sleep(typeDelayMs);
|
|
169
|
-
}
|
|
170
|
-
for (let index = 0; index < dots; index += 1) {
|
|
171
|
-
if (dotDelayMs > 0)
|
|
172
|
-
await sleep(dotDelayMs);
|
|
173
|
-
stream.write(".");
|
|
174
|
-
}
|
|
175
|
-
if (colored)
|
|
176
|
-
stream.write(ANSI.reset);
|
|
177
|
-
stream.write("\n");
|
|
178
|
-
const startedAt = Date.now();
|
|
179
|
-
let frameIndex = 0;
|
|
180
|
-
while (true) {
|
|
181
|
-
const elapsed = Date.now() - startedAt;
|
|
182
|
-
const progress = barDurationMs === 0 ? 1 : Math.min(1, easeInOutCubic(elapsed / barDurationMs));
|
|
183
|
-
const sweep = (frameIndex * barFrameMs) % 1_600;
|
|
184
|
-
const triangle = sweep < 800 ? sweep / 800 : 2 - sweep / 800;
|
|
185
|
-
const shinePosition = triangle * (barWidth - 1);
|
|
186
|
-
const percentage = Math.round(progress * 100);
|
|
187
|
-
stream.write(`\r${ANSI.clearLine}${renderGlassBar(progress, shinePosition, barWidth, colored)} ${ANSI.dim}${String(percentage).padStart(3, " ")}%${ANSI.reset}`);
|
|
188
|
-
if (progress >= 1)
|
|
189
|
-
break;
|
|
190
|
-
frameIndex += 1;
|
|
191
|
-
await sleep(barFrameMs);
|
|
192
|
-
}
|
|
193
|
-
stream.write(` ${ANSI.green}${ANSI.bold}✓${ANSI.reset}\n`);
|
|
194
|
-
}
|
|
195
|
-
function bannerFrame(subtitle, offset, colored) {
|
|
196
|
-
const artWidth = Math.max(...exports.TELE_BIBZ_ASCII.map((line) => [...line].length));
|
|
197
|
-
const leading = Math.max(0, Math.floor((artWidth - [...exports.TERMINAL_BRAND_TEXT].length) / 2));
|
|
198
|
-
const tagline = " ".repeat(leading) + exports.TERMINAL_BRAND_TEXT;
|
|
199
|
-
const lines = paintRainbow(exports.TELE_BIBZ_ASCII.join("\n"), { color: colored, offset }).split("\n");
|
|
200
|
-
lines.push(colored ? `${ANSI.dim}${tagline}${ANSI.reset}` : tagline);
|
|
201
|
-
if (subtitle)
|
|
202
|
-
lines.push(colored ? `${ANSI.cyan}${ANSI.bold}${subtitle}${ANSI.reset}` : subtitle);
|
|
203
|
-
return lines;
|
|
204
|
-
}
|
|
205
|
-
function tonePrefix(tone, colored) {
|
|
206
|
-
if (!colored)
|
|
207
|
-
return "";
|
|
208
|
-
if (tone === "success")
|
|
209
|
-
return ANSI.green;
|
|
210
|
-
if (tone === "error")
|
|
211
|
-
return ANSI.red;
|
|
212
|
-
return ANSI.cyan;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Prints the static "Tele Bibz" banner (rainbow-painted once, no animation).
|
|
216
|
-
* Suitable for short-lived CLI commands and non-interactive streams.
|
|
217
|
-
*/
|
|
218
|
-
function printTeleBibzBanner(options = {}) {
|
|
219
|
-
const stream = options.stream ?? process.stdout;
|
|
220
|
-
const colored = useColor(options, stream);
|
|
221
|
-
const lines = bannerFrame(options.subtitle, 0, colored);
|
|
222
|
-
if (options.message) {
|
|
223
|
-
const prefix = options.tone === "error" ? "✗ " : options.tone === "success" ? "✓ " : "";
|
|
224
|
-
lines.push(colored ? `${tonePrefix(options.tone ?? "info", colored)}${prefix}${options.message}${ANSI.reset}` : `${prefix}${options.message}`);
|
|
225
|
-
}
|
|
226
|
-
stream.write(`${lines.join("\n")}\n`);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Prints the animated rainbow "Tele Bibz" banner. The rainbow flows until
|
|
230
|
-
* `stop()` is called (typically once the bot is connected), then the banner
|
|
231
|
-
* freezes and an optional status line is printed.
|
|
232
|
-
*/
|
|
233
|
-
function startTeleBibzBanner(options = {}) {
|
|
234
|
-
const stream = options.stream ?? process.stdout;
|
|
235
|
-
const colored = useColor(options, stream);
|
|
236
|
-
const frameMs = Math.max(16, options.frameMs ?? 70);
|
|
237
|
-
const subtitle = options.subtitle;
|
|
238
|
-
if (!stream.isTTY) {
|
|
239
|
-
printTeleBibzBanner({ ...options, subtitle });
|
|
240
|
-
return { stop: () => undefined };
|
|
241
|
-
}
|
|
242
|
-
let stopped = false;
|
|
243
|
-
let linesPrinted = 0;
|
|
244
|
-
const writeFrame = (offset) => {
|
|
245
|
-
const lines = bannerFrame(subtitle, offset, colored);
|
|
246
|
-
linesPrinted = lines.length;
|
|
247
|
-
stream.write(lines.join("\n") + "\n");
|
|
248
|
-
};
|
|
249
|
-
const clearFrame = () => {
|
|
250
|
-
for (let index = 0; index < linesPrinted; index += 1)
|
|
251
|
-
stream.write(`${ANSI.cursorUp}${ANSI.clearLine}`);
|
|
252
|
-
stream.write("\r");
|
|
253
|
-
};
|
|
254
|
-
stream.write(ANSI.hideCursor);
|
|
255
|
-
writeFrame(0);
|
|
256
|
-
void (async () => {
|
|
257
|
-
let offset = 0;
|
|
258
|
-
while (!stopped) {
|
|
259
|
-
await sleep(frameMs);
|
|
260
|
-
if (stopped)
|
|
261
|
-
break;
|
|
262
|
-
offset = (offset + 14) % 360;
|
|
263
|
-
clearFrame();
|
|
264
|
-
writeFrame(offset);
|
|
265
|
-
}
|
|
266
|
-
})();
|
|
267
|
-
return {
|
|
268
|
-
stop(message, tone = "success") {
|
|
269
|
-
if (stopped)
|
|
270
|
-
return;
|
|
271
|
-
stopped = true;
|
|
272
|
-
clearFrame();
|
|
273
|
-
writeFrame(0);
|
|
274
|
-
if (message) {
|
|
275
|
-
const prefix = tone === "error" ? "✗ " : tone === "success" ? "✓ " : "";
|
|
276
|
-
const line = colored ? `${tonePrefix(tone, colored)}${ANSI.bold}${prefix}${message}${ANSI.reset}` : `${prefix}${message}`;
|
|
277
|
-
stream.write(`${line}\n`);
|
|
278
|
-
}
|
|
279
|
-
stream.write(ANSI.showCursor);
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
/** Prints a single dim status line (used for "Listening for updates..." style messages). */
|
|
284
|
-
function printStatusLine(text, options = {}) {
|
|
285
|
-
const stream = options.stream ?? process.stdout;
|
|
286
|
-
const colored = useColor(options, stream);
|
|
287
|
-
stream.write(colored ? `${ANSI.dim}${text}${ANSI.reset}\n` : `${text}\n`);
|
|
288
|
-
}
|
|
289
|
-
function buildTerminalBranding(options = {}) {
|
|
290
|
-
const stream = process.stdout;
|
|
291
|
-
const colored = useColor(options, stream);
|
|
292
|
-
const color = (value, code) => colored ? `${code}${value}${ANSI.reset}` : value;
|
|
293
|
-
const title = "TELEBIBZ CLI";
|
|
294
|
-
const width = Math.max([...title].length, [...exports.TERMINAL_BRAND_TEXT].length);
|
|
295
|
-
const horizontal = "═".repeat(width + 2);
|
|
296
|
-
const line = (value) => `║ ${pad(value, width)} ║`;
|
|
297
|
-
return [
|
|
298
|
-
color(`╔${horizontal}╗`, ANSI.cyan),
|
|
299
|
-
color(line(title), ANSI.blue),
|
|
300
|
-
color(line(exports.TERMINAL_BRAND_TEXT), ANSI.magenta),
|
|
301
|
-
color(`╚${horizontal}╝`, ANSI.cyan),
|
|
302
|
-
color("Runtime logs: colorful structured output.", ANSI.dim),
|
|
303
|
-
].join("\n");
|
|
304
|
-
}
|
|
305
|
-
function printTerminalBranding(options = {}) {
|
|
306
|
-
process.stdout.write(`${buildTerminalBranding(options)}\n`);
|
|
307
|
-
}
|
|
308
|
-
function startTerminalAnimation(message = "Starting telebibz", options = {}) {
|
|
309
|
-
const stream = options.stream ?? process.stdout;
|
|
310
|
-
const colored = useColor(options, stream);
|
|
311
|
-
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
312
|
-
const intervalMs = Math.max(60, options.intervalMs ?? 90);
|
|
313
|
-
let index = 0;
|
|
314
|
-
let stopped = false;
|
|
315
|
-
const paint = () => {
|
|
316
|
-
if (stopped || !stream.isTTY)
|
|
317
|
-
return;
|
|
318
|
-
const frame = frames[index++ % frames.length] ?? "⠋";
|
|
319
|
-
const text = `${frame} ${message}`;
|
|
320
|
-
stream.write(`\r${ANSI.clearLine}${colored ? ANSI.cyan : ""}${text}${colored ? ANSI.reset : ""}`);
|
|
321
|
-
};
|
|
322
|
-
if (!stream.isTTY)
|
|
323
|
-
return { stop: () => undefined };
|
|
324
|
-
stream.write(ANSI.hideCursor);
|
|
325
|
-
paint();
|
|
326
|
-
const timer = setInterval(paint, intervalMs);
|
|
327
|
-
timer.unref?.();
|
|
328
|
-
return {
|
|
329
|
-
stop(finalMessage = "Done") {
|
|
330
|
-
if (stopped)
|
|
331
|
-
return;
|
|
332
|
-
stopped = true;
|
|
333
|
-
clearInterval(timer);
|
|
334
|
-
const prefix = finalMessage.toLowerCase().includes("error") ? ANSI.yellow : ANSI.green;
|
|
335
|
-
stream.write(`\r${ANSI.clearLine}${colored ? prefix : ""}${finalMessage}${colored ? ANSI.reset : ""}\n${ANSI.showCursor}`);
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runBroadcast = runBroadcast;
|
|
4
|
-
const errors_js_1 = require("../api/errors.js");
|
|
5
|
-
const concurrency_js_1 = require("../utils/concurrency.js");
|
|
6
|
-
function sleep(delayMs) { return new Promise((resolve) => setTimeout(resolve, delayMs)); }
|
|
7
|
-
function describeError(error) {
|
|
8
|
-
if (error instanceof errors_js_1.TelegramError)
|
|
9
|
-
return { message: error.message, kind: error.kind };
|
|
10
|
-
return { message: error instanceof Error ? error.message : String(error), kind: undefined };
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Sends to many chats in parallel with automatic 429 retry.
|
|
14
|
-
*
|
|
15
|
-
* There is no proactive cooldown: all chats (up to `concurrency`) are attempted
|
|
16
|
-
* at once. The only waiting ever done is the `retry_after` delay Telegram itself
|
|
17
|
-
* returns with a 429 answer, so bursts of 1000+ chats still deliver completely
|
|
18
|
-
* instead of failing.
|
|
19
|
-
*/
|
|
20
|
-
async function runBroadcast(chatIds, send, options = {}) {
|
|
21
|
-
const startedAt = Date.now();
|
|
22
|
-
const maxAttempts = options.maxAttempts ?? 10;
|
|
23
|
-
const failures = [];
|
|
24
|
-
let delivered = 0;
|
|
25
|
-
let processed = 0;
|
|
26
|
-
const total = chatIds.length;
|
|
27
|
-
await (0, concurrency_js_1.mapWithConcurrency)(chatIds, options.concurrency ?? Infinity, async (chatId) => {
|
|
28
|
-
let attempts = 0;
|
|
29
|
-
while (true) {
|
|
30
|
-
if (options.signal?.aborted) {
|
|
31
|
-
failures.push({ chatId, attempts, error: "aborted", errorKind: "aborted" });
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
attempts += 1;
|
|
35
|
-
try {
|
|
36
|
-
await send(chatId);
|
|
37
|
-
delivered += 1;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
const telegram = error instanceof errors_js_1.TelegramError ? error : undefined;
|
|
42
|
-
if (telegram?.kind === "rate-limit" && attempts < maxAttempts) {
|
|
43
|
-
// Telegram told us exactly how long to wait; honor it (plus a small
|
|
44
|
-
// jitter so retried chats do not fire as one synchronized wave).
|
|
45
|
-
const retryAfterMs = Math.max(0, (telegram.retryAfter ?? 1) * 1000);
|
|
46
|
-
await sleep(retryAfterMs + Math.random() * 250);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const { message, kind } = describeError(error);
|
|
50
|
-
failures.push({ chatId, attempts, error: message, errorKind: kind });
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
processed += 1;
|
|
55
|
-
options.onProgress?.({ total, processed, delivered, failed: failures.length });
|
|
56
|
-
});
|
|
57
|
-
return { total, delivered, failed: failures.length, durationMs: Date.now() - startedAt, failures };
|
|
58
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenBucketLimiter = exports.MemoryCache = void 0;
|
|
4
|
-
const storage_js_1 = require("../storage/storage.js");
|
|
5
|
-
class MemoryCache {
|
|
6
|
-
storage;
|
|
7
|
-
namespace;
|
|
8
|
-
constructor(namespace = "telebibz", storage = new storage_js_1.MemoryStorage()) {
|
|
9
|
-
this.storage = storage;
|
|
10
|
-
this.namespace = namespace;
|
|
11
|
-
}
|
|
12
|
-
key(key) { return `${this.namespace}:${key}`; }
|
|
13
|
-
get(key) { return this.storage.get(this.key(key)); }
|
|
14
|
-
set(key, value, ttlMs) { return this.storage.set(this.key(key), value, ttlMs === undefined ? {} : { ttlMs }); }
|
|
15
|
-
delete(key) { return this.storage.delete(this.key(key)); }
|
|
16
|
-
async invalidate(prefix = "") { const keys = []; for await (const key of this.storage.keys())
|
|
17
|
-
if (key.startsWith(this.key(prefix)))
|
|
18
|
-
keys.push(key); for (const key of keys)
|
|
19
|
-
await this.storage.delete(key); }
|
|
20
|
-
async getOrSet(key, factory, ttlMs) { const existing = await this.get(key); if (existing !== undefined)
|
|
21
|
-
return existing; const value = await factory(); await this.set(key, value, ttlMs); return value; }
|
|
22
|
-
}
|
|
23
|
-
exports.MemoryCache = MemoryCache;
|
|
24
|
-
class TokenBucketLimiter {
|
|
25
|
-
capacity;
|
|
26
|
-
refillPerSecond;
|
|
27
|
-
buckets = new Map();
|
|
28
|
-
constructor(capacity, refillPerSecond) {
|
|
29
|
-
this.capacity = capacity;
|
|
30
|
-
this.refillPerSecond = refillPerSecond;
|
|
31
|
-
if (capacity <= 0 || refillPerSecond <= 0)
|
|
32
|
-
throw new RangeError("capacity and refillPerSecond must be positive");
|
|
33
|
-
}
|
|
34
|
-
consume(key, cost = 1) { if (!Number.isFinite(cost) || cost <= 0)
|
|
35
|
-
throw new RangeError("cost must be positive"); const now = Date.now(); const current = this.buckets.get(key) ?? { tokens: this.capacity, updatedAt: now }; const elapsedSeconds = (now - current.updatedAt) / 1000; current.tokens = Math.min(this.capacity, current.tokens + elapsedSeconds * this.refillPerSecond); current.updatedAt = now; if (current.tokens < cost) {
|
|
36
|
-
const retryAfterMs = Math.ceil(((cost - current.tokens) / this.refillPerSecond) * 1000);
|
|
37
|
-
this.buckets.set(key, current);
|
|
38
|
-
return { allowed: false, remaining: Math.floor(current.tokens), resetAt: now + retryAfterMs, retryAfterMs };
|
|
39
|
-
} current.tokens -= cost; this.buckets.set(key, current); return { allowed: true, remaining: Math.floor(current.tokens), resetAt: now + Math.ceil(((this.capacity - current.tokens) / this.refillPerSecond) * 1000) }; }
|
|
40
|
-
clear(key) { if (key === undefined)
|
|
41
|
-
this.buckets.clear();
|
|
42
|
-
else
|
|
43
|
-
this.buckets.delete(key); }
|
|
44
|
-
}
|
|
45
|
-
exports.TokenBucketLimiter = TokenBucketLimiter;
|
package/dist-cjs/src/cli.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.main = main;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_child_process_1 = require("node:child_process");
|
|
6
|
-
const handler_js_1 = require("./webhook/handler.js");
|
|
7
|
-
const bot_js_1 = require("./core/bot.js");
|
|
8
|
-
const terminal_js_1 = require("./branding/terminal.js");
|
|
9
|
-
async function commandDoctor() {
|
|
10
|
-
(0, terminal_js_1.printTeleBibzBanner)({ subtitle: "telebibz doctor" });
|
|
11
|
-
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
12
|
-
console.log(JSON.stringify({ node: process.version, tokenPresent: Boolean(token), cwd: process.cwd(), package: "@xbibzlibrary/telebibz" }, null, 2));
|
|
13
|
-
if (token) {
|
|
14
|
-
const bot = new bot_js_1.Bot({ token, branding: false });
|
|
15
|
-
const health = await bot.health();
|
|
16
|
-
console.log(JSON.stringify(health, null, 2));
|
|
17
|
-
if (!health.apiReachable)
|
|
18
|
-
process.exitCode = 1;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async function commandStart() {
|
|
22
|
-
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
23
|
-
if (!token)
|
|
24
|
-
throw new Error("TELEGRAM_BOT_TOKEN is required");
|
|
25
|
-
const bot = new bot_js_1.Bot(token);
|
|
26
|
-
await bot.start();
|
|
27
|
-
}
|
|
28
|
-
async function commandInit(name) {
|
|
29
|
-
const dir = name || "my-telebibz-bot";
|
|
30
|
-
(0, terminal_js_1.printTeleBibzBanner)({ subtitle: "telebibz init" });
|
|
31
|
-
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
32
|
-
await (0, promises_1.writeFile)(`${dir}/index.ts`, `import { Bot } from "@xbibzlibrary/telebibz";\n\nconst bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);\nbot.command("start", (ctx) => ctx.reply("Hello from telebibz"));\nawait bot.start();\n`);
|
|
33
|
-
await (0, promises_1.writeFile)(`${dir}/.env.example`, "TELEGRAM_BOT_TOKEN=\n");
|
|
34
|
-
console.log(`Created ${dir}`);
|
|
35
|
-
}
|
|
36
|
-
async function run(name, args) {
|
|
37
|
-
return new Promise((resolve) => {
|
|
38
|
-
const child = (0, node_child_process_1.spawn)(name, args, { stdio: "inherit", shell: false });
|
|
39
|
-
child.on("exit", (code, signal) => resolve(signal ? 1 : code ?? 1));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
async function main(argv = process.argv.slice(2)) {
|
|
43
|
-
const [command, argument] = argv;
|
|
44
|
-
switch (command) {
|
|
45
|
-
case "start":
|
|
46
|
-
await commandStart();
|
|
47
|
-
break;
|
|
48
|
-
case "doctor":
|
|
49
|
-
await commandDoctor();
|
|
50
|
-
break;
|
|
51
|
-
case "init":
|
|
52
|
-
await commandInit(argument ?? "my-telebibz-bot");
|
|
53
|
-
break;
|
|
54
|
-
case "generate":
|
|
55
|
-
process.exitCode = await run("node", ["scripts/generate-api.mjs"]);
|
|
56
|
-
break;
|
|
57
|
-
case "build":
|
|
58
|
-
process.exitCode = await run("npm", ["run", "build"]);
|
|
59
|
-
break;
|
|
60
|
-
case "test":
|
|
61
|
-
process.exitCode = await run("npm", ["test"]);
|
|
62
|
-
break;
|
|
63
|
-
case "webhook": {
|
|
64
|
-
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
65
|
-
if (!token)
|
|
66
|
-
throw new Error("TELEGRAM_BOT_TOKEN is required");
|
|
67
|
-
const bot = new bot_js_1.Bot({ token, branding: false });
|
|
68
|
-
(0, terminal_js_1.printTeleBibzBanner)({ subtitle: "telebibz webhook", message: "Webhook handler ready" });
|
|
69
|
-
const webhookOptions = process.env.TELEGRAM_WEBHOOK_SECRET ? { secretToken: process.env.TELEGRAM_WEBHOOK_SECRET } : {};
|
|
70
|
-
const handler = (0, handler_js_1.createWebhookHandler)(bot, webhookOptions);
|
|
71
|
-
await (0, promises_1.access)(".");
|
|
72
|
-
console.log(`Handler type: ${typeof handler}`);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
case "inspect":
|
|
76
|
-
console.log(JSON.stringify({ cwd: process.cwd(), node: process.version }, null, 2));
|
|
77
|
-
break;
|
|
78
|
-
default: console.log("telebibz commands: start, init, dev, generate, webhook, doctor, test, inspect, build");
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (process.argv[1]?.endsWith("/cli.js") || process.argv[1]?.endsWith("/cli.ts"))
|
|
82
|
-
void main().catch((error) => {
|
|
83
|
-
const message = error instanceof Error ? error.message : "Unknown CLI error";
|
|
84
|
-
console.error(`telebibz: ${message}`);
|
|
85
|
-
process.exitCode = 1;
|
|
86
|
-
});
|