Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Bot For Code Cleanliness, Improved Performance, and Overall Usability #213

Merged
merged 16 commits into from Nov 4, 2021

Conversation

srhinos
Copy link
Contributor

@srhinos srhinos commented Oct 27, 2021

This implements several improvements found in other PRs on this repository. I also took it upon myself to refactor the bot to use Asyncio to juggle tasks on the backend and threading to seperate the GUI from said backend. This means no issues with locked GUI.

I refactored out a lot of the really egregious design decisions up to a certain point and did a half assed job merging and removing a lot of unnecessary bloat. Theres still a LOT of room for improvement too now that the CV is running on asyncio too. I'm sure I'll eventually add it but this is what I felt like doing tonight.

Edit: To clairfy, this also integrates the following active PRs as well:
#208
#164
#134
#106

@JKamsker
Copy link

Thanks! I will try it out today when im home :)

@Pookiemon
Copy link

GJ on all the edits but i cant seem to get it to run =[ this is the error i get. not sure how to fix it yet.. i have a feeling its due to not finding the reference LastResults

[DEBUG] starting new loop [DEBUG] starting new loop [INFO] Cast fishing rod [DEBUG] Pause for: 6 s [DEBUG] release b [ERROR] Task exception was never retrieved future: <Task finished name='fishing_loop' coro=<fishing_loop() done, defined at C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py:10> exception=AttributeError("'dict' object has no attribute 'run_in_executor'")> Traceback (most recent call last): File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 22, in fishing_loop last_results.add(await call_appropriate_fishing_action(ctx, last_results)) File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 77, in call_appropriate_fishing_action await cast(ctx) File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_actions.py", line 50, in cast await release_key(ctx, "b") File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\wrappers\win32api_wrapper.py", line 40, in release_key await loop.run_in_executor( AttributeError: 'dict' object has no attribute 'run_in_executor'

@srhinos
Copy link
Contributor Author

srhinos commented Oct 27, 2021

GJ on all the edits but i cant seem to get it to run =[ this is the error i get. not sure how to fix it yet.. i have a feeling its due to not finding the reference LastResults

`[DEBUG] starting new loop

[DEBUG] starting new loop

[INFO] Cast fishing rod

[DEBUG] Pause for: 6 s

[DEBUG] release b

[ERROR] Task exception was never retrieved

future: <Task finished name='fishing_loop' coro=<fishing_loop() done, defined at C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py:10> exception=AttributeError("'dict' object has no attribute 'run_in_executor'")>

Traceback (most recent call last):

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 22, in fishing_loop

last_results.add(await call_appropriate_fishing_action(ctx, last_results))

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 77, in call_appropriate_fishing_action

await cast(ctx)

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_actions.py", line 50, in cast

await release_key(ctx, "b")

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\wrappers\win32api_wrapper.py", line 40, in release_key

await loop.run_in_executor(

AttributeError: 'dict' object has no attribute 'run_in_executor'`

Thanks for error msg! I did like six mini refactors of various scales while implementing asynchronous stuff so just missed a rename before pushing, lemme fix rq

@Pookiemon
Copy link

GJ on all the edits but i cant seem to get it to run =[ this is the error i get. not sure how to fix it yet.. i have a feeling its due to not finding the reference LastResults
`[DEBUG] starting new loop
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s
[DEBUG] release b
[ERROR] Task exception was never retrieved
future: <Task finished name='fishing_loop' coro=<fishing_loop() done, defined at C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py:10> exception=AttributeError("'dict' object has no attribute 'run_in_executor'")>
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 22, in fishing_loop

last_results.add(await call_appropriate_fishing_action(ctx, last_results))

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 77, in call_appropriate_fishing_action

await cast(ctx)

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_actions.py", line 50, in cast

await release_key(ctx, "b")

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\wrappers\win32api_wrapper.py", line 40, in release_key

await loop.run_in_executor(

AttributeError: 'dict' object has no attribute 'run_in_executor'`

Thanks for error msg! I did like six mini refactors of various scales while implementing asynchronous stuff so just missed a rename before pushing, lemme fix rq

roger that will test once you push the update =]

@NewWorldDev
Copy link

#206 fixes the GUI freezing bug FYI

@srhinos
Copy link
Contributor Author

srhinos commented Oct 27, 2021

#206 fixes the GUI freezing bug FYI

I saw but it doesn't really fix freezing GUI, it just solves for how to work around it. This completely solves freezing GUI and can still integrate in keybinds in a less hacky way since I can forcefully cancel the fishing loop anywhere in the UI now

@srhinos
Copy link
Contributor Author

srhinos commented Oct 27, 2021

GJ on all the edits but i cant seem to get it to run =[ this is the error i get. not sure how to fix it yet.. i have a feeling its due to not finding the reference LastResults
`[DEBUG] starting new loop
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s
[DEBUG] release b
[ERROR] Task exception was never retrieved
future: <Task finished name='fishing_loop' coro=<fishing_loop() done, defined at C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py:10> exception=AttributeError("'dict' object has no attribute 'run_in_executor'")>
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 22, in fishing_loop

last_results.add(await call_appropriate_fishing_action(ctx, last_results))

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_loop.py", line 77, in call_appropriate_fishing_action

await cast(ctx)

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\functionality\fishing_actions.py", line 50, in cast

await release_key(ctx, "b")

File "C:\Users\Admin\Desktop\new-world-fishing-bot-main\wrappers\win32api_wrapper.py", line 40, in release_key

await loop.run_in_executor(

AttributeError: 'dict' object has no attribute 'run_in_executor'`

Thanks for error msg! I did like six mini refactors of various scales while implementing asynchronous stuff so just missed a rename before pushing, lemme fix rq

roger that will test once you push the update =]

Fixed!

@Pookiemon
Copy link

Not sure if others having this issue.. it loads and runs but the loop just does not work properly for me.

[DEBUG] starting new loop
[DEBUG] starting new loop
[INFO] Found a fish!
[DEBUG] Press mouse key for: 1.86 s
[DEBUG] starting new loop
[DEBUG] starting new loop
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s
[DEBUG] release b
[DEBUG] Pause for: 1 s
[DEBUG] Pause for: 0.21 s
[DEBUG] Pause for: 4 s
[DEBUG] press b
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s
[DEBUG] release b
[DEBUG] Pause for: 1 s
[DEBUG] Pause for: 0.19 s
[DEBUG] Pause for: 4 s
[DEBUG] press b
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s

it just says in a casting cycle it will cast wait a few seconds then reel in and repeat never getting a fish.

@srhinos
Copy link
Contributor Author

srhinos commented Oct 28, 2021

Not sure if others having this issue.. it loads and runs but the loop just does not work properly for me.

[DEBUG] starting new loop
[DEBUG] starting new loop
[INFO] Found a fish!
[DEBUG] Press mouse key for: 1.86 s
[DEBUG] starting new loop
[DEBUG] starting new loop
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s
[DEBUG] release b
[DEBUG] Pause for: 1 s
[DEBUG] Pause for: 0.21 s
[DEBUG] Pause for: 4 s
[DEBUG] press b
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s
[DEBUG] release b
[DEBUG] Pause for: 1 s
[DEBUG] Pause for: 0.19 s
[DEBUG] Pause for: 4 s
[DEBUG] press b
[DEBUG] starting new loop
[INFO] Cast fishing rod
[DEBUG] Pause for: 6 s

it just says in a casting cycle it will cast wait a few seconds then reel in and repeat never getting a fish.

I changed the base images that image detection is done off of, I need to revert those changes since they were specific to my set up. Suggest also reverting specifically those images

@srhinos
Copy link
Contributor Author

srhinos commented Oct 28, 2021

Just reverted the resouce changes I made to config.yml and the resource images, also cloned the jpg fish into the png as well since they essentially act as the same thing, I just got better results with transparency involved.

@Siterizer Siterizer added this to Backlog in Issues Oct 28, 2021
@Siterizer Siterizer moved this from Backlog to In progress in Issues Oct 28, 2021
@Siterizer Siterizer self-assigned this Oct 28, 2021
@Siterizer Siterizer added the enhancement New feature or request label Oct 28, 2021
@Siterizer
Copy link
Owner

@srhinos Idk how you did this but it's working like a charm! Will try to understand this, maybe make some improvements and will let you know

@cobra-7777
Copy link

cobra-7777 commented Oct 28, 2021

Mine is not very happy :D When i press "start fishing" it spits this out.

bot.py:114: RuntimeWarning: coroutine 'fishing_loop' was never awaited
  self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[ERROR] Exception in callback FishingBoi.do_create_task()
handle: <Handle FishingBoi.do_create_task()>
Traceback (most recent call last):
  File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37\lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "bot.py", line 114, in do_create_task
    self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop")
TypeError: create_task() got an unexpected keyword argument 'name'

Looks like its not too happy with the 'name' in this function?

    def do_create_task(self):
        self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop")

EDIT:
Removing name="fishing_loop" entirely gets rid of the error, however idk if it has broken the bot. It can start fishing but does a really really poor job at recognizing anything. It was able to hook a fish once, but didnt reel it. Other than that it just doesnt click whenever a fish bites the line.

@srhinos
Copy link
Contributor Author

srhinos commented Oct 28, 2021 via email

@cobra-7777
Copy link

cobra-7777 commented Oct 28, 2021

So the changes I’ve made cause the minimum python version to run this to be 3.8, highly suggest installing the most recent version of python regardless but yeah, without the name variable for the task, we can’t search for it and cancel it to stop it.

On Oct 28, 2021 at 08:25, <syntax001 @.***)> wrote: Mine is not very happy :D When i press "start fishing" it spits this out. bot.py:114: RuntimeWarning: coroutine 'fishing_loop' was never awaited self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop") RuntimeWarning: Enable tracemalloc to get the object allocation traceback [ERROR] Exception in callback FishingBoi.do_create_task() handle: <Handle FishingBoi.do_create_task()> Traceback (most recent call last): File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37\lib\asyncio\events.py", line 88, in _run self._context.run(self._callback, *self._args) File "bot.py", line 114, in do_create_task self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop") TypeError: create_task() got an unexpected keyword argument 'name' Looks like its not too happy with the 'name' in this function? def do_create_task(self): self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop") — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (#213 (comment)), or unsubscribe (https://github.com/notifications/unsubscribe-auth/ABR2SQMTY4V3CMVNTPQSO6DUJF2QVANCNFSM5GZ3BNOQ). Triage notifications on the go with GitHub Mobile for iOS (https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or Android (https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub).

Ah dang, I'll try Python 3,8. But do you think having Python 3.7.7 also made the image recognition mess up? After removing name="fishing_loop" i wasnt able to stop the bot via the button as you said, but the bot had a lot of trouble recognizing when a fish had bit the line, and when to reel.

@srhinos
Copy link
Contributor Author

srhinos commented Oct 28, 2021 via email

@cobra-7777
Copy link

You need to make sure you match the recommended settings that are mentioned in the readme or do what I did and manually take screenshots + replace the current ones with ones based on your own brightness and everything (which is a lot of effort!)

On Oct 28, 2021 at 10:00, <syntax001 @.)> wrote: > > > So the changes I’ve made cause the minimum python version to run this to be 3.8, highly suggest installing the most recent version of python regardless but yeah, without the name variable for the task, we can’t search for it and cancel it to stop it. > … (#) > On Oct 28, 2021 at 08:25, <syntax001 @.)> wrote: Mine is not very happy :D When i press "start fishing" it spits this out. bot.py:114: RuntimeWarning: coroutine 'fishing_loop' was never awaited self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop") RuntimeWarning: Enable tracemalloc to get the object allocation traceback [ERROR] Exception in callback FishingBoi.do_create_task() handle: <Handle FishingBoi.do_create_task()> Traceback (most recent call last): File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37\lib\asyncio\events.py", line 88, in _run self._context.run(self._callback, *self._args) File "bot.py", line 114, in do_create_task self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop") TypeError: create_task() got an unexpected keyword argument 'name' Looks like its not too happy with the 'name' in this function? def do_create_task(self): self.asyncio_event_loop.create_task(fishing_loop(self.config), name="fishing_loop") — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (#213 (comment) (#213 (comment))), or unsubscribe (https://github.com/notifications/unsubscribe-auth/ABR2SQMTY4V3CMVNTPQSO6DUJF2QVANCNFSM5GZ3BNOQ). Triage notifications on the go with GitHub Mobile for iOS (https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or Android (https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub). > > Ah dang, I'll try Python 3,8. But do you think having Pythong 3.7.7 also made the image recognition mess up? After removing name="fishing_loop" i wasnt able to stop the bot via the button as you said, but the bot had a lot of trouble recognizing when a fish had bit the line, and when to reel. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (#213 (comment)), or unsubscribe (https://github.com/notifications/unsubscribe-auth/ABR2SQL3LMERE2NO2PUI4FLUJGFSBANCNFSM5GZ3BNOQ). Triage notifications on the go with GitHub Mobile for iOS (https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or Android (https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub).

My settings should be all good, im running Siterizers version perfectly fine. I just thought i'd clone yours and give it a try but it seems to be really off. Are the pictures the same as the ones provided by Siterizer? Ill give it a try with his pictures instead and see if it makes a difference.

@blablub84
Copy link

can anyone share a compiled version?
otherwise as long as i apply the changes to the 27 files, and use pyton 3.8 i should be fine with the old compile guide?

@srhinos
Copy link
Contributor Author

srhinos commented Oct 29, 2021 via email

@Siterizer
Copy link
Owner

@srhinos @blablub84 There are some errors in this version, will try to fix them now

@Siterizer
Copy link
Owner

Okay, new release is here.
Code: https://github.com/Siterizer/new-world-fishing-bot/tree/v2.0.0
Compiled .zip: https://github.com/Siterizer/new-world-fishing-bot/releases/tag/v2.0.0

Tested it for about an hour and it's working. But will be glad about your feedback

@srhinos
Copy link
Contributor Author

srhinos commented Oct 29, 2021 via email

@ComictypX
Copy link
Contributor

Nice work @srhinos! I was also wondering if the templatematching would be faster if we switch to greyscale.

But I see that you are not using the latest version of PR #134. In commit dcaf9c4 I already added support for 16:10, 21:9 and 32:9 aspect ratios.

This is also missing in the 2.0.0 Branch @Siterizer :)

@Sevenn56
Copy link

Sevenn56 commented Nov 1, 2021

Hello buddies ! I have to admit that i'm a begginer and i dont know how to modify or use your version ? Can you do à step by step to show me ? Or add me discord Seven#9428
Thanks buddies

@tallglen
Copy link

tallglen commented Nov 3, 2021

Okay, new release is here. Code: https://github.com/Siterizer/new-world-fishing-bot/tree/v2.0.0 Compiled .zip: https://github.com/Siterizer/new-world-fishing-bot/releases/tag/v2.0.0

Tested it for about an hour and it's working. But will be glad about your feedback

When I do a code compare between v2.0.0 and v1.2.1, the only change I see is to the README.md

I've been testing the 2 major PRs and happy to see that we have multithreading now and no more "Not Responding" problems with the GUI or inability to stop/pause fishing.

Testing srhinos' PR (main), my fish detection fails every other cast but otherwise hooks the fish almost immediately whereas the vanilla experience was a bit of randomness as to how fast it would hook the fish.

Testing NewWorldDev's PR (feature/pause-hotkey) I've had more consistent successful hooks with; nice work with the in-window stats and colorization. @NewWorldDev have you thought about ways to animation cancel the flourish that happens when fish are caught?

@Siterizer Siterizer merged commit 6a4027c into Siterizer:main Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Issues
In progress
Development

Successfully merging this pull request may close these issues.

None yet

10 participants