Compare commits
	
		
			No commits in common. "70c8fd7a0c623830b71dfc9e36d767d728c0c0b1" and "0a2f7fe00dbd5a0c7fa5cacd43127ef135c8fc2d" have entirely different histories.
		
	
	
		
			70c8fd7a0c
			...
			0a2f7fe00d
		
	
		
					 6 changed files with 11 additions and 29 deletions
				
			
		|  | @ -3,12 +3,12 @@ from misskey.exceptions import MisskeyAPIException | ||||||
| from client import client_connection | from client import client_connection | ||||||
| from db_utils import insert_character | from db_utils import insert_character | ||||||
| from custom_types import Character | from custom_types import Character | ||||||
| from config import RARITY_TO_WEIGHT |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def add_character( | def add_character( | ||||||
|         name: str, |         name: str, | ||||||
|         rarity: int, |         rarity: int, | ||||||
|  |         weight: float, | ||||||
|         image_url: str) -> tuple[int, str]: |         image_url: str) -> tuple[int, str]: | ||||||
|     ''' |     ''' | ||||||
|     Adds a character to the database, uploading the image from a public URL to |     Adds a character to the database, uploading the image from a public URL to | ||||||
|  | @ -17,6 +17,7 @@ def add_character( | ||||||
|     Args: |     Args: | ||||||
|         name (str): Character name. |         name (str): Character name. | ||||||
|         rarity (int): Character rarity (e.g., 1-5). |         rarity (int): Character rarity (e.g., 1-5). | ||||||
|  |         weight (float): Pull weight (e.g., 0.02). | ||||||
|         image_url (str): Public URL of the image from the post (e.g., from |         image_url (str): Public URL of the image from the post (e.g., from | ||||||
|             note['files'][i]['url']). |             note['files'][i]['url']). | ||||||
| 
 | 
 | ||||||
|  | @ -35,8 +36,8 @@ def add_character( | ||||||
|         raise ValueError('Character name cannot be empty.') |         raise ValueError('Character name cannot be empty.') | ||||||
|     if rarity < 1: |     if rarity < 1: | ||||||
|         raise ValueError('Rarity must be a positive integer.') |         raise ValueError('Rarity must be a positive integer.') | ||||||
|     if rarity not in RARITY_TO_WEIGHT.keys(): |     if weight <= 0: | ||||||
|         raise ValueError(f'Invalid rarity: {rarity}') |         raise ValueError('Weight must be a positive number.') | ||||||
|     if not image_url: |     if not image_url: | ||||||
|         raise ValueError('Image URL must be provided.') |         raise ValueError('Image URL must be provided.') | ||||||
| 
 | 
 | ||||||
|  | @ -58,7 +59,7 @@ def add_character( | ||||||
|     character_id = insert_character( |     character_id = insert_character( | ||||||
|             stripped_name, |             stripped_name, | ||||||
|             rarity, |             rarity, | ||||||
|             RARITY_TO_WEIGHT[rarity], |             float(weight), | ||||||
|             file_id |             file_id | ||||||
|     ) |     ) | ||||||
|     return character_id, file_id |     return character_id, file_id | ||||||
|  |  | ||||||
|  | @ -21,15 +21,6 @@ def get_config_file() -> str: | ||||||
|         raise ConfigError(f'Could not find {config_path}') |         raise ConfigError(f'Could not find {config_path}') | ||||||
|     return config_path |     return config_path | ||||||
| 
 | 
 | ||||||
| def get_rarity_to_weight(config_section): |  | ||||||
|     """Parses Rarity_X keys from config and returns a {rarity: weight} dict.""" |  | ||||||
|     rarity_weights = {} |  | ||||||
|     for key, value in config_section.items(): |  | ||||||
|         if key.startswith("rarity_"): |  | ||||||
|             rarity = int(key.removeprefix("rarity_")) |  | ||||||
|             rarity_weights[rarity] = float(value) |  | ||||||
|     return rarity_weights |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| config = configparser.ConfigParser() | config = configparser.ConfigParser() | ||||||
| config.read(get_config_file()) | config.read(get_config_file()) | ||||||
|  | @ -52,5 +43,3 @@ NOTIFICATION_POLL_INTERVAL = int(config['notification']['PollInterval']) | ||||||
| NOTIFICATION_BATCH_SIZE = int(config['notification']['BatchSize']) | NOTIFICATION_BATCH_SIZE = int(config['notification']['BatchSize']) | ||||||
| 
 | 
 | ||||||
| GACHA_ROLL_INTERVAL = int(config['gacha']['RollInterval']) | GACHA_ROLL_INTERVAL = int(config['gacha']['RollInterval']) | ||||||
| 
 |  | ||||||
| RARITY_TO_WEIGHT = get_rarity_to_weight(config['gacha']) |  | ||||||
|  | @ -26,14 +26,14 @@ def get_random_character() -> Character | None: | ||||||
|     if not characters: |     if not characters: | ||||||
|         return None |         return None | ||||||
| 
 | 
 | ||||||
|     weights = [config.RARITY_TO_WEIGHT[c['rarity']] for c in characters] |     weights = [c['weight'] for c in characters] | ||||||
|     chosen = choices(characters, weights=weights, k=1)[0] |     chosen = choices(characters, weights=weights, k=1)[0] | ||||||
| 
 | 
 | ||||||
|     return { |     return { | ||||||
|         'id': chosen['id'], |         'id': chosen['id'], | ||||||
|         'name': chosen['name'], |         'name': chosen['name'], | ||||||
|         'rarity': chosen['rarity'], |         'rarity': chosen['rarity'], | ||||||
|         'weight': config.RARITY_TO_WEIGHT[chosen['rarity']], |         'weight': chosen['weight'], | ||||||
|         'image_url': chosen['file_id'] |         'image_url': chosen['file_id'] | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -103,10 +103,10 @@ dumbass.', | ||||||
|             'attachment_urls': None |             'attachment_urls': None | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     if len(arguments) != 2: |     if len(arguments) != 3: | ||||||
|         return { |         return { | ||||||
|             'message': f'{author} Please specify the following attributes \ |             'message': f'{author} Please specify the following attributes \ | ||||||
| in order: name, rarity', | in order: name, rarity, drop weighting', | ||||||
|             'attachment_urls': None |             'attachment_urls': None | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -126,6 +126,7 @@ must be a decimal value between 0.0 and 1.0', | ||||||
|     character_id, file_id = add_character( |     character_id, file_id = add_character( | ||||||
|         name=arguments[0], |         name=arguments[0], | ||||||
|         rarity=int(arguments[1]), |         rarity=int(arguments[1]), | ||||||
|  |         weight=float(arguments[2]), | ||||||
|         image_url=image_url |         image_url=image_url | ||||||
|     ) |     ) | ||||||
|     return { |     return { | ||||||
|  | @ -139,7 +140,7 @@ def do_help(author: str) -> BotResponse: | ||||||
|     return { |     return { | ||||||
|         'message':f'{author} Here\'s what I can do:\n \ |         'message':f'{author} Here\'s what I can do:\n \ | ||||||
|             - `roll` Pulls a random character.\ |             - `roll` Pulls a random character.\ | ||||||
|             - `create <name> <rarity>` Creates a character using a given image.\ |             - `create <name> <rarity> <weight>` Creates a character using a given image.\ | ||||||
|             - `signup` Registers your account.\ |             - `signup` Registers your account.\ | ||||||
|             - `delete_account` Deletes your account.\ |             - `delete_account` Deletes your account.\ | ||||||
|             - `help` Shows this message', |             - `help` Shows this message', | ||||||
|  |  | ||||||
|  | @ -9,14 +9,6 @@ DatabaseLocation = ./gacha_game.db | ||||||
| [gacha] | [gacha] | ||||||
| ; Number of seconds players have to wait between rolls | ; Number of seconds players have to wait between rolls | ||||||
| RollInterval = 72000 | RollInterval = 72000 | ||||||
| ; Rarity drop weights (1 to 5 stars) |  | ||||||
| ; Format: rarity=weight per line |  | ||||||
| ; In order: common, uncommon, rare, epic and legendary (Example values below) |  | ||||||
| Rarity_1 = 0.7    |  | ||||||
| Rarity_2 = 0.2 |  | ||||||
| Rarity_3 = 0.08 |  | ||||||
| Rarity_4 = 0.015 |  | ||||||
| Rarity_5 = 0.005  |  | ||||||
| 
 | 
 | ||||||
| [notification] | [notification] | ||||||
| ; Number of seconds to sleep while awaiting new notifications | ; Number of seconds to sleep while awaiting new notifications | ||||||
|  |  | ||||||
|  | @ -1 +0,0 @@ | ||||||
| ALTER TABLE characters DROP COLUMN weight; |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue