new function with audio message. Read audio from db

This commit is contained in:
KerradKerridi
2022-08-28 23:37:27 +03:00
parent 6da8d8211c
commit b162d5c50b
2 changed files with 38 additions and 30 deletions

13
db.py
View File

@@ -2,6 +2,7 @@ import sqlite3
import configparser
import os
import sys
import random
config_path = os.path.join(sys.path[0], 'settings.ini')
config = configparser.ConfigParser()
@@ -124,13 +125,15 @@ class BotDB:
except sqlite3.Error as error:
print(error)
def get_random_audio(self):
def get_random_audio(self, user_id):
"""Получает данные о войсе юзера из БД"""
try:
result = self.cursor.execute(
"SELECT `file_name` FROM `audio_message_reference` WHERE `author_id` = ? ORDER BY date_added DESC LIMIT 1",
(user_id,))
return result.fetchone()[0]
file_name = self.cursor.execute(
"SELECT `file_name` FROM `audio_message_reference` WHERE `author_id` <> ?", (user_id,))
file_name_massive = file_name.fetchall()
number_element = random.randint(0, len(file_name_massive)-1)
audio_for_user = file_name_massive[number_element]
return audio_for_user
except sqlite3.Error as error:
print(error)