mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-28 18:50:48 +00:00
Feature: Migrate notify.py from AzurLaneAutoScript and upgrade dep onepush ver. to 1.3.0 (#418)
Co-authored-by: LmeSzinc <lmeszincsales@gmail.com>
This commit is contained in:
parent
a0fd30193c
commit
39af23657e
@ -1,4 +1,75 @@
|
|||||||
|
import onepush.core
|
||||||
|
import yaml
|
||||||
|
from onepush import get_notifier
|
||||||
|
from onepush.core import Provider
|
||||||
|
from onepush.exceptions import OnePushException
|
||||||
|
from onepush.providers.custom import Custom
|
||||||
|
from requests import Response
|
||||||
|
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
|
|
||||||
def handle_notify(*args, **kwargs):
|
onepush.core.log = logger
|
||||||
logger.error('Error notify is not supported yet')
|
|
||||||
|
|
||||||
|
def handle_notify(_config: str, **kwargs) -> bool:
|
||||||
|
try:
|
||||||
|
config = {}
|
||||||
|
for item in yaml.safe_load_all(_config):
|
||||||
|
config.update(item)
|
||||||
|
except Exception:
|
||||||
|
logger.error("Fail to load onepush config, skip sending")
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
provider_name: str = config.pop("provider", None)
|
||||||
|
if provider_name is None:
|
||||||
|
logger.info("No provider specified, skip sending")
|
||||||
|
return False
|
||||||
|
notifier: Provider = get_notifier(provider_name)
|
||||||
|
required: list[str] = notifier.params["required"]
|
||||||
|
config.update(kwargs)
|
||||||
|
|
||||||
|
# pre check
|
||||||
|
for key in required:
|
||||||
|
if key not in config:
|
||||||
|
logger.warning(
|
||||||
|
f"Notifier {notifier.name} require param '{key}' but not provided"
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(notifier, Custom):
|
||||||
|
if "method" not in config or config["method"] == "post":
|
||||||
|
config["datatype"] = "json"
|
||||||
|
if not ("data" in config or isinstance(config["data"], dict)):
|
||||||
|
config["data"] = {}
|
||||||
|
if "title" in kwargs:
|
||||||
|
config["data"]["title"] = kwargs["title"]
|
||||||
|
if "content" in kwargs:
|
||||||
|
config["data"]["content"] = kwargs["content"]
|
||||||
|
|
||||||
|
if provider_name.lower() == "gocqhttp":
|
||||||
|
access_token = config.get("access_token")
|
||||||
|
if access_token:
|
||||||
|
config["token"] = access_token
|
||||||
|
|
||||||
|
resp = notifier.notify(**config)
|
||||||
|
if isinstance(resp, Response):
|
||||||
|
if resp.status_code != 200:
|
||||||
|
logger.warning("Push notify failed!")
|
||||||
|
logger.warning(f"HTTP Code:{resp.status_code}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if provider_name.lower() == "gocqhttp":
|
||||||
|
return_data: dict = resp.json()
|
||||||
|
if return_data["status"] == "failed":
|
||||||
|
logger.warning("Push notify failed!")
|
||||||
|
logger.warning(
|
||||||
|
f"Return message:{return_data['wording']}")
|
||||||
|
return False
|
||||||
|
except OnePushException:
|
||||||
|
logger.exception("Push notify failed")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
logger.info("Push notify success")
|
||||||
|
return True
|
@ -21,6 +21,7 @@ pyyaml
|
|||||||
inflection
|
inflection
|
||||||
prettytable==2.2.1
|
prettytable==2.2.1
|
||||||
pydantic>=2.4
|
pydantic>=2.4
|
||||||
|
onepush==1.3.0
|
||||||
|
|
||||||
# OCR
|
# OCR
|
||||||
pponnxcr==2.0
|
pponnxcr==2.0
|
||||||
|
@ -37,6 +37,7 @@ markdown-it-py==2.2.0 # via rich
|
|||||||
mdurl==0.1.2 # via markdown-it-py
|
mdurl==0.1.2 # via markdown-it-py
|
||||||
mpmath==1.3.0 # via sympy
|
mpmath==1.3.0 # via sympy
|
||||||
numpy==1.24.3 # via -r requirements-in.txt, onnxruntime, opencv-python, pponnxcr, scipy, shapely
|
numpy==1.24.3 # via -r requirements-in.txt, onnxruntime, opencv-python, pponnxcr, scipy, shapely
|
||||||
|
onepush==1.3.0 # via -r requirements-in.txt
|
||||||
onnxruntime==1.14.1 # via pponnxcr
|
onnxruntime==1.14.1 # via pponnxcr
|
||||||
opencv-python==4.7.0.72 # via -r requirements-in.txt, pponnxcr
|
opencv-python==4.7.0.72 # via -r requirements-in.txt, pponnxcr
|
||||||
packaging==20.9 # via deprecation, onnxruntime, uiautomator2
|
packaging==20.9 # via deprecation, onnxruntime, uiautomator2
|
||||||
@ -48,6 +49,7 @@ protobuf==4.23.0 # via onnxruntime
|
|||||||
psutil==5.9.3 # via -r requirements-in.txt
|
psutil==5.9.3 # via -r requirements-in.txt
|
||||||
py==1.11.0 # via retry
|
py==1.11.0 # via retry
|
||||||
pyclipper==1.3.0.post4 # via pponnxcr
|
pyclipper==1.3.0.post4 # via pponnxcr
|
||||||
|
pycryptodome==3.20.0 # via onepush
|
||||||
pydantic==2.4.2 # via -r requirements-in.txt
|
pydantic==2.4.2 # via -r requirements-in.txt
|
||||||
pydantic-core==2.10.1 # via pydantic
|
pydantic-core==2.10.1 # via pydantic
|
||||||
pyelftools==0.29 # via apkutils2
|
pyelftools==0.29 # via apkutils2
|
||||||
@ -58,7 +60,7 @@ pyreadline3==3.4.1 # via humanfriendly
|
|||||||
python-dotenv==1.0.0 # via uvicorn
|
python-dotenv==1.0.0 # via uvicorn
|
||||||
pywebio==1.8.3 # via -r requirements-in.txt
|
pywebio==1.8.3 # via -r requirements-in.txt
|
||||||
pyyaml==6.0 # via -r requirements-in.txt, uvicorn
|
pyyaml==6.0 # via -r requirements-in.txt, uvicorn
|
||||||
requests==2.30.0 # via adbutils, uiautomator2
|
requests==2.30.0 # via adbutils, onepush, uiautomator2
|
||||||
retry==0.9.2 # via adbutils, uiautomator2
|
retry==0.9.2 # via adbutils, uiautomator2
|
||||||
rich==13.3.5 # via -r requirements-in.txt
|
rich==13.3.5 # via -r requirements-in.txt
|
||||||
scipy==1.10.1 # via -r requirements-in.txt
|
scipy==1.10.1 # via -r requirements-in.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user