You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.5 KiB

import importlib
import threading
import time
import traceback
from flask import Flask
app = Flask(__name__)
from bunch import Bunch
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
import bot
global_state = Bunch()
g = global_state
g.local_state = False
g.connection = False
g.mcdata = False
g.pos = False
@app.route('/')
def hello_world():
#print(chunks.chunks)
return str(g.chunks.get_block_at(84,62,54))
#return 'ok'
reload_timeout = time.time()
def main():
def reload_bot(event):
global reload_timeout
if time.time() - reload_timeout > 2.0:
reload_timeout = time.time()
print('Reloading...')
g.running = False
event_handler = PatternMatchingEventHandler(patterns=['*.py'], ignore_patterns=['./main.py'])
event_handler.on_any_event = reload_bot
observer = Observer()
observer.schedule(event_handler, '.', recursive=True)
observer.start()
try:
while True:
try:
g.running = True
bot.bot(global_state)
importlib.reload(bot)
except BaseException as e:
g.running = True
traceback.print_exc()
print('Locking...')
while g.running:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == '__main__':
threading.Thread(target=app.run).start()
time.sleep(1)
main()