From 7b32ee7fcf42c2e5d6c9048664df7b26dee3c1bc Mon Sep 17 00:00:00 2001 From: Moon Date: Fri, 13 Jun 2025 11:23:34 +0900 Subject: [PATCH] had to change some things to get cursor for db working. --- bot/add_character.py | 14 ++++---------- bot/bot_app.py | 5 ++++- example_config.ini | 17 +++++++---------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/bot/add_character.py b/bot/add_character.py index 7590c1b..55089fe 100644 --- a/bot/add_character.py +++ b/bot/add_character.py @@ -1,6 +1,6 @@ import requests from fediverse_factory import get_fediverse_service -from db_utils import get_db_connection +import db_utils from config import RARITY_TO_WEIGHT def add_character(name: str, rarity: int, weight: float, image_url: str) -> tuple[int, str]: @@ -47,20 +47,14 @@ def add_character(name: str, rarity: int, weight: float, image_url: str) -> tupl except RuntimeError as e: raise RuntimeError(f"Failed to upload image: {e}") from e - # Insert into database - conn = get_db_connection() - cur = conn.cursor() - cur.execute( + # Insert into database using the global connection pattern + db_utils.CURSOR.execute( 'INSERT INTO characters (name, rarity, weight, file_id) VALUES (?, ?, ?, ?)', (stripped_name, rarity, float(weight), file_id) ) - conn.commit() - character_id = cur.lastrowid + character_id = db_utils.CURSOR.lastrowid return character_id, file_id except Exception as e: raise - finally: - if 'conn' in locals(): - conn.close() diff --git a/bot/bot_app.py b/bot/bot_app.py index f4bc1e0..b4a95c8 100644 --- a/bot/bot_app.py +++ b/bot/bot_app.py @@ -1,11 +1,14 @@ import time import traceback from parsing import parse_notification -from db_utils import get_config, set_config +from db_utils import get_config, set_config, connect from fediverse_factory import get_fediverse_service import config def stream_notifications(): + # Initialize database connection + connect() + # Initialize the Fediverse service fediverse_service = get_fediverse_service() diff --git a/example_config.ini b/example_config.ini index 58cf483..cb9aa89 100644 --- a/example_config.ini +++ b/example_config.ini @@ -5,6 +5,13 @@ DefaultAdmins = ['admin@example.tld'] ; SQLite Database location DatabaseLocation = ./gacha_game.db +; Instance type - either "misskey" or "pleroma" +InstanceType = misskey +; Web server port (default: 5000) +WebPort = 5000 +; Comma-separated list of trusted fediverse instances (leave empty to allow only local users) +; Example: TrustedInstances = mastodon.social,misskey.io,pleroma.example.com +TrustedInstances = [gacha] ; Number of seconds players have to wait between rolls @@ -32,13 +39,3 @@ User = @bot@example.tld ; API key for the bot ; Generate one by going to Settings > API > Generate access token Token = abcdefghijklmnopqrstuvwxyz012345 - -; Instance type - either "misskey" or "pleroma" -InstanceType = misskey - -; Web server port (default: 5000) -WebPort = 5000 - -; Comma-separated list of trusted fediverse instances (leave empty to allow only local users) -; Example: TrustedInstances = mastodon.social,misskey.io,pleroma.example.com -TrustedInstances =