@will-17173/telegram-cli 0.1.1 → 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/README.md +109 -6
- package/README.zh-CN.md +110 -7
- package/dist/cli/app.js +3 -1
- package/dist/cli/app.js.map +1 -1
- package/dist/commands/account.js +3 -1
- package/dist/commands/account.js.map +1 -1
- package/dist/commands/config.js +96 -13
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/group.js +107 -0
- package/dist/commands/group.js.map +1 -0
- package/dist/commands/telegram-runner.js +84 -0
- package/dist/commands/telegram-runner.js.map +1 -0
- package/dist/commands/telegram.js +92 -129
- package/dist/commands/telegram.js.map +1 -1
- package/dist/config/credential-store.js +76 -22
- package/dist/config/credential-store.js.map +1 -1
- package/dist/config/env.js +12 -1
- package/dist/config/env.js.map +1 -1
- package/dist/index.js +0 -0
- package/dist/presenters/group.js +106 -0
- package/dist/presenters/group.js.map +1 -0
- package/dist/presenters/human.js +7 -9
- package/dist/presenters/human.js.map +1 -1
- package/dist/presenters/ink/listen.js +376 -141
- package/dist/presenters/ink/listen.js.map +1 -1
- package/dist/presenters/listen-message.js +3 -236
- package/dist/presenters/listen-message.js.map +1 -1
- package/dist/services/attachment-download.js +5 -2
- package/dist/services/attachment-download.js.map +1 -1
- package/dist/services/auto-download-coordinator.js +214 -0
- package/dist/services/auto-download-coordinator.js.map +1 -0
- package/dist/services/group-service.js +164 -0
- package/dist/services/group-service.js.map +1 -0
- package/dist/services/listen-attachment.js +248 -0
- package/dist/services/listen-attachment.js.map +1 -0
- package/dist/services/message-service.js +54 -4
- package/dist/services/message-service.js.map +1 -1
- package/dist/services/query-service.js +37 -32
- package/dist/services/query-service.js.map +1 -1
- package/dist/services/sync-service.js +18 -6
- package/dist/services/sync-service.js.map +1 -1
- package/dist/telegram/client-factory.js +4 -2
- package/dist/telegram/client-factory.js.map +1 -1
- package/dist/telegram/fake-group-management.js +264 -0
- package/dist/telegram/fake-group-management.js.map +1 -0
- package/dist/telegram/group-types.js +19 -0
- package/dist/telegram/group-types.js.map +1 -0
- package/dist/telegram/mtcute-client.js +73 -8
- package/dist/telegram/mtcute-client.js.map +1 -1
- package/dist/telegram/mtcute-group-management.js +464 -0
- package/dist/telegram/mtcute-group-management.js.map +1 -0
- package/dist/telegram/proxy.js +27 -0
- package/dist/telegram/proxy.js.map +1 -0
- package/package.json +10 -12
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { MtPeerNotFoundError, tl } from '@mtcute/node';
|
|
2
|
+
import { TelegramGroupAdminRequiredError, TelegramGroupMemberNotFoundError, TelegramGroupNotFoundError, } from './group-types.js';
|
|
3
|
+
export class MtcuteGroupManagement {
|
|
4
|
+
client;
|
|
5
|
+
ensureReady;
|
|
6
|
+
constructor(client, ensureReady) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.ensureReady = ensureReady;
|
|
9
|
+
}
|
|
10
|
+
async getGroup(chat) {
|
|
11
|
+
await this.ensureReady();
|
|
12
|
+
const chatId = normalizePeerId(chat);
|
|
13
|
+
try {
|
|
14
|
+
const peer = await this.client.getChat(chatId);
|
|
15
|
+
const group = requireGroup(peer, chat);
|
|
16
|
+
const full = await this.client.getFullChat(chatId);
|
|
17
|
+
const me = await this.client.getMe();
|
|
18
|
+
const currentMember = await this.client.getChatMember({ chatId, userId: me.id });
|
|
19
|
+
return {
|
|
20
|
+
id: group.id,
|
|
21
|
+
title: group.title,
|
|
22
|
+
username: group.username ?? null,
|
|
23
|
+
type: group.chatType,
|
|
24
|
+
member_count: full.membersCount > 0 ? full.membersCount : null,
|
|
25
|
+
current_user_role: currentMember?.status ?? null,
|
|
26
|
+
current_user_rank: currentMember?.title ?? null,
|
|
27
|
+
permissions: mapAdminRights(currentMember?.permissions ?? null),
|
|
28
|
+
default_restrictions: mapRestrictions(group.defaultPermissions),
|
|
29
|
+
slow_mode_seconds: full.slowmodeSeconds ?? null,
|
|
30
|
+
message_ttl_seconds: full.ttlPeriod ?? null,
|
|
31
|
+
content_protected: group.hasContentProtection,
|
|
32
|
+
forum: group.isForum,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof TelegramGroupNotFoundError)
|
|
37
|
+
throw error;
|
|
38
|
+
if (isPeerNotFoundError(error))
|
|
39
|
+
throw new TelegramGroupNotFoundError(chat);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async listMembers(request) {
|
|
44
|
+
await this.ensureReady();
|
|
45
|
+
const chatId = normalizePeerId(request.chat);
|
|
46
|
+
try {
|
|
47
|
+
const peer = await this.client.getChat(chatId);
|
|
48
|
+
const group = requireGroup(peer, request.chat);
|
|
49
|
+
const usesLocalQuery = request.query != null && usesLocalMemberQuery(request.type);
|
|
50
|
+
const members = await this.client.getChatMembers(chatId, {
|
|
51
|
+
type: request.type,
|
|
52
|
+
query: usesLocalQuery ? undefined : request.query,
|
|
53
|
+
limit: usesLocalQuery ? 200 : request.limit,
|
|
54
|
+
});
|
|
55
|
+
const reportedTotal = members.total;
|
|
56
|
+
const resultMembers = usesLocalQuery
|
|
57
|
+
? members.filter((member) => memberMatchesQuery(member, request.query)).slice(0, request.limit)
|
|
58
|
+
: members;
|
|
59
|
+
return {
|
|
60
|
+
chat_id: group.id,
|
|
61
|
+
chat_title: group.title,
|
|
62
|
+
filter: request.type,
|
|
63
|
+
query: request.query ?? null,
|
|
64
|
+
limit: request.limit,
|
|
65
|
+
total: !usesLocalQuery
|
|
66
|
+
&& typeof reportedTotal === 'number'
|
|
67
|
+
&& Number.isSafeInteger(reportedTotal)
|
|
68
|
+
&& reportedTotal >= 0
|
|
69
|
+
? reportedTotal
|
|
70
|
+
: null,
|
|
71
|
+
members: resultMembers.map(mapMemberSummary),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error instanceof TelegramGroupNotFoundError)
|
|
76
|
+
throw error;
|
|
77
|
+
if (isPeerNotFoundError(error))
|
|
78
|
+
throw new TelegramGroupNotFoundError(request.chat);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async getMember(chat, user) {
|
|
83
|
+
await this.ensureReady();
|
|
84
|
+
const chatId = normalizePeerId(chat);
|
|
85
|
+
const userId = normalizePeerId(user);
|
|
86
|
+
let group;
|
|
87
|
+
try {
|
|
88
|
+
const peer = await this.client.getChat(chatId);
|
|
89
|
+
group = requireGroup(peer, chat);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error instanceof TelegramGroupNotFoundError)
|
|
93
|
+
throw error;
|
|
94
|
+
if (isPeerNotFoundError(error))
|
|
95
|
+
throw new TelegramGroupNotFoundError(chat);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const member = await this.client.getChatMember({ chatId, userId });
|
|
100
|
+
if (member == null)
|
|
101
|
+
throw new TelegramGroupMemberNotFoundError(chat, user);
|
|
102
|
+
return {
|
|
103
|
+
chat_id: group.id,
|
|
104
|
+
member: mapMemberDetails(member),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (error instanceof TelegramGroupMemberNotFoundError)
|
|
109
|
+
throw error;
|
|
110
|
+
if (isPeerNotFoundError(error) || isMemberNotFoundError(error)) {
|
|
111
|
+
throw new TelegramGroupMemberNotFoundError(chat, user);
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async listAuditEvents(request) {
|
|
117
|
+
await this.ensureReady();
|
|
118
|
+
const chatId = normalizePeerId(request.chat);
|
|
119
|
+
let group;
|
|
120
|
+
try {
|
|
121
|
+
const peer = await this.client.getChat(chatId);
|
|
122
|
+
group = requireGroup(peer, request.chat);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error instanceof TelegramGroupNotFoundError)
|
|
126
|
+
throw error;
|
|
127
|
+
if (isPeerNotFoundError(error))
|
|
128
|
+
throw new TelegramGroupNotFoundError(request.chat);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
const eventLogOptions = {
|
|
132
|
+
query: request.query,
|
|
133
|
+
users: request.users?.map(normalizePeerId),
|
|
134
|
+
};
|
|
135
|
+
if (request.types == null) {
|
|
136
|
+
try {
|
|
137
|
+
const events = await this.client.getChatEventLog(chatId, {
|
|
138
|
+
...eventLogOptions,
|
|
139
|
+
limit: request.limit,
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
chat_id: group.id,
|
|
143
|
+
chat_title: group.title,
|
|
144
|
+
events: events.map(mapAuditEvent).slice(0, request.limit),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
throwAuditError(error, request.chat);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!request.types.includes('other')) {
|
|
152
|
+
const filters = [...new Set(request.types.flatMap((type) => RAW_FILTERS_BY_TYPE[type]))];
|
|
153
|
+
if (filters.length > 0)
|
|
154
|
+
eventLogOptions.filters = filters;
|
|
155
|
+
}
|
|
156
|
+
const requestedTypes = new Set(request.types);
|
|
157
|
+
const filteredEvents = [];
|
|
158
|
+
try {
|
|
159
|
+
for await (const event of this.client.iterChatEventLog(chatId, eventLogOptions)) {
|
|
160
|
+
const mappedEvent = mapAuditEvent(event);
|
|
161
|
+
if (!requestedTypes.has(mappedEvent.type))
|
|
162
|
+
continue;
|
|
163
|
+
filteredEvents.push(mappedEvent);
|
|
164
|
+
if (filteredEvents.length >= request.limit)
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throwAuditError(error, request.chat);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
chat_id: group.id,
|
|
173
|
+
chat_title: group.title,
|
|
174
|
+
events: filteredEvents,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function normalizePeerId(peer) {
|
|
179
|
+
if (typeof peer === 'number')
|
|
180
|
+
return peer;
|
|
181
|
+
const trimmed = peer.trim();
|
|
182
|
+
if (trimmed === '')
|
|
183
|
+
return peer;
|
|
184
|
+
const numeric = Number.parseInt(trimmed, 10);
|
|
185
|
+
if (Number.isNaN(numeric))
|
|
186
|
+
return peer;
|
|
187
|
+
if (!Number.isSafeInteger(numeric) && /^-?\d+$/.test(trimmed))
|
|
188
|
+
return trimmed;
|
|
189
|
+
return String(numeric) === trimmed ? numeric : peer;
|
|
190
|
+
}
|
|
191
|
+
function usesLocalMemberQuery(type) {
|
|
192
|
+
return type === 'recent' || type === 'admins' || type === 'bots';
|
|
193
|
+
}
|
|
194
|
+
function memberMatchesQuery(member, query) {
|
|
195
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
196
|
+
const username = member.user.username?.toLowerCase() ?? null;
|
|
197
|
+
if (normalizedQuery.startsWith('@')) {
|
|
198
|
+
return username != null && username.includes(normalizedQuery.slice(1));
|
|
199
|
+
}
|
|
200
|
+
return member.user.displayName.toLowerCase().includes(normalizedQuery)
|
|
201
|
+
|| (username?.includes(normalizedQuery) ?? false);
|
|
202
|
+
}
|
|
203
|
+
function requireGroup(peer, requestedChat) {
|
|
204
|
+
if (peer.type !== 'chat' || (peer.chatType !== 'group' && peer.chatType !== 'supergroup')) {
|
|
205
|
+
throw new TelegramGroupNotFoundError(requestedChat);
|
|
206
|
+
}
|
|
207
|
+
return peer;
|
|
208
|
+
}
|
|
209
|
+
function mapAdminRights(rights) {
|
|
210
|
+
if (rights == null)
|
|
211
|
+
return null;
|
|
212
|
+
return {
|
|
213
|
+
change_info: rights.changeInfo === true,
|
|
214
|
+
delete_messages: rights.deleteMessages === true,
|
|
215
|
+
ban_users: rights.banUsers === true,
|
|
216
|
+
invite_users: rights.inviteUsers === true,
|
|
217
|
+
pin_messages: rights.pinMessages === true,
|
|
218
|
+
add_admins: rights.addAdmins === true,
|
|
219
|
+
manage_call: rights.manageCall === true,
|
|
220
|
+
anonymous: rights.anonymous === true,
|
|
221
|
+
manage_topics: rights.manageTopics === true,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function mapRestrictions(permissions) {
|
|
225
|
+
if (permissions == null)
|
|
226
|
+
return null;
|
|
227
|
+
return {
|
|
228
|
+
view_messages: !permissions.canViewMessages,
|
|
229
|
+
send_messages: !permissions.canSendMessages,
|
|
230
|
+
send_media: !permissions.canSendMedia,
|
|
231
|
+
send_stickers: !permissions.canSendStickers,
|
|
232
|
+
send_gifs: !permissions.canSendGifs,
|
|
233
|
+
send_games: !permissions.canSendGames,
|
|
234
|
+
send_inline: !permissions.canUseInline,
|
|
235
|
+
embed_links: !permissions.canAddWebPreviews,
|
|
236
|
+
send_polls: !permissions.canSendPolls,
|
|
237
|
+
change_info: !permissions.canChangeInfo,
|
|
238
|
+
invite_users: !permissions.canInviteUsers,
|
|
239
|
+
pin_messages: !permissions.canPinMessages,
|
|
240
|
+
manage_topics: !permissions.canManageTopics,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function mapMemberSummary(member) {
|
|
244
|
+
return {
|
|
245
|
+
id: member.user.id,
|
|
246
|
+
display_name: member.user.displayName,
|
|
247
|
+
username: member.user.username ?? null,
|
|
248
|
+
status: member.status,
|
|
249
|
+
rank: member.title ?? null,
|
|
250
|
+
joined_at: toIsoDate(member.joinedDate),
|
|
251
|
+
restricted_until: toIsoDate(member.restrictions?.untilDate ?? null),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function mapMemberDetails(member) {
|
|
255
|
+
return {
|
|
256
|
+
...mapMemberSummary(member),
|
|
257
|
+
admin_rights: mapAdminRights(member.permissions),
|
|
258
|
+
restrictions: mapRestrictions(member.restrictions),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function mapAuditEvent(event) {
|
|
262
|
+
const action = readAuditAction(event);
|
|
263
|
+
const type = mapAuditEventType(action);
|
|
264
|
+
return {
|
|
265
|
+
id: String(event.id),
|
|
266
|
+
date: event.date.toISOString(),
|
|
267
|
+
type,
|
|
268
|
+
actor: mapAuditActor(event.actor),
|
|
269
|
+
target: mapAuditTarget(action),
|
|
270
|
+
summary: `Telegram group audit event: ${type.replaceAll('_', ' ')}`,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function mapAuditActor(actor) {
|
|
274
|
+
if (actor == null)
|
|
275
|
+
return null;
|
|
276
|
+
return {
|
|
277
|
+
id: actor.id,
|
|
278
|
+
display_name: actor.displayName,
|
|
279
|
+
username: actor.username ?? null,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const INFO_ACTIONS = [
|
|
283
|
+
'title_changed',
|
|
284
|
+
'description_changed',
|
|
285
|
+
'username_changed',
|
|
286
|
+
'usernames_changed',
|
|
287
|
+
'photo_changed',
|
|
288
|
+
];
|
|
289
|
+
const SETTINGS_ACTIONS = [
|
|
290
|
+
'invites_toggled',
|
|
291
|
+
'signatures_toggled',
|
|
292
|
+
'signature_profiles_toggled',
|
|
293
|
+
'stickerset_changed',
|
|
294
|
+
'history_toggled',
|
|
295
|
+
'def_perms_changed',
|
|
296
|
+
'linked_chat_changed',
|
|
297
|
+
'location_changed',
|
|
298
|
+
'slow_mode_changed',
|
|
299
|
+
'call_started',
|
|
300
|
+
'call_ended',
|
|
301
|
+
'call_setting_changed',
|
|
302
|
+
'ttl_changed',
|
|
303
|
+
'no_forwards_toggled',
|
|
304
|
+
'forum_toggled',
|
|
305
|
+
'available_reactions_changed',
|
|
306
|
+
'emoji_status_changed',
|
|
307
|
+
'emoji_stickerset_changed',
|
|
308
|
+
'peer_color_changed',
|
|
309
|
+
'profile_peer_color_changed',
|
|
310
|
+
'wallpaper_changed',
|
|
311
|
+
'toggle_anti_spam',
|
|
312
|
+
'toggle_autotranslation',
|
|
313
|
+
'sub_extend',
|
|
314
|
+
'participant_rank_edited',
|
|
315
|
+
'user_admin_perms_changed',
|
|
316
|
+
];
|
|
317
|
+
const RAW_FILTERS_BY_TYPE = {
|
|
318
|
+
info_changed: INFO_ACTIONS,
|
|
319
|
+
settings_changed: SETTINGS_ACTIONS,
|
|
320
|
+
member_joined: ['user_joined', 'user_joined_invite', 'user_joined_approved'],
|
|
321
|
+
member_left: ['user_left'],
|
|
322
|
+
member_invited: ['user_invited'],
|
|
323
|
+
member_banned: ['user_perms_changed'],
|
|
324
|
+
member_unbanned: ['user_perms_changed'],
|
|
325
|
+
member_restricted: ['user_perms_changed'],
|
|
326
|
+
member_unrestricted: ['user_perms_changed'],
|
|
327
|
+
admin_promoted: ['user_admin_perms_changed'],
|
|
328
|
+
admin_demoted: ['user_admin_perms_changed'],
|
|
329
|
+
message_deleted: ['msg_deleted'],
|
|
330
|
+
message_edited: ['msg_edited'],
|
|
331
|
+
message_pinned: ['msg_pinned'],
|
|
332
|
+
invite_changed: ['invite_deleted', 'invite_edited', 'invite_revoked'],
|
|
333
|
+
topic_changed: ['topic_created', 'topic_edited', 'topic_deleted'],
|
|
334
|
+
other: [],
|
|
335
|
+
};
|
|
336
|
+
function readAuditAction(event) {
|
|
337
|
+
try {
|
|
338
|
+
const action = event.action;
|
|
339
|
+
return action != null && typeof action === 'object' ? action : null;
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function mapAuditEventType(action) {
|
|
346
|
+
if (action == null)
|
|
347
|
+
return 'other';
|
|
348
|
+
const actionType = typeof action?.type === 'string' ? action.type : null;
|
|
349
|
+
switch (actionType) {
|
|
350
|
+
case 'user_joined':
|
|
351
|
+
case 'user_joined_invite':
|
|
352
|
+
case 'user_joined_approved':
|
|
353
|
+
return 'member_joined';
|
|
354
|
+
case 'user_left':
|
|
355
|
+
return 'member_left';
|
|
356
|
+
case 'user_invited':
|
|
357
|
+
return 'member_invited';
|
|
358
|
+
case 'user_perms_changed':
|
|
359
|
+
return mapMemberPermissionChange(action);
|
|
360
|
+
case 'user_admin_perms_changed':
|
|
361
|
+
return mapAdminPermissionChange(action);
|
|
362
|
+
case 'msg_deleted':
|
|
363
|
+
return 'message_deleted';
|
|
364
|
+
case 'msg_edited':
|
|
365
|
+
return 'message_edited';
|
|
366
|
+
case 'msg_pinned':
|
|
367
|
+
return 'message_pinned';
|
|
368
|
+
case 'invite_deleted':
|
|
369
|
+
case 'invite_edited':
|
|
370
|
+
case 'invite_revoked':
|
|
371
|
+
return 'invite_changed';
|
|
372
|
+
case 'topic_created':
|
|
373
|
+
case 'topic_edited':
|
|
374
|
+
case 'topic_deleted':
|
|
375
|
+
return 'topic_changed';
|
|
376
|
+
default:
|
|
377
|
+
if (isActionType(actionType, INFO_ACTIONS))
|
|
378
|
+
return 'info_changed';
|
|
379
|
+
if (isActionType(actionType, SETTINGS_ACTIONS))
|
|
380
|
+
return 'settings_changed';
|
|
381
|
+
return 'other';
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function mapMemberPermissionChange(action) {
|
|
385
|
+
const oldStatus = action.old?.status;
|
|
386
|
+
const newStatus = action.new?.status;
|
|
387
|
+
if (newStatus === 'banned')
|
|
388
|
+
return 'member_banned';
|
|
389
|
+
if (newStatus === 'restricted')
|
|
390
|
+
return 'member_restricted';
|
|
391
|
+
if (!isMemberStatus(oldStatus) || !isMemberStatus(newStatus))
|
|
392
|
+
return 'other';
|
|
393
|
+
if (oldStatus === 'banned')
|
|
394
|
+
return 'member_unbanned';
|
|
395
|
+
if (oldStatus === 'restricted')
|
|
396
|
+
return 'member_unrestricted';
|
|
397
|
+
return 'other';
|
|
398
|
+
}
|
|
399
|
+
function mapAdminPermissionChange(action) {
|
|
400
|
+
if (!isMemberStatus(action.old?.status) || !isMemberStatus(action.new?.status))
|
|
401
|
+
return 'other';
|
|
402
|
+
const wasAdmin = action.old?.status === 'admin' || action.old?.status === 'creator';
|
|
403
|
+
const isAdmin = action.new?.status === 'admin' || action.new?.status === 'creator';
|
|
404
|
+
if (!wasAdmin && isAdmin)
|
|
405
|
+
return 'admin_promoted';
|
|
406
|
+
if (wasAdmin && !isAdmin)
|
|
407
|
+
return 'admin_demoted';
|
|
408
|
+
return wasAdmin && isAdmin ? 'settings_changed' : 'other';
|
|
409
|
+
}
|
|
410
|
+
function mapAuditTarget(action) {
|
|
411
|
+
const actionType = typeof action?.type === 'string' ? action.type : null;
|
|
412
|
+
switch (actionType) {
|
|
413
|
+
case 'user_invited':
|
|
414
|
+
return mapAuditActor(action?.member?.user ?? null);
|
|
415
|
+
case 'user_perms_changed':
|
|
416
|
+
case 'user_admin_perms_changed':
|
|
417
|
+
return mapAuditActor(action?.new?.user ?? action?.old?.user ?? null);
|
|
418
|
+
case 'participant_rank_edited':
|
|
419
|
+
return mapAuditActor(action?.user ?? null);
|
|
420
|
+
default:
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function isActionType(value, types) {
|
|
425
|
+
return value != null && types.includes(value);
|
|
426
|
+
}
|
|
427
|
+
function isMemberStatus(status) {
|
|
428
|
+
return status === 'creator'
|
|
429
|
+
|| status === 'admin'
|
|
430
|
+
|| status === 'member'
|
|
431
|
+
|| status === 'restricted'
|
|
432
|
+
|| status === 'banned'
|
|
433
|
+
|| status === 'left';
|
|
434
|
+
}
|
|
435
|
+
function toIsoDate(date) {
|
|
436
|
+
return date?.toISOString() ?? null;
|
|
437
|
+
}
|
|
438
|
+
function isPeerNotFoundError(error) {
|
|
439
|
+
if (error instanceof MtPeerNotFoundError)
|
|
440
|
+
return true;
|
|
441
|
+
if (!(error instanceof Error))
|
|
442
|
+
return false;
|
|
443
|
+
return /PEER_ID_INVALID|CHANNEL_(?:INVALID|PRIVATE)|CHAT_ID_INVALID|(?:peer|chat|dialog).*(?:not found|invalid)/i.test(error.message);
|
|
444
|
+
}
|
|
445
|
+
function isMemberNotFoundError(error) {
|
|
446
|
+
return error instanceof Error
|
|
447
|
+
&& /USER_NOT_PARTICIPANT|PARTICIPANT_ID_INVALID|member.*not found|not.*participant/i.test(error.message);
|
|
448
|
+
}
|
|
449
|
+
function throwAuditError(error, chat) {
|
|
450
|
+
if (isChatAdminRequiredError(error))
|
|
451
|
+
throw new TelegramGroupAdminRequiredError(chat);
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
function isChatAdminRequiredError(error) {
|
|
455
|
+
if (tl.RpcError.is(error, 'CHAT_ADMIN_REQUIRED'))
|
|
456
|
+
return true;
|
|
457
|
+
if (!(error instanceof Error))
|
|
458
|
+
return false;
|
|
459
|
+
const candidate = error;
|
|
460
|
+
return candidate.code === 400
|
|
461
|
+
&& candidate.text === 'CHAT_ADMIN_REQUIRED'
|
|
462
|
+
&& candidate.message === 'CHAT_ADMIN_REQUIRED';
|
|
463
|
+
}
|
|
464
|
+
//# sourceMappingURL=mtcute-group-management.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mtcute-group-management.js","sourceRoot":"","sources":["../../src/telegram/mtcute-group-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AA0BtD,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,kBAAkB,CAAA;AAEzB,MAAM,OAAO,qBAAqB;IAEb;IACA;IAFnB,YACmB,MAAsB,EACtB,WAAgC;QADhC,WAAM,GAAN,MAAM,CAAgB;QACtB,gBAAW,GAAX,WAAW,CAAqB;IAChD,CAAC;IAEJ,KAAK,CAAC,QAAQ,CAAC,IAAqB;QAClC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAA;QACxB,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;QAEpC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YAC9C,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CA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Ae,CAAC,KAAc,EAAE,IAAqB;IAC5D,IAAI,wBAAwB,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,+BAA+B,CAAC,IAAI,CAAC,CAAA;IACpF,MAAM,KAAK,CAAA;AACb,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7D,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC3C,MAAM,SAAS,GAAG,KAAmD,CAAA;IACrE,OAAO,SAAS,CAAC,IAAI,KAAK,GAAG;WACxB,SAAS,CAAC,IAAI,KAAK,qBAAqB;WACxC,SAAS,CAAC,OAAO,KAAK,qBAAqB,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { proxyTransportFromUrl } from '@mtcute/node';
|
|
2
|
+
const INVALID_PROXY_ERROR = 'Telegram proxy configuration is invalid.';
|
|
3
|
+
function parseTelegramProxy(raw) {
|
|
4
|
+
const proxy = raw?.trim();
|
|
5
|
+
if (!proxy) {
|
|
6
|
+
throw new Error(INVALID_PROXY_ERROR);
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
return {
|
|
10
|
+
proxy,
|
|
11
|
+
transport: proxyTransportFromUrl(proxy),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new Error(INVALID_PROXY_ERROR);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function normalizeTelegramProxy(raw) {
|
|
19
|
+
return parseTelegramProxy(raw).proxy;
|
|
20
|
+
}
|
|
21
|
+
export function telegramTransportOptions(proxy) {
|
|
22
|
+
if (proxy === undefined) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
return { transport: parseTelegramProxy(proxy).transport };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/telegram/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAEpD,MAAM,mBAAmB,GAAG,0CAA0C,CAAA;AAatE,SAAS,kBAAkB,CAAC,GAAuB;IACjD,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,CAAA;IACzB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC;QACH,OAAO;YACL,KAAK;YACL,SAAS,EAAE,qBAAqB,CAAC,KAAK,CAAC;SACxC,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAuB;IAC5D,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAA;AACtC,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAyB;IAChE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,CAAA;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@will-17173/telegram-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"bin": {
|
|
@@ -18,16 +18,6 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
23
|
-
"build": "pnpm clean && tsc -p tsconfig.build.json",
|
|
24
|
-
"dev": "tsx src/dev.ts",
|
|
25
|
-
"test": "vitest run",
|
|
26
|
-
"test:watch": "vitest",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"prepack": "pnpm build",
|
|
29
|
-
"prepublishOnly": "pnpm test && pnpm typecheck && pnpm build"
|
|
30
|
-
},
|
|
31
21
|
"dependencies": {
|
|
32
22
|
"@mtcute/node": "^0.30.3",
|
|
33
23
|
"better-sqlite3": "^12.10.0",
|
|
@@ -46,5 +36,13 @@
|
|
|
46
36
|
"tsx": "^4.20.6",
|
|
47
37
|
"typescript": "^5.9.3",
|
|
48
38
|
"vitest": "^4.0.18"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
42
|
+
"build": "pnpm clean && tsc -p tsconfig.build.json",
|
|
43
|
+
"dev": "tsx src/dev.ts",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
49
47
|
}
|
|
50
|
-
}
|
|
48
|
+
}
|