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 'id' FROM 'users' WHERE 'chat_id' = ?", (chat_id,))
return result.fetchone()[0]
def close(self):
self.conn.close()