Код базы данных:
from aiogram import Bot, Dispatcher, executor, types
import sqlite3
conn = sqlite3.connect('hellshopdb.db')
cursor = conn.cursor()
class BotDB:
def __init__(self, db_file):
self.conn = sqlite3.connect(db_file)
self.cursor = self.conn.cursor()
def user_exists(self, chat_id):
result = self.cursor.execute("SELECT 'id' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
return bool(len(result.fetchall()))
def get_user_id(self, chat_id):
self.cursor.execute("SELECT 'id' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
return result.fetchone()[0]
def add_user(self, chat_id):
self.cursor.execute("INSERT OR IGNORE INTO 'users' ('chat_id') VALUES (?)", (chat_id,))
return self.conn.commit()
def get_balance(self, chat_id):
self.cursor.execute("SELECT 'balance' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
return self.cursor.fetchone()
def close(self):
self.conn.close()
Код хендлера:
@dp.message_handler(commands=['Профиль'])
@dp.message_handler(Text(equals='Профиль', ignore_case=True))
async def command_prof(message: types.Message):
chat_id = message.from_user.id
balance = BotDB.get_balance(chat_id)
await message.answer(f' Баланс: {balance}', reply_markup=op)
Вот что выводиться в самом боте: