From 17f32d122e135e99b78a4a1c474ebb43411221c3 Mon Sep 17 00:00:00 2001 From: fredix Date: Sun, 13 Oct 2024 15:10:16 +0200 Subject: [PATCH 1/2] fixed issue #69 : sqlite do not init database --- bot/func/interactions.py | 1 - bot/run.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/func/interactions.py b/bot/func/interactions.py index fbb553f..516da79 100644 --- a/bot/func/interactions.py +++ b/bot/func/interactions.py @@ -65,7 +65,6 @@ def load_allowed_ids_from_db(): conn.close() return user_ids -allowed_ids = load_allowed_ids_from_db() def get_all_users_from_db(): conn = sqlite3.connect('users.db') diff --git a/bot/run.py b/bot/run.py index 4d59a20..3e1fd48 100644 --- a/bot/run.py +++ b/bot/run.py @@ -62,6 +62,7 @@ def init_db(): # db_user_ids = load_allowed_ids_from_db() # allowed_ids.extend([user_id for user_id in db_user_ids if user_id not in allowed_ids]) + def register_user(user_id, user_name): conn = sqlite3.connect('users.db') c = conn.cursor() @@ -363,6 +364,7 @@ async def ollama_request(message: types.Message, prompt: str = None): async def main(): init_db() + allowed_ids = load_allowed_ids_from_db() await bot.set_my_commands(commands) await dp.start_polling(bot, skip_update=True) From 429c98dfd48fa85a86b8824befc79f0db1a617aa Mon Sep 17 00:00:00 2001 From: fredix Date: Mon, 14 Oct 2024 20:18:48 +0200 Subject: [PATCH 2/2] fixed issue #69 : USER_IDS was not loaded --- bot/func/interactions.py | 4 ++-- bot/run.py | 2 +- requirements.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/func/interactions.py b/bot/func/interactions.py index 516da79..8209454 100644 --- a/bot/func/interactions.py +++ b/bot/func/interactions.py @@ -12,7 +12,7 @@ from dotenv import load_dotenv load_dotenv() token = os.getenv("TOKEN") -#allowed_ids = list(map(int, os.getenv("USER_IDS", "").split(","))) +allowed_ids = list(map(int, os.getenv("USER_IDS", "").split(","))) admin_ids = list(map(int, os.getenv("ADMIN_IDS", "").split(","))) ollama_base_url = os.getenv("OLLAMA_BASE_URL") ollama_port = os.getenv("OLLAMA_PORT", "11434") @@ -62,6 +62,7 @@ def load_allowed_ids_from_db(): c = conn.cursor() c.execute("SELECT id FROM users") user_ids = [row[0] for row in c.fetchall()] + print(f"users_ids: {user_ids}") conn.close() return user_ids @@ -82,7 +83,6 @@ def remove_user_from_db(user_id): conn.commit() conn.close() if removed: - global allowed_ids allowed_ids = [id for id in allowed_ids if id != user_id] return removed diff --git a/bot/run.py b/bot/run.py index 3e1fd48..eb6dca6 100644 --- a/bot/run.py +++ b/bot/run.py @@ -14,7 +14,6 @@ start_kb = InlineKeyboardBuilder() settings_kb = InlineKeyboardBuilder() - start_kb.row( types.InlineKeyboardButton(text="ℹ️ About", callback_data="about"), types.InlineKeyboardButton(text="⚙️ Settings", callback_data="settings"), @@ -365,6 +364,7 @@ async def ollama_request(message: types.Message, prompt: str = None): async def main(): init_db() allowed_ids = load_allowed_ids_from_db() + print(f"allowed_ids: {allowed_ids}") await bot.set_my_commands(commands) await dp.start_polling(bot, skip_update=True) diff --git a/requirements.txt b/requirements.txt index ae4f875..f679629 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ python-dotenv==1.0.0 -aiogram==3.2.0 -ollama \ No newline at end of file +aiogram==3.13.1 +ollama