diff --git a/lib/bot.py b/lib/bot.py index 69630d3..5398511 100755 --- a/lib/bot.py +++ b/lib/bot.py @@ -1,6 +1,7 @@ import os import discord import status +import datetime from mcstatus import MinecraftServer from datetime import datetime @@ -13,7 +14,7 @@ import settings import developer import bot_functions as functions -from variables import * +from python_variables import * copyfile(".env", "lib/.env") #Copies the env file to the lib directory @@ -75,8 +76,11 @@ async def on_message(message): elif ('botinfo') in message_command: msg = "Minecraft Bot - Version {}\n".format(str(os.environ['VERSION'])) msg = "{}Total Discord Servers: {}\n".format(msg, database.get_total("*")) + msg = "{}{}\n".format(msg, functions.uptime()) #msg = "{}Total Minecraft Servers: {}\n".format(msg, database.get_total("minecraft_server")) #msg = "{}Percentage of servers using maps: {}%\n".format(msg, str((int(database.get_total("map"))/int(database.get_total("minecraft_server"))*100))) + elif ('uptime') in message_command: + msg = functions.uptime() elif ('developer') in message_command: msg = developer.developer_check(user_message, message.author, guild_id) elif ('status') in message_command: diff --git a/lib/bot_functions.py b/lib/bot_functions.py index 3887772..bcd3c78 100755 --- a/lib/bot_functions.py +++ b/lib/bot_functions.py @@ -2,7 +2,8 @@ import database from googletrans import Translator -from variables import * +from python_variables import * +from uptime import * def help(user_message, prefix, guild_id): @@ -27,4 +28,14 @@ def language(user_message, guild_id): user_message = user_message[len(prefix):] user_message = translator.translate(user_message, src=database.read_database("language", guild_id), dest='en') #Translate the message to English user_message = "{}{}".format(prefix,user_message.text) #Rebuild message - return user_message.lower() #Returns the lowercase message \ No newline at end of file + return user_message.lower() #Returns the lowercase message + +def plural(int_value): + if str(int_value) == "1": + return "" + return "s" + +def uptime(): + curr_time = datetime.datetime.now() + uptime = curr_time - start_time + return "Bot Uptime: {} day{}, {} hour{}, {} minute{} and {} second{}".format(uptime.days, plural(uptime.days), uptime.seconds//3600, plural(uptime.seconds//3600), uptime.seconds//60, plural(uptime.seconds//60), uptime.seconds%60, plural(uptime.seconds%60)) \ No newline at end of file diff --git a/lib/databaseSetup.py b/lib/databaseSetup.py index 28bb632..0dd49fd 100755 --- a/lib/databaseSetup.py +++ b/lib/databaseSetup.py @@ -2,7 +2,7 @@ import sqlite3 from sqlite3 import Error import os -from variables import * +#from python_variables import * def create_initial_connection(db_file): conn = None @@ -83,6 +83,6 @@ def main(): create_table(conn, create_player_table_sql) create_table(conn, create_dev_table_sql) - add_primary_developer(conn, PrimaryDeveloper) + add_primary_developer(conn, "AlastairHolland#6538") conn.commit() \ No newline at end of file diff --git a/lib/variables.py b/lib/python_variables.py similarity index 93% rename from lib/variables.py rename to lib/python_variables.py index 09ab203..0790df6 100755 --- a/lib/variables.py +++ b/lib/python_variables.py @@ -19,6 +19,7 @@ commands = { #Sets the commands for the help "support" : "Join our support server", "botinfo" : "Get information on the bot", "version" : "Gives the bot release version", + "uptime" : "Gives the uptime of the bot", "donate" : "Allows you to donate to the development of this project" } diff --git a/lib/uptime.py b/lib/uptime.py new file mode 100755 index 0000000..40ff182 --- /dev/null +++ b/lib/uptime.py @@ -0,0 +1,2 @@ +import datetime +start_time = datetime.datetime.now() diff --git a/run.py b/run.py index 766f132..1c31749 100755 --- a/run.py +++ b/run.py @@ -4,6 +4,7 @@ def run(): from lib import librarySetup from lib import databaseSetup from lib import shell + from lib import uptime librarySetup.checkLibraries() #Check and install libraries databaseSetup.main() #Create database