fix: drop redundant telegram audit union
This commit is contained in:
@@ -102,22 +102,30 @@ export async function auditTelegramGroupMembership(params: {
|
|||||||
const res = await fetchWithTimeout(url, params.timeoutMs, fetcher);
|
const res = await fetchWithTimeout(url, params.timeoutMs, fetcher);
|
||||||
const json = (await res.json()) as
|
const json = (await res.json()) as
|
||||||
| TelegramApiOk<{ status?: string }>
|
| TelegramApiOk<{ status?: string }>
|
||||||
| TelegramApiErr
|
| TelegramApiErr;
|
||||||
| unknown;
|
|
||||||
if (!res.ok || !isRecord(json) || json.ok !== true) {
|
if (!res.ok || !isRecord(json) || json.ok !== true) {
|
||||||
const desc =
|
const desc =
|
||||||
isRecord(json) && json.ok === false && typeof json.description === "string"
|
isRecord(json) &&
|
||||||
|
json.ok === false &&
|
||||||
|
typeof json.description === "string"
|
||||||
? json.description
|
? json.description
|
||||||
: `getChatMember failed (${res.status})`;
|
: `getChatMember failed (${res.status})`;
|
||||||
groups.push({ chatId, ok: false, status: null, error: desc });
|
groups.push({ chatId, ok: false, status: null, error: desc });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const status = isRecord((json as TelegramApiOk<unknown>).result)
|
const status = isRecord((json as TelegramApiOk<unknown>).result)
|
||||||
? (json as TelegramApiOk<{ status?: string }>).result.status ?? null
|
? ((json as TelegramApiOk<{ status?: string }>).result.status ?? null)
|
||||||
: null;
|
: null;
|
||||||
const ok =
|
const ok =
|
||||||
status === "creator" || status === "administrator" || status === "member";
|
status === "creator" ||
|
||||||
groups.push({ chatId, ok, status, error: ok ? null : "bot not in group" });
|
status === "administrator" ||
|
||||||
|
status === "member";
|
||||||
|
groups.push({
|
||||||
|
chatId,
|
||||||
|
ok,
|
||||||
|
status,
|
||||||
|
error: ok ? null : "bot not in group",
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
groups.push({
|
groups.push({
|
||||||
chatId,
|
chatId,
|
||||||
@@ -137,4 +145,3 @@ export async function auditTelegramGroupMembership(params: {
|
|||||||
elapsedMs: Date.now() - started,
|
elapsedMs: Date.now() - started,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user