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_unique_event_from_content(config, text, chance, genre_id)[source]#
Function to get a unique event based on the event content.
- Parameters:
config (Configuration) – App configuration
text (str) – Event test
chance (int) – Event chance
genre_id (int) – Genre id from event
- Returns:
Found genre or None in case of not found
- Return type:
EVENT | 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.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.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_owned_characters(config, user)[source]#
Function to get all characters from the database which are assigned to a user and assigned to a not finished game.
- Parameters:
config (Configuration) – App configuration
user (USER) – User object
- Return type:
list[CHARACTER]
- async src.db.get_all_open_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_all_running_user_games(config, process_data)[source]#
Function get all running 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_game_id_from_character_id(config, character_id)[source]#
This function get the game id based on the handed over character id if the character is assigned to a game and the game is not finished.
- Parameters:
config (Configuration) – App configuration
character_id (int) – Character ID
- Returns:
Game ID or None
- Return type:
int | None