-
Notifications
You must be signed in to change notification settings - Fork 2
/
constants.ts
68 lines (58 loc) · 1.75 KB
/
constants.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
import {
Bot,
Context,
SessionFlavor,
} from "https://deno.land/x/[email protected]/mod.ts";
import { freeStorage } from "https://deno.land/x/[email protected]/free/src/mod.ts";
import { SocialLayerClient } from "./client.ts";
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
await load();
export interface TemporaryStorageData {
groupId: number | undefined;
offset: number;
lastLoadMoreMessageId: number | undefined;
lastStartISO: string | undefined;
lastEndISO: string | undefined;
subscription: string;
isSubs: boolean;
hour: number;
days: number;
}
export interface GlobalStorageData {
keys: string;
}
export interface SessionData {
temporary: TemporaryStorageData;
global: GlobalStorageData;
}
export const GLOBAL_KEY: string = "global";
export function globalStorage(): {
read(key: string): Promise<GlobalStorageData>;
write(key: string, data: GlobalStorageData): Promise<void>;
delete(key: string): Promise<void>;
getToken(): Promise<string>;
} {
return freeStorage<GlobalStorageData>(bot.token);
}
export function TEMPORARY_KEY(
chatId: number,
is_topic_message: boolean,
message_thread_id: number | undefined,
): string {
return `${chatId}/${
(is_topic_message && message_thread_id) ? message_thread_id : 0
}`;
}
export function temporaryStorage(): {
read(key: string): Promise<TemporaryStorageData>;
write(key: string, data: TemporaryStorageData): Promise<void>;
delete(key: string): Promise<void>;
getToken(): Promise<string>;
} {
return freeStorage<TemporaryStorageData>(bot.token);
}
export type SolaContext = Context & SessionFlavor<SessionData>;
export const bot = new Bot<SolaContext>(
Deno.env.get("TELEGRAM_BOT_TOKEN")!,
);
export const socialLayerClient = new SocialLayerClient();