vk_chat_bot/vk/vk_database.py

45 lines
1.4 KiB
Python

import database
class VkDatabase(database.BasicDatabase):
def __init__(self, connection_string: str):
super().__init__(connection_string)
self.cursor.execute("""
CREATE TABLE IF NOT EXISTS chats (
id BIGINT,
active TINYINT NOT NULL DEFAULT 0,
rules VARCHAR(2000),
greeting_join VARCHAR(1000),
greeting_rejoin VARCHAR(1000),
birthday_message VARCHAR(1000),
ai_prompt VARCHAR(2048),
PRIMARY KEY (id))
""")
self.cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
chat_id BIGINT,
user_id BIGINT,
last_message BIGINT NOT NULL DEFAULT 0,
messages_today SMALLINT NOT NULL DEFAULT 0,
messages_month SMALLINT NOT NULL DEFAULT 0,
warnings TINYINT NOT NULL DEFAULT 0,
happy_birthday TINYINT NOT NULL DEFAULT 1,
about VARCHAR(1000),
PRIMARY KEY (chat_id, user_id),
CONSTRAINT fk_users_chats FOREIGN KEY (chat_id) REFERENCES chats (id) ON DELETE CASCADE)
""")
self.conn.commit()
def user_toggle_happy_birthday(self, chat_id: int, user_id: int, happy_birthday: int):
self.user_update(chat_id, user_id, happy_birthday=happy_birthday)
DB: VkDatabase
def create_database(connection_string: str):
global DB
DB = VkDatabase(connection_string)