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
256956c55e
commit
16ee7b2b01
5
.gitignore
vendored
5
.gitignore
vendored
@ -667,8 +667,7 @@ res_data
|
||||
GsData.db
|
||||
GenshinUID
|
||||
data
|
||||
plugins
|
||||
!plugins/core_user/
|
||||
!plugins/core_command/
|
||||
plugins/*
|
||||
!plugins/core_command
|
||||
!plugins/gs_test.py
|
||||
logs
|
||||
|
63
gsuid_core/plugins/core_command/core_restart/__init__.py
Normal file
63
gsuid_core/plugins/core_command/core_restart/__init__.py
Normal file
@ -0,0 +1,63 @@
|
||||
import os
|
||||
|
||||
from gsuid_core.sv import SV
|
||||
from gsuid_core.bot import Bot
|
||||
from gsuid_core.gss import gss
|
||||
from gsuid_core.models import Event
|
||||
from gsuid_core.logger import logger
|
||||
|
||||
from .restart import restart_message, restart_genshinuid
|
||||
|
||||
sv_core_config = SV('Core管理', pm=0)
|
||||
|
||||
|
||||
@gss.on_bot_connect
|
||||
async def check_msg():
|
||||
try:
|
||||
logger.info('检查遗留信息...')
|
||||
update_log = await restart_message()
|
||||
if update_log == {}:
|
||||
return
|
||||
for BOT in gss.active_bot:
|
||||
bot = gss.active_bot[BOT]
|
||||
if update_log['send_type'] == 'group':
|
||||
await bot.target_send(
|
||||
update_log['msg'],
|
||||
'group',
|
||||
update_log['send_to'],
|
||||
update_log['bot_id'],
|
||||
'',
|
||||
'',
|
||||
)
|
||||
else:
|
||||
await bot.target_send(
|
||||
update_log['msg'],
|
||||
'direct',
|
||||
update_log['send_to'],
|
||||
update_log['bot_id'],
|
||||
'',
|
||||
'',
|
||||
)
|
||||
logger.info('遗留信息检查完毕!')
|
||||
except Exception:
|
||||
logger.warning('遗留信息检查失败!')
|
||||
|
||||
|
||||
@sv_core_config.on_fullmatch(('core重启'))
|
||||
async def send_restart_msg(bot: Bot, ev: Event):
|
||||
await bot.logger.warning('开始执行[重启]')
|
||||
if ev.group_id:
|
||||
send_id = ev.group_id
|
||||
send_type = 'group'
|
||||
else:
|
||||
send_id = ev.user_id
|
||||
send_type = 'direct'
|
||||
await bot.send('正在执行[gs重启]...')
|
||||
await restart_genshinuid(bot.bot_id, send_type, str(send_id))
|
||||
|
||||
|
||||
@sv_core_config.on_fullmatch(('core关闭', 'Core关闭'))
|
||||
async def send_shutdown_msg(bot: Bot, ev: Event):
|
||||
await bot.logger.warning('开始执行[关闭]')
|
||||
await bot.send('正在执行[gs关闭Core]...')
|
||||
os._exit(0)
|
69
gsuid_core/plugins/core_command/core_restart/restart.py
Normal file
69
gsuid_core/plugins/core_command/core_restart/restart.py
Normal file
@ -0,0 +1,69 @@
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import platform
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
||||
|
||||
bot_start = Path(__file__).parents[4] / 'core.py'
|
||||
restart_sh_path = Path().cwd() / 'gs_restart.sh'
|
||||
update_log_path = Path(__file__).parent / 'update_log.json'
|
||||
|
||||
_restart_sh = '''#!/bin/bash
|
||||
kill -9 {}
|
||||
{} &'''
|
||||
|
||||
restart_command = core_plugins_config.get_config('restart_command').data
|
||||
|
||||
|
||||
async def get_restart_sh() -> str:
|
||||
args = f'{restart_command} {str(bot_start.absolute())}'
|
||||
return _restart_sh.format(str(bot_start.absolute()), args)
|
||||
|
||||
|
||||
async def restart_genshinuid(
|
||||
bot_id: str, send_type: str, send_id: str
|
||||
) -> None:
|
||||
pid = os.getpid()
|
||||
restart_sh = await get_restart_sh()
|
||||
with open(restart_sh_path, "w", encoding="utf8") as f:
|
||||
f.write(restart_sh)
|
||||
if platform.system() == 'Linux':
|
||||
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 platform.system() == 'Linux':
|
||||
subprocess.Popen(
|
||||
f'kill -9 {pid} & {restart_command} {bot_start}',
|
||||
shell=True,
|
||||
)
|
||||
else:
|
||||
subprocess.Popen(
|
||||
f'taskkill /F /PID {pid} & {restart_command} {bot_start}',
|
||||
shell=True,
|
||||
)
|
||||
|
||||
|
||||
async def restart_message() -> dict:
|
||||
if update_log_path.exists():
|
||||
with open(update_log_path, 'r', encoding='utf-8') as f:
|
||||
update_log = json.load(f)
|
||||
msg = f'{update_log["msg"]}\n重启时间:{update_log["time"]}'
|
||||
update_log['msg'] = msg
|
||||
os.remove(update_log_path)
|
||||
os.remove(restart_sh_path)
|
||||
return update_log
|
||||
else:
|
||||
return {}
|
44
gsuid_core/plugins/core_command/user_login/__init__.py
Normal file
44
gsuid_core/plugins/core_command/user_login/__init__.py
Normal file
@ -0,0 +1,44 @@
|
||||
from gsuid_core.sv import SV
|
||||
from gsuid_core.bot import Bot
|
||||
from gsuid_core.models import Event
|
||||
from gsuid_core.utils.cookie_manager.qrlogin import qrcode_login
|
||||
from gsuid_core.utils.cookie_manager.add_ck import (
|
||||
deal_ck,
|
||||
get_ck_by_stoken,
|
||||
get_ck_by_all_stoken,
|
||||
)
|
||||
|
||||
sv_core_user_config = SV('用户管理', pm=2)
|
||||
sv_core_user_add = SV('用户添加')
|
||||
sv_core_user_qrcode_login = SV('扫码登陆')
|
||||
sv_core_user_addck = SV('添加CK', area='DIRECT')
|
||||
|
||||
|
||||
@sv_core_user_config.on_fullmatch(('刷新全部CK', '刷新全部ck'))
|
||||
async def send_refresh_all_ck_msg(bot: Bot, ev: Event):
|
||||
await bot.logger.info('开始执行[刷新全部CK]')
|
||||
im = await get_ck_by_all_stoken(ev.bot_id)
|
||||
await bot.send(im)
|
||||
|
||||
|
||||
@sv_core_user_add.on_fullmatch(('刷新CK', '刷新ck'))
|
||||
async def send_refresh_ck_msg(bot: Bot, ev: Event):
|
||||
await bot.logger.info('开始执行[刷新CK]')
|
||||
im = await get_ck_by_stoken(ev.bot_id, ev.user_id)
|
||||
await bot.send(im)
|
||||
|
||||
|
||||
@sv_core_user_qrcode_login.on_fullmatch(('扫码登陆', '扫码登录'))
|
||||
async def send_qrcode_login(bot: Bot, ev: Event):
|
||||
await bot.logger.info('开始执行[扫码登陆]')
|
||||
im = await qrcode_login(bot, ev, ev.user_id)
|
||||
if not im:
|
||||
return
|
||||
im = await deal_ck(ev.bot_id, im, ev.user_id)
|
||||
await bot.send(im)
|
||||
|
||||
|
||||
@sv_core_user_addck.on_prefix(('添加'))
|
||||
async def send_add_ck_msg(bot: Bot, ev: Event):
|
||||
im = await deal_ck(ev.bot_id, ev.text, ev.user_id)
|
||||
await bot.send(im)
|
@ -104,5 +104,6 @@ class GsServer:
|
||||
|
||||
@classmethod
|
||||
def on_bot_connect(cls, func: Callable):
|
||||
cls.bot_connect_def.add(func)
|
||||
if func not in cls.bot_connect_def:
|
||||
cls.bot_connect_def.add(func)
|
||||
return func
|
||||
|
@ -27,3 +27,5 @@ async def start_check():
|
||||
await site.auth.create_role_user('admin')
|
||||
|
||||
logger.info(('WebConsole挂载成功:' f'http://{HOST}:{PORT}/genshinuid'))
|
||||
if HOST == 'localhost' or HOST == '127.0.0.1':
|
||||
logger.info('WebConsole挂载于本地, 如想外网访问请修改config.json中host为0.0.0.0!')
|
||||
|
Loading…
x
Reference in New Issue
Block a user