def _get_preset(preset_json: dict) -> VersionedPreset: try: preset = VersionedPreset(preset_json) preset.get_preset() # test if valid return preset except Exception as e: raise InvalidAction(f"invalid preset: {e}")
def from_json(cls, data) -> "GameSessionEntry": player_entries = [ PlayerSessionEntry.from_json(player_json) for player_json in data["players"] ] return GameSessionEntry( id=data["id"], name=data["name"], presets=[ VersionedPreset(preset_json) for preset_json in data["presets"] ], players={ player_entry.id: player_entry for player_entry in player_entries }, actions=[ GameSessionAction.from_json(item) for item in data["actions"] ], seed_hash=data["seed_hash"], word_hash=data["word_hash"], spoiler=data["spoiler"], permalink=data["permalink"], state=GameSessionState(data["state"]), generation_in_progress=data["generation_in_progress"], )
def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": json_dict = migrate_description(json_dict) has_spoiler = "game_modifications" in json_dict if not has_spoiler: raise ValueError( "Unable to read details of seed log with spoiler disabled") permalink = Permalink( seed_number=json_dict["info"]["seed"], spoiler=has_spoiler, presets={ index: VersionedPreset(preset).get_preset() for index, preset in enumerate(json_dict["info"]["presets"]) }, ) return LayoutDescription( version=json_dict["info"]["version"], permalink=permalink, all_patches=game_patches_serializer.decode( json_dict["game_modifications"], { index: preset.configuration for index, preset in permalink.presets.items() }), item_order=json_dict["item_order"], )
def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": version = json_dict.get("schema_version") if version != cls.schema_version(): raise RuntimeError("Unsupported log file version '{}'. Expected {}.".format(version, cls.schema_version())) has_spoiler = "game_modifications" in json_dict if not has_spoiler: raise ValueError("Unable to read details of seed log with spoiler disabled") permalink = Permalink( seed_number=json_dict["info"]["seed"], spoiler=has_spoiler, presets={ index: VersionedPreset(preset).get_preset() for index, preset in enumerate(json_dict["info"]["presets"]) }, ) return LayoutDescription( version=json_dict["info"]["version"], permalink=permalink, all_patches=game_patches_serializer.decode( json_dict["game_modifications"], { index: preset.layout_configuration for index, preset in permalink.presets.items() }), item_order=json_dict["item_order"], )
async def on_message(self, message: discord.Message): if message.author == self.user: return if message.guild.id != self.configuration["guild"]: return for attachment in message.attachments: filename: str = attachment.filename if filename.endswith(VersionedPreset.file_extension()): data = await attachment.read() versioned_preset = VersionedPreset( json.loads(data.decode("utf-8"))) await reply_for_preset(message, versioned_preset) channel: discord.TextChannel = message.channel if self.configuration["channel_name_filter"] in channel.name: await look_for_permalinks(message.content, channel)
def all_presets(self) -> List[Preset]: return [ VersionedPreset(json.loads(preset.preset)).get_preset() for preset in sorted(self.presets, key=lambda it: it.row) ]