minecraft-bot/main.py

53 lines
1.2 KiB
Python

from flask import Flask
app = Flask(__name__)
USERNAME = ''
PASSWORD = ''
SERVER = ''
from custom.managers import DataManager, ChunksManager, ChatManager
from minecraft import authentication
from minecraft.exceptions import YggdrasilError
from minecraft.networking.connection import Connection
from minecraft.networking.packets import Packet, clientbound, serverbound
@app.route('/')
def hello_world():
return 'Hello, World!'
def main():
mcdata = DataManager('./mcdata')
auth_token = authentication.AuthenticationToken()
try:
auth_token.authenticate(USERNAME, PASSWORD)
except YggdrasilError as e:
print(e)
sys.exit()
print("Logged in as %s..." % auth_token.username)
connection = Connection(
SERVER, 25565, auth_token=auth_token)
def handle_join_game(join_game_packet):
print('Connected.')
connection.register_packet_listener(
handle_join_game, clientbound.play.JoinGamePacket)
chunks = ChunksManager(mcdata)
chunks.register(connection)
chat = ChatManager()
chat.register(connection)
connection.connect()
print('connected')
app.run()
if __name__ == '__main__':
main()