diff --git a/README.md b/README.md index 5fc7b91..68b2b39 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ More functions listed below. ## Running the bot To run this bot, just start __run.py__ in Python3
-To change settings in this bot, run __setup.py__ in Python3 +To change settings in this bot, run __configure.py__ in Python3 ### Prerequisites You need __*Python 3.5.9*__+ and a stable internet connection in order to run this bot. diff --git a/configure.py b/configure.py new file mode 100755 index 0000000..e5593db --- /dev/null +++ b/configure.py @@ -0,0 +1,4 @@ +def configure(): + from lib import setup + setup.environment() +configure() \ No newline at end of file diff --git a/lib/__pycache__/setup.cpython-36.pyc b/lib/__pycache__/setup.cpython-36.pyc index 45c9e7e..0833d59 100755 Binary files a/lib/__pycache__/setup.cpython-36.pyc and b/lib/__pycache__/setup.cpython-36.pyc differ diff --git a/lib/bot.py b/lib/bot.py index d3ec1c6..cf96281 100755 --- a/lib/bot.py +++ b/lib/bot.py @@ -33,26 +33,26 @@ messagetime = datetime.now().time() async def on_message(message): server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT'])) print(message.content) + '''Anti Spam Variables''' global oldauthor global oldcommand global oldmsg global messagetime msg = "" + '''Checking which command has been issued''' if message.author == client.user: #Make sure that the bot doesn't reply to itself return - #elif message.content.startswith('?status'): - # query = server.query() - # msg = ("The server has the following players online: {0}".format(", ".join(query.players.names))) + elif message.content.startswith('?map'): - msg = "http://map.alastairserver.co.uk" + msg = os.environ['MAP'] elif message.content.startswith('?servername'): msg = os.environ['SERVER'] elif message.content.startswith('?help'): msg = "Commands: \n - ?help \n - ?servername \n - ?map\n - ?status\n - ?minecraftNickname [USERNAME] [NICKNAME]\n - ?download" elif message.content.startswith('?download'): - msg = "http://server.alastairserver.co.uk/Public/Minecraft%20World%20Downloads/" + msg = os.environ['DOWNLOAD'] elif message.content.startswith('?status'): try: status = server.status() @@ -62,12 +62,9 @@ async def on_message(message): else: msg = str("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency)) except: - msg = "Server doesn't seem to be repsonding; please message Alastair for help" + msg = "Server doesn't seem to be repsonding; please message {} for help".format(os.environ["ADMINNAME"]) checkNicknames = msg.split("\n - ") - #print("TESTING") - #print(checkNicknames) for i in checkNicknames: - #print(i) path = "nicknames/" + i try: n = open(path, "r") @@ -89,15 +86,16 @@ async def on_message(message): else: return if (message.content == oldcommand) and (message.author == oldauthor): - s1 = str(messagetime) - s2 =str(datetime.now().time()) - FMT = '%H:%M:%S.%f' - tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT) - if tdelta.seconds < 60: - if "Please don't spam commands" in oldmsg: - return - else: - msg = "Please don't spam commands\nWait " + str(round(60-tdelta.seconds, 0)) + " seconds to use this command" + if os.environ['ANTISPAM'] == "TRUE": + s1 = str(messagetime) + s2 =str(datetime.now().time()) + FMT = '%H:%M:%S.%f' + tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT) + if tdelta.seconds < 60: + if "Please don't spam commands" in oldmsg: + return + else: + msg = "Please don't spam commands\nWait " + str(round(60-tdelta.seconds, 0)) + " seconds to use this command" messagetime = datetime.now().time() oldauthor = message.author oldcommand = message.content diff --git a/lib/configure.py b/lib/configure.py deleted file mode 100755 index 2e3b8e0..0000000 --- a/lib/configure.py +++ /dev/null @@ -1,5 +0,0 @@ -def configure(): - - - -configure() \ No newline at end of file diff --git a/lib/online.py b/lib/online.py index 3d9bdd3..ac5ebd4 100755 --- a/lib/online.py +++ b/lib/online.py @@ -5,6 +5,7 @@ import difflib from mcstatus import MinecraftServer from datetime import datetime from datetime import timedelta +import os server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT'])) diff --git a/lib/setup.py b/lib/setup.py index 555b53b..598c041 100755 --- a/lib/setup.py +++ b/lib/setup.py @@ -2,7 +2,7 @@ def environment(): import os '''Prevents overwriting of the environment file''' - settingList = ["Token", "Server IP", "Port", "Command Prefix", "Custom File"] + settingList = ["Token", "Server IP", "Port", "Command Prefix", "Custom File", "Server Map", "World Downloads", "Anti Spam", "Owner Name"] if os.path.isfile('.env'): #Checks to see if there is an environment file overwrite = input("Would you like to change your current settings? (y/n) > ") overwrite = overwrite.lower() #Makes the input string lowercase @@ -14,7 +14,9 @@ def environment(): else: return #Exit function else: - settingsChoice = "12345" + settingsChoice = "" + for s in range(1, len(settingList)+1): + settingsChoice = settingsChoice + str(s) '''Gets information''' if str(settingList.index("Token")+1) in settingsChoice: @@ -73,9 +75,47 @@ def environment(): custom = "TRUE" else: custom = os.environ['CUSTOM'] + if str(settingList.index("Server Map")+1) in settingsChoice: + mapCheck = input("Do you have an online map on your server? (y/n) > ") + mapCheck = mapCheck.lower() + if mapCheck == "y" or mapCheck == "yes": + mapURL = input("What's the URL of the map? (Leave blank if you can't remember, you can set it later) > ") + if mapURL == "": + mapURL = "There is no URL set for the map" + else: + mapURL = input("There is no online map on this server") + else: + mapURL = os.environ['MAP'] + + if str(settingList.index("World Downloads")+1) in settingsChoice: + worldCheck = input("Do you have an online world download on your server? (y/n) > ") + worldCheck = worldCheck.lower() + if worldCheck == "y" or mapCheck == "yes": + worldURL = input("What's the URL of the download? (Leave blank if you can't remember, you can set it later) > ") + if worldURL == "": + worldURL = "There is no URL set for the download" + else: + worldURL = input("There is no online map on this server") + else: + worldURL = os.environ['DOWNLOAD'] + + if str(settingList.index("Anti Spam")+1) in settingsChoice: + spam = input("Stop users from spamming commands? (y/n) > ") + spam = spam.lower() + if spam == "y" or spam == "yes": + antiSpam = "TRUE" + else: + antiSpam = "FALSE" + else: + antiSpam = os.environ['ANTISPAM'] + + if str(settingList.index("Owner Name")+1) in settingsChoice: + owner = input("What's the name of the server owner? > ") + else: + owner = os.environ['ADMINNAME'] '''Concantinate into a string''' - data = "TOKEN={}\nSERVER={}\nPORT={}\nPREFIX={}\nCUSTOM={}".format(token,serverIP,port,commandPrefix,custom) #Sets the format of the data + data = "TOKEN={}\nSERVER={}\nPORT={}\nPREFIX={}\nCUSTOM={}\nMAP={}\nDOWNLOAD={}\nANTISPAM={}\nADMINNAME={}".format(token,serverIP,port,commandPrefix,custom,mapURL,worldURL,antiSpam,owner) #Sets the format of the data '''Write data to the .env file''' creds = open(".env", "w") @@ -96,5 +136,4 @@ def environment(): if tryAgain == "y" or tryAgain == "yes": environment() else: - return -environment() \ No newline at end of file + return \ No newline at end of file diff --git a/run.py b/run.py index 77f76ea..b69587a 100755 --- a/run.py +++ b/run.py @@ -4,13 +4,12 @@ def run(): librarySetup.checkLibraries() from lib import setup - from lib import bot - from lib import online + #from lib import online import os if not os.path.isfile('.env'): setup.environment() - os.system("python3 bot.py") + os.system("python3 lib/bot.py") run() \ No newline at end of file