This commit is contained in:
		
							
								
								
									
										14
									
								
								next_song.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								next_song.py
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | ||||
| #!/usr/bin/env python3 | ||||
| from json.decoder import JSONDecodeError | ||||
| import random, glob, os, json | ||||
|  | ||||
|  | ||||
| @@ -11,15 +12,24 @@ if __name__ == "__main__": | ||||
|     def get_air_support(): | ||||
|         return random.choice(glob.glob(f"{air_support_folder}/*.ogg")) | ||||
|  | ||||
|     def create_state_from_scratch() -> dict: | ||||
|         state = {"current_song_type": "jingle"} | ||||
|         with open(f"{songs_folder}/state.json", "w") as f: | ||||
|             json.dump(state, f, indent=4) | ||||
|         return state | ||||
|  | ||||
|     # state loading | ||||
|     if not os.path.isfile(f"{songs_folder}/state.json"): | ||||
|         # create state file if it doesnt exist | ||||
|         with open(f"{songs_folder}/state.json", "w") as f: | ||||
|             state = {"current_song_type": "jingle"} | ||||
|             json.dump(state, f, indent=4) | ||||
|             state = create_state_from_scratch() | ||||
|     else: | ||||
|         try: | ||||
|             with open(f"{songs_folder}/state.json") as f: | ||||
|                 state = json.load(f) | ||||
|         except JSONDecodeError: | ||||
|             # if file doesnt exist, we recreate a state on the disk | ||||
|             state = create_state_from_scratch() | ||||
|  | ||||
|     # song choice | ||||
|     if state["current_song_type"] == "song": | ||||
|   | ||||
		Reference in New Issue
	
	Block a user