Add tablist header and footer to mc!tab command

* Waiting for upstream support from pyCraft so this uses my fork
feature/embed-uploads
Tristan Gosselin-Hane 7 years ago
parent d31913134a
commit 51cad28ab3
  1. 2
      Pipfile
  2. 26
      Pipfile.lock
  3. 1
      docker-compose.yml
  4. 27
      webhook-bridge.py

@ -6,7 +6,6 @@ name = "pypi"
[dev-packages] [dev-packages]
[packages] [packages]
minecraft = {git = "https://github.com/ammaraskar/pyCraft.git"}
requests = "*" requests = "*"
cryptography = "*" cryptography = "*"
future = "*" future = "*"
@ -15,6 +14,7 @@ mcstatus = "*"
quarry = "*" quarry = "*"
discord-py = {git = "https://github.com/Rapptz/discord.py.git", ref = "rewrite"} discord-py = {git = "https://github.com/Rapptz/discord.py.git", ref = "rewrite"}
bidict = "*" bidict = "*"
minecraft = {git = "https://github.com/starcraft66/pyCraft.git", ref = "feature/add-player-list-header-and-footer-packet"}
[requires] [requires]
python_version = "3.6" python_version = "3.6"

26
Pipfile.lock generated

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "92f71d787f478e45589c4939466682bc725279f844ced3c62a92a4b5e21515e1" "sha256": "21ac16059e4c1c4b6aa022bacaa0d0fdc42c09ea4277129278fc848c52742b46"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -154,10 +154,10 @@
}, },
"future": { "future": {
"hashes": [ "hashes": [
"sha256:eb6d4df04f1fb538c99f69c9a28b255d1ee4e825d479b9c62fc38c0cf38065a4" "sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.17.0" "version": "==0.17.1"
}, },
"hyperlink": { "hyperlink": {
"hashes": [ "hashes": [
@ -188,8 +188,8 @@
"version": "==2.2" "version": "==2.2"
}, },
"minecraft": { "minecraft": {
"git": "https://github.com/ammaraskar/pyCraft.git", "git": "https://github.com/starcraft66/pyCraft.git",
"ref": "527f3d31468dbaf8c1cbfffd0cbf46e987d319a0" "ref": "154b3e30d4f3690a53b821f22b8c281c7ac893d5"
}, },
"pyasn1": { "pyasn1": {
"hashes": [ "hashes": [
@ -234,11 +234,11 @@
}, },
"requests": { "requests": {
"hashes": [ "hashes": [
"sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c", "sha256:65b3a120e4329e33c9889db89c80976c5272f56ea92d3e74da8a463992e3ff54",
"sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279" "sha256:ea881206e59f41dbd0bd445437d792e43906703fff75ca8ff43ccdb11f33f263"
], ],
"index": "pypi", "index": "pypi",
"version": "==2.20.0" "version": "==2.20.1"
}, },
"service-identity": { "service-identity": {
"hashes": [ "hashes": [
@ -256,10 +256,10 @@
}, },
"sqlalchemy": { "sqlalchemy": {
"hashes": [ "hashes": [
"sha256:c5951d9ef1d5404ed04bae5a16b60a0779087378928f997a294d1229c6ca4d3e" "sha256:84412de3794acee05630e7788f25e80e81f78eb4837e7b71d0499129f660486a"
], ],
"index": "pypi", "index": "pypi",
"version": "==1.2.12" "version": "==1.2.13"
}, },
"twisted": { "twisted": {
"hashes": [ "hashes": [
@ -269,10 +269,10 @@
}, },
"urllib3": { "urllib3": {
"hashes": [ "hashes": [
"sha256:41c3db2fc01e5b907288010dec72f9d0a74e37d6994e6eb56849f59fea2265ae", "sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39",
"sha256:8819bba37a02d143296a4d032373c4dd4aca11f6d4c9973335ca75f9c8475f59" "sha256:de9529817c93f27c8ccbfead6985011db27bd0ddfcdb2d86f3f663385c6a9c22"
], ],
"version": "==1.24" "version": "==1.24.1"
}, },
"zope.interface": { "zope.interface": {
"hashes": [ "hashes": [

@ -7,3 +7,4 @@ services:
volumes: volumes:
- ./:/app:Z - ./:/app:Z
- ./:/data:Z - ./:/data:Z
- ../pyCraft:/pyCraft:Z

@ -39,7 +39,8 @@ BOT_USERNAME = ""
NEXT_MESSAGE_TIME = datetime.now(timezone.utc) NEXT_MESSAGE_TIME = datetime.now(timezone.utc)
PREVIOUS_MESSAGE = "" PREVIOUS_MESSAGE = ""
PLAYER_LIST = bidict() PLAYER_LIST = bidict()
MOTD = "Not yet implemented" TAB_HEADER = ""
TAB_FOOTER = ""
LAST_CONNECTION_TIME = datetime.now(timezone.utc) LAST_CONNECTION_TIME = datetime.now(timezone.utc)
@ -101,6 +102,13 @@ def remove_emoji(string):
return emoji_pattern.sub(r'', string) return emoji_pattern.sub(r'', string)
def strip_colour(string):
colour_pattern = re.compile(
u"\U000000A7" # selection symbol
".", flags=re.UNICODE)
return colour_pattern.sub(r'', string)
def setup_logging(level): def setup_logging(level):
if level.lower() == "debug": if level.lower() == "debug":
log_level = logging.DEBUG log_level = logging.DEBUG
@ -234,6 +242,18 @@ def main():
connection.register_packet_listener( connection.register_packet_listener(
handle_tab_list, clientbound.play.PlayerListItemPacket) handle_tab_list, clientbound.play.PlayerListItemPacket)
connection.register_packet_listener(
handle_player_list_header_and_footer_update, clientbound.play.PlayerListHeaderAndFooterPacket)
def handle_player_list_header_and_footer_update(header_footer_packet):
global TAB_FOOTER, TAB_HEADER
logging.debug("Got Tablist H/F Update: header={}".format(header_footer_packet.header))
logging.debug("Got Tablist H/F Update: footer={}".format(header_footer_packet.footer))
# Strip out colour codes
TAB_HEADER = strip_colour(json.loads(header_footer_packet.header)["text"])
TAB_FOOTER = strip_colour(json.loads(header_footer_packet.footer)["text"])
def handle_tab_list(tab_list_packet): def handle_tab_list(tab_list_packet):
logging.debug("Processing tab list packet") logging.debug("Processing tab list packet")
for action in tab_list_packet.actions: for action in tab_list_packet.actions:
@ -514,8 +534,9 @@ def main():
await message.author.create_dm() await message.author.create_dm()
send_channel = message.author.dm_channel send_channel = message.author.dm_channel
player_list = ", ".join(list(map(lambda x: x[1], PLAYER_LIST.items()))) player_list = ", ".join(list(map(lambda x: x[1], PLAYER_LIST.items())))
msg = "MOTD: {}\n" \ msg = "{}\n" \
"Players online: {}".format(MOTD, player_list) "Players online: {}\n" \
"{}".format(TAB_HEADER, player_list, TAB_FOOTER)
await send_channel.send(msg) await send_channel.send(msg)
except discord.errors.Forbidden: except discord.errors.Forbidden:
if isinstance(message.author, discord.abc.User): if isinstance(message.author, discord.abc.User):

Loading…
Cancel
Save