- auto update fixed

- keyboard ghosting for full auto fixed
This commit is contained in:
DESKTOP-JVKHS7I\Adam 2020-06-26 00:13:53 +05:30
parent cfc41d6a5c
commit decfdfb994
7 changed files with 68 additions and 34 deletions

View File

@ -1,2 +1,2 @@
from fishy.__main__ import main from fishy.__main__ import main
__version__ = "0.3.9" __version__ = "0.3.10"

View File

@ -2,8 +2,8 @@ import ctypes
import logging import logging
import os import os
import sys import sys
import traceback
import keyboard
import win32con import win32con
import win32gui import win32gui
@ -11,7 +11,7 @@ import fishy
from fishy import web, helper, gui from fishy import web, helper, gui
from fishy.engine.event_handler import EngineEventHandler from fishy.engine.event_handler import EngineEventHandler
from fishy.gui import GUI from fishy.gui import GUI
from fishy.helper import Config from fishy.helper import Config, hotkey
# noinspection PyBroadException # noinspection PyBroadException
@ -35,7 +35,7 @@ def initialize(c: Config, window_to_hide):
try: try:
helper.auto_upgrade() helper.auto_upgrade()
except Exception: except Exception:
pass logging.error(traceback.format_exc())
if not c.get("debug", False): if not c.get("debug", False):
win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE) win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE)
@ -60,7 +60,7 @@ def main():
bot = EngineEventHandler(c, lambda: gui_window) bot = EngineEventHandler(c, lambda: gui_window)
gui_window = GUI(c, lambda: bot) gui_window = GUI(c, lambda: bot)
keyboard.add_hotkey("f9", gui_window.funcs.start_engine) hotkey.initalize()
gui_window.start() gui_window.start()

View File

@ -10,9 +10,8 @@ import pytesseract
from fishy.engine.IEngine import IEngine from fishy.engine.IEngine import IEngine
from fishy.engine.window import Window from fishy.engine.window import Window
from pynput import keyboard, mouse from pynput import keyboard, mouse
from pynput.keyboard import Key
from fishy.helper import Config from fishy.helper import Config, hotkey
mse = mouse.Controller() mse = mouse.Controller()
kb = keyboard.Controller() kb = keyboard.Controller()
@ -68,6 +67,12 @@ def get_values_from_image(img, tesseract_dir):
return None return None
def unassign_keys():
keys = ["up", "down", "left", "right"]
for k in keys:
hotkey.free_key(k)
class FullAuto(IEngine): class FullAuto(IEngine):
def __init__(self, config, gui_ref): def __init__(self, config, gui_ref):
super().__init__(config, gui_ref) super().__init__(config, gui_ref)
@ -79,6 +84,8 @@ class FullAuto(IEngine):
logging.warning("Please callibrate first") logging.warning("Please callibrate first")
def run(self): def run(self):
logging.info("Loading please wait...")
self.initalize_keys()
try: try:
Window.init(False) Window.init(False)
@ -101,15 +108,13 @@ class FullAuto(IEngine):
self.gui.bot_started(True) self.gui.bot_started(True)
logging.info("Controlls:\nUP: Callibrate\nLEFT: Print Coordinates\nDOWN: Set target\nRIGHT: Move to target") logging.info("Controlls:\nUP: Callibrate\nLEFT: Print Coordinates\nDOWN: Set target\nRIGHT: Move to target")
with keyboard.Listener( while self.start:
on_press=self.on_press, Window.loop()
):
while self.start:
Window.loop()
# self.window.show("test", func=image_pre_process) # self.window.show("test", func=image_pre_process)
Window.loop_end() Window.loop_end()
self.gui.bot_started(False) self.gui.bot_started(False)
unassign_keys()
def get_coods(self): def get_coods(self):
return get_values_from_image(self.window.processed_image(func=image_pre_process), self.tesseract_dir) return get_values_from_image(self.window.processed_image(func=image_pre_process), self.tesseract_dir)
@ -192,25 +197,22 @@ class FullAuto(IEngine):
kb.release('w') kb.release('w')
print("done") print("done")
def on_press(self, key): def initalize_keys(self):
if key == Key.left: hotkey.set_hotkey("left", lambda: logging.info(self.get_coods()))
logging.info(self.get_coods()) hotkey.set_hotkey("up", lambda: self.callibrate())
elif key == Key.up:
self.callibrate() def down():
elif key == Key.right:
self.move_to(self.config.get("target", None))
elif key == Key.down:
t = self.get_coods()[:-1] t = self.get_coods()[:-1]
self.config.set("target", t) self.config.set("target", t)
print(f"target_coods are {t}") print(f"target_coods are {t}")
hotkey.set_hotkey("down", down)
hotkey.set_hotkey("right", lambda: self.move_to(self.config.get("target", None)))
if __name__ == '__main__': if __name__ == '__main__':
logging.getLogger("").setLevel(logging.DEBUG) logging.getLogger("").setLevel(logging.DEBUG)
# noinspection PyTypeChecker # noinspection PyTypeChecker
bot = FullAuto(Config(), None) bot = FullAuto(Config(), None)
hotkey.initalize()
bot.toggle_start() bot.toggle_start()
with keyboard.Listener(
on_release=bot.on_press,
) as listener:
listener.join()

View File

@ -9,7 +9,7 @@ from fishy import helper
import typing import typing
from fishy.helper import not_implemented from fishy.helper import not_implemented, hotkey
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from . import GUI from . import GUI
@ -101,6 +101,8 @@ def _create(gui: 'GUI'):
gui._root.update() gui._root.update()
gui._root.minsize(gui._root.winfo_width() + 10, gui._root.winfo_height() + 10) gui._root.minsize(gui._root.winfo_width() + 10, gui._root.winfo_height() + 10)
hotkey.set_hotkey("f9", gui.funcs.start_engine)
def set_destroy(): def set_destroy():
gui._destroyed = True gui._destroyed = True

View File

@ -9,7 +9,6 @@ import sys
import urllib.request import urllib.request
from os import execl from os import execl
import pkg_resources
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -46,7 +45,7 @@ def _get_highest_version(index, pkg):
html = urllib.request.urlopen(url) html = urllib.request.urlopen(url)
if html.getcode() != 200: if html.getcode() != 200:
raise Exception # not found raise Exception # not found
soup = BeautifulSoup(html.read(), "html5lib") soup = BeautifulSoup(html.read(), "html.parser")
versions = [] versions = []
for link in soup.find_all('a'): for link in soup.find_all('a'):
text = link.get_text() text = link.get_text()
@ -60,13 +59,13 @@ def _get_highest_version(index, pkg):
return max(versions) return max(versions)
def _get_current_version(pkg): def _get_current_version():
""" """
Gets the current version of the package installed Gets the current version of the package installed
:param pkg: name of the installed package
:return: version normalized :return: version normalized
""" """
return _normalize_version(pkg_resources.get_distribution(pkg).version) import fishy
return _normalize_version(fishy.__version__)
def auto_upgrade(): def auto_upgrade():
@ -78,7 +77,8 @@ def auto_upgrade():
index = "https://pypi.python.org/simple" index = "https://pypi.python.org/simple"
pkg = "fishy" pkg = "fishy"
hightest_version = _get_highest_version(index, pkg) hightest_version = _get_highest_version(index, pkg)
if hightest_version > _get_current_version(pkg): if hightest_version > _get_current_version():
logging.info(f"Updating to v{'.'.join(hightest_version)}, Please Wait...") version = '.'.join([str(x) for x in hightest_version])
logging.info(f"Updating to v{version}, Please Wait...")
subprocess.call(["python", '-m', 'pip', 'install', '--upgrade', 'fishy', '--user']) subprocess.call(["python", '-m', 'pip', 'install', '--upgrade', 'fishy', '--user'])
execl(sys.executable, *([sys.executable] + sys.argv)) execl(sys.executable, *([sys.executable] + sys.argv))

View File

@ -23,6 +23,10 @@ def not_implemented():
logging.error("Not Implemented") logging.error("Not Implemented")
def empty_function():
pass
def open_web(website): def open_web(website):
""" """
Opens a website on browser, Opens a website on browser,

26
fishy/helper/hotkey.py Normal file
View File

@ -0,0 +1,26 @@
import keyboard
from fishy.helper import helper
hotkeys = {"f9": helper.empty_function,
"up": helper.empty_function,
"down": helper.empty_function,
"left": helper.empty_function,
"right": helper.empty_function}
def set_hotkey(key, func):
hotkeys[key] = func
def _run_callback(k):
return lambda: hotkeys[k]()
def free_key(k):
set_hotkey(k, helper.empty_function)
def initalize():
for k in hotkeys.keys():
keyboard.add_hotkey(k, _run_callback(k))