mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
✨ 新增内置插件
This commit is contained in:
parent
c5d35ac3a2
commit
955c073ce8
3
.gitignore
vendored
3
.gitignore
vendored
@ -667,7 +667,8 @@ res_data
|
||||
GsData.db
|
||||
GenshinUID
|
||||
data
|
||||
plugins/*
|
||||
plugins
|
||||
!plugins/core_user/
|
||||
!plugins/core_command/
|
||||
!plugins/gs_test.py
|
||||
logs
|
||||
|
@ -46,7 +46,7 @@ class GsClient:
|
||||
msg = MessageReceive(
|
||||
bot_id='Nonebot222',
|
||||
user_type='direct',
|
||||
user_pm=2,
|
||||
user_pm=1,
|
||||
group_id=None,
|
||||
user_id='511',
|
||||
content=content,
|
||||
|
0
gsuid_core/plugins/core_command/__full__.py
Normal file
0
gsuid_core/plugins/core_command/__full__.py
Normal file
30
gsuid_core/plugins/core_command/install_plugins/__init__.py
Normal file
30
gsuid_core/plugins/core_command/install_plugins/__init__.py
Normal file
@ -0,0 +1,30 @@
|
||||
from gsuid_core.sv import SV
|
||||
from gsuid_core.bot import Bot
|
||||
from gsuid_core.models import Event
|
||||
|
||||
from ._plugins import refresh_list, get_plugins_url, install_plugins
|
||||
|
||||
sv_core_install_plugins = SV('core管理插件', pm=1)
|
||||
|
||||
|
||||
@sv_core_install_plugins.on_prefix(('core安装插件'))
|
||||
async def send_plugins_install(bot: Bot, ev: Event):
|
||||
plugins_url = await get_plugins_url(ev.text.strip().lower())
|
||||
if not plugins_url:
|
||||
return await bot.send('不存在该插件...可以使用[core刷新插件列表]获取最新列表!')
|
||||
|
||||
await bot.send('开始安装...请稍等一段时间...')
|
||||
if install_plugins(plugins_url):
|
||||
await bot.send('安装成功!使用[gs重启]以应用...')
|
||||
else:
|
||||
await bot.send('安装失败...请查看控制台!')
|
||||
|
||||
|
||||
@sv_core_install_plugins.on_prefix(('core刷新插件列表'))
|
||||
async def refresh_plugins_list(bot: Bot, ev: Event):
|
||||
_list = await refresh_list()
|
||||
if len(_list) <= 3:
|
||||
im = f'刷新成功! 刷新插件{",".join(_list)}!'
|
||||
else:
|
||||
im = f'刷新成功! 已刷新{len(_list)}个插件!'
|
||||
await bot.send(im)
|
53
gsuid_core/plugins/core_command/install_plugins/_plugins.py
Normal file
53
gsuid_core/plugins/core_command/install_plugins/_plugins.py
Normal file
@ -0,0 +1,53 @@
|
||||
import re
|
||||
from typing import Dict, List, Tuple, Optional
|
||||
|
||||
import aiohttp
|
||||
from git.repo import Repo
|
||||
|
||||
from gsuid_core.logger import logger
|
||||
|
||||
from .api import PLUGINS_PATH, proxy_url, plugins_lib
|
||||
|
||||
plugins_list: Dict[str, str] = {}
|
||||
|
||||
|
||||
async def refresh_list() -> List[str]:
|
||||
refresh_list = []
|
||||
async with aiohttp.ClientSession() as session:
|
||||
logger.info(f'稍等...开始刷新插件列表, 地址: {plugins_lib}')
|
||||
async with session.get(plugins_lib) as resp:
|
||||
content = await resp.text()
|
||||
_plugins_list: List[Tuple[str, str]] = re.findall(
|
||||
r'\[([^]]+)\]\(([^)]+)\)', content
|
||||
)
|
||||
for i in _plugins_list:
|
||||
if i[0].lower() not in plugins_list:
|
||||
refresh_list.append(i[0])
|
||||
logger.info(f'[刷新插件列表] 列表新增插件 {i[0]}')
|
||||
plugins_list[i[0].lower()] = i[1]
|
||||
return refresh_list
|
||||
|
||||
|
||||
async def get_plugins_url(name: str) -> Optional[str]:
|
||||
if not plugins_list:
|
||||
await refresh_list()
|
||||
|
||||
if name in plugins_list:
|
||||
return plugins_list[name]
|
||||
else:
|
||||
for _n in plugins_list:
|
||||
sim = len(set(_n) & set(name))
|
||||
if sim >= 0.5 * len(_n):
|
||||
return plugins_list[_n]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def install_plugins(url: str) -> bool:
|
||||
plugin_name = url.split('/')[-1]
|
||||
git_path = f'{proxy_url}{url}.git'
|
||||
logger.info(f'稍等...开始安装插件, 地址: {git_path}')
|
||||
Repo.clone_from(
|
||||
git_path, PLUGINS_PATH / plugin_name, single_branch=True, depth=1
|
||||
)
|
||||
return True
|
10
gsuid_core/plugins/core_command/install_plugins/api.py
Normal file
10
gsuid_core/plugins/core_command/install_plugins/api.py
Normal file
@ -0,0 +1,10 @@
|
||||
from pathlib import Path
|
||||
|
||||
# raw_url = 'https://raw.githubusercontent.com'
|
||||
# repo_title = 'Genshin-bots/GenshinUID-docs/master/docs'
|
||||
# plugins_lib = f'{raw_url}/{repo_title}/PluginsList.md'
|
||||
plugins_lib = 'https://docs.gsuid.gbots.work/PluginsList.md'
|
||||
|
||||
proxy_url = 'https://ghproxy.com/'
|
||||
|
||||
PLUGINS_PATH = Path(__file__).parents[1]
|
@ -104,7 +104,8 @@ class SQLA:
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
_uid = data['uid'] if 'uid' in data else ''
|
||||
if await self.bind_exists(user_id):
|
||||
_sr_uid = data['sr_uid'] if 'sr_uid' in data else ''
|
||||
if _uid and await self.bind_exists(user_id):
|
||||
uid_list = await self.get_bind_uid_list(user_id)
|
||||
if uid_list and _uid in uid_list:
|
||||
uid_list.remove(_uid)
|
||||
@ -114,6 +115,16 @@ class SQLA:
|
||||
await self.update_bind_data(user_id, data)
|
||||
await session.commit()
|
||||
return 0
|
||||
elif _sr_uid and await self.bind_exists(user_id):
|
||||
uid_list = await self.get_bind_sruid_list(user_id)
|
||||
if uid_list and _sr_uid in uid_list:
|
||||
uid_list.remove(_sr_uid)
|
||||
else:
|
||||
return -1
|
||||
data['sr_uid'] = '_'.join(uid_list)
|
||||
await self.update_bind_data(user_id, data)
|
||||
await session.commit()
|
||||
return 0
|
||||
else:
|
||||
return -1
|
||||
|
||||
|
6
poetry.lock
generated
6
poetry.lock
generated
@ -1608,14 +1608,14 @@ reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "platformdirs"
|
||||
version = "3.4.0"
|
||||
version = "3.5.0"
|
||||
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "platformdirs-3.4.0-py3-none-any.whl", hash = "sha256:01437886022decaf285d8972f9526397bfae2ac55480ed372ed6d9eca048870a"},
|
||||
{file = "platformdirs-3.4.0.tar.gz", hash = "sha256:a5e1536e5ea4b1c238a1364da17ff2993d5bd28e15600c2c8224008aff6bbcad"},
|
||||
{file = "platformdirs-3.5.0-py3-none-any.whl", hash = "sha256:47692bc24c1958e8b0f13dd727307cff1db103fca36399f457da8e05f222fdc4"},
|
||||
{file = "platformdirs-3.5.0.tar.gz", hash = "sha256:7954a68d0ba23558d753f73437c55f89027cf8f5108c19844d4b82e5af396335"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
|
Loading…
x
Reference in New Issue
Block a user