mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-04 11:20:01 +08:00
update v0.0.5.0
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from models.group_remind import GroupRemind
|
||||
from typing import List
|
||||
from nonebot.adapters.cqhttp.message import MessageSegment
|
||||
from services.log import logger
|
||||
from configs.path_config import DATA_PATH
|
||||
from utils.message_builder import image
|
||||
@@ -9,9 +10,8 @@ from datetime import datetime
|
||||
from services.db_context import db
|
||||
from models.level_user import LevelUser
|
||||
from configs.config import ADMIN_DEFAULT_AUTH
|
||||
from utils.static_data import group_manager
|
||||
from utils.manager import group_manager, plugins2settings_manager
|
||||
from utils.image_utils import CreateImg
|
||||
from configs.config import plugins2info_dict
|
||||
import aiofiles
|
||||
import aiohttp
|
||||
import asyncio
|
||||
@@ -24,70 +24,16 @@ except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
|
||||
command_dict = {
|
||||
"早晚安": "zwa",
|
||||
"进群欢迎": "hy",
|
||||
"每日开箱重置提醒": "kxcz",
|
||||
"b站转发解析": "blpar",
|
||||
"epic": "epic",
|
||||
"丢人爬": "pa",
|
||||
"原神黄历提醒": "almanac",
|
||||
}
|
||||
command_list = list(command_dict.values())
|
||||
command_info_dt = {
|
||||
"早晚安": "将会在每晚11:59晚安,在6:01早安哦",
|
||||
"每日开箱重置提醒": "将会在每日00:01提示开箱重置!",
|
||||
"epic": "将会在每日中午12:01发送可白嫖的epic游戏",
|
||||
"原神黄历提醒": "将会在每日8:00发送当日的原神黄历",
|
||||
}
|
||||
|
||||
|
||||
async def remind_status(group: int, name: str, flag: bool) -> str:
|
||||
_name = ""
|
||||
if name in command_dict.values():
|
||||
_name = list(command_dict.keys())[list(command_dict.values()).index(name)]
|
||||
if flag:
|
||||
rst = "开启"
|
||||
if await GroupRemind.get_status(group, name):
|
||||
return f"该群已经{rst}过 {_name},请勿重复开启!"
|
||||
else:
|
||||
rst = "关闭"
|
||||
if not await GroupRemind.get_status(group, name):
|
||||
return f"该群已经{rst}过 {_name},请勿重复关闭!"
|
||||
if await GroupRemind.set_status(group, name, flag):
|
||||
info = command_info_dt[_name] if command_info_dt.get(_name) else ""
|
||||
if info:
|
||||
info = "\n" + info
|
||||
return f"成功{rst} {_name}!0v0 {info}"
|
||||
else:
|
||||
return f"{rst} {_name} 失败了..."
|
||||
|
||||
|
||||
async def set_group_status(name: str, group_id: int):
|
||||
flag = None
|
||||
if name[:2] == "开启":
|
||||
flag = True
|
||||
elif name[:2] == "关闭":
|
||||
flag = False
|
||||
cmd = name[2:]
|
||||
if cmd in ["全部通知", "所有通知"]:
|
||||
for command in command_list:
|
||||
await remind_status(group_id, command, flag)
|
||||
return f"已{name[:2]}所有通知!"
|
||||
return await remind_status(group_id, command_dict[cmd], flag)
|
||||
|
||||
|
||||
async def group_current_status(group_id: int):
|
||||
result = (
|
||||
f'(被动技能)\n早晚安通知:{"√" if await GroupRemind.get_status(group_id, "zwa") else "×"}\n'
|
||||
f'进群欢迎:{"√" if await GroupRemind.get_status(group_id, "hy") else "×"}\n'
|
||||
f'每日开箱重置通知:{"√" if await GroupRemind.get_status(group_id, "kxcz") else "×"}\n'
|
||||
f'b站转发解析:{"√" if await GroupRemind.get_status(group_id, "blpar") else "×"}\n'
|
||||
f'丢人爬:{"√" if await GroupRemind.get_status(group_id, "pa") else "×"}\n'
|
||||
f'epic免费游戏:{"√" if await GroupRemind.get_status(group_id, "epic") else "×"}\n'
|
||||
f'原神黄历提醒:{"√" if await GroupRemind.get_status(group_id, "almanac") else "×"}'
|
||||
)
|
||||
return result
|
||||
async def group_current_status(group_id: int) -> str:
|
||||
"""
|
||||
获取当前所有通知的开关
|
||||
:param group_id: 群号
|
||||
"""
|
||||
rst = "[被动技能 状态]\n"
|
||||
_data = group_manager.get_task_data()
|
||||
for task in _data.keys():
|
||||
rst += f'{_data[task]}: {"√" if await group_manager.check_group_task_status(group_id, task) else "×"}\n'
|
||||
return rst.strip()
|
||||
|
||||
|
||||
custom_welcome_msg_json = (
|
||||
@@ -95,13 +41,21 @@ custom_welcome_msg_json = (
|
||||
)
|
||||
|
||||
|
||||
async def custom_group_welcome(msg, imgs, user_id, group_id):
|
||||
async def custom_group_welcome(
|
||||
msg: str, imgs: List[str], user_id: int, group_id: int
|
||||
) -> str:
|
||||
"""
|
||||
替换群欢迎消息
|
||||
:param msg: 欢迎消息文本
|
||||
:param imgs: 欢迎消息图片,只取第一张
|
||||
:param user_id: 用户id,用于log记录
|
||||
:param group_id: 群号
|
||||
"""
|
||||
img_result = ""
|
||||
img = imgs[0] if imgs else ""
|
||||
result = ""
|
||||
if os.path.exists(DATA_PATH + f"custom_welcome_msg/{group_id}.jpg"):
|
||||
os.remove(DATA_PATH + f"custom_welcome_msg/{group_id}.jpg")
|
||||
# print(custom_welcome_msg_json)
|
||||
if not custom_welcome_msg_json.exists():
|
||||
custom_welcome_msg_json.parent.mkdir(parents=True, exist_ok=True)
|
||||
data = {}
|
||||
@@ -133,54 +87,99 @@ async def custom_group_welcome(msg, imgs, user_id, group_id):
|
||||
return f"替换群欢迎消息成功:\n{result}" + img_result
|
||||
|
||||
|
||||
def change_group_switch(cmd: str, group_id: int, is_super: bool = False):
|
||||
task_data = None
|
||||
|
||||
|
||||
async def change_group_switch(cmd: str, group_id: int, is_super: bool = False):
|
||||
global task_data
|
||||
"""
|
||||
修改群功能状态
|
||||
:param cmd: 功能名称
|
||||
:param group_id: 群号
|
||||
:param is_super: 是否位超级用户,超级用户用于私聊开关功能状态
|
||||
"""
|
||||
if not task_data:
|
||||
task_data = group_manager.get_task_data()
|
||||
group_help_file = Path(DATA_PATH) / "group_help" / f"{group_id}.png"
|
||||
group_id = str(group_id)
|
||||
status = cmd[:2]
|
||||
cmd = cmd[2:]
|
||||
for plugin_cmd in plugins2info_dict.keys():
|
||||
if cmd in plugins2info_dict[plugin_cmd]["cmd"]:
|
||||
if is_super:
|
||||
plugin_cmd = f'{plugin_cmd}:super'
|
||||
type_ = 'plugin'
|
||||
modules = plugins2settings_manager.get_plugin_module(cmd, True)
|
||||
if cmd == '全部被动':
|
||||
for task in task_data:
|
||||
if status == "开启":
|
||||
if group_manager.get_plugin_status(plugin_cmd, group_id):
|
||||
return f"功能 {cmd} 正处于开启状态!不要重复开启."
|
||||
group_manager.unblock_plugin(plugin_cmd, group_id)
|
||||
if not await group_manager.check_group_task_status(group_id, task):
|
||||
await group_manager.open_group_task(group_id, task)
|
||||
else:
|
||||
if not group_manager.get_plugin_status(plugin_cmd, group_id):
|
||||
if await group_manager.check_group_task_status(group_id, task):
|
||||
await group_manager.close_group_task(group_id, task)
|
||||
return f"已 {status} 全部被动技能!"
|
||||
if cmd in [task_data[x] for x in task_data.keys()]:
|
||||
type_ = 'task'
|
||||
modules = [x for x in task_data.keys() if task_data[x] == cmd]
|
||||
for module in modules:
|
||||
if is_super:
|
||||
module = f"{module}:super"
|
||||
if status == "开启":
|
||||
if type_ == 'task':
|
||||
if await group_manager.check_group_task_status(group_id, module):
|
||||
return f"被动 {task_data[module]} 正处于开启状态!不要重复开启."
|
||||
await group_manager.open_group_task(group_id, module)
|
||||
else:
|
||||
if group_manager.get_plugin_status(module, group_id):
|
||||
return f"功能 {cmd} 正处于开启状态!不要重复开启."
|
||||
group_manager.unblock_plugin(module, group_id)
|
||||
else:
|
||||
if type_ == 'task':
|
||||
if not await group_manager.check_group_task_status(group_id, module):
|
||||
return f"被动 {task_data[module]} 正处于关闭状态!不要重复关闭."
|
||||
await group_manager.close_group_task(group_id, module)
|
||||
else:
|
||||
if not group_manager.get_plugin_status(module, group_id):
|
||||
return f"功能 {cmd} 正处于关闭状态!不要重复关闭."
|
||||
group_manager.block_plugin(plugin_cmd, group_id)
|
||||
if group_help_file.exists():
|
||||
group_help_file.unlink()
|
||||
return f"{status} {cmd} 功能!"
|
||||
return f"没有找到 {cmd} 功能..."
|
||||
group_manager.block_plugin(module, group_id)
|
||||
if group_help_file.exists():
|
||||
group_help_file.unlink()
|
||||
return f"{status} {cmd} 功能!"
|
||||
|
||||
|
||||
def set_plugin_status(cmd: str, block_type: str = "all"):
|
||||
"""
|
||||
设置插件功能状态(超级用户使用)
|
||||
:param cmd: 功能名称
|
||||
:param block_type: 限制类型, 'all': 私聊+群里, 'private': 私聊, 'group': 群聊
|
||||
"""
|
||||
status = cmd[:2]
|
||||
cmd = cmd[2:]
|
||||
for plugin_cmd in plugins2info_dict.keys():
|
||||
if cmd in plugins2info_dict[plugin_cmd]["cmd"]:
|
||||
if status == "开启":
|
||||
group_manager.unblock_plugin(plugin_cmd)
|
||||
else:
|
||||
group_manager.block_plugin(plugin_cmd, block_type=block_type)
|
||||
break
|
||||
module = plugins2settings_manager.get_plugin_module(cmd)
|
||||
if status == "开启":
|
||||
group_manager.unblock_plugin(module)
|
||||
else:
|
||||
group_manager.block_plugin(module, block_type=block_type)
|
||||
|
||||
|
||||
async def get_plugin_status():
|
||||
"""
|
||||
获取功能状态
|
||||
"""
|
||||
return await asyncio.get_event_loop().run_in_executor(None, _get_plugin_status)
|
||||
|
||||
|
||||
def _get_plugin_status():
|
||||
rst = '\t功能\n'
|
||||
flag_str = '状态'.rjust(4) + '\n'
|
||||
for plugin_cmd in plugins2info_dict:
|
||||
flag = group_manager.get_plugin_block_type(plugin_cmd)
|
||||
flag = flag.upper() + ' CLOSE' if flag else 'OPEN'
|
||||
rst += f'{plugins2info_dict[plugin_cmd]["cmd"][0]}\n'
|
||||
flag_str += f'{flag}\n'
|
||||
height = len(rst.split('\n')) * 24
|
||||
def _get_plugin_status() -> MessageSegment:
|
||||
"""
|
||||
合成功能状态图片
|
||||
"""
|
||||
rst = "\t功能\n"
|
||||
flag_str = "状态".rjust(4) + "\n"
|
||||
for module in plugins2settings_manager.get_data():
|
||||
flag = group_manager.get_plugin_block_type(module)
|
||||
flag = flag.upper() + " CLOSE" if flag else "OPEN"
|
||||
try:
|
||||
rst += f'{plugins2settings_manager.get(module)["cmd"][0]}\n'
|
||||
except IndexError:
|
||||
rst += f"{module}\n"
|
||||
flag_str += f"{flag}\n"
|
||||
height = len(rst.split("\n")) * 24
|
||||
a = CreateImg(150, height, font_size=20)
|
||||
a.text((10, 10), rst)
|
||||
b = CreateImg(200, height, font_size=20)
|
||||
@@ -192,6 +191,10 @@ def _get_plugin_status():
|
||||
|
||||
|
||||
async def update_member_info(group_id: int) -> bool:
|
||||
"""
|
||||
更新群成员信息
|
||||
:param group_id: 群号
|
||||
"""
|
||||
bot = get_bot()
|
||||
_group_user_list = await bot.get_group_member_list(group_id=group_id)
|
||||
_error_member_list = []
|
||||
@@ -267,7 +270,3 @@ async def update_member_info(group_id: int) -> bool:
|
||||
user_id=int(list(bot.config.superusers)[0]), message=result[:-1]
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user