- 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
__version__ = "0.3.9"
__version__ = "0.3.10"

View File

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

View File

@ -10,9 +10,8 @@ import pytesseract
from fishy.engine.IEngine import IEngine
from fishy.engine.window import Window
from pynput import keyboard, mouse
from pynput.keyboard import Key
from fishy.helper import Config
from fishy.helper import Config, hotkey
mse = mouse.Controller()
kb = keyboard.Controller()
@ -68,6 +67,12 @@ def get_values_from_image(img, tesseract_dir):
return None
def unassign_keys():
keys = ["up", "down", "left", "right"]
for k in keys:
hotkey.free_key(k)
class FullAuto(IEngine):
def __init__(self, config, gui_ref):
super().__init__(config, gui_ref)
@ -79,6 +84,8 @@ class FullAuto(IEngine):
logging.warning("Please callibrate first")
def run(self):
logging.info("Loading please wait...")
self.initalize_keys()
try:
Window.init(False)
@ -101,15 +108,13 @@ class FullAuto(IEngine):
self.gui.bot_started(True)
logging.info("Controlls:\nUP: Callibrate\nLEFT: Print Coordinates\nDOWN: Set target\nRIGHT: Move to target")
with keyboard.Listener(
on_press=self.on_press,
):
while self.start:
Window.loop()
while self.start:
Window.loop()
# self.window.show("test", func=image_pre_process)
Window.loop_end()
# self.window.show("test", func=image_pre_process)
Window.loop_end()
self.gui.bot_started(False)
unassign_keys()
def get_coods(self):
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')
print("done")
def on_press(self, key):
if key == Key.left:
logging.info(self.get_coods())
elif key == Key.up:
self.callibrate()
elif key == Key.right:
self.move_to(self.config.get("target", None))
elif key == Key.down:
def initalize_keys(self):
hotkey.set_hotkey("left", lambda: logging.info(self.get_coods()))
hotkey.set_hotkey("up", lambda: self.callibrate())
def down():
t = self.get_coods()[:-1]
self.config.set("target", 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__':
logging.getLogger("").setLevel(logging.DEBUG)
# noinspection PyTypeChecker
bot = FullAuto(Config(), None)
hotkey.initalize()
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
from fishy.helper import not_implemented
from fishy.helper import not_implemented, hotkey
if typing.TYPE_CHECKING:
from . import GUI
@ -101,6 +101,8 @@ def _create(gui: 'GUI'):
gui._root.update()
gui._root.minsize(gui._root.winfo_width() + 10, gui._root.winfo_height() + 10)
hotkey.set_hotkey("f9", gui.funcs.start_engine)
def set_destroy():
gui._destroyed = True

View File

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

View File

@ -23,6 +23,10 @@ def not_implemented():
logging.error("Not Implemented")
def empty_function():
pass
def open_web(website):
"""
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))