feat(telegram): improve group handling and default display name to @username
- /lottosettings now opens settings in private DM instead of group - Bot only reacts to / commands in groups (keyboard buttons ignored) - Reply keyboard buttons removed from group messages - Default display name now uses @username instead of 'Anon' - Users can still manually update display name in settings - Updated all display name usages to use centralized getDisplayName()
This commit is contained in:
@@ -165,6 +165,7 @@ class BotDatabase {
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* Default display name is @username if available, otherwise 'Anon'
|
||||
*/
|
||||
createUser(
|
||||
telegramId: number,
|
||||
@@ -175,13 +176,15 @@ class BotDatabase {
|
||||
if (!this.db) throw new Error('Database not initialized');
|
||||
|
||||
const now = new Date().toISOString();
|
||||
// Default display name: @username if available, otherwise 'Anon'
|
||||
const defaultDisplayName = username ? `@${username}` : 'Anon';
|
||||
|
||||
this.db.prepare(`
|
||||
INSERT INTO users (telegram_id, username, first_name, last_name, display_name, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, 'Anon', ?, ?)
|
||||
`).run(telegramId, username || null, firstName || null, lastName || null, now, now);
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(telegramId, username || null, firstName || null, lastName || null, defaultDisplayName, now, now);
|
||||
|
||||
logger.info('New user created', { telegramId, username });
|
||||
logger.info('New user created', { telegramId, username, displayName: defaultDisplayName });
|
||||
|
||||
return this.getUser(telegramId)!;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ class NotificationScheduler {
|
||||
if (status.result.is_winner) {
|
||||
const user = await stateManager.getUser(telegramId);
|
||||
winnerTelegramId = telegramId;
|
||||
winnerDisplayName = user?.displayName || 'Anon';
|
||||
winnerDisplayName = user ? stateManager.getDisplayName(user) : 'Anon';
|
||||
|
||||
const winningTicket = status.tickets.find(t => t.is_winning_ticket);
|
||||
if (winningTicket) {
|
||||
@@ -396,7 +396,7 @@ class NotificationScheduler {
|
||||
if (status.result.is_winner) {
|
||||
const user = await stateManager.getUser(telegramId);
|
||||
winnerTelegramId = telegramId;
|
||||
winnerDisplayName = user?.displayName || 'Anon';
|
||||
winnerDisplayName = user ? stateManager.getDisplayName(user) : 'Anon';
|
||||
|
||||
const winningTicket = status.tickets.find(t => t.is_winning_ticket);
|
||||
if (winningTicket) {
|
||||
|
||||
@@ -170,9 +170,17 @@ class StateManager {
|
||||
|
||||
/**
|
||||
* Get user's display name (for announcements)
|
||||
* Priority: displayName > @username > 'Anon'
|
||||
*/
|
||||
getDisplayName(user: TelegramUser): string {
|
||||
return user.displayName || 'Anon';
|
||||
if (user.displayName && user.displayName !== 'Anon') {
|
||||
return user.displayName;
|
||||
}
|
||||
// Fall back to @username if available
|
||||
if (user.username) {
|
||||
return `@${user.username}`;
|
||||
}
|
||||
return 'Anon';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user