Catch all config errors (#414)

This commit is contained in:
aeon0
2022-01-08 19:25:24 +01:00
committed by GitHub
parent f450dc7591
commit 8dfe8a2163
4 changed files with 24 additions and 12 deletions
+2 -2
View File
@@ -68,9 +68,9 @@ class Bot:
elif self._config.char["type"] == "necro":
self._char: IChar = Necro(self._config.necro, self._config.char, self._screen, self._template_finder, self._ui_manager, self._pather)
elif self._config.char["type"] == "basic":
self._char: IChar = Basic(self._config.basic, self._config.char, self._screen, self._template_finder, self._ui_manager, self._pather)
self._char: IChar = Basic(self._config.basic, self._config.char, self._screen, self._template_finder, self._ui_manager, self._pather)
elif self._config.char["type"] == "basic_ranged":
self._char: IChar = Basic_Ranged(self._config.basic, self._config.char, self._screen, self._template_finder, self._ui_manager, self._pather)
self._char: IChar = Basic_Ranged(self._config.basic_ranged, self._config.char, self._screen, self._template_finder, self._ui_manager, self._pather)
else:
Logger.error(f'{self._config.char["type"]} is not supported! Closing down bot.')
os._exit(1)
+4 -4
View File
@@ -157,16 +157,16 @@ class Config:
self.barbarian = self._config["barbarian"]
if "barbarian" in self._custom:
self.barbarian.update(self._custom["barbarian"])
# Basic config
self.basic = self._config["basic"]
if "basic" in self._custom:
self.basic.update(self._custom["basic"])
self.basic.update(self._custom["basic"])
# Basic Ranged config
self.basic = self._config["basic_ranged"]
self.basic_ranged = self._config["basic_ranged"]
if "basic_ranged" in self._custom:
self.basic_ranged.update(self._custom["basic_ranged"])
self.basic_ranged.update(self._custom["basic_ranged"])
# Necro config
self.necro = self._config["necro"]
+9 -4
View File
@@ -13,10 +13,11 @@ from utils.auto_settings import adjust_settings, backup_settings, restore_settin
from config import Config
from logger import Logger
config = Config(print_warnings=True)
game_controller = GameController(config)
debugger_controller = GraphicDebuggerController(config)
# Will be initialized in the __main__() function
config = None
game_controller = None
debugger_controller = None
def start_or_pause_bot():
global game_controller
@@ -56,7 +57,8 @@ def main():
print(f"ERROR: Unkown logg_lvl {config.general['logg_lvl']}. Must be one of [info, debug]")
# Create folder for debug screenshots if they dont exist yet
os.system("mkdir stats")
if not os.path.exists("stats"):
os.system("mkdir stats")
if not os.path.exists("info_screenshots") and config.general["info_screenshots"]:
os.system("mkdir info_screenshots")
if not os.path.exists("loot_screenshots") and (config.general["loot_screenshots"] or config.general["message_api_type"] == "discord"):
@@ -87,6 +89,9 @@ def main():
if __name__ == "__main__":
# To avoid cmd just closing down, except any errors and add a input() to the end
try:
config = Config(print_warnings=True)
game_controller = GameController(config)
debugger_controller = GraphicDebuggerController(config)
main()
except:
traceback.print_exc()
+9 -2
View File
@@ -1,5 +1,5 @@
# Mostly copied from: https://github.com/patrikoss/pyclick
from os import stat
import os
import mouse as _mouse
from mouse import _winmouse
import pytweening
@@ -7,6 +7,7 @@ import numpy as np
import random
import math
import time
import traceback
from config import Config
from typing import Union, Tuple
@@ -184,7 +185,13 @@ class HumanCurve():
class mouse:
# TODO: Not nice, this will execute every single time someone imports custom_mouse...
_config = Config()
try:
_config = Config()
except Exception as e:
traceback.print_exc()
print("Press Enter to exit ...")
input()
os._exit(-1)
@staticmethod
def sleep(duration, get_now=time.perf_counter):