-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.ts
106 lines (83 loc) · 2.4 KB
/
data.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
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
98
99
100
101
102
103
104
105
106
type Sudoer = number;
export interface Language {
from: "en" | "ru";
targetLang?: string;
edit: number;
group?: number;
translators: number[];
main: number;
beta: number;
}
let paths = new Array<string>();
for await (const entry of Deno.readDir("./")) {
if (
!entry.isFile ||
!entry.name.startsWith("data") ||
!entry.name.endsWith(".json") ||
entry.name == "data.json"
) {
continue;
}
paths.push(entry.name);
}
paths = paths.filter((p) => p != "data.json");
paths.sort(
(a, b) =>
Number(a.replace(".json", "").split("-")[1]) -
Number(b.replace(".json", "").split("-")[1]),
);
const path = paths.slice(-1)[0] || "data.json";
const data = JSON.parse(await Deno.readTextFile(path));
export const languages: Record<string, Language> = data.languages;
export const sudoers: Sudoer[] = data.sudoers;
export const support = -1001266712138;
export const channels: Record<
string,
Record<string, { name: string; flags?: string[] }>
> = {
ru: {
"-1001003307527": { name: "@tginfo" },
"-1001313913616": { name: "@betainfo", flags: ["beta"] },
"-1001719500532": { name: "rualt", flags: ["alt"] },
},
en: {
"-1001263222189": { name: "@tginfoen" },
"-1001335406586": { name: "@betainfoen", flags: ["beta"] },
"-1001253459535": { name: "enalt", flags: ["alt"] },
},
};
export async function update(
func: (
languages: Record<string, Language>,
sudoers: Sudoer[],
) => Promise<void> | void,
) {
const result = func(languages, sudoers);
result instanceof Promise && (await result);
await Deno.writeTextFile(
`data-${Date.now()}.json`,
JSON.stringify({ languages, sudoers }),
);
}
// deno-lint-ignore no-explicit-any
export async function updateWithFileData(data: any) {
if (typeof data.languages === "object" && Array.isArray(data.sudoers)) {
await update((languages, sudoers) => {
for (const k in data.languages) {
languages[k] = data.languages[k];
}
sudoers.splice(0, sudoers.length);
for (const sudoer of data.sudoers) {
sudoers.push(sudoer);
}
});
return true;
}
return false;
}
export function dump() {
return new TextEncoder().encode(JSON.stringify({ languages, sudoers }));
}
export const INLINE_INVITE_LINK_NAME = "tgnftrnsltrbtnln";
export const pilotChats = { ru: -1001964648754, en: -1001192070541 } as const;
export const copilotsChat = -1001266712138;