How to use the mcstatus.MinecraftServer function in mcstatus

To help you get started, we’ve selected a few mcstatus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fixator10 / Fixator10-Cogs / minecraftdata / minecraftdata.py View on Github external
async def server(self, ctx, server_ip: str):
        """Get info about server"""
        try:
            server = await self.bot.loop.run_in_executor(None, MinecraftServer.lookup, server_ip)
        except Exception as e:
            await ctx.send(chat.error(_("Unable to resolve IP: {}").format(e)))
            return
        async with ctx.channel.typing():
            try:
                status = await self.bot.loop.run_in_executor(None, server.status)
            except OSError as e:
                await ctx.send(chat.error(_("Unable to get server's status: {}").format(e)))
                return
            try:
                query = await self.bot.loop.run_in_executor(None, server.query)
            except (ConnectionResetError, OSError):
                query = None
        icon = (
            discord.File(BytesIO(b64decode(status.favicon.split(",", 1)[1])), filename="icon.png")
            if status.favicon
github wurstmineberg / api.wurstmineberg.de / api / v2.py View on Github external
def api_world_status(world: minecraft.World):
    """Returns JSON containing info about the given world, including whether the server is running, the current Minecraft version, and the list of people who are online. Requires mcstatus."""
    import mcstatus

    result = api.util2.short_world_status(world)
    server = mcstatus.MinecraftServer.lookup(api.util.CONFIG['worldHost'] if world.is_main else '{}.{}'.format(world, api.util.CONFIG['worldHost']))
    try:
        status = server.status()
    except ConnectionRefusedError:
        result['list'] = []
    else:
        result['list'] = [str(api.util2.Player(player.id)) for player in (status.players.sample or [])]
    return result
github CloudBotIRC / CloudBot / plugins / minecraft_ping.py View on Github external
def mcping(text):
    """ - gets info about the Minecraft server at """
    try:
        server = MinecraftServer.lookup(text)
    except (IOError, ValueError) as e:
        return e

    try:
        s = server.status()
    except socket.gaierror:
        return "Invalid hostname"
    except socket.timeout:
        return "Request timed out"
    except ConnectionRefusedError:
        return "Connection refused"
    except ConnectionError:
        return "Connection error"
    except (IOError, ValueError) as e:
        return "Error pinging server: {}".format(e)
github UltrosBot / Ultros-contrib / Minecraft / plugins / minecraft / __init__.py View on Github external
def query_command(self, protocol, caller, source, command, raw_args,
                      parsed_args):
        if len(parsed_args) < 1:
            caller.respond("Usage: {CHARS}mcquery ")
        address = parsed_args[0]
        target = source

        if isinstance(source, User):
            target = caller

        try:
            q = MinecraftServer.lookup(address)
            status = q.status()
        except Exception as e:
            target.respond("Error retrieving status: %s" % e)
            self.logger.exception("Error retrieving status")
            return

        servername = status.description

        if isinstance(servername, dict):
            servername = servername.get("text", "")

        done = ""
        done += "[%s] %s | " % (status.version.name, servername)
        done += "%s/%s " % (status.players.online, status.players.max)
        if "plugins" in status.raw:
            done += "| %s plugins" % len(status.raw["plugins"])
github Dinnerbone / mcstatus / mcstatus / scripts / mcstatus.py View on Github external
\b
    $ mcstatus example.org status
    version: v1.8.8 (protocol 47)
    description: "A Minecraft Server"
    players: 1/20 ['Dinnerbone (61699b2e-d327-4a01-9f1e-0ea8c3f06bc6)']

    \b
    $ mcstatus example.org query
    host: 93.148.216.34:25565
    software: v1.8.8 vanilla
    plugins: []
    motd: "A Minecraft Server"
    players: 1/20 ['Dinnerbone (61699b2e-d327-4a01-9f1e-0ea8c3f06bc6)']
    """
    global server
    server = MinecraftServer.lookup(address)
github CCOSTAN / Home-AssistantConfig / config / custom_components / sensor / minecraft.py View on Github external
"""Setup the Minecraft server platform."""
    from mcstatus import MinecraftServer as mcserver
    logger = logging.getLogger(__name__)

    server = config.get('server')
    name = config.get('name')

    if server is None:
        logger.error('No server specified')
        return False
    elif name is None:
        logger.error('No name specified')
        return False

    add_devices([
        MCServerSensor(server, name, mcserver)
    ])