Merge pull request #65 from SemjonKerner/fixup_sound_notify

playsound whenever user interaction is required
This commit is contained in:
Adam Saudagar 2021-05-08 03:25:58 +05:30 committed by GitHub
commit fb76efdca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 51 deletions

View File

@ -1,20 +1,21 @@
import time import time
import typing import typing
import cv2
import logging
from threading import Thread from threading import Thread
from typing import Callable from typing import Callable
from typing import Optional from typing import Optional
from playsound import playsound
import cv2
import logging
from fishy.engine.semifisher.fishing_event import FishEvent
from fishy.engine.common.window import WindowClient from fishy.engine.common.window import WindowClient
from fishy.engine.semifisher.fishing_mode import Colors, FishingMode from fishy.engine.semifisher.fishing_mode import Colors, FishingMode
from fishy.engine.common.IEngine import IEngine from fishy.engine.common.IEngine import IEngine
from fishy.engine.semifisher.fishing_mode import FishingMode
from fishy.engine.semifisher.fishing_event import FishEvent
from fishy.engine.semifisher import fishing_mode, fishing_event from fishy.engine.semifisher import fishing_mode, fishing_event
from fishy.engine.semifisher.pixel_loc import PixelLoc from fishy.engine.semifisher.pixel_loc import PixelLoc
from fishy.helper import helper
from fishy.helper.luaparser import sv_color_extract from fishy.helper.luaparser import sv_color_extract
@ -85,6 +86,9 @@ class SemiFisherEngine(IEngine):
if self.start: if self.start:
self.thread = Thread(target=self.run) self.thread = Thread(target=self.run)
self.thread.start() self.thread.start()
playsound(helper.manifest_file("beep.wav"), False)
else:
helper.playsound_multiple(helper.manifest_file("beep.wav"))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -5,20 +5,17 @@ also implements callbacks which is called when states are changed
""" """
import logging import logging
import time import time
import random
from fishy.engine.semifisher import fishing_mode
from playsound import playsound
from fishy import web
from fishy.engine.semifisher.fishing_mode import State, FishingMode
from fishy.helper import helper
import keyboard import keyboard
from playsound import playsound
from win32gui import GetWindowText, GetForegroundWindow from win32gui import GetWindowText, GetForegroundWindow
from fishy import web
from fishy.engine.semifisher import fishing_mode
from fishy.engine.semifisher.fishing_mode import State, FishingMode
from fishy.helper import helper
from fishy.helper.config import config from fishy.helper.config import config
import random
class FishEvent: class FishEvent:
fishCaught = 0 fishCaught = 0
@ -55,7 +52,7 @@ def if_eso_is_focused(func):
def _sound_and_send_fishy_data(): def _sound_and_send_fishy_data():
if FishEvent.fishCaught > 0: if FishEvent.fishCaught > 0:
web.send_hole_deplete(FishEvent.fishCaught, time.time() - FishEvent.hole_start_time, FishEvent.fish_times) web.send_fish_caught(FishEvent.fishCaught, time.time() - FishEvent.hole_start_time, FishEvent.fish_times)
FishEvent.fishCaught = 0 FishEvent.fishCaught = 0
if FishEvent.sound: if FishEvent.sound:
@ -87,16 +84,16 @@ def subscribe():
def fisher_callback(event: State): def fisher_callback(event: State):
callbacks_map = { callbacks_map = {
State.IDLE: on_idle, State.IDLE: on_idle,
State.LOOKAWAY: on_lookaway, State.LOOKAWAY: on_idle,
State.LOOKING: on_looking, State.LOOKING: on_looking,
State.DEPLETED: on_depleted, State.DEPLETED: on_depleted,
State.NOBAIT: on_nobait, State.NOBAIT: lambda: on_user_interact("You need to equip bait!"),
State.FISHING: on_fishing, State.FISHING: on_fishing,
State.REELIN: on_reelin, State.REELIN: on_reelin,
State.LOOT: on_loot, State.LOOT: on_loot,
State.INVFULL: on_invfull, State.INVFULL: lambda: on_user_interact("Inventory is full!"),
State.FIGHT: on_fight, State.FIGHT: lambda: on_user_interact("Character is FIGHTING!"),
State.DEAD: on_dead State.DEAD: lambda: on_user_interact("Character died!")
} }
try: try:
@ -119,10 +116,6 @@ def on_depleted():
_sound_and_send_fishy_data() _sound_and_send_fishy_data()
def on_lookaway():
return
@if_eso_is_focused @if_eso_is_focused
def on_looking(): def on_looking():
""" """
@ -132,11 +125,13 @@ def on_looking():
keyboard.press_and_release(FishEvent.action_key) keyboard.press_and_release(FishEvent.action_key)
def on_nobait(): def on_user_interact(msg):
msg = "No bait equipped!"
logging.info(msg) logging.info(msg)
web.send_notification(msg) web.send_notification(msg)
if FishEvent.sound:
playsound(helper.manifest_file("sound.mp3"), False)
def on_fishing(): def on_fishing():
FishEvent.stickInitTime = time.time() FishEvent.stickInitTime = time.time()
@ -170,21 +165,3 @@ def on_loot():
_fishing_sleep(0) _fishing_sleep(0)
keyboard.press_and_release(FishEvent.collect_key) keyboard.press_and_release(FishEvent.collect_key)
_fishing_sleep(0) _fishing_sleep(0)
def on_invfull():
msg = "Inventory full!"
logging.info(msg)
web.send_notification(msg)
def on_fight():
msg = "FIGHTING!"
logging.info(msg)
web.send_notification(msg)
def on_dead():
msg = "Character is dead!"
logging.info(msg)
web.send_notification(msg)

View File

@ -2,5 +2,5 @@ from .auto_update import auto_upgrade, upgrade_avail, versions
from .config import Config from .config import Config
from .helper import open_web, initialize_uid, install_thread_excepthook, unhandled_exception_logging, manifest_file, \ from .helper import open_web, initialize_uid, install_thread_excepthook, unhandled_exception_logging, manifest_file, \
create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, \ create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, \
not_implemented, update, get_savedvarsdir not_implemented, update, get_savedvarsdir, playsound_multiple
from .luaparser import sv_color_extract from .luaparser import sv_color_extract

View File

@ -7,6 +7,7 @@ import time
import traceback import traceback
import webbrowser import webbrowser
import requests import requests
from playsound import playsound
from io import BytesIO from io import BytesIO
from threading import Thread from threading import Thread
from zipfile import ZipFile from zipfile import ZipFile
@ -23,6 +24,19 @@ import winshell
from fishy import web from fishy import web
def playsound_multiple(path, count=2):
if count < 1:
logging.debug("Please don't make me beep 0 times or less.")
return
def _ps_m():
for i in range(count-1):
playsound(path, True)
playsound(path, False)
Thread(target=_ps_m).start()
def not_implemented(): def not_implemented():
logging.error("Not Implemented") logging.error("Not Implemented")

View File

@ -3,9 +3,6 @@ from threading import Thread
from typing import Dict, Callable, Optional from typing import Dict, Callable, Optional
import keyboard import keyboard
from playsound import playsound
from fishy.helper import helper
class Key(Enum): class Key(Enum):
@ -27,7 +24,6 @@ def _get_callback(k):
if not _hotkeys[k]: if not _hotkeys[k]:
return return
playsound(helper.manifest_file("beep.wav"), False)
Thread(target=_hotkeys[k]).start() Thread(target=_hotkeys[k]).start()
return callback return callback

View File

@ -1,2 +1,2 @@
from .urls import get_notification_page, get_terms_page from .urls import get_notification_page, get_terms_page
from .web import register_user, send_notification, send_hole_deplete, is_subbed, unsub, get_session, sub from .web import register_user, send_notification, send_fish_caught, is_subbed, unsub, get_session, sub

View File

@ -62,7 +62,7 @@ def send_notification(message):
@uses_session @uses_session
@fallback(None) @fallback(None)
def send_hole_deplete(fish_caught, hole_time, fish_times): def send_fish_caught(fish_caught, hole_time, fish_times):
hole_data = { hole_data = {
"fish_caught": fish_caught, "fish_caught": fish_caught,
"hole_time": hole_time, "hole_time": hole_time,