mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
notify config endpoint changed
This commit is contained in:
parent
50083edd8a
commit
84f6b25f4f
@ -5,7 +5,6 @@ from tkinter.filedialog import askopenfilename
|
||||
from fishy.helper import helper
|
||||
|
||||
from fishy import web
|
||||
from fishy.gui.notification import _give_notification_link
|
||||
|
||||
from tkinter import *
|
||||
from tkinter.ttk import *
|
||||
@ -44,6 +43,14 @@ def start_semifisher_config(gui: 'GUI'):
|
||||
gui.config.set("sound_notification", sound.instate(['selected']), False)
|
||||
gui.config.save_config()
|
||||
|
||||
def toggle_sub():
|
||||
if web.is_subbed(config.get("uid"))[0]:
|
||||
if web.unsub(config.get("uid")):
|
||||
gui._notify.set(0)
|
||||
else:
|
||||
if web.sub(config.get("uid")):
|
||||
gui._notify.set(1)
|
||||
|
||||
top = PopUp(save, gui._root, background=gui._root["background"])
|
||||
controls_frame = Frame(top)
|
||||
top.title("Config")
|
||||
@ -51,11 +58,10 @@ def start_semifisher_config(gui: 'GUI'):
|
||||
Label(controls_frame, text="Notification:").grid(row=0, column=0)
|
||||
|
||||
gui._notify = IntVar(0)
|
||||
gui._notify_check = Checkbutton(controls_frame, command=lambda: _give_notification_link(gui),
|
||||
variable=gui._notify)
|
||||
gui._notify_check = Checkbutton(controls_frame, command=toggle_sub, variable=gui._notify)
|
||||
gui._notify_check.grid(row=0, column=1)
|
||||
gui._notify_check['state'] = DISABLED
|
||||
is_subbed = web.is_subbed(config.get('uid'))
|
||||
is_subbed = web.is_subbed(config.get('uid'), lazy=False)
|
||||
if is_subbed[1]:
|
||||
gui._notify_check['state'] = NORMAL
|
||||
gui._notify.set(is_subbed[0])
|
||||
|
@ -14,7 +14,7 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
def _give_notification_link(gui: 'GUI'):
|
||||
def discord_login(gui: 'GUI'):
|
||||
if web.is_subbed(config.get("uid"))[0]:
|
||||
web.unsub(config.get("uid"))
|
||||
return
|
||||
@ -46,7 +46,9 @@ def _give_notification_link(gui: 'GUI'):
|
||||
f'<p><span style="font-size:20px">Step 1.</span><br/>'
|
||||
f'Join <a href="https://discord.definex.in/">Discord server</a></p>'
|
||||
f'<p><span style="font-size:20px">Step 2.</span><br/>'
|
||||
f'Enter username (ex. Fishy#1234)'
|
||||
f'run !login command in #bot-spam channel'
|
||||
f'<p><span style="font-size:20px">Step 3.</span><br/>'
|
||||
f'enter login code'
|
||||
f'</div>', background=gui._root["background"])
|
||||
|
||||
html_label.pack(pady=(20, 5))
|
||||
@ -57,8 +59,6 @@ def _give_notification_link(gui: 'GUI'):
|
||||
|
||||
html_label = HTMLLabel(top,
|
||||
html=f'<div style="color: {gui._console["fg"]}; text-align: center">'
|
||||
f'<p><span style="font-size:20px">Step 3.</span><br/>'
|
||||
f'Install Discord App on your phone</p>'
|
||||
f'<p><span style="font-size:20px">Step 4.</span><br/></p>'
|
||||
f'</div>', background=gui._root["background"])
|
||||
|
@ -1,5 +1,5 @@
|
||||
import logging
|
||||
from tkinter import OptionMenu, Button
|
||||
from tkinter import OptionMenu, Button, IntVar
|
||||
from typing import List, Callable, Optional
|
||||
import threading
|
||||
|
||||
@ -29,7 +29,6 @@ class GUI:
|
||||
self._root: Optional[ThemedTk] = None
|
||||
self._console = None
|
||||
self._start_button = None
|
||||
self._notify = None
|
||||
self._notify_check = None
|
||||
self._engine_select: Optional[OptionMenu] = None
|
||||
self._config_button: Optional[Button] = None
|
||||
@ -37,6 +36,9 @@ class GUI:
|
||||
|
||||
self._thread = threading.Thread(target=self.create, args=())
|
||||
|
||||
self._notify = None
|
||||
self.login = None
|
||||
|
||||
root_logger = logging.getLogger('')
|
||||
root_logger.setLevel(logging.DEBUG)
|
||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||
|
@ -10,6 +10,7 @@ from fishy import helper
|
||||
import typing
|
||||
|
||||
from fishy.helper import hotkey
|
||||
from .discord_login import discord_login
|
||||
from ..helper.config import config
|
||||
from ..helper.hotkey import Key
|
||||
|
||||
@ -37,8 +38,10 @@ def _create(gui: 'GUI'):
|
||||
menubar = Menu(gui._root)
|
||||
|
||||
filemenu = Menu(menubar, tearoff=0)
|
||||
|
||||
filemenu.add_checkbutton(label="Login", command=lambda: discord_login(gui), variable=gui.login)
|
||||
filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut(False))
|
||||
filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True))
|
||||
# filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True))
|
||||
|
||||
def _toggle_mode():
|
||||
config.set("dark_mode", not config.get("dark_mode", True))
|
||||
@ -49,7 +52,7 @@ def _create(gui: 'GUI'):
|
||||
filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode,
|
||||
variable=dark_mode_var)
|
||||
|
||||
menubar.add_cascade(label="File", menu=filemenu)
|
||||
menubar.add_cascade(label="Options", menu=filemenu)
|
||||
|
||||
debug_menu = Menu(menubar, tearoff=0)
|
||||
debug_menu.add_command(label="Check PixelVal",
|
||||
|
@ -9,7 +9,7 @@ else:
|
||||
|
||||
user = domain + "/api/user"
|
||||
notify = domain + "/api/notify"
|
||||
subscription = domain + "/api/subscription/"
|
||||
subscription = domain + "/api/notify_semifish"
|
||||
hole_depleted = domain + "/api/hole_depleted"
|
||||
session = domain + "/api/session"
|
||||
terms = domain + "/terms.html"
|
||||
|
@ -7,7 +7,6 @@ from . import urls
|
||||
from .decorators import fallback, uses_session
|
||||
from ..helper.config import config
|
||||
|
||||
_is_subbed = None
|
||||
_session_id = None
|
||||
|
||||
|
||||
@ -43,40 +42,36 @@ def send_hole_deplete(uid, fish_caught, hole_time, fish_times):
|
||||
|
||||
|
||||
@fallback(False)
|
||||
def sub(uid, name):
|
||||
body = {"uid": uid, "discord_name": name}
|
||||
def sub(uid):
|
||||
body = {"uid": uid}
|
||||
response = requests.post(urls.subscription, json=body)
|
||||
return response.json()["success"]
|
||||
result = response.json()
|
||||
return result["success"]
|
||||
|
||||
|
||||
@fallback((False, False))
|
||||
def is_subbed(uid, lazy=True):
|
||||
def is_subbed(uid):
|
||||
"""
|
||||
:param uid:
|
||||
:param lazy:
|
||||
:return: Tuple[is_subbed, success]
|
||||
"""
|
||||
global _is_subbed
|
||||
|
||||
if lazy and _is_subbed is not None:
|
||||
return _is_subbed, True
|
||||
|
||||
if uid is None:
|
||||
return False, False
|
||||
|
||||
body = {"uid": uid}
|
||||
response = requests.get(urls.subscription, params=body)
|
||||
_is_subbed = response.json()["subbed"]
|
||||
return _is_subbed, True
|
||||
is_subbed = response.json()["subbed"]
|
||||
return is_subbed, True
|
||||
|
||||
|
||||
@fallback(None)
|
||||
def unsub(uid):
|
||||
global _is_subbed
|
||||
|
||||
_is_subbed = False
|
||||
body = {"uid": uid}
|
||||
requests.delete(urls.subscription, json=body)
|
||||
response = requests.delete(urls.subscription, json=body)
|
||||
result = response.json()
|
||||
return result["success"]
|
||||
|
||||
|
||||
@fallback(None)
|
||||
|
Loading…
Reference in New Issue
Block a user