-
Notifications
You must be signed in to change notification settings - Fork 19
/
client.ts
35 lines (32 loc) · 1.09 KB
/
client.ts
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
import * as log from "std/log/mod.ts";
import { Api, MTProtoSender, TelegramClient } from "$grm";
export const sensitives = [
/([+]?\d{1,3}([-\s]+)?|)\d{3}([-\s]+)?\d{3}([-\s]+)?\d{4}/,
/[0-9a-f]{32}/,
/[0-9]{10}:[0-9A-z_-]{35}/,
];
export const lsKey = "deactivate_security";
export class Client extends TelegramClient {
invoke(request: Api.AnyRequest, sender?: MTProtoSender) {
if (!localStorage.getItem(lsKey)) {
let content = "";
if (
request instanceof Api.messages.EditMessage ||
request instanceof Api.messages.SendMessage ||
request instanceof Api.messages.SendMedia
) {
content = request.message ?? "";
} else if (request instanceof Api.messages.SendMultiMedia) {
content = request.multiMedia.map((v) => v.message).join("");
}
for (const sensitive of sensitives) {
if (sensitive.test(content)) {
throw new Error("Request might contain sensitive information");
}
}
} else {
log.warning("the security module is not active");
}
return super.invoke(request, sender);
}
}