diff --git a/addon_examples/properties.py b/addon_examples/addon_state_management.py similarity index 82% rename from addon_examples/properties.py rename to addon_examples/addon_state_management.py index 871f09d..0933d13 100644 --- a/addon_examples/properties.py +++ b/addon_examples/addon_state_management.py @@ -9,7 +9,7 @@ from hippolyzer.lib.proxy.region import ProxiedRegion from hippolyzer.lib.proxy.sessions import Session -class PropertyHelloWorldAddon(BaseAddon): +class AddonStateHelloWorldAddon(BaseAddon): # How to say hello, value shared across sessions and will be the same # regardless of which session is active when accessed. # "hello_greeting" is added to session_manager.addon_ctx's dict and will survive reloads @@ -28,7 +28,11 @@ class PropertyHelloWorldAddon(BaseAddon): # Shared across sessions and will die if the addon is reloaded self.hello_punctuation = "!" - @handle_command(greeting=Parameter(str, sep=None)) + @handle_command( + # Use the longer-form `Parameter()` for declaring this because + # this field should be greedy and take the rest of the message (no separator.) + greeting=Parameter(str, sep=None), + ) async def set_hello_greeting(self, _session: Session, _region: ProxiedRegion, greeting: str): """Set the person to say hello to""" self.hello_greeting = greeting @@ -38,7 +42,10 @@ class PropertyHelloWorldAddon(BaseAddon): """Set the person to say hello to""" self.hello_person = person - @handle_command(punctuation=Parameter(str, sep=None)) + @handle_command( + # Punctuation should have no whitespace, so using a simple parameter is OK. + punctuation=str, + ) async def set_hello_punctuation(self, _session: Session, _region: ProxiedRegion, punctuation: str): """Set the punctuation to use for saying hello""" self.hello_punctuation = punctuation @@ -47,8 +54,8 @@ class PropertyHelloWorldAddon(BaseAddon): async def say_hello(self, _session: Session, _region: ProxiedRegion): """Say hello using the configured hello variables""" # These aren't instance properties, they can be accessed via the class as well. - hello_person = PropertyHelloWorldAddon.hello_person + hello_person = AddonStateHelloWorldAddon.hello_person send_chat(f"{self.hello_greeting} {hello_person}{self.hello_punctuation}") -addons = [PropertyHelloWorldAddon()] +addons = [AddonStateHelloWorldAddon()]