@sunafterrainwm/telegram-entities-builder 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +365 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +247 -0
- package/dist/index.d.mts +186 -184
- package/dist/index.mjs +325 -345
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/src/cjs.cts +3 -0
- package/src/index.ts +3 -1
- package/dist/index.d.ts +0 -240
- package/dist/index.js +0 -385
- package/dist/index.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,356 +1,336 @@
|
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
mergePayload(text, entities, wrappers = []) {
|
|
138
|
-
const startOffset = this.#text.length;
|
|
139
|
-
this.#text += text;
|
|
140
|
-
this.#entities.push(
|
|
141
|
-
...wrappers.map(
|
|
142
|
-
(w) => ({
|
|
143
|
-
...w,
|
|
144
|
-
offset: startOffset,
|
|
145
|
-
length: text.length
|
|
146
|
-
})
|
|
147
|
-
),
|
|
148
|
-
...entities.map((e) => ({
|
|
149
|
-
...e,
|
|
150
|
-
offset: e.offset + startOffset
|
|
151
|
-
}))
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
merge(wrapperEntities = []) {
|
|
155
|
-
if (!this.#parent) {
|
|
156
|
-
throw new Error("Cannot merge: This builder is not a fork or has already been merged.");
|
|
157
|
-
}
|
|
158
|
-
this.#parent.mergePayload(this.#text, this.#entities, wrapperEntities);
|
|
159
|
-
this.#parent = void 0;
|
|
160
|
-
}
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Main implementation of IEntityBuilder that eagerly evaluates and stores entities.
|
|
4
|
+
*/
|
|
5
|
+
var EntityBuilder = class EntityBuilder {
|
|
6
|
+
#text = "";
|
|
7
|
+
#entities = [];
|
|
8
|
+
#parent;
|
|
9
|
+
addText(text) {
|
|
10
|
+
this.#text += text;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
addTextEntity(text, entity) {
|
|
14
|
+
text = String(text);
|
|
15
|
+
if (text.length > 0) {
|
|
16
|
+
this.#entities.push({
|
|
17
|
+
...entity,
|
|
18
|
+
offset: this.#text.length,
|
|
19
|
+
length: text.length
|
|
20
|
+
});
|
|
21
|
+
this.#text += text;
|
|
22
|
+
}
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
addTextEntities(text, entities) {
|
|
26
|
+
for (const entity of entities) this.#entities.push({
|
|
27
|
+
...entity,
|
|
28
|
+
offset: this.#text.length,
|
|
29
|
+
length: text.length
|
|
30
|
+
});
|
|
31
|
+
this.#text += text;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
addTextSegmentList(segments) {
|
|
35
|
+
for (const segment of segments) if (segment.entity) this.addTextEntity(segment.text, segment.entity);
|
|
36
|
+
else if (segment.entities) this.addTextEntities(segment.text, segment.entities);
|
|
37
|
+
else this.#text += segment.text;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
buildTextPayload() {
|
|
41
|
+
return {
|
|
42
|
+
text: this.#text,
|
|
43
|
+
entities: this.#entities
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
buildCaptionPayload() {
|
|
47
|
+
return {
|
|
48
|
+
caption: this.#text,
|
|
49
|
+
caption_entities: this.#entities
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
buildInlinePayload() {
|
|
53
|
+
return {
|
|
54
|
+
message_text: this.#text,
|
|
55
|
+
entities: this.#entities
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
sortEntities() {
|
|
59
|
+
this.#entities.sort((a, b) => a.offset - b.offset || a.length - b.length);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
sliceInplace(start, end) {
|
|
63
|
+
if (!start && !end) return this;
|
|
64
|
+
const len = this.#text.length;
|
|
65
|
+
const s = start === void 0 ? 0 : start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
66
|
+
const e = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
67
|
+
if (s >= e) {
|
|
68
|
+
this.#text = "";
|
|
69
|
+
this.#entities = [];
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
this.#text = this.#text.slice(s, e);
|
|
73
|
+
this.#entities = this.#entities.flatMap((entity) => {
|
|
74
|
+
const overlapStart = Math.max(s, entity.offset);
|
|
75
|
+
const overlapEnd = Math.min(e, entity.offset + entity.length);
|
|
76
|
+
if (overlapStart < overlapEnd) return [{
|
|
77
|
+
...entity,
|
|
78
|
+
offset: overlapStart - s,
|
|
79
|
+
length: overlapEnd - overlapStart
|
|
80
|
+
}];
|
|
81
|
+
return [];
|
|
82
|
+
});
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
slice(start, end) {
|
|
86
|
+
return this.clone().sliceInplace(start, end);
|
|
87
|
+
}
|
|
88
|
+
trimStart() {
|
|
89
|
+
const trimmedLength = this.#text.trimStart().length;
|
|
90
|
+
const diff = this.#text.length - trimmedLength;
|
|
91
|
+
if (diff > 0) this.sliceInplace(diff);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
trimEnd() {
|
|
95
|
+
const trimmedLength = this.#text.trimEnd().length;
|
|
96
|
+
if (trimmedLength < this.#text.length) this.sliceInplace(0, trimmedLength);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
trim() {
|
|
100
|
+
const originalLength = this.#text.length;
|
|
101
|
+
const startOffset = originalLength - this.#text.trimStart().length;
|
|
102
|
+
const endOffset = this.#text.trimEnd().length;
|
|
103
|
+
if (startOffset > 0 || endOffset < originalLength) this.sliceInplace(startOffset, endOffset);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
clone() {
|
|
107
|
+
const instance = new EntityBuilder();
|
|
108
|
+
instance.#text = this.#text;
|
|
109
|
+
instance.#entities = structuredClone(this.#entities);
|
|
110
|
+
return instance;
|
|
111
|
+
}
|
|
112
|
+
fork() {
|
|
113
|
+
const instance = new EntityBuilder();
|
|
114
|
+
instance.#parent = this;
|
|
115
|
+
return instance;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Merges a payload text and its entities into this builder, optionally wrapping them with additional entities.
|
|
119
|
+
*/
|
|
120
|
+
mergePayload(text, entities, wrappers = []) {
|
|
121
|
+
const startOffset = this.#text.length;
|
|
122
|
+
this.#text += text;
|
|
123
|
+
this.#entities.push(...wrappers.map((w) => ({
|
|
124
|
+
...w,
|
|
125
|
+
offset: startOffset,
|
|
126
|
+
length: text.length
|
|
127
|
+
})), ...entities.map((e) => ({
|
|
128
|
+
...e,
|
|
129
|
+
offset: e.offset + startOffset
|
|
130
|
+
})));
|
|
131
|
+
}
|
|
132
|
+
merge(wrapperEntities = []) {
|
|
133
|
+
if (!this.#parent) throw new Error("Cannot merge: This builder is not a fork or has already been merged.");
|
|
134
|
+
this.#parent.mergePayload(this.#text, this.#entities, wrapperEntities);
|
|
135
|
+
this.#parent = void 0;
|
|
136
|
+
}
|
|
161
137
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
138
|
+
/**
|
|
139
|
+
* A lazy implementation of IEntityBuilderBase that stores segments and flattens them into an EntityBuilder only when needed.
|
|
140
|
+
*/
|
|
141
|
+
var LazyEntityBuilder = class LazyEntityBuilder {
|
|
142
|
+
#segments = [];
|
|
143
|
+
#parent;
|
|
144
|
+
/**
|
|
145
|
+
* Flattens the lazy segments into a new EntityBuilder instance.
|
|
146
|
+
*/
|
|
147
|
+
flatten() {
|
|
148
|
+
const builder = new EntityBuilder();
|
|
149
|
+
builder.addTextSegmentList(this.#segments);
|
|
150
|
+
return builder;
|
|
151
|
+
}
|
|
152
|
+
addText(text) {
|
|
153
|
+
this.#segments.push({ text });
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
addTextEntity(text, entity) {
|
|
157
|
+
this.#segments.push({
|
|
158
|
+
text,
|
|
159
|
+
entity
|
|
160
|
+
});
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
addTextEntities(text, entities) {
|
|
164
|
+
this.#segments.push({
|
|
165
|
+
text,
|
|
166
|
+
entities
|
|
167
|
+
});
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
addTextSegmentList(segments) {
|
|
171
|
+
this.#segments.push(...segments);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
clone() {
|
|
175
|
+
const instance = new LazyEntityBuilder();
|
|
176
|
+
instance.#segments = structuredClone(this.#segments);
|
|
177
|
+
return instance;
|
|
178
|
+
}
|
|
179
|
+
fork() {
|
|
180
|
+
const instance = new LazyEntityBuilder();
|
|
181
|
+
instance.#parent = this;
|
|
182
|
+
return instance;
|
|
183
|
+
}
|
|
184
|
+
merge(wrapperEntities = []) {
|
|
185
|
+
if (!this.#parent) throw new Error("Cannot merge: This builder is not a fork or has already been merged.");
|
|
186
|
+
const wrappedSegments = this.#segments.map((seg) => {
|
|
187
|
+
if (seg.text.length === 0) return seg;
|
|
188
|
+
const existing = seg.entities ? [...seg.entities] : seg.entity ? [seg.entity] : [];
|
|
189
|
+
return {
|
|
190
|
+
text: seg.text,
|
|
191
|
+
entities: [...existing, ...wrapperEntities]
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
this.#parent.addTextSegmentList(wrappedSegments);
|
|
195
|
+
this.#parent = void 0;
|
|
196
|
+
}
|
|
216
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Abstract proxy class that delegates all IEntityBuilder operations to an underlying builder instance.
|
|
200
|
+
*/
|
|
217
201
|
var EntityBuilderProxy = class {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
202
|
+
_entities;
|
|
203
|
+
constructor(_entities) {
|
|
204
|
+
this._entities = _entities;
|
|
205
|
+
}
|
|
206
|
+
get entities() {
|
|
207
|
+
return this._entities;
|
|
208
|
+
}
|
|
209
|
+
addText(...args) {
|
|
210
|
+
this._entities.addText(...args);
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
addTextEntity(...args) {
|
|
214
|
+
this._entities.addTextEntity(...args);
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
addTextEntities(...args) {
|
|
218
|
+
this._entities.addTextEntities(...args);
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
addTextSegmentList(...args) {
|
|
222
|
+
this._entities.addTextSegmentList(...args);
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
sliceInplace(...args) {
|
|
226
|
+
this._entities.sliceInplace(...args);
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
slice(...args) {
|
|
230
|
+
return this.fork().sliceInplace(...args);
|
|
231
|
+
}
|
|
232
|
+
trim() {
|
|
233
|
+
this._entities.trim();
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
trimStart() {
|
|
237
|
+
this._entities.trimStart();
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
trimEnd() {
|
|
241
|
+
this._entities.trimEnd();
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
sortEntities() {
|
|
245
|
+
this._entities.sortEntities();
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
clone() {
|
|
249
|
+
const newInstance = Object.create(this.constructor.prototype);
|
|
250
|
+
newInstance._entities.clone();
|
|
251
|
+
return newInstance;
|
|
252
|
+
}
|
|
253
|
+
fork() {
|
|
254
|
+
return this._entities.fork();
|
|
255
|
+
}
|
|
256
|
+
merge(...args) {
|
|
257
|
+
this._entities.merge(...args);
|
|
258
|
+
}
|
|
259
|
+
buildTextPayload() {
|
|
260
|
+
return this._entities.buildTextPayload();
|
|
261
|
+
}
|
|
262
|
+
buildCaptionPayload() {
|
|
263
|
+
const { text, entities } = this.buildTextPayload();
|
|
264
|
+
return {
|
|
265
|
+
caption: text,
|
|
266
|
+
caption_entities: entities
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
buildInlinePayload() {
|
|
270
|
+
const { text, entities, link_preview_options } = this.buildTextPayload();
|
|
271
|
+
return {
|
|
272
|
+
message_text: text,
|
|
273
|
+
entities,
|
|
274
|
+
link_preview_options
|
|
275
|
+
};
|
|
276
|
+
}
|
|
293
277
|
};
|
|
294
278
|
function upperFirst(input) {
|
|
295
|
-
|
|
279
|
+
return input.slice(0, 1).toUpperCase() + input.slice(1);
|
|
296
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Escapes a string to be used as a valid tag by removing or replacing invalid characters.
|
|
283
|
+
*/
|
|
297
284
|
function escapeTag(input) {
|
|
298
|
-
|
|
285
|
+
return input.replaceAll(/["'′]/g, "").split(/[^\p{L}\p{N}_]/gu).map((s) => upperFirst(s)).join("");
|
|
299
286
|
}
|
|
300
|
-
|
|
287
|
+
const SymbolMessageComposer = Symbol("MessageComposer");
|
|
288
|
+
/**
|
|
289
|
+
* A high-level composer that wraps an IEntityBuilder and provides additional features like tags and link preview options.
|
|
290
|
+
*/
|
|
301
291
|
var MessageComposer = class extends EntityBuilderProxy {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
entities.trimEnd();
|
|
343
|
-
return {
|
|
344
|
-
...entities.buildTextPayload(),
|
|
345
|
-
link_preview_options: this.linkPreviewOptions
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
export {
|
|
350
|
-
EntityBuilder,
|
|
351
|
-
EntityBuilderProxy,
|
|
352
|
-
LazyEntityBuilder,
|
|
353
|
-
MessageComposer,
|
|
354
|
-
escapeTag
|
|
292
|
+
[SymbolMessageComposer] = true;
|
|
293
|
+
#upperTags = /* @__PURE__ */ new Set();
|
|
294
|
+
#tags = [];
|
|
295
|
+
/**
|
|
296
|
+
* Options for link preview generation.
|
|
297
|
+
*/
|
|
298
|
+
linkPreviewOptions;
|
|
299
|
+
constructor(entities) {
|
|
300
|
+
if (entities && SymbolMessageComposer in entities) throw new TypeError("Cannot nest MessageComposer inside MessageComposer");
|
|
301
|
+
super(entities ?? new EntityBuilder());
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Gets the current list of tags.
|
|
305
|
+
*/
|
|
306
|
+
get tags() {
|
|
307
|
+
return [...this.#tags];
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Adds one or more tags, escaping them and avoiding duplicates.
|
|
311
|
+
*/
|
|
312
|
+
addTags(...tags) {
|
|
313
|
+
for (let tag of tags) {
|
|
314
|
+
tag = escapeTag(tag);
|
|
315
|
+
const upperTag = tag.toUpperCase();
|
|
316
|
+
if (this.#upperTags.has(upperTag)) continue;
|
|
317
|
+
this.#upperTags.add(upperTag);
|
|
318
|
+
this.#tags.push(tag);
|
|
319
|
+
}
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
buildTextPayload() {
|
|
323
|
+
const entities = this.entities.clone();
|
|
324
|
+
entities.trimEnd().addText("\n\n");
|
|
325
|
+
for (const tag of this.tags) entities.addTextEntity(`#${tag}`, { type: "hashtag" }).addText(" ");
|
|
326
|
+
entities.trimEnd();
|
|
327
|
+
return {
|
|
328
|
+
...entities.buildTextPayload(),
|
|
329
|
+
link_preview_options: this.linkPreviewOptions
|
|
330
|
+
};
|
|
331
|
+
}
|
|
355
332
|
};
|
|
333
|
+
|
|
334
|
+
//#endregion
|
|
335
|
+
export { EntityBuilder, EntityBuilderProxy, LazyEntityBuilder, MessageComposer, MessageComposer as default, escapeTag };
|
|
356
336
|
//# sourceMappingURL=index.mjs.map
|