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
Showing with 68 additions and 32 deletions.
  1. +1 −1 README.md
  2. +4 −0 configure.py
  3. BIN lib/__pycache__/setup.cpython-36.pyc
  4. +16 −18 lib/bot.py
  5. +0 −5 lib/configure.py
  6. +1 −0 lib/online.py
  7. +44 −5 lib/setup.py
  8. +2 −3 run.py
@@ -13,7 +13,7 @@ More functions listed below.

## Running the bot
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
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 @@
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 @@
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 @@
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

This file was deleted.

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


server = MinecraftServer(os.environ['SERVER'], int(os.environ['PORT']))
@@ -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()
return
5 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()

0 comments on commit 93faa04

Please sign in to comment.
You can’t perform that action at this time.