Skip to content

Commit

Permalink
reworked example plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Wargamer-Senpai committed Oct 20, 2023
1 parent e1c6042 commit 8c85da2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
1 change: 0 additions & 1 deletion plugins/example-plugin/config.py

This file was deleted.

81 changes: 57 additions & 24 deletions plugins/example-plugin/main.py
Original file line number Diff line number Diff line change
@@ -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)
# 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")

0 comments on commit 8c85da2

Please sign in to comment.