Skip to content
Permalink
Browse files
Added more functionality to the settings
  • Loading branch information
hollan84 committed May 3, 2020
1 parent f1682a6 commit 93faa045376a088c1dea51790c1c6dc89c669e6e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 32 deletions.
@@ -13,7 +13,7 @@ More functions listed below.


## Running the bot ## Running the bot
To run this bot, just start __run.py__ in Python3 <br/> To run this bot, just start __run.py__ in Python3 <br/>
To change settings in this bot, run __setup.py__ in Python3 To change settings in this bot, run __configure.py__ in Python3


### Prerequisites ### Prerequisites
You need __*Python 3.5.9*__+ and a stable internet connection in order to run this bot. You need __*Python 3.5.9*__+ and a stable internet connection in order to run this bot.
@@ -0,0 +1,4 @@
def configure():
from lib import setup
setup.environment()
configure()
Binary file not shown.
@@ -33,26 +33,26 @@ messagetime = datetime.now().time()
async def on_message(message): async def on_message(message):
server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT'])) server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT']))
print(message.content) print(message.content)

'''Anti Spam Variables''' '''Anti Spam Variables'''
global oldauthor global oldauthor
global oldcommand global oldcommand
global oldmsg global oldmsg
global messagetime global messagetime
msg = "" msg = ""

'''Checking which command has been issued''' '''Checking which command has been issued'''
if message.author == client.user: #Make sure that the bot doesn't reply to itself if message.author == client.user: #Make sure that the bot doesn't reply to itself
return 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'): elif message.content.startswith('?map'):
msg = "http://map.alastairserver.co.uk" msg = os.environ['MAP']
elif message.content.startswith('?servername'): elif message.content.startswith('?servername'):
msg = os.environ['SERVER'] msg = os.environ['SERVER']
elif message.content.startswith('?help'): elif message.content.startswith('?help'):
msg = "Commands: \n - ?help \n - ?servername \n - ?map\n - ?status\n - ?minecraftNickname [USERNAME] [NICKNAME]\n - ?download" msg = "Commands: \n - ?help \n - ?servername \n - ?map\n - ?status\n - ?minecraftNickname [USERNAME] [NICKNAME]\n - ?download"
elif message.content.startswith('?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'): elif message.content.startswith('?status'):
try: try:
status = server.status() status = server.status()
@@ -62,12 +62,9 @@ async def on_message(message):
else: else:
msg = str("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency)) msg = str("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
except: 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 - ") checkNicknames = msg.split("\n - ")
#print("TESTING")
#print(checkNicknames)
for i in checkNicknames: for i in checkNicknames:
#print(i)
path = "nicknames/" + i path = "nicknames/" + i
try: try:
n = open(path, "r") n = open(path, "r")
@@ -89,15 +86,16 @@ async def on_message(message):
else: else:
return return
if (message.content == oldcommand) and (message.author == oldauthor): if (message.content == oldcommand) and (message.author == oldauthor):
s1 = str(messagetime) if os.environ['ANTISPAM'] == "TRUE":
s2 =str(datetime.now().time()) s1 = str(messagetime)
FMT = '%H:%M:%S.%f' s2 =str(datetime.now().time())
tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT) FMT = '%H:%M:%S.%f'
if tdelta.seconds < 60: tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT)
if "Please don't spam commands" in oldmsg: if tdelta.seconds < 60:
return if "Please don't spam commands" in oldmsg:
else: return
msg = "Please don't spam commands\nWait " + str(round(60-tdelta.seconds, 0)) + " seconds to use this command" else:
msg = "Please don't spam commands\nWait " + str(round(60-tdelta.seconds, 0)) + " seconds to use this command"
messagetime = datetime.now().time() messagetime = datetime.now().time()
oldauthor = message.author oldauthor = message.author
oldcommand = message.content oldcommand = message.content

This file was deleted.

@@ -5,6 +5,7 @@ import difflib
from mcstatus import MinecraftServer from mcstatus import MinecraftServer
from datetime import datetime from datetime import datetime
from datetime import timedelta from datetime import timedelta
import os




server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT'])) server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT']))
@@ -2,7 +2,7 @@ def environment():
import os import os


'''Prevents overwriting of the environment file''' '''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 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 = input("Would you like to change your current settings? (y/n) > ")
overwrite = overwrite.lower() #Makes the input string lowercase overwrite = overwrite.lower() #Makes the input string lowercase
@@ -14,7 +14,9 @@ def environment():
else: else:
return #Exit function return #Exit function
else: else:
settingsChoice = "12345" settingsChoice = ""
for s in range(1, len(settingList)+1):
settingsChoice = settingsChoice + str(s)


'''Gets information''' '''Gets information'''
if str(settingList.index("Token")+1) in settingsChoice: if str(settingList.index("Token")+1) in settingsChoice:
@@ -73,9 +75,47 @@ def environment():
custom = "TRUE" custom = "TRUE"
else: else:
custom = os.environ['CUSTOM'] 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''' '''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''' '''Write data to the .env file'''
creds = open(".env", "w") creds = open(".env", "w")
@@ -96,5 +136,4 @@ def environment():
if tryAgain == "y" or tryAgain == "yes": if tryAgain == "y" or tryAgain == "yes":
environment() environment()
else: else:
return return
environment()
5 run.py
@@ -4,13 +4,12 @@ def run():
librarySetup.checkLibraries() librarySetup.checkLibraries()


from lib import setup from lib import setup
from lib import bot #from lib import online
from lib import online
import os import os




if not os.path.isfile('.env'): if not os.path.isfile('.env'):
setup.environment() setup.environment()


os.system("python3 bot.py") os.system("python3 lib/bot.py")
run() run()

0 comments on commit 93faa04

Please sign in to comment.