新增几个core的默认配置

This commit is contained in:
Wuyi无疑 2023-05-11 02:59:49 +08:00
parent 71a0574e84
commit 3064e17bd2
12 changed files with 190 additions and 65 deletions

View File

@ -98,6 +98,7 @@ def main():
continue
config = all_config_list[config_name][name]
if isinstance(config, GsListStrConfig):
data[name] = data[name].replace('', ':')
value = data[name].split(':')
else:
value = data[name]

View File

@ -0,0 +1,35 @@
from gsuid_core.aps import scheduler
from gsuid_core.logger import logger
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
from .auto_task import update_core, restart_core, update_all_plugins
config = core_plugins_config
UCT = config.get_config('AutoUpdateCoreTime').data
UPT = config.get_config('AutoUpdatePluginsTime').data
RCT = config.get_config('AutoRestartCoreTime').data
# 自动更新core
@scheduler.scheduled_job('cron', hour=UCT[0], minute=UCT[1])
async def update_core_at_night():
if config.get_config('AutoUpdateCore').data:
logger.info('[Core自动任务] 开始更新 [早柚核心]')
await update_core()
# 自动更新插件列表
@scheduler.scheduled_job('cron', hour=UPT[0], minute=UPT[1])
async def update_all_plugins_at_night():
if config.get_config('AutoUpdatePlugins').data:
logger.info('[Core自动任务] 开始更新 [插件目录]')
await update_all_plugins()
# 自动更新插件列表
@scheduler.scheduled_job('cron', hour=RCT[0], minute=RCT[1])
async def auto_restart_at_night():
if config.get_config('AutoRestartCore').data:
logger.info('[Core自动任务] 开始执行 [自动重启]')
await restart_core()

View File

@ -0,0 +1,22 @@
from typing import List
from gsuid_core.utils.plugins_update.api import PLUGINS_PATH
from gsuid_core.utils.plugins_update._plugins import update_from_git
from gsuid_core.plugins.core_command.core_restart.restart import (
restart_genshinuid,
)
async def update_core() -> List[str]:
return update_from_git()
async def update_all_plugins() -> List[str]:
log_list = []
for plugin in PLUGINS_PATH.iterdir():
log_list.extend(update_from_git(0, plugin))
return log_list
async def restart_core():
await restart_genshinuid('', '', '', False)

View File

@ -24,7 +24,7 @@ async def get_restart_sh() -> str:
async def restart_genshinuid(
bot_id: str, send_type: str, send_id: str
bot_id: str, send_type: str, send_id: str, is_send: bool = True
) -> None:
pid = os.getpid()
restart_sh = await get_restart_sh()
@ -34,16 +34,17 @@ async def restart_genshinuid(
os.system(f'chmod +x {str(restart_sh_path)}')
os.system(f'chmod +x {str(bot_start)}')
now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
update_log = {
'type': 'restart',
'msg': '重启完成!',
'bot_id': bot_id,
'send_type': send_type,
'send_to': send_id,
'time': now_time,
}
with open(str(update_log_path), 'w', encoding='utf-8') as f:
json.dump(update_log, f)
if is_send:
update_log = {
'type': 'restart',
'msg': '重启完成!',
'bot_id': bot_id,
'send_type': send_type,
'send_to': send_id,
'time': now_time,
}
with open(str(update_log_path), 'w', encoding='utf-8') as f:
json.dump(update_log, f)
if platform.system() == 'Linux':
subprocess.Popen(
f'kill -9 {pid} & {restart_command} {bot_start}',

View File

@ -220,7 +220,7 @@ async def _deal_ck(bot_id: str, mes: str, user_id: str) -> str:
if uid and sr_uid:
break
else:
if not (uid or sr_uid):
if not (uid_bind or sr_uid_bind):
return f'你的米游社账号{account_id}尚未绑定原神/星铁账号,请前往米游社操作!'
except Exception:
pass

View File

@ -1,6 +1,6 @@
from typing import Dict
from .models import GSC, GsStrConfig, GsBoolConfig
from .models import GSC, GsStrConfig, GsBoolConfig, GsListStrConfig
CONIFG_DEFAULT: Dict[str, GSC] = {
'proxy': GsStrConfig('设置代理', '设置国际服的代理地址', ''),
@ -25,4 +25,28 @@ CONIFG_DEFAULT: Dict[str, GSC] = {
'该选项已经无效且可能有一定危险性...',
False,
),
'AutoUpdateCore': GsBoolConfig(
'自动更新Core',
'每晚凌晨三点四十自动更新core本体, 但不会自动重启应用更新',
True,
),
'AutoUpdatePlugins': GsBoolConfig(
'自动更新Core内所有插件',
'每晚凌晨四点十分自动更新全部插件, 但不会自动重启应用更新',
True,
),
'AutoRestartCore': GsBoolConfig(
'自动重启Core',
'每晚凌晨四点四十自动重启core',
False,
),
'AutoUpdateCoreTime': GsListStrConfig(
'自动更新Core时间设置', '每晚自动更新Core时间设置(时, 分)', ['3', '40']
),
'AutoUpdatePluginsTime': GsListStrConfig(
'自动更新Core内所有插件时间设置', '每晚自动更新Core内所有插件时间设置(时, 分)', ['4', '10']
),
'AutoRestartCoreTime': GsListStrConfig(
'自动重启Core时间设置', '每晚自动重启Core时间设置(时, 分)', ['4', '40']
),
}

View File

@ -1,12 +1,14 @@
import time
from pathlib import Path
from typing import Dict, List, Union, Optional
import aiohttp
from git.repo import Repo
from git.exc import GitCommandError, InvalidGitRepositoryError
from git.exc import GitCommandError, NoSuchPathError, InvalidGitRepositoryError
from gsuid_core.logger import logger
from .api import PLUGINS_PATH, proxy_url, plugins_lib
from .api import CORE_PATH, PLUGINS_PATH, proxy_url, plugins_lib
plugins_list: Dict[str, Dict[str, str]] = {}
@ -104,26 +106,39 @@ def check_status(plugin_name: str) -> int:
return 4
def update_plugins(
plugin_name: str,
def update_from_git(
level: int = 0,
repo_like: Union[str, Path, None] = None,
log_key: List[str] = [],
log_limit: int = 10,
) -> Union[str, List]:
for _n in PLUGINS_PATH.iterdir():
_name = _n.name
sim = len(set(_name.lower()) & set(plugin_name.lower()))
if sim >= 0.5 * len(_name):
plugin_name = _name
break
log_limit: int = 5,
) -> List[str]:
try:
if repo_like is None:
repo = Repo(CORE_PATH)
plugin_name = '早柚核心'
elif isinstance(repo_like, Path):
repo = Repo(repo_like)
plugin_name = repo_like.name
else:
repo = check_plugins(repo_like)
plugin_name = repo_like
except InvalidGitRepositoryError:
logger.warning('[更新] 更新失败, 非有效Repo路径!')
return ['更新失败, 该路径并不是一个有效的GitRepo路径, 请使用`git clone`安装插件...']
except NoSuchPathError:
logger.warning('[更新] 更新失败, 该路径不存在!')
return ['更新失败, 路径/插件不存在!']
repo = check_plugins(plugin_name)
if not repo:
return '更新失败, 不存在该插件!'
logger.warning('[更新] 更新失败, 该插件不存在!')
return ['更新失败, 不存在该插件!']
o = repo.remotes.origin
if level >= 2:
logger.warning(f'[更新][{plugin_name}] 正在执行 git clean --xdf')
logger.warning('[更新] 你有 2 秒钟的时间中断该操作...')
time.sleep(2)
repo.git.clean('-xdf')
# 还原上次更改
if level >= 1:
@ -133,12 +148,13 @@ def update_plugins(
try:
pull_log = o.pull()
logger.info(f'[更新][{plugin_name}] {pull_log}')
logger.info(f'[更新][{repo.head.commit.hexsha[:7]}] 获取远程最新版本')
except GitCommandError as e:
logger.warning(e)
return '更新失败, 请检查控制台...'
logger.warning(f'[更新] 更新失败...{e}!')
return ['更新失败, 请检查控制台...']
commits = list(repo.iter_commits(max_count=40))
log_list = []
log_list = [f'更新插件 {plugin_name} 中...']
for commit in commits:
if isinstance(commit.message, str):
if log_key:
@ -152,3 +168,20 @@ def update_plugins(
if len(log_list) >= log_limit:
break
return log_list
def update_plugins(
plugin_name: str,
level: int = 0,
log_key: List[str] = [],
log_limit: int = 10,
) -> Union[str, List]:
for _n in PLUGINS_PATH.iterdir():
_name = _n.name
sim = len(set(_name.lower()) & set(plugin_name.lower()))
if sim >= 0.5 * len(_name):
plugin_name = _name
break
log_list = update_from_git(level, plugin_name, log_key, log_limit)
return log_list

View File

@ -8,3 +8,4 @@ plugins_lib = 'https://docs.gsuid.gbots.work/plugin_list.json'
proxy_url = 'https://ghproxy.com/'
PLUGINS_PATH = Path(__file__).parents[2] / 'plugins'
CORE_PATH = Path(__file__).parents[3]

View File

@ -41,9 +41,17 @@ def get_text_panel(label: str, name: str, value: str):
}
def get_container_panel(
content: List[Dict],
):
def get_grid_panel(content: List[Dict]):
_data = [{'body': [i]} for i in content]
data = {
'type': 'grid',
'columns': _data,
'id': 'u:18d6cb8e78bb',
}
return data
def get_container_panel(content: List[Dict]):
return {
'type': 'flex',
'className': 'p-1',

View File

@ -4,7 +4,7 @@ from gsuid_core.utils.plugins_config.models import (
GsBoolConfig,
GsListStrConfig,
)
from gsuid_core.webconsole.create_base_panel import (
from gsuid_core.webconsole.create_base_panel import ( # get_grid_panel,
get_text_panel,
get_switch_panel,
get_container_panel,

60
poetry.lock generated
View File

@ -1306,41 +1306,41 @@ reference = "mirrors"
[[package]]
name = "msgspec"
version = "0.14.2"
version = "0.15.0"
description = "A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML."
category = "main"
optional = false
python-versions = ">=3.8"
files = [
{file = "msgspec-0.14.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:8ed61cad6b20f0218a8d239294c4b30b4e82854871ba0434cf0d54497043bffe"},
{file = "msgspec-0.14.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a12e704786256431d559c2027d6135a64f2339f009118d97906709cd8409e7ac"},
{file = "msgspec-0.14.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2039451b22813af2fd5cbe99eaecfc318d64fcee5af0ce5b3d5cce12427d24cd"},
{file = "msgspec-0.14.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:57a79cfa306fda2c66f4fc7eb72836c0f78fd9a6d748d028960b387797f0381b"},
{file = "msgspec-0.14.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:87c4cd1bb197be11f89ad779038c8989d6ffcb8b360705107f034e4d2783c0a6"},
{file = "msgspec-0.14.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b965c14851f146537f1b732cd2ed16c38e0c59662f23b72d396aee21e81aed4f"},
{file = "msgspec-0.14.2-cp310-cp310-win_amd64.whl", hash = "sha256:4f13e47803aedbb32c9375317fedbd20af3397dc024d311eebdc635c07f6f908"},
{file = "msgspec-0.14.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a0a3908309581e4e632457fac1938fec7fd84121396ddab6ddca37784e6db068"},
{file = "msgspec-0.14.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d03861f0d271b696faefb1a885ea0c7dc7db70baaa05c7f18086f2b9085d1cb8"},
{file = "msgspec-0.14.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8b8a766b9f3e7f87946965a8ffc6e72f7a3ec8d031b3168df16762bfd3d03205"},
{file = "msgspec-0.14.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:580464c7ca5c47a1422973c853301bbfd3d1a4184bdb6bddb73b5df094d8fc55"},
{file = "msgspec-0.14.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:26bcb3a69b348be2757ab19e86038e586920522a99d49d358c12890fbcfb6aa8"},
{file = "msgspec-0.14.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:59491de3566c7789bdb0a152f305e150a6ba3e825af471680b05a029a664a89a"},
{file = "msgspec-0.14.2-cp311-cp311-win_amd64.whl", hash = "sha256:3288b65ee7c78d08f32003a8b5ca72fff12c6a7400bd35f9d65630c9d58efce2"},
{file = "msgspec-0.14.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1fc99f0929fa91cc53fa35f59be366d67f116c2b7f0f3b29dc60e3179f6fb205"},
{file = "msgspec-0.14.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:587371a65798a0f0182d0a7a4b7c4b87a5f46e25e8821c6474b3f717dcfcad14"},
{file = "msgspec-0.14.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:03ddc8c518afbea4fb89afb587d77f11d00909f003966d437f31fb8fffdfac28"},
{file = "msgspec-0.14.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f97006b9c9e24e9677fb84f43586fb4d03a72eb426199656a1c24775c62b9fe4"},
{file = "msgspec-0.14.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:d469aede5d986223d6ec9a8d0713156f96fd6b427b12e14f81d26627a47687b9"},
{file = "msgspec-0.14.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:d85e9bfd1441216010c084626d968e96a3d88d762959c5eb430de62076cd7fe9"},
{file = "msgspec-0.14.2-cp38-cp38-win_amd64.whl", hash = "sha256:78361dadef4b993b8c4a887d3d267b89b0ea0846259eadf2fe993659e4dbf9c8"},
{file = "msgspec-0.14.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:94fc3d9a8835f18c18b48fdf49f7d445184061bfbc457a6623a4eb1f74ebe806"},
{file = "msgspec-0.14.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:1c8f7e631fad9d5a33fcfb0f2a27eb86dc0390e91d6b51c95a604b7ccbc264f1"},
{file = "msgspec-0.14.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7e50885274e2041e49ec5d7cce8e59768f599c27dfb4c046edaf9ab25b1fddc2"},
{file = "msgspec-0.14.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eee59e73982ca0d730f8d4e8fb5f01da9fa466490dea43ea1bcfa23b8a8bbc0d"},
{file = "msgspec-0.14.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ff7c987330e2be62eb8811bc2da33507e8edeb761f4fd343f2fa5fdafce4f989"},
{file = "msgspec-0.14.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:decd1d2015d340ebfd58f29ed2916e118ca255b6a94fc1787a236a2654dfd8ff"},
{file = "msgspec-0.14.2-cp39-cp39-win_amd64.whl", hash = "sha256:8927efaf506e5a8f9ffe76602e08d30a80c19b38d50a7e783887c317573ecd80"},
{file = "msgspec-0.14.2.tar.gz", hash = "sha256:907ed4305a97b50248e6b86e79ddc8edcf9b718eab0c93a6b46d673c5edbe3a4"},
{file = "msgspec-0.15.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:415519f68cd3f1a224f87ed415459ac3b86e4f6e82815a036e4238c62006f696"},
{file = "msgspec-0.15.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2b57b6869ef1717c0343465198e19284d1e6aa5f292af2726284e4dfedfedeef"},
{file = "msgspec-0.15.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ff80bd40469915cc61686086a2503b901e17040f8a191099d8ccaa45dc72df8c"},
{file = "msgspec-0.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:beb3789519253b22338cca48053ba5ac8b442633e3af8f58e264d776a98ff6d0"},
{file = "msgspec-0.15.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:bf3ab3f8d5752dbe68babc77d21b42575b916793515442e3890aef680e212154"},
{file = "msgspec-0.15.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:05fc603508e0c8021249d3e531fa4bb72d167bdfa76d869d48f96a5b8f9b50bf"},
{file = "msgspec-0.15.0-cp310-cp310-win_amd64.whl", hash = "sha256:42c2f9fe0b58dc6f2b15720490c67554b5ba0007d3ee94340ca4448bda917287"},
{file = "msgspec-0.15.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:0c75fd847709e30265f050375c408fec1c07797694162834aa86ab3b3cf055da"},
{file = "msgspec-0.15.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:381c7a891adcc741e617956ba987912bc21864f9dd27b8cfb03bfb0aded5e1fd"},
{file = "msgspec-0.15.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8a46a9818570362d4022161684cdb97ecd102953043059ee4902862940f48f8d"},
{file = "msgspec-0.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:20bf8018bff6bb85f5315ba6fd47b2f9373ab67e8bb59b0d7a7def22bbbf9f70"},
{file = "msgspec-0.15.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:8cee590163788fce21c5998d09198ef08ec06c1ca68ef50f2d5ed9e54d308538"},
{file = "msgspec-0.15.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:9d61de44b248feef82c8979a1e9912c923527cfb1d01c93b7bb5d6ca93ed09d6"},
{file = "msgspec-0.15.0-cp311-cp311-win_amd64.whl", hash = "sha256:8b7e0354c37b742e1c02fe0cd3ced97db516c8da62ac5a408609e9f5858aaf24"},
{file = "msgspec-0.15.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1b5b7c1b69416eab3ab2ad1c9593b749226b80555532292fae5fe9d154794089"},
{file = "msgspec-0.15.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:cc253e4ad51d360590358ab2cee5a6139f04ad994e0fcbff52e7f61fca475c3e"},
{file = "msgspec-0.15.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:490c88d76d573cce16653434ace3d9a8a8675ef6e350f114752fe60e69b6a232"},
{file = "msgspec-0.15.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fffa7ec85f27577f7f5471b390bf902d58ccd89b3612cf40bfb92f4ba75e6c95"},
{file = "msgspec-0.15.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:22713a1f618b4094c0268c6fbeef530397e5f3fa5292e4afd51caddad645843f"},
{file = "msgspec-0.15.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:c4c7e0abfac3a67f3e1d51e1d1313fd4205528e17663ff264b1945c3370b18bd"},
{file = "msgspec-0.15.0-cp38-cp38-win_amd64.whl", hash = "sha256:cd198ed4445914ebc25a24b6cc6020902bb6b888fc9b39500ef4500841b1b437"},
{file = "msgspec-0.15.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ddef8fdc06676dd1bec9fe67b3128f84079469ee6424384cbb29a90c9033b559"},
{file = "msgspec-0.15.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:346960762d648a6512b51f30be7c1267630e0bbc6fd65e8b23a3f54e5f562656"},
{file = "msgspec-0.15.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:07ee1d1a15e3b319dcd7326470216928a7b58d47460b253577ccd0ab5dcf5c3c"},
{file = "msgspec-0.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:550b359c49562d52849103b87b4f7381fbc0adf958afa316599befb9a3e3379e"},
{file = "msgspec-0.15.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:9178a7550a5516295c682e6e5c143782503719b4c816496349a4a0f1b62397ef"},
{file = "msgspec-0.15.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:4d3cde786110a92f764666b9f963b4389d5d1798bf1aca2422a59931d8d1f694"},
{file = "msgspec-0.15.0-cp39-cp39-win_amd64.whl", hash = "sha256:f77cc91d3cb8a7bccfba28fe4aec537178384509bfce222f8eca287b7e5d0214"},
{file = "msgspec-0.15.0.tar.gz", hash = "sha256:d760ff747165d84965791bfcd14588f61f111708036d80f1980387e3760035e7"},
]
[package.extras]

View File

@ -30,7 +30,7 @@ httpx==0.24.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
idna==3.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
loguru==0.6.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
lxml==4.9.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
msgspec==0.14.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
msgspec==0.15.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
multidict==6.0.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
passlib==1.7.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pillow==9.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"