-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclash.ts
More file actions
48 lines (39 loc) · 1.23 KB
/
clash.ts
File metadata and controls
48 lines (39 loc) · 1.23 KB
1
2
3
4
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import QRCode from "qrcode";
import { Context } from "telegraf";
import { BotState } from "../../state";
export async function handleSubscriptionClashCallback(
ctx: Context,
botState: BotState,
) {
const callbackQuery = ctx.callbackQuery;
if (!callbackQuery || !("data" in callbackQuery)) {
return await ctx.answerCbQuery();
}
const data = callbackQuery.data;
if (!data) {
return await ctx.answerCbQuery();
}
const user = ctx.from;
if (!user || !user.username) {
return ctx.answerCbQuery("Не удалось определить пользователя.");
}
const userEntry = await botState.findUserByTelegramId(user.id);
if (!userEntry || userEntry.is_deleted) {
return ctx.answerCbQuery("Для начала используйте /start");
}
const subLink = botState.getSubLink(userEntry.id, "clash");
const qrBuffer = await QRCode.toBuffer(subLink, {
errorCorrectionLevel: "H",
type: "png",
margin: 8,
scale: 6,
});
await ctx.editMessageText(
`*Нажмите на ссылку, чтобы скопировать* \n\`\`\`\n${subLink}\n\`\`\``,
{ parse_mode: "MarkdownV2" },
);
await ctx.replyWithPhoto(
{ source: qrBuffer },
{ caption: `QR-код для VPN Clash подписки 🧷` },
);
}