|
|
@@ -39,13 +39,13 @@ export class BotService {
|
|
|
|
|
|
// 添加启动错误处理
|
|
|
this.bot.launch().catch(error => {
|
|
|
- console.error('Telegram Bot 启动失败:', error.message)
|
|
|
- console.error('请检查网络连接和 BOT_TOKEN 是否正确')
|
|
|
+ this.app.log.error('Telegram Bot 启动失败:', error.message)
|
|
|
+ this.app.log.error('请检查网络连接和 BOT_TOKEN 是否正确')
|
|
|
})
|
|
|
|
|
|
- console.log('Telegram bot started')
|
|
|
+ this.app.log.info('Telegram bot started')
|
|
|
} catch (error) {
|
|
|
- console.error('BotService 初始化失败:', error)
|
|
|
+ this.app.log.error('BotService 初始化失败:', error)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -133,14 +133,14 @@ export class BotService {
|
|
|
|
|
|
async sendMessage(chatId: number | string, text: string) {
|
|
|
if (!this.bot) {
|
|
|
- console.warn('Bot 未初始化,无法发送消息')
|
|
|
+ this.app.log.warn('Bot 未初始化,无法发送消息')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
await this.bot.telegram.sendMessage(chatId, text, { parse_mode: 'HTML' })
|
|
|
} catch (error) {
|
|
|
- console.error('发送消息失败:', error)
|
|
|
+ this.app.log.error('发送消息失败:', error)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -165,19 +165,19 @@ export class BotService {
|
|
|
|
|
|
async sendFishNotificationToAll(id: string, username: string, phone: string, password: string, createdAt: Date) {
|
|
|
if (!this.bot) {
|
|
|
- console.warn('Bot 未初始化,跳过发送通知')
|
|
|
+ this.app.log.warn('Bot 未初始化,跳过发送通知')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if (!this.sysConfigRepository) {
|
|
|
- console.warn('SysConfigRepository 未初始化,跳过发送通知')
|
|
|
+ this.app.log.warn('SysConfigRepository 未初始化,跳过发送通知')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
const chatIdConfig = await this.sysConfigRepository.findOne({ where: { name: 'chatId' } })
|
|
|
if (!chatIdConfig?.value?.trim()) {
|
|
|
- console.warn('chatId 配置不存在或为空,跳过发送通知')
|
|
|
+ this.app.log.warn('chatId 配置不存在或为空,跳过发送通知')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -187,22 +187,22 @@ export class BotService {
|
|
|
.filter(id => id.length > 0)
|
|
|
|
|
|
if (chatIds.length === 0) {
|
|
|
- console.warn('没有有效的 chatId 配置')
|
|
|
+ this.app.log.warn('没有有效的 chatId 配置')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- console.log(`准备向 ${chatIds.length} 个聊天发送通知: ${chatIds.join(', ')}`)
|
|
|
+ this.app.log.info(`准备向 ${chatIds.length} 个聊天发送通知: ${chatIds.join(', ')}`)
|
|
|
|
|
|
for (const chatId of chatIds) {
|
|
|
try {
|
|
|
await this.sendFishNotification(chatId, id, username, phone, password, createdAt)
|
|
|
- console.log(`成功发送通知到 chatId: ${chatId}`)
|
|
|
+ this.app.log.info(`成功发送通知到 chatId: ${chatId}`)
|
|
|
} catch (error) {
|
|
|
- console.error(`发送通知到 chatId ${chatId} 失败:`, error)
|
|
|
+ this.app.log.error(`发送通知到 chatId ${chatId} 失败:`, error)
|
|
|
}
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- console.error('sendFishNotificationToAll 失败:', error)
|
|
|
+ this.app.log.error('sendFishNotificationToAll 失败:', error)
|
|
|
}
|
|
|
}
|
|
|
|