mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
Update tg issues
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { config } from "./util/config.js";
|
||||
import { logger } from "./util/logger.js";
|
||||
import { db, pool } from "./db/client.js";
|
||||
import { createBotClient, closeBotClient, onBotUpdate } from "./tdlib/client.js";
|
||||
import { createBotClient, closeBotClient, onBotUpdate, getUser } from "./tdlib/client.js";
|
||||
import { startSendListener, stopSendListener } from "./send-listener.js";
|
||||
import { handleMessage } from "./commands.js";
|
||||
import { mkdir } from "fs/promises";
|
||||
@@ -49,14 +49,27 @@ async function main(): Promise<void> {
|
||||
const userId = senderId.user_id as number;
|
||||
|
||||
if (text && userId) {
|
||||
// Get user info for display name (async but fire-and-forget for perf)
|
||||
handleMessage({
|
||||
chatId: BigInt(chatId),
|
||||
userId: BigInt(userId),
|
||||
text,
|
||||
firstName: "User", // TDLib provides this via a separate getUser call
|
||||
username: undefined,
|
||||
}).catch((err) => {
|
||||
(async () => {
|
||||
let firstName = "User";
|
||||
let lastName: string | undefined;
|
||||
let username: string | undefined;
|
||||
try {
|
||||
const userInfo = await getUser(userId);
|
||||
firstName = userInfo.firstName;
|
||||
lastName = userInfo.lastName;
|
||||
username = userInfo.username;
|
||||
} catch {
|
||||
// Fall back to defaults if getUser fails
|
||||
}
|
||||
await handleMessage({
|
||||
chatId: BigInt(chatId),
|
||||
userId: BigInt(userId),
|
||||
text,
|
||||
firstName,
|
||||
lastName,
|
||||
username,
|
||||
});
|
||||
})().catch((err) => {
|
||||
log.error({ err, chatId, userId }, "Failed to handle message");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ async function handleNewPackage(payload: string): Promise<void> {
|
||||
userSubs.set(key, patterns);
|
||||
}
|
||||
|
||||
const creator = data.creator ? ` by ${data.creator}` : "";
|
||||
const creator = data.creator ? ` by ${escapeHtml(data.creator)}` : "";
|
||||
for (const [telegramUserId, patterns] of userSubs) {
|
||||
const msg = [
|
||||
`🔔 <b>New package matching your subscriptions:</b>`,
|
||||
|
||||
@@ -143,6 +143,28 @@ export async function sendPhotoMessage(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get basic info about a Telegram user (name, username).
|
||||
*/
|
||||
export async function getUser(
|
||||
userId: number
|
||||
): Promise<{ firstName: string; lastName?: string; username?: string }> {
|
||||
if (!client) throw new Error("Bot client not initialized");
|
||||
const user = (await client.invoke({
|
||||
_: "getUser",
|
||||
user_id: userId,
|
||||
})) as {
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
usernames?: { editable_username?: string };
|
||||
};
|
||||
return {
|
||||
firstName: user.first_name ?? "User",
|
||||
lastName: user.last_name || undefined,
|
||||
username: user.usernames?.editable_username || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updates from TDLib. The bot listens for new messages this way.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user