### Asynchronous OpenTTD Admin Bot Example Source: https://github.com/liki-mc/pyopenttdadmin/blob/main/README.md This snippet shows how to create an echo bot using the asynchronous API with `asyncio`. It mirrors the synchronous example but utilizes `await` for operations like login, subscription, and sending messages. This is suitable for non-blocking applications. ```python import asyncio from aiopyopenttdadmin import Admin, AdminUpdateType, openttdpacket # Set the IP address and port number for connection ip_address = "127.0.0.1" port_number = 3977 async def main(): # Instantiate the Admin class and establish connection to the server admin = Admin(ip = ip_address, port = port_number) await admin.login("pyOpenTTDAdmin", password = "toor") # assuming the password is "toor" # Subscribe to receive chat updates await admin.subscribe(AdminUpdateType.CHAT) # Print chat packets @admin.add_handler(openttdpacket.ChatPacket) async def chat_packet(admin: Admin, packet: openttdpacket.ChatPacket): print(f'ID: {packet.id} Message: {packet.message}') # Echo chat @admin.add_handler(openttdpacket.ChatPacket) async def echo_chat(admin: Admin, packet: openttdpacket.ChatPacket): await admin.send_global(packet.message) # Run admin print("running") await admin.run() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Synchronous OpenTTD Admin Bot Example Source: https://github.com/liki-mc/pyopenttdadmin/blob/main/README.md This snippet demonstrates how to create a basic echo bot using the synchronous API. It connects to an OpenTTD server, logs in, subscribes to chat updates, and echoes received chat messages back to the server. Ensure the server's admin port is accessible and the password is correct. ```python from pyopenttdadmin import Admin, AdminUpdateType, openttdpacket # Set the IP address and port number for connection ip_address = "127.0.0.1" port_number = 3977 # Instantiate the Admin class and establish connection to the server admin = Admin(ip = ip_address, port = port_number) admin.login("pyOpenTTDAdmin", password = "toor") # assuming the password is "toor" # Subscribe to receive chat updates admin.subscribe(AdminUpdateType.CHAT) # Print chat packets @admin.add_handler(openttdpacket.ChatPacket) def chat_packet(admin: Admin, packet: openttdpacket.ChatPacket): print(f'ID: {packet.id} Message: {packet.message}') # Echo chat @admin.add_handler(openttdpacket.ChatPacket) def echo_chat(admin: Admin, packet: openttdpacket.ChatPacket): admin.send_global(packet.message) # Run admin admin.run() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.