db#
This File contains the database setup, initialization functions and general database related functions.
- class src.db.ImportResult(file_path, data, success=False, import_number=0, text_genre='', text_character='')[source]#
Result class from importing a file.
- async src.db.get_genre_double_cond(config, genre_id, genre_name=None)[source]#
This function retrieves the last GENRE object from the database based on the provided genre name. The reason for returning the last entry is to manage adaptions to genre over time, ensuring that without deleting old versions in case of traceability to old games.
- Parameters:
config (Configuration) – Programm configuration
genre_name (str) – Genre name to search for
- Returns:
Found last genre with loaded inspirational words and events or None
- Return type:
GENRE | None
- async src.db.check_exist_unique_character(config, character)[source]#
Function checks whether the character passed is unique.
- Parameters:
config (Configuration) – App configuration
genre (dict) – New character from yml load
- Returns:
Transferred character already exists.
- Return type:
- async src.db.check_exist_unique_genre(config, genre)[source]#
Function checks whether the genre passed is unique.
- Parameters:
config (Configuration) – App configuration
genre (dict) – New genre from yml load
- Returns:
Transferred genre already exists.
- Return type:
- async src.db.create_genre_from_input(config, result)[source]#
Function to create genre from imported file.
- Parameters:
config (Configuration) – App configuration
result (ImportResult) – Result class from importing a file
- async src.db.create_character_from_input(config, result)[source]#
Function to create character from imported file.
- Parameters:
config (Configuration) – App configuration
result (ImportResult) – Result class from importing a file
- async src.db.get_characters_from_ids(config, ids)[source]#
Function to get characters from a list of ids.
- Parameters:
config (Configuration) – App configuration
- Returns:
List of characters
- Return type:
list[CHARACTER]
- async src.db.get_object_by_id(config, obj_type, obj_id)[source]#
Function to get a object from the database by its id.
- Parameters:
config (Configuration) – App configuration
obj_type (UserGameCharacterAssociation) – Type of the object to get
obj_id (int) – Id of the object to get
- Return type:
- async src.db.get_all_active_genre(config)[source]#
Function to get all genres from the database.
- Parameters:
config (Configuration) – App configuration
- Returns:
List of all genres in the database
- Return type:
list[GENRE]
- async src.db.process_player(config, user_list)[source]#
Function to process a user list and add them to the database if they are not already there.
- Parameters:
config (Configuration) – App configuration
user_list (list[discord.member.Member]) – List of users to process
- Returns:
processed user list
- Return type:
list[User]
- async src.db.update_db_objs(config, objs)[source]#
Function to update a game or player object in the database
- Parameters:
config (Configuration) – App configuration
obj (GAME | USER | TALE | GENRE) – Object to update in the database
- Return type:
- async src.db.get_available_characters(config)[source]#
Function to get all characters from the database which are not assigned to a user.
- Parameters:
config (Configuration) – App configuration
- Return type:
list[CHARACTER]
- async src.db.get_all_user_games(config, process_data)[source]#
Function get all games loaded with user participations from the database from a user.
- Parameters:
config (Configuration) – App configuration
process_data (ProcessInput) – Process input data structure
- Return type:
- async src.db.get_all_running_games(config, process_data)[source]#
Function to get all available games from the database which are not finished.
- Parameters:
config (Configuration) – App configuration
process_data (ProcessInput) – Game data object
- Return type:
- async src.db.get_tale_from_game_id(config, game_id)[source]#
Function to get the tale based on handed over game id.
- Parameters:
config (Configuration) – App configuration
game_id (int) – Game id
- Returns:
One Tale or None
- Return type:
TALE | None
- async src.db.get_games_w_status(config, status)[source]#
This function get all changeable games back. Games that have the status CREATED, RUNNING or PAUSED can be changed.
- Parameters:
config (Configuration) – App configuration
- Returns:
The list if changeable games
- Return type:
list[Game]
- async src.db.get_user_from_dc_id(config, dc_id)[source]#
Get the user object based on handed over discord id.
- Parameters:
config (Configuration) – App configuration
dc_id (str) – Discord ID of user
- Returns:
One User or None
- Return type:
USER | None
- async src.db.get_mapped_ugc_association(config, game_id, user_id)[source]#
Function get the association object based on handed over game and user id.
- Parameters:
config (Configuration) – App configuration
game_id (int) – Game id
user_id (int) – User id
- Returns:
Linked association object
- Return type:
UserGameCharacterAssociation | None
- async src.db.count_regist_char_from_game(config, game_id)[source]#
Function get the number of registered character in a handed over game based on id.
- Parameters:
config (Configuration) – App configuration
game_id (int) – Game id
- Returns:
Count of registered characters
- Return type:
- async src.db.get_active_user_from_game(config, game_id)[source]#
Function get all active user based on game ID and if a character is selected in game association.
- Parameters:
config (Configuration) – App configuration
game_id (int) – Game ID
- Returns:
All active user in game or None
- Return type:
list[USER] | None
- async src.db.get_character_from_game_id(config, game_id)[source]#
Function get all registered characters from a game based on handed over game id.
- Parameters:
config (Configuration) – App configuration
game_id (int) – Game id
- Returns:
List of characters or None
- Return type:
list[CHARACTER] | None
- async src.db.get_stories_messages_for_ai(config, tale_id)[source]#
This function retrieves all stories for a given tale id and formats them into a list of messages suitable for AI processing.
- Parameters:
config (Configuration) – App configuration
tale_id (int) – Tale ID to retrieve stories
- Returns:
List of messages formatted for AI
- Return type:
- async src.db.channel_id_exist(config, channel_id)[source]#
This function checks if a channel ID exists in a game.
- Parameters:
config (Configuration) – App configuration
channel_id (str) – Channel ID
- Returns:
Any game started with same channel ID
- Return type:
- async src.db.check_only_init_stories(config, tale_id)[source]#
This function checks whether there are stories that have a story type other than INIT.
- Parameters:
config (Configuration) – App configuration
tale_id (int) – Tale id to get all stories
- Returns:
Identify whether there are only stories that have the type INIT.
- Return type:
- async src.db.delete_init_stories(config, tale_id, game_id)[source]#
This function deletes all INIT stories from a tale and returns the Discord message IDs associated with those stories.
- Parameters:
config (Configuration) – App configuration
tale_id (int) – Tale ID to delete stories from
game_id (int) – Game ID
- Returns:
List of Discord message IDs that were associated with the deleted stories
- Return type:
- async src.db.get_active_genre(config)[source]#
This function retrieves all active genres from the database.
- Parameters:
config (Configuration) – App configuration
- Returns:
List with all active genres
- Return type:
list[GENRE]
- async src.db.deactivate_genre_with_id(config, genre_id)[source]#
This function deactivates a genre based on the handed over genre id.
- Parameters:
config (Configuration) – App configuration
genre_id (int) – Genre id to deactivate
- Return type:
- async src.db.get_inactive_genre(config)[source]#
This function retrieves all inactive genres from the database.
- Parameters:
config (Configuration) – App configuration
- Returns:
List with all inactive genres
- Return type:
list[GENRE]
- async src.db.activate_genre_with_id(config, genre_id)[source]#
This function activates a genre based on the handed over genre id.
- Parameters:
config (Configuration) – App configuration
genre_id (int) – Genre id to activate
- Return type: