Nickname added

This commit is contained in:
Artyom Ashirov 2024-11-14 18:24:04 +03:00
parent a3bde60b87
commit 52779d20ab
5 changed files with 7 additions and 6 deletions

Binary file not shown.

View File

@ -90,6 +90,7 @@ const initDb = async () => {
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
telegram_id TEXT UNIQUE NOT NULL, telegram_id TEXT UNIQUE NOT NULL,
username TEXT,
country TEXT, country TEXT,
city TEXT, city TEXT,
district TEXT, district TEXT,

View File

@ -31,7 +31,6 @@ export default class AdminUserHandler {
GROUP BY u.id GROUP BY u.id
ORDER BY u.created_at DESC ORDER BY u.created_at DESC
`); `);
if (users.length === 0) { if (users.length === 0) {
await this.bot.sendMessage(msg.chat.id, 'No users registered yet.'); await this.bot.sendMessage(msg.chat.id, 'No users registered yet.');
return; return;
@ -54,7 +53,7 @@ export default class AdminUserHandler {
// Create inline keyboard with user list // Create inline keyboard with user list
const keyboard = { const keyboard = {
inline_keyboard: users.map(user => [{ inline_keyboard: users.map(user => [{
text: `ID: ${user.telegram_id} | Balance: $${user.total_balance || 0}`, text: `ID: ${user.telegram_id} | Nickname: ${user.username? "@" + user.username: "None"} | Balance: $${user.total_balance || 0}`,
callback_data: `view_user_${user.telegram_id}` callback_data: `view_user_${user.telegram_id}`
}]) }])
}; };

View File

@ -57,10 +57,11 @@ export default class UserHandler {
async handleStart(msg) { async handleStart(msg) {
const chatId = msg.chat.id; const chatId = msg.chat.id;
const userId = msg.from.id; const userId = msg.from.id;
const username = msg.chat.username;
try { try {
// Create user profile // Create user profile
await User.create(userId); await User.create(userId, username);
const keyboard = { const keyboard = {
reply_markup: { reply_markup: {

View File

@ -1,7 +1,7 @@
import db from '../config/database.js'; import db from '../config/database.js';
export default class User { export default class User {
static async create(telegramId) { static async create(telegramId, username) {
try { try {
// First check if user exists // First check if user exists
const existingUser = await this.getById(telegramId); const existingUser = await this.getById(telegramId);
@ -14,8 +14,8 @@ export default class User {
// Create new user // Create new user
const result = await db.runAsync( const result = await db.runAsync(
'INSERT INTO users (telegram_id) VALUES (?)', 'INSERT INTO users (telegram_id, username) VALUES (?, ?)',
[telegramId.toString()] [telegramId.toString(), username]
); );
// Commit transaction // Commit transaction