async def cmd_start(message):
    await message.channel.send("Launching Server...")
    status = get_status()

    if status == "Offline":
        await start_server()
        author = message.author
        # loops until server has started and pings person who launched
        while True:
            await asyncio.sleep(5)
            if get_status() == "Online":
                await message.channel.send(f"{author.mention}, the "
                                           f"server has started!")
                break

    elif status == "Online":
        await message.channel.send("The server is already online.")

    elif status == 'Starting ...' or status == 'Loading ...':
        text = "The server is already starting..."
        await message.channel.send(text)

    elif status == 'Stopping ...' or status == 'Saving ...':
        text = "The server is stopping. Please wait."
        await message.channel.send(text)

    else:
        text = ("An error occurred. Either the status server is not "
                "responding or you didn't set the server name "
                "correctly.\n\nTrying to launch the server anyways.")
        await message.channel.send(text)
        await start_server()
async def cmd_stop(message):
    await message.channel.send("Stopping the server.")
    status = get_status()

    if status != 'Stopping ...' or status != 'Saving ...':
        await stop_server()

    else:
        await message.channel.send("The server is already offline.")
Beispiel #3
0
async def launch(ctx):
    """ Launches the Minecraft Server"""
    server_status = get_status()

    if server_status == "Offline":
        await ctx.send("Starting the server...")
        await start_server()

        # if pinging a person, server will ping them when launching
        # else ping the the user who sent the command on launch
        if len(ctx.message.mentions) == 0:
            author = ctx.author
        else:
            author = ctx.message.mentions[0]

        # logs event to console
        logging.info(f'Server launched by: '
                     f'{author.name}#{author.discriminator}')

        # loops until server has started and pings person who launched
        while True:
            await asyncio.sleep(5)
            if get_status() == "Online":
                await ctx.send(f"{author.mention}, the server has started!")
                break

    elif server_status == "Online":
        await ctx.send("The server is already Online.")

    elif server_status == "Starting ..." or server_status == "Loading ...":
        await ctx.send("The server is already starting...")

    elif server_status == "Stopping ..." or server_status == "Saving ...":
        await ctx.send("The server is stopping. Please wait.")

    else:
        text = "An error occurred. Either the status server is not " \
               "responding or you didn't set the server name " \
               "correctly.\n\nTrying to launch the server anyways."
        await ctx.send(text)
        await start_server()
Beispiel #4
0
async def serverStatus():
    server_status = get_status()
    if server_status == "Online":
        text = f"Server: {get_status()} | " \
               f"Players: {get_number_of_players()} | " \
               f"TPS: {get_tps()} | " \
               f"--help"
    else:
        text = f"Server: {get_status()} | " \
               f"{get_ip()} | " \
               f"--help"
    activity = discord.Activity(type=discord.ActivityType.watching, name=text)
    await bot.change_presence(activity=activity)
Beispiel #5
0
async def stop(ctx):
    server_status = get_status()

    if server_status != 'Stopping ...' and server_status != 'Saving ...' and \
            server_status != 'Offline' and server_status != 'Loading ...':
        await ctx.send("Stopping the server...")
        await stop_server()

        # logs event to console
        logging.info(f'Server stopped by: '
                     f'{ctx.author.name}#{ctx.author.discriminator}')

    elif server_status == 'Loading ...':
        await ctx.send(f"The server is currently loading. "
                       f"Please try again later.")

    else:
        await ctx.send("The server is already Offline.")
async def on_message(message):

    if message.author == client.user:
        return

    if message.content.startswith('--'):

        if message.content == '--launch server':

            await message.channel.send("Launching Server...")
            status = get_status()

            if status == "Offline":
                await start_server()

            elif status == "Online":
                await message.channel.send("The server is already Online")

            else:
                await message.channel.send(
                    "An error occured. Either the status server is not responding, or you didn't set the server name correctly.\nTrying to launch server anyway."
                )
                await start_server()

        elif message.content == '--server status':
            await message.channel.send("Getting status...")
            status = get_status()
            await message.channel.send("The server is {}".format(status))

        elif message.content == '--players':
            await message.channel.send("Getting players...")
            try:
                players = get_number_of_players()
            except:
                await message.channel.send("There are no players on the server"
                                           )
            else:
                await message.channel.send(
                    "There are {} players on the server".format(players))

        elif message.content == '--stop server':
            await message.channel.send("Stopping the server.")
            await stop_server

        elif message.content == '--help':
            embed = discord.Embed(title="Help")
            embed.add_field(name="--launch server",
                            value="Launches the server",
                            inline=False)
            embed.add_field(name="--server status",
                            value="Gets the server status",
                            inline=False)
            embed.add_field(name="--players",
                            value="Gets the number of players",
                            inline=False)
            embed.add_field(name="--stop server",
                            value="Stops the server",
                            inline=False)
            embed.add_field(name="--help",
                            value="Displays this message",
                            inline=False)
            await message.channel.send(embed=embed)
        else:
            await message.channel.send(
                "Unknown command, use --help to see a list of all availiable commands"
            )
Beispiel #7
0
async def on_message(message):

    if message.author == client.user:
        return

    if message.content.startswith('--'):

        if message.content.lower() == '--launch server':

            await message.channel.send("Launching Server...")
            status = get_status()

            if status == "Offline":
                await start_server()
                author = message.author
                # loops until server has started and pings person who launched
                while True:
                    await asyncio.sleep(5)
                    if get_status() == "Online":
                        await message.channel.send(f"{author.mention}, the "
                                                   f"server has started!")
                        break

            elif status == "Online":
                await message.channel.send("The server is already Online.")

            elif status == 'Starting ...' or status == 'Loading ...':
                text = "The server is already starting..."
                await message.channel.send(text)

            elif status == 'Stopping ...' or status == 'Saving ...':
                text = "The server is stopping. Please wait."
                await message.channel.send(text)

            else:
                text = "An error occurred. Either the status server is not " \
                       "responding or you didn't set the server name " \
                       "correctly.\n\nTrying to launch the server anyways."
                await message.channel.send(text)
                await start_server()

        elif message.content.lower() == '--server status':
            await message.channel.send(f"The server is {get_status()}.")

        elif message.content.lower() == '--players':
            text = f"There are {get_number_of_players()} players online."
            await message.channel.send(text)

        elif message.content.lower() == '--server info':
            ip, status, players, software, version = get_server_info()
            text = f"**IP:** {ip} \n**Status:** {status} \n**Players: " \
                   f"**{players} \n**Version:** {software} {version}"
            embed = discord.Embed()
            embed.add_field(name="Server Info", value=text, inline=False)
            await message.channel.send(embed=embed)

        elif message.content.lower() == '--stop server':
            await message.channel.send("Stopping the server.")
            status = get_status()

            if status != 'Stopping ...' or status != 'Saving ...':
                await stop_server()

            else:
                await message.channel.send("The server is already Offline.")

        elif message.content.lower() == '--help':
            embed = discord.Embed(title="Help")
            embed.add_field(name="--launch server",
                            value="Launches the server",
                            inline=False)
            embed.add_field(name="--server status",
                            value="Gets the server status",
                            inline=False)
            embed.add_field(name="--server info",
                            value="Gets the server info",
                            inline=False)
            embed.add_field(name="--players",
                            value="Gets the number of players",
                            inline=False)
            embed.add_field(name="--stop server",
                            value="Stops the server",
                            inline=False)
            embed.add_field(name="--crash",
                            value="Shuts down the bot",
                            inline=False)
            embed.add_field(name="--help",
                            value="Displays this message",
                            inline=False)
            await message.channel.send(embed=embed)

        elif message.content == '--crash':
            quitBrowser()
            text = "Bot Shutting Down..."
            await client.change_presence(activity=discord.Game(name=text))
            sys.exit()

        else:
            await message.channel.send("Unknown command, use --help to see a "
                                       "list of all avaliable commands.")