Siterizer / new-world-fishing-bot

user friendly python script who is able to catch fish in the game New World
GNU General Public License v3.0
294 stars 124 forks source link

[Suggestion] Better and more simplistic logging #226

Closed cobra-7777 closed 2 years ago

cobra-7777 commented 2 years ago

image

So for all of you that like running the bot for a few hours at a time, it can be really hard to figure out what happened if the bot unexpectedly stops, your character dies, or you get disconnected. Im gonna show you how you can make a few small changes to make it much easier to see:

Youll have to be running the bot in a Python virtual environment, or make your own EXE if you wanna make these changes yourself. If you cant, maybe Siterizer will implement something like this at some point (but the poor man must be busy with all these suggestions, so cut him some slack :D).

First of all, and the easiest change you can make to make logging much better: Displaying the current time instead of [INFO].

For this, we have to go to logging_wrapper.py Change the following line from:

format="[%(levelname)s] %(message)s",

to

format="[%(asctime)s] %(message)s",

Thats the time done!

Now lets do counters in fishing_actions.py:

At the very top, under all the imports, add the two new variables:

from win32api import mouse_event
from utils.config import dict, random_timeout
from time import sleep
from wrappers.win32api_wrapper import *
from wrappers.logging_wrapper import info, debug
import utils.global_variables as gv
import random

fish_counter=0
cast_counter=0

Make sure that you add 'info' to the import from loggingwrapper, like so:

from wrappers.logging_wrapper import info, debug

Now add two lines to the bottom of your fish_notice() function, dont forget the top line too, 'global fish_counter':

def fish_notice():
    global fish_counter
    notice_timeout = random_timeout(dict['fishing']['timeouts']['notice'])
    debug("Press mouse key for: {} s".format(notice_timeout))
    press_mouse_key()
    sleep(notice_timeout)
    release_mouse_key()
    fish_counter = fish_counter + 1
    info("The Bot Has Caught (" + str(fish_counter-1) + ") Fish!")

And at the very start of our cast() function:

def cast():
    global cast_counter
    cast_counter = cast_counter + 1
    info("Casting Fishing Rod... This Is Cast Number (" + str(cast_counter) + ")")

Inside fishing_loop.py, change the following from 'info' to 'debug'

info("Cast fishing rod") to debug("Cast fishing rod")

This hides the default cast message, since we just made our own! You can also delete it entirely, if you dont want it to show in debug.

And thats all for our counters!

Now lets clean up the logging a little bit, and make it more simplistic.

In fishing_actions.py, you want to change 'info' to 'debug' on the following lines:

45: debug("Green color spotted, Reeling a fish")

53: debug("Orange color spotted, Pause fishing")

57: debug("Red color spotted, Pause fishing")

No more spammy reeling messages! However, now the bot prints nothing when its reeling.

So lets make it print "Reeling a fish", but only once each time it reels!

At the very bottom of global_variables.py, add the following:

hasReel=False

In fishing_loop.py, add our new boolean to the 1st result_from_model function:

    elif result_from_model == '1': # 1 - model noticed a fish(left click to initiate fishing)
        info("Found a fish!")
        gv.hasReel=True
        fish_notice()
        return '1'

In fishing_loop.py, also add our new boolean to the 5th result_from_model function, this time setting it to false:

    elif result_from_model == '5': #5 - model did not match anything (left click, wait x sec)
        debug("Cast fishing rod")
        gv.hasReel=False
        cast()
        return '5'

Now inside fishing_actions.py, add the following import at the top:

import utils.global_variables as gv

Inside fishing_actions.py, we want our reel function to look like this:

def reel_fish():
    reel_timeout = random_timeout(dict['fishing']['timeouts']['reeling'])
    debug("Press mouse key for: {} s".format(reel_timeout))

    if(gv.hasReel == False):
        info("Reeling A Fish...")

    press_mouse_key()
    sleep(reel_timeout)
    release_mouse_key()

Now we only get one message each time the bot reels! If you want to see the bot print every time it detects a color however, you can change the logging level in config.yml to DEBUG.

Hope this helps you get a better overview of what the bot is doing. Theres much more you can do with this, but what I've shown here will make it look similar to the screenshot attached here. Happy fishing!

Siterizer commented 2 years ago

Sorry, end of the support. Statement: https://github.com/Siterizer/new-world-fishing-bot#new-world-fishing-bot-end-of-support