Skip to content

Commit

Permalink
Merge pull request #71 from fredix/main
Browse files Browse the repository at this point in the history
fixed issue #69 : sqlite do not init database
  • Loading branch information
ruecat authored Oct 28, 2024
2 parents 58ce0a2 + 429c98d commit 8534944
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions bot/func/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -62,10 +62,10 @@ 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

allowed_ids = load_allowed_ids_from_db()

def get_all_users_from_db():
conn = sqlite3.connect('users.db')
Expand All @@ -83,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

Expand Down
4 changes: 3 additions & 1 deletion bot/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -62,6 +61,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()
Expand Down Expand Up @@ -363,6 +363,8 @@ 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)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
python-dotenv==1.0.0
aiogram==3.2.0
ollama
aiogram==3.13.1
ollama

0 comments on commit 8534944

Please sign in to comment.