Skip to content

Commit 3980d42

Browse files
authored
Merge pull request #47 from KnightNiwrem/master
Bot API 9.1
2 parents f58c6fb + 169fd2f commit 3980d42

File tree

2 files changed

+112
-12
lines changed

2 files changed

+112
-12
lines changed

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Deno",
3+
"image": "ghcr.io/knightniwrem/devcontainer-deno:latest",
4+
"customizations": {
5+
"vscode": {
6+
"settings": {},
7+
"extensions": [
8+
"denoland.vscode-deno",
9+
"github.copilot",
10+
"github.copilot-chat",
11+
"kilocode.kilo-code"
12+
]
13+
}
14+
}
15+
}

src/format.ts

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,35 @@ export interface Stringable {
1717
toString(): string;
1818
}
1919

20+
/**
21+
* Represents caption object with optional formatting entities.
22+
*
23+
* This interface is used to store plain caption along with its associated
24+
* formatting information (such as bold, italic, links, etc.) as message entities.
25+
*
26+
* @example
27+
* ```typescript
28+
* const formattedCaption: CaptionWithEntities = {
29+
* caption: "Hello world!",
30+
* caption_entities: [
31+
* { type: "bold", offset: 0, length: 5 },
32+
* { type: "italic", offset: 6, length: 5 }
33+
* ]
34+
* };
35+
* ```
36+
*/
37+
export interface CaptionWithEntities {
38+
/**
39+
* Plain caption value for this `FormattedString`
40+
*/
41+
caption: string;
42+
43+
/**
44+
* Format caption_entities for this `FormattedString`
45+
*/
46+
caption_entities?: MessageEntity[];
47+
}
48+
2049
/**
2150
* Represents text object with optional formatting entities.
2251
*
@@ -47,32 +76,59 @@ export interface TextWithEntities {
4776
}
4877

4978
/**
50-
* Represents caption object with optional formatting entities.
79+
* Represents text object with optional formatting entities.
5180
*
52-
* This interface is used to store plain caption along with its associated
81+
* This interface is used to store plain text along with its associated
5382
* formatting information (such as bold, italic, links, etc.) as message entities.
5483
*
5584
* @example
5685
* ```typescript
57-
* const formattedCaption: CaptionWithEntities = {
58-
* caption: "Hello world!",
59-
* caption_entities: [
86+
* const formattedText: TextWithTextEntities = {
87+
* text: "Hello world!",
88+
* text_entities: [
6089
* { type: "bold", offset: 0, length: 5 },
6190
* { type: "italic", offset: 6, length: 5 }
6291
* ]
6392
* };
6493
* ```
6594
*/
66-
export interface CaptionWithEntities {
95+
export interface TextWithTextEntities {
6796
/**
68-
* Plain caption value for this `FormattedString`
97+
* Plain text value for this `FormattedString`
6998
*/
70-
caption: string;
99+
text: string;
100+
/**
101+
* Format entities for this `FormattedString`
102+
*/
103+
text_entities?: MessageEntity[];
104+
}
71105

106+
/**
107+
* Represents title object with optional formatting entities.
108+
*
109+
* This interface is used to store plain title along with its associated
110+
* formatting information (such as bold, italic, links, etc.) as message entities.
111+
*
112+
* @example
113+
* ```typescript
114+
* const formattedTitle: TitleWithTitleEntities = {
115+
* title: "Hello world!",
116+
* title_entities: [
117+
* { type: "bold", offset: 0, length: 5 },
118+
* { type: "italic", offset: 6, length: 5 }
119+
* ]
120+
* };
121+
* ```
122+
*/
123+
export interface TitleWithTitleEntities {
72124
/**
73-
* Format caption_entities for this `FormattedString`
125+
* Plain text value for this `FormattedString`
74126
*/
75-
caption_entities?: MessageEntity[];
127+
title: string;
128+
/**
129+
* Format entities for this `FormattedString`
130+
*/
131+
title_entities?: MessageEntity[];
76132
}
77133

78134
/**
@@ -81,7 +137,12 @@ export interface CaptionWithEntities {
81137
* and caption content in Telegram Bot API calls.
82138
*/
83139
export class FormattedString
84-
implements TextWithEntities, CaptionWithEntities, Stringable {
140+
implements
141+
CaptionWithEntities,
142+
TextWithEntities,
143+
TextWithTextEntities,
144+
TitleWithTitleEntities,
145+
Stringable {
85146
/**
86147
* The entities backing this FormattedString.
87148
*/
@@ -121,6 +182,30 @@ export class FormattedString
121182
return this.rawText;
122183
}
123184

185+
/**
186+
* Gets the title. Alias for rawText.
187+
* Used when this FormattedString is used as title.
188+
*/
189+
get title() {
190+
return this.rawText;
191+
}
192+
193+
/**
194+
* Gets the text_entities. Alias for rawEntities.
195+
* Used when this FormattedString is used as text with text_entities.
196+
*/
197+
get text_entities() {
198+
return this.rawEntities;
199+
}
200+
201+
/**
202+
* Gets the title_entities. Alias for rawEntities.
203+
* Used when this FormattedString is used as title_entities.
204+
*/
205+
get title_entities() {
206+
return this.rawEntities;
207+
}
208+
124209
/**
125210
* Gets the caption entities. This is an alias for the raw entities.
126211
* Used when this FormattedString is used as caption content.
@@ -1202,7 +1287,7 @@ export function linkMessage(
12021287
"linkMessage can only be used for supergroups and channel messages. Refusing to transform into link.",
12031288
);
12041289
return fmt`${stringLike}`;
1205-
} else if (chatId < -1002147483647 || chatId > -1000000000000) {
1290+
} else if (chatId < -1997852516352 || chatId > -1000000000001) {
12061291
console.warn(
12071292
"linkMessage is not able to link messages whose chatIds are greater than -1000000000000 or less than -1002147483647 at this moment. Refusing to transform into link.",
12081293
);

0 commit comments

Comments
 (0)