-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontext.ts
43 lines (37 loc) · 1.09 KB
/
context.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
import {
ChatTypeContext,
CommandContext,
Context as BaseContext,
Filter,
LazySessionFlavor,
Message,
NextFunction,
ParseMode,
} from "./deps.ts";
export interface SessionData {
dnd: boolean; // Do not disturb mode status
interval?: [number, number]; // Unavailability [StartHour, EndHour]
tz?: string; // User's entered timezone
}
interface CustomContextFlavor {
alert(text: string): Promise<true>;
comment(text: string, options?: ParseMode): Promise<Message.TextMessage>;
}
export type Context =
& BaseContext
& LazySessionFlavor<SessionData>
& CustomContextFlavor;
type GroupContext = ChatTypeContext<Context, "group" | "supergroup">;
export type ReportContext =
| CommandContext<GroupContext>
| Filter<
GroupContext,
"msg:entities:mention" | "msg:caption_entities:mention"
>;
export async function customMethods(ctx: Context, next: NextFunction) {
ctx.alert = (text: string) =>
ctx.answerCallbackQuery({ text, show_alert: true });
ctx.comment = (text: string, parseMode?: ParseMode) =>
ctx.reply(text, { parse_mode: parseMode });
await next();
}