diff --git a/fishy/__init__.py b/fishy/__init__.py index a11ce4f..bb9d58d 100644 --- a/fishy/__init__.py +++ b/fishy/__init__.py @@ -1,2 +1,2 @@ from fishy.__main__ import main -__version__ = "0.2.5" +__version__ = "0.2.6" diff --git a/fishy/__main__.py b/fishy/__main__.py index e8ad7dd..8c26167 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -11,7 +11,7 @@ import fishy from fishy.systems import * from fishy.systems import helper from fishy.systems.config import Config -from fishy.systems.gui import GUI, GUIStreamHandler, GUIEvent, GUIFunction +from fishy.systems.gui import GUI, GUIEvent, GUIFunction class Fishy: @@ -100,7 +100,7 @@ class Fishy: def initialize(c: Config, gui): if c.get("first_launch", True, False): - helper.create_shortcut() + helper.create_shortcut(gui) c.set("first_launch", False) try: @@ -115,10 +115,7 @@ def initialize(c: Config, gui): helper.install_thread_excepthook() sys.excepthook = helper.unhandled_exception_logging - rootLogger = logging.getLogger('') - rootLogger.setLevel(logging.DEBUG) - new_console = GUIStreamHandler(gui) - rootLogger.addHandler(new_console) + def wait_and_check(): @@ -132,11 +129,11 @@ def main(): c = Config() events_buffer = [] gui = GUI(c, lambda a, b=None: events_buffer.append((a, b))) - initialize(c, gui) - gui.start() logging.info(f"Fishybot v{fishy.__version__}") + initialize(c, gui) + helper.check_addon() bot = Fishy(gui, events_buffer) diff --git a/fishy/systems/gui.py b/fishy/systems/gui.py index 793d2c2..2adcafb 100644 --- a/fishy/systems/gui.py +++ b/fishy/systems/gui.py @@ -4,6 +4,7 @@ import time from enum import Enum from logging import StreamHandler from tkinter import * +from tkinter import filedialog, messagebox from tkinter.ttk import * from typing import Tuple, List, Callable, Optional @@ -33,6 +34,7 @@ class GUIEvent(Enum): class GUIFunction(Enum): LOG = 0 # args: str STARTED = 1 # args: bool + ASK_DIRECTORY = 2 # callback: callable class GUI: @@ -53,6 +55,11 @@ class GUI: self.thread = threading.Thread(target=self.create, args=()) + rootLogger = logging.getLogger('') + rootLogger.setLevel(logging.DEBUG) + new_console = GUIStreamHandler(self) + rootLogger.addHandler(new_console) + def create(self): self.root = ThemedTk(theme="equilux", background=True) self.root.title("Fiishybot for Elder Scrolls Online") @@ -64,7 +71,7 @@ class GUI: menubar = Menu(self.root) filemenu = Menu(menubar, tearoff=0) - filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut()) + filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut(self)) dark_mode_var = IntVar() dark_mode_var.set(int(self.config.get('dark_mode', True))) @@ -109,7 +116,7 @@ class GUI: # region controls left_frame = Frame(controls_frame) - Label(left_frame, text="Android IP").grid(row=0, column=0) + # Label(left_frame, text="Android IP").grid(row=0, column=0) ip = Entry(left_frame) ip.insert(0, self.config.get("ip", "")) ip.grid(row=0, column=1) @@ -175,8 +182,13 @@ class GUI: if func[0] == GUIFunction.LOG: self._write_to_console(func[1][0]) elif func[0] == GUIFunction.STARTED: - self._bot_running = func[1][0] + # self._bot_running = func[1][0] self.start_button["text"] = "STOP" if self._bot_running else "START" + elif func[0] == GUIFunction.ASK_DIRECTORY: + messagebox.showinfo("Directory?", func[1][1]) + path = filedialog.askdirectory() + if path != '': + threading.Thread(target=func[1][0], args=(path,)).start() def _apply_theme(self, dark): self.root["theme"] = "equilux" if dark else "breeze" diff --git a/fishy/systems/helper.py b/fishy/systems/helper.py index c16e8cd..d607553 100644 --- a/fishy/systems/helper.py +++ b/fishy/systems/helper.py @@ -15,11 +15,15 @@ from uuid import uuid1 from hashlib import md5 import requests +from whatsmyip.ip import get_ip +from whatsmyip.providers import GoogleDnsProvider import fishy from fishy.systems.config import Config import functools +from fishy.systems.gui import GUIFunction + def round_float(v, ndigits=2, rt_str=False): """ @@ -75,8 +79,9 @@ def disable_logging(func): @disable_logging def req(config: Config, data): url = 'https://dcserver1.herokuapp.com/fishy' + ip = get_ip(GoogleDnsProvider) h = config.get("hash", md5(str(uuid1()).encode()).hexdigest()) - body = {"hash": h, "data": data} + body = {"hash": h, "data": data, "ip": ip} requests.post(url, json=body) @@ -117,18 +122,34 @@ def get_data_file_path(rel_path): return os.path.join(os.path.dirname(fishy.__file__), rel_path) -def create_shortcut(): - user = os.path.expanduser("~") - shutil.copy(get_data_file_path('FishybotESO.lnk'), os.path.join(user, "Desktop", "Fishybot ESO.lnk")) +def create_shortcut(gui): + try: + user = os.path.expanduser("~") + if os.path.exists(os.path.join(user, "Desktop")): + path = os.path.join(user, "Desktop", "Fishybot ESO.lnk") + _copy_shortcut(path) + else: + gui.call(GUIFunction.ASK_DIRECTORY, (_copy_shortcut, + "Could not find Desktop please specify path to create shortcut")) + except Exception: + logging.info("Couldn't create shortcut") + traceback.print_exc() + + +def _copy_shortcut(path): + shutil.copy(get_data_file_path('FishybotESO.lnk'), path) logging.info("Shortcut created") def check_addon(): - user = os.path.expanduser("~") - addon_dir = os.path.join(user, "Documents", "Elder Scrolls Online", "live", "Addons") - if not os.path.exists(os.path.join(addon_dir, 'ProvisionsChalutier')): - logging.info("Addon not found, installing it...") - with ZipFile(get_data_file_path("ProvisionsChalutier.zip"), 'r') as zip: - zip.extractall(path=addon_dir) - logging.info("Please make sure you enable \"Allow outdated addons\" in-game\n" - "Also, make sure the addon is visible clearly on top left corner of the game window") + try: + user = os.path.expanduser("~") + addon_dir = os.path.join(user, "Documents", "Elder Scrolls Online", "live", "Addons") + if not os.path.exists(os.path.join(addon_dir, 'ProvisionsChalutier')): + logging.info("Addon not found, installing it...") + with ZipFile(get_data_file_path("ProvisionsChalutier.zip"), 'r') as zip: + zip.extractall(path=addon_dir) + logging.info("Please make sure you enable \"Allow outdated addons\" in-game\n" + "Also, make sure the addon is visible clearly on top left corner of the game window") + except Exception: + print("couldn't install addon, try doing it manually") diff --git a/requirements.txt b/requirements.txt index 57dc77e..aff8dc7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ ttkthemes pyautogui requests beautifulsoup4 +whatsmyip