minecraft-bot/main.py

50 lines
1.1 KiB
Python
Raw Normal View History

import importlib
import threading
import time
2020-09-06 21:39:21 +00:00
from flask import Flask
app = Flask(__name__)
from bunch import Bunch
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
2020-09-06 22:10:00 +00:00
import bot
global_state = Bunch()
g = global_state
2020-09-06 22:10:00 +00:00
2020-09-06 21:39:21 +00:00
@app.route('/')
def hello_world():
#print(chunks.chunks)
return str(g.chunks.get_block_at(84,62,54))
#return 'ok'
2020-09-06 22:10:00 +00:00
reload_timeout = time.time()
2020-09-06 22:10:00 +00:00
def main():
def reload_bot(event):
global reload_timeout
if time.time() - reload_timeout > 5.0:
reload_timeout = time.time()
print('Reloading...')
importlib.reload(bot)
event_handler = PatternMatchingEventHandler(patterns=['*.py'], ignore_patterns=['./main.py'])
event_handler.on_any_event = reload_bot
2020-09-06 22:10:00 +00:00
observer = Observer()
observer.schedule(event_handler, '.', recursive=True)
observer.start()
2020-09-06 22:10:00 +00:00
try:
while True:
bot.bot(global_state)
except KeyboardInterrupt:
observer.stop()
observer.join()
2020-09-06 22:10:00 +00:00
if __name__ == '__main__':
threading.Thread(target=app.run).start()
2020-09-06 22:10:00 +00:00
main()