This commit is contained in:
Andrey Kondratev
2025-08-29 10:57:50 +05:00
parent 6bde4bfd4c
commit b483ed71f2
11 changed files with 106 additions and 50 deletions

View File

@@ -84,7 +84,7 @@ export class QuixoticBot {
await this.bot.sendMessage(chatId,
'🎵 Добро пожаловать в Quixotic!\n\n' +
'Найди любую песню на YouTube и получи MP3 файл прямо в чат.\n\n' +
'Найди любую песню на SoundCloud и получи MP3 файл прямо в чат.\n\n' +
'Нажми кнопку ниже, чтобы начать поиск:',
{ reply_markup: keyboard }
);
@@ -98,7 +98,7 @@ export class QuixoticBot {
this.bot.onText(/\/help/, async (msg: Message) => {
const chatId = msg.chat.id;
const helpText = `🎵 *Quixotic - YouTube to MP3*
const helpText = `🎵 *Quixotic - SoundCloud to MP3*
*Как пользоваться:*
1⃣ Нажми кнопку "Открыть Quixotic"
@@ -112,8 +112,8 @@ export class QuixoticBot {
/history - История поиска
*Возможности:*
✅ Поиск по YouTube
✅ Высокое качество MP3 (128kbps)
✅ Поиск по SoundCloud
✅ Высокое качество MP3 (192kbps)
✅ Быстрая конвертация
✅ История поиска`;
@@ -218,19 +218,7 @@ export class QuixoticBot {
}
private async getSearchHistory(userId: number): Promise<SearchResult[]> {
return new Promise((resolve, reject) => {
this.db['db'].all(
`SELECT query, created_at FROM search_history
WHERE user_id = ?
ORDER BY created_at DESC
LIMIT 10`,
[userId],
(err: Error | null, rows: SearchResult[]) => {
if (err) reject(err);
else resolve(rows || []);
}
);
});
return this.db.getSearchHistory(userId);
}
private async sendAudioFile(chatId: number, audioUrl: string, title: string): Promise<void> {
@@ -272,4 +260,4 @@ if (require.main === module) {
}
new QuixoticBot(token, webAppUrl);
}
}

View File

@@ -1,4 +1,4 @@
import { Pool, QueryResult } from 'pg';
import { Pool } from 'pg';
interface TelegramUser {
id: number;
@@ -52,7 +52,7 @@ export class Database {
await this.pool.query(`CREATE TABLE IF NOT EXISTS downloads (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
youtube_id TEXT NOT NULL,
track_id TEXT NOT NULL,
title TEXT NOT NULL,
file_path TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
@@ -85,10 +85,10 @@ export class Database {
return result.rows[0].id;
}
async addDownload(userId: number, youtubeId: string, title: string, filePath: string): Promise<number> {
async addDownload(userId: number, trackId: string, title: string, filePath: string): Promise<number> {
const result = await this.pool.query(
'INSERT INTO downloads (user_id, youtube_id, title, file_path) VALUES ($1, $2, $3, $4) RETURNING id',
[userId, youtubeId, title, filePath]
'INSERT INTO downloads (user_id, track_id, title, file_path) VALUES ($1, $2, $3, $4) RETURNING id',
[userId, trackId, title, filePath]
);
return result.rows[0].id;
}
@@ -101,7 +101,15 @@ export class Database {
return result.rows[0] || undefined;
}
async getSearchHistory(userId: number, limit: number = 10): Promise<{query: string, created_at: string}[]> {
const result = await this.pool.query(
'SELECT query, created_at FROM search_history WHERE user_id = $1 ORDER BY created_at DESC LIMIT $2',
[userId, limit]
);
return result.rows;
}
async close(): Promise<void> {
await this.pool.end();
}
}
}

View File

@@ -198,8 +198,8 @@ app.get('/health', (req: Request, res: Response) => {
});
// Error handler
app.use((err: Error, req: Request, res: Response, next: any) => {
console.error(err.stack);
app.use((_err: Error, _req: Request, res: Response, _next: any) => {
console.error(_err.stack);
res.status(500).json({ error: 'Something went wrong!' });
});
@@ -238,11 +238,16 @@ app.listen(port, () => {
const botToken = process.env.TELEGRAM_BOT_TOKEN;
const webAppUrl = process.env.WEB_APP_URL || `http://localhost:${port}`;
if (botToken) {
const bot = new QuixoticBot(botToken, webAppUrl);
console.log('🤖 Telegram bot started');
if (botToken && botToken.length > 10) {
try {
new QuixoticBot(botToken, webAppUrl);
console.log('🤖 Telegram bot started');
} catch (error: any) {
console.error('❌ Bot initialization failed:', error.message);
console.warn('⚠️ Bot disabled due to error');
}
} else {
console.warn('⚠️ TELEGRAM_BOT_TOKEN not found - bot will not start');
console.warn('⚠️ TELEGRAM_BOT_TOKEN not found or invalid - bot will not start');
}
export default app;
export default app;