Spaces:
Sleeping
Sleeping
Surf Studio commited on
Commit ·
a885574
1
Parent(s): bb015c0
修复私有会话/机器人读取:数字 id 先暖化实体缓存再解析(VIP Surfers 这类私聊现在能读)
Browse files- lib/telegramUser.js +24 -4
lib/telegramUser.js
CHANGED
|
@@ -403,6 +403,26 @@ async function reconnect() {
|
|
| 403 |
return { ok: true, username: me?.username || null, id: String(me?.id || '') }
|
| 404 |
}
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
/** Every group / channel the logged-in account belongs to. */
|
| 407 |
async function listDialogs({ limit = 300 } = {}) {
|
| 408 |
const session = await getSetting('tg_session')
|
|
@@ -558,7 +578,7 @@ async function addChannel(input) {
|
|
| 558 |
}
|
| 559 |
} else {
|
| 560 |
try {
|
| 561 |
-
chat = await
|
| 562 |
} catch (err) {
|
| 563 |
throw friendlyError(err)
|
| 564 |
}
|
|
@@ -590,7 +610,7 @@ async function refreshChannelTitles(c, list) {
|
|
| 590 |
const out = []
|
| 591 |
for (const item of list) {
|
| 592 |
try {
|
| 593 |
-
const chat = await
|
| 594 |
out.push({ ...item, ...chatToChannel(chat, item.ref), addedAt: item.addedAt })
|
| 595 |
} catch {
|
| 596 |
out.push(item)
|
|
@@ -691,7 +711,7 @@ async function inspect(input, { limit = 12, takeover = true } = {}) {
|
|
| 691 |
const target =
|
| 692 |
list.find((item) => String(item.ref || '') === key || String(item.id || '') === key) || { ref: key }
|
| 693 |
const c = await client(session, { takeover })
|
| 694 |
-
const entity = await
|
| 695 |
const messages = await c.getMessages(entity, { limit })
|
| 696 |
const out = []
|
| 697 |
for (const message of messages) {
|
|
@@ -784,7 +804,7 @@ async function sync({ upsert, upsertParams, takeover = false }) {
|
|
| 784 |
errors.push(`${channel.title || '未命名频道'}: 频道信息不完整,请删除后重新添加`)
|
| 785 |
continue
|
| 786 |
}
|
| 787 |
-
const entity = await
|
| 788 |
const depth = Number(channel.hits || 0) > 0 ? MESSAGES_PER_CHANNEL_HOT : MESSAGES_PER_CHANNEL
|
| 789 |
const messages = await c.getMessages(entity, { limit: depth })
|
| 790 |
scanned += messages.length
|
|
|
|
| 403 |
return { ok: true, username: me?.username || null, id: String(me?.id || '') }
|
| 404 |
}
|
| 405 |
|
| 406 |
+
/**
|
| 407 |
+
* Resolve a chat by username / id / invite ref. Numeric ids only resolve when
|
| 408 |
+
* the entity is in the client cache, so on a fresh process we warm the cache
|
| 409 |
+
* from the dialog list once and retry.
|
| 410 |
+
*/
|
| 411 |
+
async function resolveEntity(c, ref) {
|
| 412 |
+
const key = ref || ''
|
| 413 |
+
try {
|
| 414 |
+
return await c.getEntity(key)
|
| 415 |
+
} catch (err) {
|
| 416 |
+
if (!/Could not find the input entity/i.test(String(err?.message || ''))) throw err
|
| 417 |
+
try {
|
| 418 |
+
await c.getDialogs({ limit: 300 })
|
| 419 |
+
} catch {
|
| 420 |
+
/* keep the original error if this fails too */
|
| 421 |
+
}
|
| 422 |
+
return c.getEntity(key)
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
/** Every group / channel the logged-in account belongs to. */
|
| 427 |
async function listDialogs({ limit = 300 } = {}) {
|
| 428 |
const session = await getSetting('tg_session')
|
|
|
|
| 578 |
}
|
| 579 |
} else {
|
| 580 |
try {
|
| 581 |
+
chat = await resolveEntity(c, ref)
|
| 582 |
} catch (err) {
|
| 583 |
throw friendlyError(err)
|
| 584 |
}
|
|
|
|
| 610 |
const out = []
|
| 611 |
for (const item of list) {
|
| 612 |
try {
|
| 613 |
+
const chat = await resolveEntity(c, item.ref || item.id)
|
| 614 |
out.push({ ...item, ...chatToChannel(chat, item.ref), addedAt: item.addedAt })
|
| 615 |
} catch {
|
| 616 |
out.push(item)
|
|
|
|
| 711 |
const target =
|
| 712 |
list.find((item) => String(item.ref || '') === key || String(item.id || '') === key) || { ref: key }
|
| 713 |
const c = await client(session, { takeover })
|
| 714 |
+
const entity = await resolveEntity(c, target.ref || target.id || key)
|
| 715 |
const messages = await c.getMessages(entity, { limit })
|
| 716 |
const out = []
|
| 717 |
for (const message of messages) {
|
|
|
|
| 804 |
errors.push(`${channel.title || '未命名频道'}: 频道信息不完整,请删除后重新添加`)
|
| 805 |
continue
|
| 806 |
}
|
| 807 |
+
const entity = await resolveEntity(c, target)
|
| 808 |
const depth = Number(channel.hits || 0) > 0 ? MESSAGES_PER_CHANNEL_HOT : MESSAGES_PER_CHANNEL
|
| 809 |
const messages = await c.getMessages(entity, { limit: depth })
|
| 810 |
scanned += messages.length
|