Add voice bot welcome tracking functionality
- Implemented methods to check and mark if a user has received a welcome message from the voice bot in both async and synchronous database classes. - Updated database schema to include a new field for tracking welcome message status. - Enhanced voice handler to utilize the new tracking methods, improving user interaction flow and engagement metrics.
This commit is contained in:
@@ -977,3 +977,63 @@ class AsyncBotDB:
|
||||
"""Закрытие соединений."""
|
||||
# Соединения закрываются в каждом методе
|
||||
pass
|
||||
|
||||
# Методы для voice bot welcome tracking
|
||||
async def check_voice_bot_welcome_received(self, user_id: int) -> bool:
|
||||
"""
|
||||
Проверяет, получал ли пользователь приветственное сообщение от voice_bot.
|
||||
|
||||
Args:
|
||||
user_id (int): Идентификатор пользователя в Telegram.
|
||||
|
||||
Returns:
|
||||
bool: True, если пользователь получал приветствие, False - иначе.
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = await self._get_connection()
|
||||
async with conn.execute(
|
||||
"SELECT voice_bot_welcome_received FROM our_users WHERE user_id = ?",
|
||||
(user_id,)
|
||||
) as cursor:
|
||||
result = await cursor.fetchone()
|
||||
if result:
|
||||
welcome_received = bool(result[0])
|
||||
self.logger.info(f"Пользователь {user_id} получал приветствие: {welcome_received}")
|
||||
return welcome_received
|
||||
else:
|
||||
self.logger.info(f"Пользователь {user_id} не найден в базе")
|
||||
return False
|
||||
except Exception as e:
|
||||
self.logger.error(f"Ошибка при проверке получения приветствия: {e}")
|
||||
return False
|
||||
finally:
|
||||
if conn:
|
||||
await conn.close()
|
||||
|
||||
async def mark_voice_bot_welcome_received(self, user_id: int) -> bool:
|
||||
"""
|
||||
Отмечает, что пользователь получил приветственное сообщение от voice_bot.
|
||||
|
||||
Args:
|
||||
user_id (int): Идентификатор пользователя в Telegram.
|
||||
|
||||
Returns:
|
||||
bool: True, если обновление прошло успешно, False - в случае ошибки.
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = await self._get_connection()
|
||||
await conn.execute(
|
||||
"UPDATE our_users SET voice_bot_welcome_received = 1 WHERE user_id = ?",
|
||||
(user_id,)
|
||||
)
|
||||
await conn.commit()
|
||||
self.logger.info(f"Пользователь {user_id} отмечен как получивший приветствие")
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"Ошибка при отметке получения приветствия: {e}")
|
||||
return False
|
||||
finally:
|
||||
if conn:
|
||||
await conn.close()
|
||||
|
||||
@@ -1492,3 +1492,60 @@ class BotDB:
|
||||
raise
|
||||
finally:
|
||||
self.close()
|
||||
|
||||
def check_voice_bot_welcome_received(self, user_id: int) -> bool:
|
||||
"""
|
||||
Проверяет, получал ли пользователь приветственное сообщение от voice_bot.
|
||||
|
||||
Args:
|
||||
user_id (int): Идентификатор пользователя в Telegram.
|
||||
|
||||
Returns:
|
||||
bool: True, если пользователь получал приветствие, False - иначе.
|
||||
"""
|
||||
self.logger.info(f"Запуск функции check_voice_bot_welcome_received. user_id={user_id}")
|
||||
try:
|
||||
self.connect()
|
||||
self.cursor.execute(
|
||||
"SELECT voice_bot_welcome_received FROM our_users WHERE user_id = ?",
|
||||
(user_id,)
|
||||
)
|
||||
result = self.cursor.fetchone()
|
||||
if result:
|
||||
welcome_received = bool(result[0])
|
||||
self.logger.info(f"Пользователь {user_id} получал приветствие: {welcome_received}")
|
||||
return welcome_received
|
||||
else:
|
||||
self.logger.info(f"Пользователь {user_id} не найден в базе")
|
||||
return False
|
||||
except sqlite3.Error as error:
|
||||
self.logger.error(f"Ошибка при проверке получения приветствия: {error}")
|
||||
return False
|
||||
finally:
|
||||
self.close()
|
||||
|
||||
def mark_voice_bot_welcome_received(self, user_id: int) -> bool:
|
||||
"""
|
||||
Отмечает, что пользователь получил приветственное сообщение от voice_bot.
|
||||
|
||||
Args:
|
||||
user_id (int): Идентификатор пользователя в Telegram.
|
||||
|
||||
Returns:
|
||||
bool: True, если обновление прошло успешно, False - в случае ошибки.
|
||||
"""
|
||||
self.logger.info(f"Запуск функции mark_voice_bot_welcome_received. user_id={user_id}")
|
||||
try:
|
||||
self.connect()
|
||||
self.cursor.execute(
|
||||
"UPDATE our_users SET voice_bot_welcome_received = 1 WHERE user_id = ?",
|
||||
(user_id,)
|
||||
)
|
||||
self.conn.commit()
|
||||
self.logger.info(f"Пользователь {user_id} отмечен как получивший приветствие")
|
||||
return True
|
||||
except sqlite3.Error as error:
|
||||
self.logger.error(f"Ошибка при отметке получения приветствия: {error}")
|
||||
return False
|
||||
finally:
|
||||
self.close()
|
||||
|
||||
@@ -86,7 +86,8 @@ CREATE TABLE IF NOT EXISTS our_users (
|
||||
has_stickers INTEGER DEFAULT 0 NOT NULL,
|
||||
emoji TEXT,
|
||||
date_added DATE NOT NULL,
|
||||
date_changed DATE NOT NULL
|
||||
date_changed DATE NOT NULL,
|
||||
voice_bot_welcome_received BOOLEAN DEFAULT 0
|
||||
);
|
||||
|
||||
-- Audio moderation tracking
|
||||
|
||||
Reference in New Issue
Block a user