更改配置文件

This commit is contained in:
惜月 2023-01-13 14:10:15 +08:00 committed by GitHub
parent 30003ff6df
commit 1bd85e3090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 52 deletions

View File

@ -1,4 +1,4 @@
from typing import Literal
from typing import Literal, List
from pydantic import BaseModel, Field
@ -9,6 +9,7 @@ class ConfigModel(BaseModel):
qrcode_bind_use_url: bool = Field(False, alias='绑定二维码以链接形式发送')
img_use_cache: bool = Field(True, alias='图片资源缓存开关')
reboot_card_ban: List[int] = Field(list, alias='禁用重启时修改群名片群列表')
sim_gacha_cd_group: int = Field(30, alias='模拟抽卡群冷却')
sim_gacha_cd_member: int = Field(60, alias='模拟抽卡群员冷却')

View File

@ -15,7 +15,6 @@ class GreetConfig:
self.new_group: str = data.get('新群见面语', '旅行者们大家好呀,这里是{nickname}对我说“help”查看帮助吧~')
self.group_greet: Dict[Union[str, int], str] = data.get('群新人欢迎语', {'默认': '欢迎新旅行者~{at_user}'})
self.group_ban = data.get('群欢迎语禁用列表', [])
self.card_open = data.get('重启时更改群名片启用列表', [])
self.save()
def save(self):
@ -23,8 +22,7 @@ class GreetConfig:
'新好友见面语': self.new_friend,
'新群见面语': self.new_group,
'群新人欢迎语': self.group_greet,
'群欢迎语禁用列表': self.group_ban,
'重启时更改群名片启用列表': self.card_open
'群欢迎语禁用列表': self.group_ban
}
save_yaml(data, GREET_CONFIG)

View File

@ -3,9 +3,6 @@ import asyncio
import random
import sys
from pathlib import Path
from typing import Optional
import nonebot
from nonebot import on_command, get_bot
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
@ -13,9 +10,8 @@ from nonebot.rule import to_me
from nonebot.params import CommandArg, ArgPlainText, Arg
from nonebot.typing import T_State
from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, GroupMessageEvent, ActionFailed
#from nonebot.adapters.onebot.v11.helpers import convert_chinese_to_bool
from LittlePaimon.plugins.NoticeAndRequest import config
from LittlePaimon.config import config
from LittlePaimon.utils import NICKNAME, DRIVER, __version__
from LittlePaimon.utils.files import save_json, load_json
from LittlePaimon.utils.update import check_update, update
@ -63,18 +59,11 @@ broadcast = on_command('广播', permission=SUPERUSER, rule=to_me(), priority=1,
})
@update_cmd.handle()
async def _(event: MessageEvent):
await update_cmd.send(f'{NICKNAME}开始更新', at_sender=True)
result = await update()
await update_cmd.finish(result, at_sender=True)
# p = await asyncio.subprocess.create_subprocess_shell('git pull', stdout=asyncio.subprocess.PIPE,
# stderr=asyncio.subprocess.PIPE)
# stdout, stderr = await p.communicate()
# results = (stdout or stderr).decode('utf-8').split('\n')
# result_msg = ''.join(result.split('|')[0].strip(' ') + '\n' for result in results)
# await update_cmd.finish(f'更新结果:{result_msg}')
@check_update_cmd.handle()
@ -84,31 +73,24 @@ async def _(event: MessageEvent):
@reboot_cmd.handle()
async def _(event: MessageEvent):
#if convert_chinese_to_bool(event.message):
async def _(bot: Bot, event: MessageEvent):
await reboot_cmd.send(f'{NICKNAME}开始执行重启,请等待{NICKNAME}的归来', at_sender=True)
save_json({'session_type': event.message_type,
'session_id': event.group_id if isinstance(event, GroupMessageEvent) else event.user_id},
Path() / 'rebooting.json')
info = load_json(Path() / 'rebooting.json')
bot = get_bot()
reboot_data = {'session_type': event.message_type,
'session_id': event.group_id if isinstance(event, GroupMessageEvent) else event.user_id,
'group_card': {}}
group_list = await bot.get_group_list()
group_list_id = [gg["group_id"] for gg in group_list]
if config.card_open:
group_len = len(config.card_open)
for i in range(group_len):
group = config.card_open[i]
if group in group_list_id:
card = await bot.get_group_member_info(group_id=group, user_id=int(bot.self_id), no_cache=True)
info[group] = {"group_id": group, "card": card["card"]}
save_json(info, Path() / 'rebooting.json')
await bot.set_group_card(group_id=group, user_id=int(bot.self_id),
card=f'{NICKNAME}重启中')
group_id_list = [g['group_id'] for g in group_list]
for group_id in group_id_list:
if group_id not in config.reboot_card_ban:
member_info = await bot.get_group_member_info(group_id=group_id, user_id=int(bot.self_id), no_cache=True)
reboot_data['group_card'][str(group_id)] = member_info['card']
await bot.set_group_card(group_id=group_id, user_id=int(bot.self_id),
card=(member_info['card'] or member_info['nickname']) + '(重启中)')
await asyncio.sleep(0.25)
save_json(reboot_data, Path() / 'rebooting.json')
if sys.argv[0].endswith('nb'):
sys.argv[0] = 'bot.py'
os.execv(sys.executable, ['python'] + sys.argv)
#else:
#await reboot_cmd.finish('取消重启')
@run_cmd.handle()
@ -162,16 +144,16 @@ async def _(event: MessageEvent, bot: Bot, msg: Message = Arg('msg'), groups: st
@DRIVER.on_bot_connect
async def _():
if (Path() / 'rebooting.json').exists():
info = load_json(Path() / 'rebooting.json')
if info['session_type'] == 'group':
await get_bot().send_group_msg(group_id=info['session_id'], message=f'{NICKNAME}已重启完成,当前版本为{__version__}')
if (reboot_file := (Path() / 'rebooting.json')).exists():
bot = get_bot()
reboot_data = load_json(reboot_file)
if reboot_data['session_type'] == 'group':
await bot.send_group_msg(group_id=reboot_data['session_id'],
message=f'{NICKNAME}已重启完成,当前版本为{__version__}')
else:
await get_bot().send_private_msg(user_id=info['session_id'], message=f'{NICKNAME}已重启完成,当前版本为{__version__}')
for group_id, card_info in info.items():
if group_id not in {"session_type", "session_id"}:
card = card_info["card"]
group_id = group_id
bot = get_bot()
await bot.set_group_card(group_id=group_id, user_id=int(bot.self_id), card=card)
(Path() / 'rebooting.json').unlink()
await bot.send_private_msg(user_id=reboot_data['session_id'],
message=f'{NICKNAME}已重启完成,当前版本为{__version__}')
for group_id, card_info in reboot_data['group_card'].items():
await bot.set_group_card(group_id=int(group_id), user_id=int(bot.self_id), card=card_info)
await asyncio.sleep(0.25)
reboot_file.unlink()

View File

@ -288,6 +288,16 @@ other_form = Form(
onText='开启',
offText='关闭'
),
InputTag(
label='禁用重启时修改群名片群列表',
name='reboot_card_ban',
value='${reboot_card_ban}',
enableBatchAdd=True,
placeholder='添加禁用群名片修改的群号',
joinValues=False,
extractValue=True,
labelRemark=Remark(shape='circle', content='默认在重启时会把所在的群的群名片中增加"重启中"作为提示,在重启完成后修改回来,在此处添加不想修改群名片的群')
),
Switch(
label='网页截图权限',
name='启用网页截图权限',

View File

@ -5,7 +5,4 @@
123456789: 针对群123456789的欢迎语
群欢迎语禁用列表:
- 123456789
- 987654321
重启时更改群名片启用列表:
- 987654321
- 123456789
- 987654321