-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.ts
110 lines (94 loc) · 3.04 KB
/
types.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
107
108
109
110
import type { Context, RawApi, Types } from "./deps.ts";
import type { PrivateChat } from "./private.ts";
import type { GroupChat } from "./group.ts";
import type { SupergroupChat } from "./supergroup.ts";
import type { ChannelChat } from "./channel.ts";
import { METHODS } from "./methods/list.ts";
import { Chats } from "./chats.ts";
export type UserId = Types.User["id"];
export type MessageId = Types.MessageId["message_id"];
export type ChatId = Types.Chat["id"];
export type MaybePromise<T> = T | Promise<T>;
export type NotificationHandler = (
message: Types.Message,
) => MaybePromise<unknown>;
export type InteractableChats =
| Types.Chat.GroupChat
| Types.Chat.SupergroupChat
| Types.Chat.ChannelChat;
export type InteractableChatTypes<C extends Context> =
| GroupChat<C>
| SupergroupChat<C>
| ChannelChat<C>;
export type ApiResponse = {
method: keyof RawApi;
payload?: unknown;
};
export type ChatType<C extends Context> =
| PrivateChat<C>
| GroupChat<C>
| SupergroupChat<C>
| ChannelChat<C>;
export type MyDefaultAdministratorRights = Record<
"groups" | "channels",
Types.ChatAdministratorRights
>;
type Category = keyof typeof METHODS;
export type Methods<T extends Category> = typeof METHODS[T][number];
export type AllMethods = Methods<Category>;
// TODO: Is there no other method for satisfying everyone.
export type Handler<C extends Context, M extends keyof RawApi> = (
environment: Chats<C>,
payload: Parameters<RawApi[M]>[0],
) => Promise<Types.ApiResponse<Awaited<ReturnType<RawApi[M]>>>>;
export type Handlers<
C extends Context,
M extends keyof RawApi,
> = Record<M, Handler<C, M>>;
// TODO: Re-think the design
type LanguageCode = string;
export type LocalizedCommands = Record<
LanguageCode,
Types.BotCommand[]
>;
type NotChatScopedBotCommands = Record<
Exclude<
Types.BotCommandScope["type"],
"chat" | "chat_member" | "chat_administrators"
>,
LocalizedCommands
>;
interface ChatScopedBotCommands {
chat: {
[chat_id: number]: LocalizedCommands;
};
chat_administrators: {
[chat_id: number]: LocalizedCommands;
};
chat_member: {
[chat_id: number]: {
[user_id: number]: LocalizedCommands;
};
};
}
export type BotCommands = NotChatScopedBotCommands & ChatScopedBotCommands;
export interface BotDescriptions {
[lang: string]: Types.BotDescription & Types.BotShortDescription;
}
export interface EnvironmentOptions {
botInfo?: Types.UserFromGetMe;
myDefaultAdministratorRights?: MyDefaultAdministratorRights;
defaultChatMenuButton?: Types.MenuButton;
defaultCommands?: Types.BotCommand[];
}
export type InlineQueryResultCached =
| Types.InlineQueryResultCachedGif
| Types.InlineQueryResultCachedAudio
| Types.InlineQueryResultCachedPhoto
| Types.InlineQueryResultCachedVideo
| Types.InlineQueryResultCachedVoice
| Types.InlineQueryResultCachedSticker
| Types.InlineQueryResultCachedDocument
| Types.InlineQueryResultCachedMpeg4Gif;
export type ChatPermissions = keyof Types.ChatPermissions;
export type ChatAdministratorRights = keyof Types.ChatAdministratorRights;