2020-09-07 21:48:16 +00:00
|
|
|
import importlib
|
|
|
|
import threading
|
|
|
|
import time
|
2020-09-09 01:52:50 +00:00
|
|
|
import traceback
|
2020-09-07 21:48:16 +00:00
|
|
|
|
2020-09-06 21:39:21 +00:00
|
|
|
from flask import Flask
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
from bunch import Bunch
|
|
|
|
from watchdog.observers import Observer
|
|
|
|
from watchdog.events import PatternMatchingEventHandler
|
2020-09-06 22:10:00 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
import bot
|
2020-09-08 21:33:42 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
global_state = Bunch()
|
|
|
|
g = global_state
|
2020-09-08 01:28:56 +00:00
|
|
|
g.connection = False
|
2020-09-09 01:52:50 +00:00
|
|
|
g.mcdata = False
|
2020-09-08 21:33:42 +00:00
|
|
|
g.pos = False
|
2020-09-09 21:58:19 +00:00
|
|
|
g.inv = {}
|
2020-09-06 22:10:00 +00:00
|
|
|
|
2020-09-06 21:39:21 +00:00
|
|
|
@app.route('/')
|
|
|
|
def hello_world():
|
2020-09-07 21:48:16 +00:00
|
|
|
#print(chunks.chunks)
|
|
|
|
return str(g.chunks.get_block_at(84,62,54))
|
|
|
|
#return 'ok'
|
2020-09-06 22:10:00 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
reload_timeout = time.time()
|
2020-09-06 22:10:00 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
def main():
|
|
|
|
def reload_bot(event):
|
|
|
|
global reload_timeout
|
2020-09-08 01:28:56 +00:00
|
|
|
if time.time() - reload_timeout > 2.0:
|
2020-09-07 21:48:16 +00:00
|
|
|
reload_timeout = time.time()
|
|
|
|
print('Reloading...')
|
2020-09-08 01:28:56 +00:00
|
|
|
g.running = False
|
2020-09-06 22:43:20 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
event_handler = PatternMatchingEventHandler(patterns=['*.py'], ignore_patterns=['./main.py'])
|
|
|
|
event_handler.on_any_event = reload_bot
|
2020-09-06 22:10:00 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
observer = Observer()
|
|
|
|
observer.schedule(event_handler, '.', recursive=True)
|
|
|
|
observer.start()
|
2020-09-06 22:10:00 +00:00
|
|
|
|
2020-09-07 21:48:16 +00:00
|
|
|
try:
|
|
|
|
while True:
|
2020-09-09 01:52:50 +00:00
|
|
|
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)
|
2020-09-09 21:58:19 +00:00
|
|
|
importlib.reload(bot)
|
2020-09-07 21:48:16 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
observer.stop()
|
|
|
|
observer.join()
|
2020-09-06 22:10:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-09-07 21:48:16 +00:00
|
|
|
threading.Thread(target=app.run).start()
|
2020-09-08 04:31:55 +00:00
|
|
|
time.sleep(1)
|
2020-09-06 22:10:00 +00:00
|
|
|
main()
|