From 84bc1f786d7217e63b4f346510f5b07b1087d3d3 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 25 Mar 2024 00:59:39 +0100 Subject: [PATCH] Added basic plugin examples --- docs/example_plugins/basic.py | 38 +++++++++++++++++++++++++++++++++ docs/example_plugins/comic.py | 0 docs/example_plugins/service.py | 34 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 docs/example_plugins/basic.py create mode 100644 docs/example_plugins/comic.py create mode 100644 docs/example_plugins/service.py diff --git a/docs/example_plugins/basic.py b/docs/example_plugins/basic.py new file mode 100644 index 0000000..9bc03f0 --- /dev/null +++ b/docs/example_plugins/basic.py @@ -0,0 +1,38 @@ +import RNS + +class BasicCommandPlugin(SidebandCommandPlugin): + command_name = "basic_example" + + def start(self): + # Do any initialisation work here + RNS.log("Basic command plugin example starting...") + + # And finally call start on superclass + super().start() + + def stop(self): + # Do any teardown work here + pass + + # And finally call stop on superclass + super().stop() + + def handle_command(self, arguments, lxm): + response_content = "Hello "+RNS.prettyhexrep(lxm.source_hash)+". " + response_content += "This is a response from the basic command example. It doesn't do much, but here is a list of the arguments you included:\n" + + for argument in arguments: + response_content += "\n"+str(argument) + + # Let the Sideband core send a reply. + self.get_sideband().send_message( + response_content, + lxm.source_hash, + False, # Don't use propagation by default, try direct first + skip_fields=True, # Don't include any additional fields automatically + no_display=True # Dot't display this message in the message stream + ) + +# Finally, tell Sideband what class in this +# file is the actual plugin class. +plugin_class = BasicCommandPlugin \ No newline at end of file diff --git a/docs/example_plugins/comic.py b/docs/example_plugins/comic.py new file mode 100644 index 0000000..e69de29 diff --git a/docs/example_plugins/service.py b/docs/example_plugins/service.py new file mode 100644 index 0000000..e9c4250 --- /dev/null +++ b/docs/example_plugins/service.py @@ -0,0 +1,34 @@ +import RNS +import time +import threading + +class BasicServicePlugin(SidebandServicePlugin): + service_name = "service_example" + + def service_jobs(self): + while self.should_run: + time.sleep(5) + RNS.log("Service ping from "+str(self)) + + RNS.log("Jobs stopped running for "+str(self)) + + def start(self): + # Do any initialisation work here + RNS.log("Basic service plugin example starting...") + self.should_run = True + self.service_thread = threading.Thread(target=self.service_jobs, daemon=True) + self.service_thread.start() + + # And finally call start on superclass + super().start() + + def stop(self): + # Do any teardown work here + self.should_run = False + + # And finally call stop on superclass + super().stop() + +# Finally, tell Sideband what class in this +# file is the actual plugin class. +plugin_class = BasicServicePlugin \ No newline at end of file