diff --git a/.gitignore b/.gitignore index 16c81e6..d9e0c77 100755 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Custom.py nicknames/ oldCustom/ -__pycache__/ \ No newline at end of file +__pycache__/ +lib/custom.py \ No newline at end of file diff --git a/lib/bot.py b/lib/bot.py index 67d5884..761a2e3 100755 --- a/lib/bot.py +++ b/lib/bot.py @@ -4,9 +4,14 @@ import status from mcstatus import MinecraftServer from datetime import datetime from datetime import timedelta +from shutil import copyfile server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT'])) +if os.environ['CUSTOM'] == "TRUE": + copyfile("Custom.py", "lib/custom.py") + import custom + status = server.status() print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency)) query = server.query() @@ -93,7 +98,10 @@ async def on_message(message): f.close() msg = "Set " + splitMessage[1] + "'s nickname to " + splitMessage[2] elif message.content.startswith(prefix): - msg = "That is not a valid command, use ?help for help" + if os.environ['CUSTOM'] == "TRUE": + msg = custom.customCode(message.content, msg) + if msg == "": + msg = "That is not a valid command, use ?help for help" else: return if (message.content == oldcommand) and (message.author == oldauthor): diff --git a/templates/customTemplate.py b/templates/customTemplate.py index 47b29f8..38b72d0 100755 --- a/templates/customTemplate.py +++ b/templates/customTemplate.py @@ -1,13 +1,15 @@ -def customCode(inputMessage): +def customCode(inputMessage, message): + import os prefix = os.environ['PREFIX'] #This gets the prefix if not inputMessage[:len(prefix)]: #Checks to see if the prefix is at the start of the message - return #If it isn't, ignore the rest of the code + return message #If it isn't, ignore the rest of the code + inputMessage = inputMessage[len(prefix):] '''Do not modify any code above this''' - if message == "example": + if inputMessage == "example": message = "This is an example of the custom code you can write" - elif message == "example2" + elif inputMessage == "example2": message = "This is also an example of the custom code you can write"