From 8c85da2e772644cd1cdc09da1225b7bad9851177 Mon Sep 17 00:00:00 2001 From: Wargamer-Senpai Date: Fri, 20 Oct 2023 18:41:46 +0200 Subject: [PATCH] reworked example plugin --- plugins/example-plugin/config.py | 1 - plugins/example-plugin/main.py | 81 ++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 25 deletions(-) delete mode 100644 plugins/example-plugin/config.py diff --git a/plugins/example-plugin/config.py b/plugins/example-plugin/config.py deleted file mode 100644 index e793e57..0000000 --- a/plugins/example-plugin/config.py +++ /dev/null @@ -1 +0,0 @@ -message_test = "Hi :wave:" \ No newline at end of file diff --git a/plugins/example-plugin/main.py b/plugins/example-plugin/main.py index a8f1fce..c10b63d 100644 --- a/plugins/example-plugin/main.py +++ b/plugins/example-plugin/main.py @@ -1,24 +1,57 @@ -from main import * # import variables and functions from head script - -################# -## import config -## only if you want to have an external config file, if no -import os -import importlib.util - -def load_config(): - config_path = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "plugins","example-plugin","config.py") - spec = importlib.util.spec_from_file_location("config", config_path) - config_module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(config_module) - return config_module - -config = load_config() -## end of config import -################# - -######################## -## your logic and stuff -## you should be able to use every variable and function from the head script -if matrix_received_message == "Hello": - func_send_message(config.message_test) \ No newline at end of file +# This is an example plugin, so its better to understand the way the bot handles plugins/external scripts. +# So make sure youve named this file main.py and put it in its own folder in the plugins directory. +# +# When programming on a plugin you dont need to restart the bot, because of the way the bot handels the plugins. + + +# needed for getting the variables that are being parsed by the bot +import sys + +# +# structur of possible values +# + +# sys.argv[1] = "Hello" +# - Description: the message the bot got + +# sys.argv[2] = "@ae5vjqrumaladsjkflklöajdsfacg4j5pfquk3bt55z5i===:chat.teamspeak.com" +# - Description: Contains the matrix user id (MXID), is unique for every user + +# sys.argv[3] = "!" +# - Description: Contains the used command prefix that is in the config of the bot + +# sys.argv[4] = "user" +# - Description: Delivers the rank of the user, if the users matrix identifier is in the admin array the value "admin" will be send else only "user" + + +# or if you like it smart +# name the variables what you want, so they fit your handwriting +message = sys.argv[1] +message_sender = sys.argv[2] +command_prefix = sys.argv[3] +user_rank = sys.argv[4] + + + +# !! READ THIS !! +# TLDR; +# print out what you want the bot to send as an answer +# +# +# Explanation: +# The bot executes the plugins one by one, as soon he gets an value returend, +# he will stop further execution of plugins and sends the value to the chat as the answer. +# If multiple values are printed by your plugin in diffrent print's they will be send together. +# + +# +# If any values you need are missing, then open an issue on github and i will look if its possible to put it in. +# https://github.com/Wargamer-Senpai/teampy/issues +# +# Have fun + + + +# your script logic here +if sys.argv[1] == sys.argv[3]+"Hello": + print("Hello World")