made config global

This commit is contained in:
Adam Saudagar 2020-10-18 00:36:07 +05:30
parent c63ff4c3ba
commit 51560f26d9
20 changed files with 92 additions and 88 deletions

View File

@ -10,7 +10,8 @@ import fishy
from fishy import web, helper, gui from fishy import web, helper, gui
from fishy.engine.common.event_handler import EngineEventHandler from fishy.engine.common.event_handler import EngineEventHandler
from fishy.gui import GUI, splash from fishy.gui import GUI, splash
from fishy.helper import Config, hotkey from fishy.helper import hotkey
from fishy.helper.config import config
def check_window_name(title): def check_window_name(title):
@ -22,11 +23,11 @@ def check_window_name(title):
# noinspection PyBroadException # noinspection PyBroadException
def initialize(c: Config, window_to_hide): def initialize(window_to_hide):
helper.create_shortcut_first(c) helper.create_shortcut_first()
helper.initialize_uid(c) helper.initialize_uid()
new_session = web.get_session(c) new_session = web.get_session()
if new_session is None: if new_session is None:
logging.error("Couldn't create a session, some features might not work") logging.error("Couldn't create a session, some features might not work")
print(f"created session {new_session}") print(f"created session {new_session}")
@ -44,14 +45,14 @@ def initialize(c: Config, window_to_hide):
except Exception: except Exception:
logging.error(traceback.format_exc()) logging.error(traceback.format_exc())
if not c.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)): if not config.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)):
win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE) win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE)
helper.install_thread_excepthook() helper.install_thread_excepthook()
sys.excepthook = helper.unhandled_exception_logging sys.excepthook = helper.unhandled_exception_logging
helper.check_addon("ProvisionsChalutier") helper.check_addon("ProvisionsChalutier")
if c.get("debug", False): if config.get("debug", False):
helper.check_addon("FooAddon") helper.check_addon("FooAddon")
@ -63,20 +64,19 @@ def main():
pil_logger.setLevel(logging.INFO) pil_logger.setLevel(logging.INFO)
window_to_hide = win32gui.GetForegroundWindow() window_to_hide = win32gui.GetForegroundWindow()
c = Config()
if not gui.check_eula(c): if not gui.check_eula():
return return
bot = EngineEventHandler(c, lambda: gui_window) bot = EngineEventHandler(lambda: gui_window)
gui_window = GUI(c, lambda: bot) gui_window = GUI(lambda: bot)
hotkey.initalize() hotkey.initalize()
gui_window.start() gui_window.start()
logging.info(f"Fishybot v{fishy.__version__}") logging.info(f"Fishybot v{fishy.__version__}")
initialize(c, window_to_hide) initialize(window_to_hide)
bot.start_event_handler() bot.start_event_handler()

View File

@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
from threading import Thread from threading import Thread
from typing import Callable from typing import Callable
from fishy.gui.funcs import GUIFuncs, GUIFuncsMock from fishy.gui.funcs import GUIFuncsMock
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from fishy.gui import GUI from fishy.gui import GUI
@ -11,12 +11,11 @@ if typing.TYPE_CHECKING:
class IEngine(ABC): class IEngine(ABC):
def __init__(self, config, gui_ref: 'Callable[[], GUI]'): def __init__(self, gui_ref: 'Callable[[], GUI]'):
self.get_gui = gui_ref self.get_gui = gui_ref
self.start = False self.start = False
self.window = None self.window = None
self.thread = None self.thread = None
self.config = config
@property @property
def gui(self): def gui(self):

View File

@ -4,12 +4,12 @@ from fishy.engine.fullautofisher.engine import FullAuto
class EngineEventHandler: class EngineEventHandler:
def __init__(self, config, gui_ref): def __init__(self, gui_ref):
self.event_handler_running = True self.event_handler_running = True
self.event = [] self.event = []
self.semi_fisher_engine = SemiFisherEngine(config, gui_ref) self.semi_fisher_engine = SemiFisherEngine(gui_ref)
self.full_fisher_engine = FullAuto(config, gui_ref) self.full_fisher_engine = FullAuto(gui_ref)
def start_event_handler(self): def start_event_handler(self):
while self.event_handler_running: while self.event_handler_running:

View File

@ -1,5 +1,4 @@
import logging import logging
from enum import Enum
from typing import List from typing import List
import cv2 import cv2
@ -82,7 +81,6 @@ class WindowClient:
""" """
Displays the processed image for debugging purposes Displays the processed image for debugging purposes
:param ready_img: send ready image, just show the `ready_img` directly :param ready_img: send ready image, just show the `ready_img` directly
:param name: unique name for the image, used to create a new window
:param resize: scale the image to make small images more visible :param resize: scale the image to make small images more visible
:param func: function to process the image :param func: function to process the image
""" """

View File

@ -12,6 +12,7 @@ from win32api import GetSystemMetrics
import numpy as np import numpy as np
from PIL import ImageGrab from PIL import ImageGrab
from fishy.helper.config import config
class Status(Enum): class Status(Enum):
@ -31,7 +32,7 @@ class WindowServer:
status = Status.STOPPED status = Status.STOPPED
def init(borderless: bool): def init():
""" """
Executed once before the main loop, Executed once before the main loop,
Finds the game window, and calculates the offset to remove the title bar Finds the game window, and calculates the offset to remove the title bar
@ -42,7 +43,7 @@ def init(borderless: bool):
client_rect = win32gui.GetClientRect(WindowServer.hwnd) client_rect = win32gui.GetClientRect(WindowServer.hwnd)
WindowServer.windowOffset = math.floor(((rect[2] - rect[0]) - client_rect[2]) / 2) WindowServer.windowOffset = math.floor(((rect[2] - rect[0]) - client_rect[2]) / 2)
WindowServer.titleOffset = ((rect[3] - rect[1]) - client_rect[3]) - WindowServer.windowOffset WindowServer.titleOffset = ((rect[3] - rect[1]) - client_rect[3]) - WindowServer.windowOffset
if borderless: if config.get("borderless"):
WindowServer.titleOffset = 0 WindowServer.titleOffset = 0
WindowServer.status = Status.RUNNING WindowServer.status = Status.RUNNING
except pywintypes.error: except pywintypes.error:
@ -93,7 +94,7 @@ def start():
if WindowServer.status == Status.RUNNING: if WindowServer.status == Status.RUNNING:
return return
init(False) init()
if WindowServer.status == Status.RUNNING: if WindowServer.status == Status.RUNNING:
Thread(target=run).start() Thread(target=run).start()

View File

@ -1,12 +1,12 @@
import math import math
import logging import logging
import time import time
from threading import Thread
from fishy.engine.fullautofisher.engine import FullAuto from fishy.engine.fullautofisher.engine import FullAuto
from pynput import keyboard, mouse from pynput import keyboard, mouse
from fishy.helper import hotkey from fishy.helper import hotkey
from fishy.helper.config import config
from fishy.helper.helper import wait_until from fishy.helper.helper import wait_until
from fishy.helper.hotkey import Key from fishy.helper.hotkey import Key
@ -85,7 +85,7 @@ class Calibrate():
time_to_reach_bottom = time.time() - y_cal_start_time time_to_reach_bottom = time.time() - y_cal_start_time
self.engine.factors = move_factor, rot_factor, time_to_reach_bottom self.engine.factors = move_factor, rot_factor, time_to_reach_bottom
self.engine.config.set("full_auto_factors", self.engine.factors) config.set("full_auto_factors", self.engine.factors)
logging.info(self.engine.factors) logging.info(self.engine.factors)
hotkey.free_key(Key.F8) hotkey.free_key(Key.F8)

View File

@ -5,17 +5,17 @@ import logging
import time import time
import numpy as np import numpy as np
import pywintypes
import pytesseract import pytesseract
from fishy.engine import SemiFisherEngine from fishy.engine import SemiFisherEngine
from fishy.engine.common.window import WindowClient from fishy.engine.common.window import WindowClient
from fishy.engine.semifisher import fishing_event, fishing_mode from fishy.engine.semifisher import fishing_mode
from fishy.engine.common.IEngine import IEngine from fishy.engine.common.IEngine import IEngine
from pynput import keyboard, mouse from pynput import keyboard, mouse
from fishy.helper import Config, hotkey from fishy.helper import hotkey
from fishy.helper.config import config
from fishy.helper.hotkey import Key from fishy.helper.hotkey import Key
mse = mouse.Controller() mse = mouse.Controller()
@ -78,9 +78,9 @@ def unassign_keys():
class FullAuto(IEngine): class FullAuto(IEngine):
rotate_by = 30 rotate_by = 30
def __init__(self, config, gui_ref): def __init__(self, gui_ref):
super().__init__(config, gui_ref) super().__init__(gui_ref)
self.factors = self.config.get("full_auto_factors", None) self.factors = config.get("full_auto_factors", None)
self._tesseract_dir = None self._tesseract_dir = None
self._target = None self._target = None
@ -96,7 +96,7 @@ class FullAuto(IEngine):
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug") self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
self.window.crop = get_crop_coods(self.window) self.window.crop = get_crop_coods(self.window)
self._tesseract_dir = self.config.get("tesseract_dir", None) self._tesseract_dir = config.get("tesseract_dir", None)
if self._tesseract_dir is None: if self._tesseract_dir is None:
logging.warning("Can't start without Tesseract Directory") logging.warning("Can't start without Tesseract Directory")
@ -189,7 +189,7 @@ class FullAuto(IEngine):
def set_target(self): def set_target(self):
t = self.get_coods()[:-1] t = self.get_coods()[:-1]
self.config.set("target", t) config.set("target", t)
print(f"target_coods are {t}") print(f"target_coods are {t}")
def initalize_keys(self): def initalize_keys(self):
@ -213,9 +213,8 @@ class FullAuto(IEngine):
if __name__ == '__main__': if __name__ == '__main__':
logging.getLogger("").setLevel(logging.DEBUG) logging.getLogger("").setLevel(logging.DEBUG)
# noinspection PyTypeChecker # noinspection PyTypeChecker
c = Config() bot = FullAuto(None)
bot = FullAuto(c, None) fisher = SemiFisherEngine(None)
fisher = SemiFisherEngine(c, None)
hotkey.initalize() hotkey.initalize()
fisher.toggle_start() fisher.toggle_start()
bot.toggle_start() bot.toggle_start()

View File

@ -1,9 +1,6 @@
import json
import logging import logging
import pickle import pickle
import time from tkinter.filedialog import askopenfile
from threading import Thread
from tkinter.filedialog import asksaveasfile, askopenfile
from fishy.engine.fullautofisher.engine import FullAuto from fishy.engine.fullautofisher.engine import FullAuto

View File

@ -1,8 +1,6 @@
import json
import logging import logging
import pickle import pickle
import time import time
from threading import Thread
from tkinter.filedialog import asksaveasfile from tkinter.filedialog import asksaveasfile
from fishy.engine.fullautofisher.engine import FullAuto from fishy.engine.fullautofisher.engine import FullAuto

View File

@ -20,8 +20,8 @@ if typing.TYPE_CHECKING:
class SemiFisherEngine(IEngine): class SemiFisherEngine(IEngine):
def __init__(self, config, gui_ref: 'Callable[[], GUI]'): def __init__(self, gui_ref: 'Callable[[], GUI]'):
super().__init__(config, gui_ref) super().__init__(gui_ref)
self.fishPixWindow = None self.fishPixWindow = None
def run(self): def run(self):
@ -76,6 +76,6 @@ class SemiFisherEngine(IEngine):
if __name__ == '__main__': if __name__ == '__main__':
logging.getLogger("").setLevel(logging.DEBUG) logging.getLogger("").setLevel(logging.DEBUG)
# noinspection PyTypeChecker # noinspection PyTypeChecker
fisher = SemiFisherEngine(None, None) fisher = SemiFisherEngine(None)
fisher.toggle_start() fisher.toggle_start()

View File

@ -14,6 +14,8 @@ from fishy.engine.semifisher.fishing_mode import State
from fishy.helper import helper from fishy.helper import helper
import keyboard import keyboard
from fishy.helper.config import config
class FishEvent: class FishEvent:
fishCaught = 0 fishCaught = 0
@ -34,6 +36,9 @@ class FishEvent:
def init(): def init():
# todo load config # todo load config
fishing_mode.subscribers.append(fisher_callback) fishing_mode.subscribers.append(fisher_callback)
FishEvent.action_key = config.get("action_key", 'e')
FishEvent.uid = config.get("uid")
FishEvent.sound = config.get("sound_notification", False)
def destroy(): def destroy():

View File

@ -6,6 +6,7 @@ from fishy.gui.notification import _give_notification_link
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
from fishy.helper.config import config
from fishy.helper.popup import PopUp from fishy.helper.popup import PopUp
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
@ -14,8 +15,8 @@ if typing.TYPE_CHECKING:
def start_fullfisher_config(gui: 'GUI'): def start_fullfisher_config(gui: 'GUI'):
def save(): def save():
gui._config.set("tesseract_dir", tesseract_entry.get(), False) gui.config.set("tesseract_dir", tesseract_entry.get(), False)
gui._config.save_config() gui.config.save_config()
top = PopUp(save, gui._root, background=gui._root["background"]) top = PopUp(save, gui._root, background=gui._root["background"])
controls_frame = Frame(top) controls_frame = Frame(top)
@ -23,7 +24,7 @@ def start_fullfisher_config(gui: 'GUI'):
Label(controls_frame, text="Tesseract Directory:").grid(row=0, column=0) Label(controls_frame, text="Tesseract Directory:").grid(row=0, column=0)
tesseract_entry = Entry(controls_frame, justify=CENTER) tesseract_entry = Entry(controls_frame, justify=CENTER)
tesseract_entry.insert(0, gui._config.get("tesseract_dir", "")) tesseract_entry.insert(0, config.get("tesseract_dir", ""))
tesseract_entry.grid(row=0, column=1) tesseract_entry.grid(row=0, column=1)
controls_frame.pack(padx=(5, 5), pady=(5, 5)) controls_frame.pack(padx=(5, 5), pady=(5, 5))
@ -32,10 +33,10 @@ def start_fullfisher_config(gui: 'GUI'):
def start_semifisher_config(gui: 'GUI'): def start_semifisher_config(gui: 'GUI'):
def save(): def save():
gui._config.set("action_key", action_key_entry.get(), False) gui.config.set("action_key", action_key_entry.get(), False)
gui._config.set("borderless", borderless.instate(['selected']), False) gui.config.set("borderless", borderless.instate(['selected']), False)
gui._config.set("sound_notification", sound.instate(['selected']), False) gui.config.set("sound_notification", sound.instate(['selected']), False)
gui._config.save_config() gui.config.save_config()
top = PopUp(save, gui._root, background=gui._root["background"]) top = PopUp(save, gui._root, background=gui._root["background"])
controls_frame = Frame(top) controls_frame = Frame(top)
@ -48,22 +49,22 @@ def start_semifisher_config(gui: 'GUI'):
variable=gui._notify) variable=gui._notify)
gui._notify_check.grid(row=0, column=1) gui._notify_check.grid(row=0, column=1)
gui._notify_check['state'] = DISABLED gui._notify_check['state'] = DISABLED
is_subbed = web.is_subbed(gui._config.get('uid')) is_subbed = web.is_subbed(config.get('uid'))
if is_subbed[1]: if is_subbed[1]:
gui._notify_check['state'] = NORMAL gui._notify_check['state'] = NORMAL
gui._notify.set(is_subbed[0]) gui._notify.set(is_subbed[0])
Label(controls_frame, text="Fullscreen: ").grid(row=1, column=0, pady=(5, 5)) Label(controls_frame, text="Fullscreen: ").grid(row=1, column=0, pady=(5, 5))
borderless = Checkbutton(controls_frame, var=BooleanVar(value=gui._config.get("borderless"))) borderless = Checkbutton(controls_frame, var=BooleanVar(value=config.get("borderless")))
borderless.grid(row=1, column=1) borderless.grid(row=1, column=1)
Label(controls_frame, text="Action Key:").grid(row=2, column=0) Label(controls_frame, text="Action Key:").grid(row=2, column=0)
action_key_entry = Entry(controls_frame, justify=CENTER) action_key_entry = Entry(controls_frame, justify=CENTER)
action_key_entry.grid(row=2, column=1) action_key_entry.grid(row=2, column=1)
action_key_entry.insert(0, gui._config.get("action_key", "e")) action_key_entry.insert(0, config.get("action_key", "e"))
Label(controls_frame, text="Sound Notification: ").grid(row=3, column=0, pady=(5, 5)) Label(controls_frame, text="Sound Notification: ").grid(row=3, column=0, pady=(5, 5))
sound = Checkbutton(controls_frame, var=BooleanVar(value=gui._config.get("sound_notification"))) sound = Checkbutton(controls_frame, var=BooleanVar(value=config.get("sound_notification")))
sound.grid(row=3, column=1) sound.grid(row=3, column=1)
controls_frame.pack(padx=(5, 5), pady=(5, 5)) controls_frame.pack(padx=(5, 5), pady=(5, 5))

View File

@ -1,6 +1,9 @@
from tkinter import messagebox from tkinter import messagebox
import typing import typing
from fishy.helper.config import config
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from fishy.gui import GUI from fishy.gui import GUI
@ -47,6 +50,6 @@ class GUIFuncs:
def start_engine(self): def start_engine(self):
def start_engine(): def start_engine():
self.gui._config.set("last_started", self.gui._engine_var.get()) config.set("last_started", self.gui._engine_var.get())
self.gui.engines[self.gui._engine_var.get()][1]() self.gui.engines[self.gui._engine_var.get()][1]()
self.gui.call_in_thread(start_engine) self.gui.call_in_thread(start_engine)

View File

@ -1,6 +1,6 @@
import logging import logging
from tkinter import OptionMenu, Button from tkinter import OptionMenu, Button
from typing import List, Callable from typing import List, Callable, Optional
import threading import threading
from ttkthemes import ThemedTk from ttkthemes import ThemedTk
@ -10,18 +10,15 @@ from fishy.gui import config_top
from fishy.gui.funcs import GUIFuncs from fishy.gui.funcs import GUIFuncs
from . import main_gui from . import main_gui
from .log_config import GUIStreamHandler from .log_config import GUIStreamHandler
from fishy.helper import Config from ..helper.config import config
class GUI: class GUI:
def __init__(self, config: Config, get_engine: Callable[[], EngineEventHandler]): def __init__(self, get_engine: Callable[[], EngineEventHandler]):
"""
:param config: used to get and set configuration settings
"""
self.funcs = GUIFuncs(self) self.funcs = GUIFuncs(self)
self.get_engine = get_engine self.get_engine = get_engine
self._config = config self.config = config
self._start_restart = False self._start_restart = False
self._destroyed = True self._destroyed = True
self._log_strings = [] self._log_strings = []
@ -29,13 +26,13 @@ class GUI:
self._bot_running = False self._bot_running = False
# UI items # UI items
self._root: ThemedTk self._root: Optional[ThemedTk] = None
self._console = None self._console = None
self._start_button = None self._start_button = None
self._notify = None self._notify = None
self._notify_check = None self._notify_check = None
self._engine_select: OptionMenu self._engine_select: Optional[OptionMenu] = None
self._config_button: Button self._config_button: Optional[Button] = None
self._engine_var = None self._engine_var = None
self._thread = threading.Thread(target=self.create, args=()) self._thread = threading.Thread(target=self.create, args=())
@ -56,7 +53,7 @@ class GUI:
"Semi Fisher": [lambda: config_top.start_semifisher_config(self), self.engine.toggle_semifisher], "Semi Fisher": [lambda: config_top.start_semifisher_config(self), self.engine.toggle_semifisher],
} }
if self._config.get('debug', False): if config.get('debug', False):
engines["Full-Auto Fisher"] = [lambda: config_top.start_fullfisher_config(self), engines["Full-Auto Fisher"] = [lambda: config_top.start_fullfisher_config(self),
self.engine.toggle_fullfisher] self.engine.toggle_fullfisher]
return engines return engines

View File

@ -10,6 +10,7 @@ from fishy import helper
import typing import typing
from fishy.helper import hotkey from fishy.helper import hotkey
from ..helper.config import config
from ..helper.hotkey import Key from ..helper.hotkey import Key
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
@ -17,7 +18,7 @@ if typing.TYPE_CHECKING:
def _apply_theme(gui: 'GUI'): def _apply_theme(gui: 'GUI'):
dark = gui._config.get("dark_mode", True) dark = config.get("dark_mode", True)
gui._root["theme"] = "equilux" if dark else "breeze" gui._root["theme"] = "equilux" if dark else "breeze"
gui._console["background"] = "#707070" if dark else "#ffffff" gui._console["background"] = "#707070" if dark else "#ffffff"
gui._console["fg"] = "#ffffff" if dark else "#000000" gui._console["fg"] = "#ffffff" if dark else "#000000"
@ -39,11 +40,11 @@ def _create(gui: 'GUI'):
filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True)) filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True))
def _toggle_mode(): def _toggle_mode():
gui._config.set("dark_mode", not gui._config.get("dark_mode", True)) config.set("dark_mode", not config.get("dark_mode", True))
gui._start_restart = True gui._start_restart = True
dark_mode_var = IntVar() dark_mode_var = IntVar()
dark_mode_var.set(int(gui._config.get('dark_mode', True))) dark_mode_var.set(int(config.get('dark_mode', True)))
filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode, filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode,
variable=dark_mode_var) variable=dark_mode_var)
@ -54,10 +55,10 @@ def _create(gui: 'GUI'):
command=lambda: gui.engine.check_pixel_val()) command=lambda: gui.engine.check_pixel_val())
debug_var = IntVar() debug_var = IntVar()
debug_var.set(int(gui._config.get('debug', False))) debug_var.set(int(config.get('debug', False)))
def keep_console(): def keep_console():
gui._config.set("debug", bool(debug_var.get())) config.set("debug", bool(debug_var.get()))
logging.debug("Restart to update the changes") logging.debug("Restart to update the changes")
debug_menu.add_checkbutton(label="Keep Console", command=keep_console, variable=debug_var) debug_menu.add_checkbutton(label="Keep Console", command=keep_console, variable=debug_var)
@ -84,7 +85,7 @@ def _create(gui: 'GUI'):
gui._engine_var = StringVar(start_frame) gui._engine_var = StringVar(start_frame)
labels = list(engines.keys()) labels = list(engines.keys())
last_started = gui._config.get("last_started", labels[0]) last_started = config.get("last_started", labels[0])
gui._engine_select = OptionMenu(start_frame, gui._engine_var, last_started, *labels) gui._engine_select = OptionMenu(start_frame, gui._engine_var, last_started, *labels)
gui._engine_select.pack(side=LEFT) gui._engine_select.pack(side=LEFT)

View File

@ -7,6 +7,7 @@ from fishy import web
import typing import typing
from fishy.libs.tkhtmlview import HTMLLabel from fishy.libs.tkhtmlview import HTMLLabel
from ..helper.config import config
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from . import GUI from . import GUI
@ -14,8 +15,8 @@ if typing.TYPE_CHECKING:
# noinspection PyProtectedMember # noinspection PyProtectedMember
def _give_notification_link(gui: 'GUI'): def _give_notification_link(gui: 'GUI'):
if web.is_subbed(gui._config.get("uid"))[0]: if web.is_subbed(config.get("uid"))[0]:
web.unsub(gui._config.get("uid")) web.unsub(config.get("uid"))
return return
# set notification checkbutton # set notification checkbutton
@ -26,8 +27,8 @@ def _give_notification_link(gui: 'GUI'):
top_running[0] = False top_running[0] = False
def check(): def check():
if web.sub(gui._config.get("uid"), discord_name.get()): if web.sub(config.get("uid"), discord_name.get()):
if web.is_subbed(gui._config.get("uid"), False)[0]: if web.is_subbed(config.get("uid"), False)[0]:
gui._notify.set(1) gui._notify.set(1)
messagebox.showinfo("Note!", "Notification configured successfully!") messagebox.showinfo("Note!", "Notification configured successfully!")
quit_top() quit_top()

View File

@ -5,20 +5,20 @@ from tkinter.ttk import *
from PIL import Image, ImageTk from PIL import Image, ImageTk
from fishy import helper, web from fishy import helper, web
from fishy.helper import Config from fishy.helper.config import config
hyperlinkPattern = re.compile(r'\[(?P<title>.*?)\]\((?P<address>.*?)\)') hyperlinkPattern = re.compile(r'\[(?P<title>.*?)\]\((?P<address>.*?)\)')
def check_eula(config): def check_eula():
if not config.get("eula", False): if not config.get("eula", False):
_run_terms_window(config) _run_terms_window()
return config.get("eula", False) return config.get("eula", False)
return config.get("eula", False) return config.get("eula", False)
def _run_terms_window(config: Config): def _run_terms_window():
def accept(): def accept():
config.set("eula", True) config.set("eula", True)
root.destroy() root.destroy()

View File

@ -54,3 +54,5 @@ class Config:
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(json.dumps(self.config_dict)) f.write(json.dumps(self.config_dict))
config = Config()

View File

@ -18,6 +18,7 @@ import winshell
from fishy import web from fishy import web
from . import Config from . import Config
from .config import config
def not_implemented(): def not_implemented():
@ -43,7 +44,7 @@ def open_web(website):
Thread(target=lambda: webbrowser.open(website, new=2)).start() Thread(target=lambda: webbrowser.open(website, new=2)).start()
def initialize_uid(config: Config): def initialize_uid():
if config.get("uid") is not None: if config.get("uid") is not None:
return return
@ -100,10 +101,10 @@ def manifest_file(rel_path):
return os.path.join(os.path.dirname(fishy.__file__), rel_path) return os.path.join(os.path.dirname(fishy.__file__), rel_path)
def create_shortcut_first(c): def create_shortcut_first():
if not c.get("shortcut_created", False): if not config.get("shortcut_created", False):
create_shortcut(False) create_shortcut(False)
c.set("shortcut_created", True) config.set("shortcut_created", True)
# noinspection PyBroadException # noinspection PyBroadException

View File

@ -5,6 +5,7 @@ from whatsmyip.providers import GoogleDnsProvider
from fishy import helper from fishy import helper
from . import urls from . import urls
from .decorators import fallback, uses_session from .decorators import fallback, uses_session
from ..helper.config import config
_is_subbed = None _is_subbed = None
_session_id = None _session_id = None
@ -79,7 +80,7 @@ def unsub(uid):
@fallback(None) @fallback(None)
def get_session(config, lazy=True): def get_session(lazy=True):
global _session_id global _session_id
if lazy and _session_id is not None: if lazy and _session_id is not None: