From 6422a1c8142bd207c719877c899575ec240bf6c9 Mon Sep 17 00:00:00 2001 From: Anti Matter Date: Wed, 20 Dec 2023 17:55:46 +1000 Subject: [PATCH 1/4] Added command to get current MC server player count --- poetry.lock | 115 +++++++++++++++++++++++++++++++++++++++++-- pyproject.toml | 1 + uqcsbot/minecraft.py | 22 +++++++++ 3 files changed, 134 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index ed25228..6152c59 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,9 +1,10 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "aio-mc-rcon" version = "3.2.0" description = "An async library for utilizing remote console on Minecraft Java Edition servers" +category = "main" optional = false python-versions = ">=3.7,<4.0" files = [ @@ -15,6 +16,7 @@ files = [ name = "aiohttp" version = "3.8.4" description = "Async http client/server framework (asyncio)" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -123,6 +125,7 @@ speedups = ["Brotli", "aiodns", "cchardet"] name = "aiosignal" version = "1.3.1" description = "aiosignal: a list of registered asynchronous callbacks" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -137,6 +140,7 @@ frozenlist = ">=1.1.0" name = "apscheduler" version = "3.10.1" description = "In-process task scheduler with Cron-like capabilities" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -148,7 +152,7 @@ files = [ pytz = "*" setuptools = ">=0.7" six = ">=1.4.0" -tzlocal = ">=2.0,<3.dev0 || >=4.dev0" +tzlocal = ">=2.0,<3.0.0 || >=4.0.0" [package.extras] doc = ["sphinx", "sphinx-rtd-theme"] @@ -166,6 +170,7 @@ zookeeper = ["kazoo"] name = "async-timeout" version = "4.0.2" description = "Timeout context manager for asyncio programs" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -173,10 +178,26 @@ files = [ {file = "async_timeout-4.0.2-py3-none-any.whl", hash = "sha256:8ca1e4fcf50d07413d66d1a5e416e42cfdf5851c981d679a09851a6853383b3c"}, ] +[[package]] +name = "asyncio-dgram" +version = "2.1.2" +description = "Higher level Datagram support for Asyncio" +category = "main" +optional = false +python-versions = ">=3.5" +files = [ + {file = "asyncio-dgram-2.1.2.tar.gz", hash = "sha256:bc28a90bc0523009fb0da16ca983c1400ff403a315754d86e037910563697f91"}, + {file = "asyncio_dgram-2.1.2-py3-none-any.whl", hash = "sha256:9ef55fc760f93c8212709329a1e28a1cf1c1f0fc8222f1be0227c2b7606a10a2"}, +] + +[package.extras] +test = ["black (>=20.8b1)", "flake8 (>=3.8.3)", "mypy (>=0.812)", "mypy-extensions (>=0.4.3)", "pytest (>=5.4.3)", "pytest-asyncio (>=0.14.0)", "typed-ast (>=1.4.3)", "typing-extensions (>=3.10.0.0)"] + [[package]] name = "attrs" version = "23.1.0" description = "Classes Without Boilerplate" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -195,6 +216,7 @@ tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pyte name = "beautifulsoup4" version = "4.12.2" description = "Screen-scraping library" +category = "main" optional = false python-versions = ">=3.6.0" files = [ @@ -213,6 +235,7 @@ lxml = ["lxml"] name = "black" version = "23.3.0" description = "The uncompromising code formatter." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -261,6 +284,7 @@ uvloop = ["uvloop (>=0.15.2)"] name = "certifi" version = "2023.7.22" description = "Python package for providing Mozilla's CA Bundle." +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -272,6 +296,7 @@ files = [ name = "charset-normalizer" version = "3.1.0" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -356,6 +381,7 @@ files = [ name = "click" version = "8.1.3" description = "Composable command line interface toolkit" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -370,6 +396,7 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." +category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -381,6 +408,7 @@ files = [ name = "discord-py" version = "2.3.1" description = "A Python wrapper for the Discord API" +category = "main" optional = false python-versions = ">=3.8.0" files = [ @@ -397,10 +425,31 @@ speed = ["Brotli", "aiodns (>=1.1)", "cchardet (==2.1.7)", "orjson (>=3.5.4)"] test = ["coverage[toml]", "pytest", "pytest-asyncio", "pytest-cov", "pytest-mock", "typing-extensions (>=4.3,<5)"] voice = ["PyNaCl (>=1.3.0,<1.6)"] +[[package]] +name = "dnspython" +version = "2.4.2" +description = "DNS toolkit" +category = "main" +optional = false +python-versions = ">=3.8,<4.0" +files = [ + {file = "dnspython-2.4.2-py3-none-any.whl", hash = "sha256:57c6fbaaeaaf39c891292012060beb141791735dbb4004798328fc2c467402d8"}, + {file = "dnspython-2.4.2.tar.gz", hash = "sha256:8dcfae8c7460a2f84b4072e26f1c9f4101ca20c071649cb7c34e8b6a93d58984"}, +] + +[package.extras] +dnssec = ["cryptography (>=2.6,<42.0)"] +doh = ["h2 (>=4.1.0)", "httpcore (>=0.17.3)", "httpx (>=0.24.1)"] +doq = ["aioquic (>=0.9.20)"] +idna = ["idna (>=2.1,<4.0)"] +trio = ["trio (>=0.14,<0.23)"] +wmi = ["wmi (>=1.5.1,<2.0.0)"] + [[package]] name = "exceptiongroup" version = "1.1.1" description = "Backport of PEP 654 (exception groups)" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -415,6 +464,7 @@ test = ["pytest (>=6)"] name = "frozenlist" version = "1.3.3" description = "A list-like structure which implements collections.abc.MutableSequence" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -498,6 +548,7 @@ files = [ name = "greenlet" version = "2.0.2" description = "Lightweight in-process concurrent programming" +category = "main" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" files = [ @@ -506,6 +557,7 @@ files = [ {file = "greenlet-2.0.2-cp27-cp27m-win32.whl", hash = "sha256:6c3acb79b0bfd4fe733dff8bc62695283b57949ebcca05ae5c129eb606ff2d74"}, {file = "greenlet-2.0.2-cp27-cp27m-win_amd64.whl", hash = "sha256:283737e0da3f08bd637b5ad058507e578dd462db259f7f6e4c5c365ba4ee9343"}, {file = "greenlet-2.0.2-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:d27ec7509b9c18b6d73f2f5ede2622441de812e7b1a80bbd446cb0633bd3d5ae"}, + {file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d967650d3f56af314b72df7089d96cda1083a7fc2da05b375d2bc48c82ab3f3c"}, {file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:30bcf80dda7f15ac77ba5af2b961bdd9dbc77fd4ac6105cee85b0d0a5fcf74df"}, {file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26fbfce90728d82bc9e6c38ea4d038cba20b7faf8a0ca53a9c07b67318d46088"}, {file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9190f09060ea4debddd24665d6804b995a9c122ef5917ab26e1566dcc712ceeb"}, @@ -514,6 +566,7 @@ files = [ {file = "greenlet-2.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:76ae285c8104046b3a7f06b42f29c7b73f77683df18c49ab5af7983994c2dd91"}, {file = "greenlet-2.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:2d4686f195e32d36b4d7cf2d166857dbd0ee9f3d20ae349b6bf8afc8485b3645"}, {file = "greenlet-2.0.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:c4302695ad8027363e96311df24ee28978162cdcdd2006476c43970b384a244c"}, + {file = "greenlet-2.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d4606a527e30548153be1a9f155f4e283d109ffba663a15856089fb55f933e47"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c48f54ef8e05f04d6eff74b8233f6063cb1ed960243eacc474ee73a2ea8573ca"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a1846f1b999e78e13837c93c778dcfc3365902cfb8d1bdb7dd73ead37059f0d0"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a06ad5312349fec0ab944664b01d26f8d1f05009566339ac6f63f56589bc1a2"}, @@ -543,6 +596,7 @@ files = [ {file = "greenlet-2.0.2-cp37-cp37m-win32.whl", hash = "sha256:3f6ea9bd35eb450837a3d80e77b517ea5bc56b4647f5502cd28de13675ee12f7"}, {file = "greenlet-2.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:7492e2b7bd7c9b9916388d9df23fa49d9b88ac0640db0a5b4ecc2b653bf451e3"}, {file = "greenlet-2.0.2-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:b864ba53912b6c3ab6bcb2beb19f19edd01a6bfcbdfe1f37ddd1778abfe75a30"}, + {file = "greenlet-2.0.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1087300cf9700bbf455b1b97e24db18f2f77b55302a68272c56209d5587c12d1"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:ba2956617f1c42598a308a84c6cf021a90ff3862eddafd20c3333d50f0edb45b"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fc3a569657468b6f3fb60587e48356fe512c1754ca05a564f11366ac9e306526"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8eab883b3b2a38cc1e050819ef06a7e6344d4a990d24d45bc6f2cf959045a45b"}, @@ -551,6 +605,7 @@ files = [ {file = "greenlet-2.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b0ef99cdbe2b682b9ccbb964743a6aca37905fda5e0452e5ee239b1654d37f2a"}, {file = "greenlet-2.0.2-cp38-cp38-win32.whl", hash = "sha256:b80f600eddddce72320dbbc8e3784d16bd3fb7b517e82476d8da921f27d4b249"}, {file = "greenlet-2.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:4d2e11331fc0c02b6e84b0d28ece3a36e0548ee1a1ce9ddde03752d9b79bba40"}, + {file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8512a0c38cfd4e66a858ddd1b17705587900dd760c6003998e9472b77b56d417"}, {file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:88d9ab96491d38a5ab7c56dd7a3cc37d83336ecc564e4e8816dbed12e5aaefc8"}, {file = "greenlet-2.0.2-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:561091a7be172ab497a3527602d467e2b3fbe75f9e783d8b8ce403fa414f71a6"}, {file = "greenlet-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:971ce5e14dc5e73715755d0ca2975ac88cfdaefcaab078a284fea6cfabf866df"}, @@ -571,6 +626,7 @@ test = ["objgraph", "psutil"] name = "humanize" version = "4.7.0" description = "Python humanize utilities" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -585,6 +641,7 @@ tests = ["freezegun", "pytest", "pytest-cov"] name = "icalendar" version = "5.0.7" description = "iCalendar parser/generator" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -600,6 +657,7 @@ pytz = "*" name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" optional = false python-versions = ">=3.5" files = [ @@ -611,6 +669,7 @@ files = [ name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -618,10 +677,27 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "mcstatus" +version = "11.1.0" +description = "A library to query Minecraft Servers for their status and capabilities." +category = "main" +optional = false +python-versions = ">=3.8.1,<4" +files = [ + {file = "mcstatus-11.1.0-py3-none-any.whl", hash = "sha256:15b81f777ac1413f5a450d221eac913dc1581169b633bd7d2417c96eb49ee965"}, + {file = "mcstatus-11.1.0.tar.gz", hash = "sha256:d14bf46db8ae5b98a68aebb7fce91a169282e9ac09eb7f6a10a20d9e7d18ca80"}, +] + +[package.dependencies] +asyncio-dgram = ">=2.1.2,<3.0.0" +dnspython = ">=2.4.2,<3.0.0" + [[package]] name = "multidict" version = "6.0.4" description = "multidict implementation" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -705,6 +781,7 @@ files = [ name = "mypy-extensions" version = "1.0.0" description = "Type system extensions for programs checked with the mypy type checker." +category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -716,6 +793,7 @@ files = [ name = "nodeenv" version = "1.8.0" description = "Node.js virtual environment builder" +category = "dev" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" files = [ @@ -730,6 +808,7 @@ setuptools = "*" name = "packaging" version = "23.1" description = "Core utilities for Python packages" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -741,6 +820,7 @@ files = [ name = "pathspec" version = "0.11.1" description = "Utility library for gitignore style pattern matching of file paths." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -752,6 +832,7 @@ files = [ name = "platformdirs" version = "3.8.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -767,6 +848,7 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest- name = "pluggy" version = "1.2.0" description = "plugin and hook calling mechanisms for python" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -782,6 +864,7 @@ testing = ["pytest", "pytest-benchmark"] name = "psycopg2-binary" version = "2.9.6" description = "psycopg2 - Python-PostgreSQL Database Adapter" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -853,6 +936,7 @@ files = [ name = "pyright" version = "1.1.334" description = "Command line wrapper for pyright" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -871,6 +955,7 @@ dev = ["twine (>=3.4.1)"] name = "pytest" version = "7.4.0" description = "pytest: simple powerful testing with Python" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -893,6 +978,7 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "pytest-datafiles" version = "3.0.0" description = "py.test plugin to create a 'tmp_path' containing predefined files/directories." +category = "dev" optional = false python-versions = "*" files = [ @@ -907,6 +993,7 @@ pytest = ">=3.6" name = "python-dateutil" version = "2.8.2" description = "Extensions to the standard Python datetime module" +category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" files = [ @@ -921,6 +1008,7 @@ six = ">=1.5" name = "python-dotenv" version = "1.0.0" description = "Read key-value pairs from a .env file and set them as environment variables" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -935,6 +1023,7 @@ cli = ["click (>=5.0)"] name = "pytz" version = "2023.3" description = "World timezone definitions, modern and historical" +category = "main" optional = false python-versions = "*" files = [ @@ -946,6 +1035,7 @@ files = [ name = "pyyaml" version = "6.0" description = "YAML parser and emitter for Python" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -995,6 +1085,7 @@ files = [ name = "requests" version = "2.31.0" description = "Python HTTP for Humans." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1016,6 +1107,7 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] name = "setuptools" version = "68.0.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1032,6 +1124,7 @@ testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs ( name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -1043,6 +1136,7 @@ files = [ name = "soupsieve" version = "2.4.1" description = "A modern CSS selector implementation for Beautiful Soup." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1054,6 +1148,7 @@ files = [ name = "sqlalchemy" version = "2.0.17" description = "Database Abstraction Library" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1101,7 +1196,7 @@ files = [ ] [package.dependencies] -greenlet = {version = "!=0.4.17", markers = "platform_machine == \"win32\" or platform_machine == \"WIN32\" or platform_machine == \"AMD64\" or platform_machine == \"amd64\" or platform_machine == \"x86_64\" or platform_machine == \"ppc64le\" or platform_machine == \"aarch64\""} +greenlet = {version = "!=0.4.17", markers = "platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\""} psycopg2-binary = {version = "*", optional = true, markers = "extra == \"postgresql_psycopg2binary\""} typing-extensions = ">=4.2.0" @@ -1133,6 +1228,7 @@ sqlcipher = ["sqlcipher3-binary"] name = "tomli" version = "2.0.1" description = "A lil' TOML parser" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1144,6 +1240,7 @@ files = [ name = "types-beautifulsoup4" version = "4.12.0.5" description = "Typing stubs for beautifulsoup4" +category = "dev" optional = false python-versions = "*" files = [ @@ -1158,6 +1255,7 @@ types-html5lib = "*" name = "types-html5lib" version = "1.1.11.14" description = "Typing stubs for html5lib" +category = "dev" optional = false python-versions = "*" files = [ @@ -1169,6 +1267,7 @@ files = [ name = "types-python-dateutil" version = "2.8.19.13" description = "Typing stubs for python-dateutil" +category = "dev" optional = false python-versions = "*" files = [ @@ -1180,6 +1279,7 @@ files = [ name = "types-pytz" version = "2023.3.0.0" description = "Typing stubs for pytz" +category = "dev" optional = false python-versions = "*" files = [ @@ -1191,6 +1291,7 @@ files = [ name = "types-requests" version = "2.31.0.1" description = "Typing stubs for requests" +category = "dev" optional = false python-versions = "*" files = [ @@ -1205,6 +1306,7 @@ types-urllib3 = "*" name = "types-urllib3" version = "1.26.25.13" description = "Typing stubs for urllib3" +category = "dev" optional = false python-versions = "*" files = [ @@ -1216,6 +1318,7 @@ files = [ name = "typing-extensions" version = "4.7.0" description = "Backported and Experimental Type Hints for Python 3.7+" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1227,6 +1330,7 @@ files = [ name = "tzdata" version = "2023.3" description = "Provider of IANA time zone data" +category = "main" optional = false python-versions = ">=2" files = [ @@ -1238,6 +1342,7 @@ files = [ name = "tzlocal" version = "5.0.1" description = "tzinfo object for the local timezone" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1255,6 +1360,7 @@ devenv = ["black", "check-manifest", "flake8", "pyroma", "pytest (>=4.3)", "pyte name = "urllib3" version = "2.0.3" description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1272,6 +1378,7 @@ zstd = ["zstandard (>=0.18.0)"] name = "yarl" version = "1.9.2" description = "Yet another URL library" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1358,4 +1465,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "c83c2c52dd6a94fb55fb0e23afc7d8e3b9d0b761e7b3d77add8a2ad70bda4379" +content-hash = "8332e7448e7a8f79b27e4e3f2597e5cfb8b312368ce0bf95c5cb13c32dc90da9" diff --git a/pyproject.toml b/pyproject.toml index 2989fa3..2f225a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ humanize = "^4.3" aiohttp = "^3.8" aio-mc-rcon = "^3.2.0" PyYAML = "^6.0" +mcstatus = "^11.1.0" [tool.poetry.scripts] botdev = "dev.cli:main" diff --git a/uqcsbot/minecraft.py b/uqcsbot/minecraft.py index da5d121..fc394ff 100644 --- a/uqcsbot/minecraft.py +++ b/uqcsbot/minecraft.py @@ -4,6 +4,7 @@ import discord from aiomcrcon import Client, IncorrectPasswordError, RCONConnectionError # type: ignore +from mcstatus import JavaServer from discord import Member, app_commands, Colour from discord.ext import commands @@ -48,6 +49,27 @@ async def send_rcon_command(self, command: str): return response + @app_commands.command() + async def mcplayers(self, interaction: discord.Interaction): + """Returns the number and list of people currently playing on the Minecraft server.""" + server = JavaServer.lookup( + "minecraft.uqcs.org:25605" + ) # Does this need to be hard coded?? Is RCON addr/IP the same? + status = server.status() # type: ignore + + # Check if there are players online + # Not none so pyright shuts up + if status.players.online > 0 and status.players.sample is not None: + # Extract player names + player_names = [player.name for player in status.players.sample] + # Format the list of players + players_list = "\n".join(player_names) + response_message = f"The server has {status.players.online} player(s) online:\n```\n{players_list}\n```" + else: + response_message = f"The server has {status.players.online} players online." + + await interaction.response.send_message(response_message) + @app_commands.command() @app_commands.describe(username="Minecraft username to whitelist.") @yelling_exemptor(input_args=["username"]) From dc2bebe74055aa3ee0e12fb02441867f0b914d30 Mon Sep 17 00:00:00 2001 From: Anti Matter Date: Sun, 24 Dec 2023 09:11:59 +1000 Subject: [PATCH 2/4] Added env variables for mc public ip and port --- uqcsbot/minecraft.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uqcsbot/minecraft.py b/uqcsbot/minecraft.py index fc394ff..d2113f9 100644 --- a/uqcsbot/minecraft.py +++ b/uqcsbot/minecraft.py @@ -17,6 +17,8 @@ RCON_PORT = os.environ.get("MC_RCON_PORT") RCON_PASSWORD = os.environ.get("MC_RCON_PASSWORD") +MC_PUBLIC_IP = os.environ.get("MC_PUBLIC_IP") +MC_PUBLIC_PORT = os.environ.get("MC_PUBLIC_PORT") class Minecraft(commands.Cog): def __init__(self, bot: UQCSBot): @@ -53,7 +55,7 @@ async def send_rcon_command(self, command: str): async def mcplayers(self, interaction: discord.Interaction): """Returns the number and list of people currently playing on the Minecraft server.""" server = JavaServer.lookup( - "minecraft.uqcs.org:25605" + f"{MC_PUBLIC_IP}:{MC_PUBLIC_PORT}" ) # Does this need to be hard coded?? Is RCON addr/IP the same? status = server.status() # type: ignore From b28b35aae54aa3e8c7c62e20515939e336757790 Mon Sep 17 00:00:00 2001 From: Anti Matter Date: Sun, 24 Dec 2023 09:14:13 +1000 Subject: [PATCH 3/4] Added public ip and port to env.example (oops) --- .env.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.example b/.env.example index c19c1d2..c0b27a9 100644 --- a/.env.example +++ b/.env.example @@ -14,6 +14,8 @@ HACKATHON_END_TIME= MC_RCON_ADDRESS= MC_RCON_PORT= MC_RCON_PASSWORD= +MC_PUBLIC_IP= +MC_PUBLIC_PORT= SB_BASE_THRESHOLD=8 SB_BIG_THRESHOLD=24 SB_RATELIMIT=30 From 9d4672b058fa6bec7f7d83628b555819b1d3259d Mon Sep 17 00:00:00 2001 From: Anti Matter Date: Sun, 24 Dec 2023 09:24:38 +1000 Subject: [PATCH 4/4] Ran black to fit code styling --- uqcsbot/minecraft.py | 1 + 1 file changed, 1 insertion(+) diff --git a/uqcsbot/minecraft.py b/uqcsbot/minecraft.py index d2113f9..534ea8b 100644 --- a/uqcsbot/minecraft.py +++ b/uqcsbot/minecraft.py @@ -20,6 +20,7 @@ MC_PUBLIC_IP = os.environ.get("MC_PUBLIC_IP") MC_PUBLIC_PORT = os.environ.get("MC_PUBLIC_PORT") + class Minecraft(commands.Cog): def __init__(self, bot: UQCSBot): self.bot = bot