Skip to main content

Python API for the WatonPlugin

Project description

WatonAPI

WatonAPI Logo

Python API for WatonPlugin

WatonAPI is an API used to connect to spigot servers with the WatonPlugin to communicate. You can send messages to the server and read messages, making it useful for cross-chat programs.

Some examples of possible use cases are:

  • Minecraft Chat CLI
  • Cross Chat Discord Bot

And many more

How to use

Documentation will be released soon

WatonAPI is an async library, meaning that it has to be run with asyncio. You can look in the examples directory to find example programs using the WatonAPI.

CLI Example

from watonapi.server import *
import asyncio

server_ip = ""
token = ""

async def async_input():
    return await asyncio.get_event_loop().run_in_executor(None, input)

async def take_input(server):
    while True:
        msg = await async_input()
        await server.send_msg('Waton CLI', msg) # When input is received, send it to the server

async def main(server):
    await server.add_listener("minecraft_msg") # Begin listening for a "minecraft_msg" packet
    await server.add_listener("player_join") # Begin listening for a "player_join" packet
    await server.add_listener("player_leave") # Begin listening for a "player_leave" packet
    
    authorized = False
    try:
        # If this doesn't fail, the token was correct and the connection authorized
        authorized = await server.connect(token)
    except Exception as e:
        print(f"Couldn't connect to server ( ERROR: {e} )")
    
    if authorized:
        input_handler = asyncio.create_task(take_input(server)) # Start an async task to get user input
        async for packet in server.get_listeners(): # Get all of the packets that we are listening for
            if packet["type"] == "minecraft_msg":
                print(f"<{packet['user']}> {packet['content']}")
            elif packet["type"] == "player_join":
                print(f"{packet['user']} joined the game!")
            elif packet["type"] == "player_leave":
                print(f"{packet['user']} left the game!")
        input_handler.cancel() # If it gets to here, the connection was lost
        print("Lost Connection")

server = Server(server_ip) # Create a server object using the server ip
asyncio.run(main(server)) # Run the main function

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

WatonAPI-0.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

WatonAPI-0.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file WatonAPI-0.1.tar.gz.

File metadata

  • Download URL: WatonAPI-0.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for WatonAPI-0.1.tar.gz
Algorithm Hash digest
SHA256 004020d4d389d5c3194f45042c87ca54e1fdd2821595479c5c521bf5a74e3726
MD5 70f5b83785cc403f54d0594fbab5102f
BLAKE2b-256 1ed3ba16da2f99198f0aa8164bdb406b46f75bee27a71b3e319ebdacb0eace78

See more details on using hashes here.

File details

Details for the file WatonAPI-0.1-py3-none-any.whl.

File metadata

  • Download URL: WatonAPI-0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for WatonAPI-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b07856870c5b62fca7193b1f6118bbd6cdc46c7e43e1962e99ad85e323603797
MD5 c602f288af1a66bab4b4b819252046d0
BLAKE2b-256 c78daeb70171596538c2e322d77fdab02c5011fe4261d15d17860cfc9b2ec5c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page