mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-11 06:39:59 +08:00
update v0.0.5.0
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import nonebot
|
||||
|
||||
nonebot.load_plugins("plugins/admin_bot_manage")
|
||||
@@ -4,16 +4,26 @@ from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
|
||||
from .data_source import custom_group_welcome
|
||||
from nonebot.adapters.cqhttp.permission import GROUP
|
||||
from configs.config import OC_LEVEL
|
||||
from services.log import logger
|
||||
|
||||
|
||||
__plugin_name__ = "自定义进群欢迎消息"
|
||||
|
||||
__zx_plugin_name__ = "自定义进群欢迎消息 [Admin]"
|
||||
__plugin_usage__ = """
|
||||
自定义进群欢迎消息 [消息] [图片](可省略)
|
||||
示例:自定义进群欢迎消息 欢迎新人![图片]
|
||||
"""
|
||||
|
||||
usage:
|
||||
指令:
|
||||
自定义进群欢迎消息 ?[文本] ?[图片]
|
||||
示例:自定义进群欢迎消息 欢迎新人![图片]
|
||||
Note:可以通过[at]来确认是否艾特新成员
|
||||
示例:自定义进群欢迎消息 欢迎你[at]
|
||||
""".strip()
|
||||
__plugin_des__ = '简易的自定义群欢迎消息'
|
||||
__plugin_cmd__ = ['自定义群欢迎消息 ?[文本] ?[图片]']
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = 'HibiKier'
|
||||
__plugin_settings__ = {
|
||||
"admin_level": OC_LEVEL,
|
||||
}
|
||||
|
||||
custom_welcome = on_command(
|
||||
"自定义进群欢迎消息",
|
||||
@@ -26,12 +36,16 @@ custom_welcome = on_command(
|
||||
|
||||
@custom_welcome.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
imgs = get_message_imgs(event.json())
|
||||
if not msg and not imgs:
|
||||
await custom_welcome.finish(__plugin_usage__)
|
||||
await custom_welcome.send(
|
||||
await custom_group_welcome(msg, imgs, event.user_id, event.group_id),
|
||||
at_sender=True,
|
||||
)
|
||||
logger.info(f"USER {event.user_id} GROUP {event.group_id} 自定义群欢迎消息:{msg}")
|
||||
try:
|
||||
msg = get_message_text(event.json())
|
||||
imgs = get_message_imgs(event.json())
|
||||
if not msg and not imgs:
|
||||
await custom_welcome.finish(__plugin_usage__)
|
||||
await custom_welcome.send(
|
||||
await custom_group_welcome(msg, imgs, event.user_id, event.group_id),
|
||||
at_sender=True,
|
||||
)
|
||||
logger.info(f"USER {event.user_id} GROUP {event.group_id} 自定义群欢迎消息:{msg}")
|
||||
except Exception as e:
|
||||
logger.error(f"自定义进群欢迎消息发生错误 {type(e)}:{e}")
|
||||
await custom_welcome.send("发生了一些未知错误...")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
|
||||
from .data_source import set_group_status, group_current_status
|
||||
from nonebot.adapters.cqhttp.permission import GROUP
|
||||
from services.log import logger
|
||||
from nonebot import on_command
|
||||
|
||||
|
||||
__plugin_name__ = "群通知开关"
|
||||
|
||||
__plugin_usage__ = """
|
||||
示例:
|
||||
开启早晚安
|
||||
关闭早晚安
|
||||
"""
|
||||
|
||||
|
||||
group_status = on_command(
|
||||
"oc_reminds",
|
||||
aliases={
|
||||
"开启早晚安",
|
||||
"关闭早晚安",
|
||||
"开启进群欢迎",
|
||||
"关闭进群欢迎",
|
||||
"开启每日开箱重置提醒",
|
||||
"关闭每日开箱重置提醒",
|
||||
"开启b站转发解析",
|
||||
"关闭b站转发解析",
|
||||
"开启epic通知",
|
||||
"关闭epic通知",
|
||||
"开启丢人爬",
|
||||
"关闭丢人爬",
|
||||
"开启原神黄历提醒",
|
||||
"关闭原神黄历提醒",
|
||||
"开启全部通知",
|
||||
"开启所有通知",
|
||||
"关闭全部通知",
|
||||
"关闭所有通知",
|
||||
"群通知状态",
|
||||
},
|
||||
permission=GROUP,
|
||||
priority=5,
|
||||
block=True,
|
||||
)
|
||||
|
||||
|
||||
@group_status.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
if state["_prefix"]["raw_command"] in ["群通知状态"]:
|
||||
await group_status.finish(await group_current_status(event.group_id))
|
||||
await group_status.send(
|
||||
await set_group_status(state["_prefix"]["raw_command"], event.group_id),
|
||||
at_sender=True,
|
||||
)
|
||||
logger.info(
|
||||
f'USER {event.user_id} GROUP {event.group_id} 使用群通知管理命令 {state["_prefix"]["raw_command"]}'
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
from nonebot.adapters.cqhttp import Bot, Event
|
||||
from nonebot.typing import T_State
|
||||
from utils.manager import group_manager, plugins2settings_manager
|
||||
from utils.utils import get_message_text
|
||||
from services.log import logger
|
||||
|
||||
cmd = []
|
||||
|
||||
|
||||
def switch_rule(bot: Bot, event: Event, state: T_State) -> bool:
|
||||
"""
|
||||
检测文本是否是关闭功能命令
|
||||
:param bot: pass
|
||||
:param event: pass
|
||||
:param state: pass
|
||||
"""
|
||||
try:
|
||||
if not cmd:
|
||||
cmd.append('关闭全部被动')
|
||||
cmd.append('开启全部被动')
|
||||
_data = group_manager.get_task_data()
|
||||
for key in _data:
|
||||
cmd.append(f"开启{_data[key]}")
|
||||
cmd.append(f"关闭{_data[key]}")
|
||||
cmd.append(f"开启 {_data[key]}")
|
||||
cmd.append(f"关闭 {_data[key]}")
|
||||
_data = plugins2settings_manager.get_data()
|
||||
for key in _data:
|
||||
try:
|
||||
for x in _data[key]["cmd"]:
|
||||
cmd.append(f"开启{x}")
|
||||
cmd.append(f"关闭{x}")
|
||||
cmd.append(f"开启 {x}")
|
||||
cmd.append(f"关闭 {x}")
|
||||
except KeyError:
|
||||
pass
|
||||
msg = get_message_text(event.json()).split()
|
||||
msg = msg[0] if msg else ""
|
||||
return msg in cmd
|
||||
except Exception as e:
|
||||
logger.error(f"检测是否为功能开关命令发生错误 {type(e)}: {e}")
|
||||
return False
|
||||
@@ -1,78 +1,106 @@
|
||||
from nonebot import on_command
|
||||
from nonebot import on_command, on_message
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, MessageEvent
|
||||
from .data_source import change_group_switch, set_plugin_status, get_plugin_status
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, MessageEvent, GROUP
|
||||
from .data_source import (
|
||||
change_group_switch,
|
||||
set_plugin_status,
|
||||
get_plugin_status,
|
||||
group_current_status,
|
||||
)
|
||||
from services.log import logger
|
||||
from configs.config import plugins2info_dict, NICKNAME
|
||||
from configs.config import NICKNAME, OC_LEVEL
|
||||
from utils.utils import get_message_text, is_number
|
||||
from nonebot.permission import SUPERUSER
|
||||
from .rule import switch_rule
|
||||
|
||||
|
||||
__plugin_name__ = "群功能开关"
|
||||
__zx_plugin_name__ = "群功能开关 [Admin]"
|
||||
|
||||
__plugin_usage__ = """
|
||||
示例:
|
||||
开启色图
|
||||
关闭色图
|
||||
"""
|
||||
usage:
|
||||
群内功能与被动技能开关
|
||||
指令:
|
||||
开启/关闭[功能]
|
||||
群被动状态
|
||||
开启全部被动
|
||||
关闭全部被动
|
||||
示例:开启/关闭色图
|
||||
""".strip()
|
||||
__plugin_superuser_usage__ = """
|
||||
usage:
|
||||
功能总开关与指定群禁用
|
||||
指令:
|
||||
功能状态
|
||||
开启/关闭[功能] [group]
|
||||
开启/关闭[功能] ['private'/'group']
|
||||
""".strip()
|
||||
__plugin_des__ = "群内功能开关"
|
||||
__plugin_cmd__ = [
|
||||
"开启/关闭[功能]",
|
||||
"群被动状态",
|
||||
"开启全部被动",
|
||||
"关闭全部被动",
|
||||
"功能状态 [_superuser]",
|
||||
"开启/关闭[功能] [group] [_superuser]",
|
||||
"开启/关闭[功能] ['private'/'group'] [_superuser]",
|
||||
]
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"admin_level": OC_LEVEL,
|
||||
}
|
||||
|
||||
switch_rule_matcher = on_message(rule=switch_rule, priority=4, block=True)
|
||||
|
||||
plugins_status = on_command("功能状态", permission=SUPERUSER, priority=5, block=True)
|
||||
|
||||
group_task_status = on_command("群被动状态", permission=GROUP, priority=5, block=True)
|
||||
|
||||
|
||||
cmds = []
|
||||
for cmd_list in plugins2info_dict.values():
|
||||
for cmd in cmd_list["cmd"]:
|
||||
cmds.append(f"开启{cmd}")
|
||||
cmds.append(f"关闭{cmd}")
|
||||
cmds = set(cmds)
|
||||
|
||||
|
||||
switch_rule = on_command(
|
||||
"switch_rule", aliases=cmds, priority=5, block=True
|
||||
)
|
||||
|
||||
plugins_status = on_command('功能状态', permission=SUPERUSER, priority=5, block=True)
|
||||
|
||||
|
||||
@switch_rule.handle()
|
||||
@switch_rule_matcher.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
_cmd = get_message_text(event.json()).split()[0]
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
await switch_rule.send(
|
||||
change_group_switch(
|
||||
state["_prefix"]["raw_command"].strip(), event.group_id
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
f'USER {event.user_id} GROUP {event.group_id} 使用群功能管理命令 {state["_prefix"]["raw_command"]}'
|
||||
)
|
||||
await switch_rule_matcher.send(await change_group_switch(_cmd, event.group_id))
|
||||
logger.info(f"USER {event.user_id} GROUP {event.group_id} 使用群功能管理命令 {_cmd}")
|
||||
else:
|
||||
if str(event.user_id) in bot.config.superusers:
|
||||
block_type = get_message_text(event.json())
|
||||
block_type = block_type if block_type else 'a'
|
||||
_cmd = state["_prefix"]["raw_command"].strip()
|
||||
block_type = " ".join(get_message_text(event.json()).split()[1:])
|
||||
block_type = block_type if block_type else "a"
|
||||
if is_number(block_type):
|
||||
if not int(block_type) in [g["group_id"] for g in await bot.get_group_list(self_id=int(bot.self_id))]:
|
||||
await switch_rule.finish(f'{NICKNAME}未加入群聊:{block_type}')
|
||||
change_group_switch(_cmd, int(block_type), True)
|
||||
group_name = (await bot.get_group_info(group_id=int(block_type)))['group_name']
|
||||
await switch_rule.send(f'已禁用群聊 {group_name}({block_type}) 的 {_cmd[2:]} 功能')
|
||||
elif block_type in ['all', 'private', 'group', 'a', 'p', 'g']:
|
||||
block_type = 'all' if block_type == 'a' else block_type
|
||||
block_type = 'private' if block_type == 'p' else block_type
|
||||
block_type = 'group' if block_type == 'g' else block_type
|
||||
if not int(block_type) in [
|
||||
g["group_id"]
|
||||
for g in await bot.get_group_list(self_id=int(bot.self_id))
|
||||
]:
|
||||
await switch_rule_matcher.finish(f"{NICKNAME}未加入群聊:{block_type}")
|
||||
await change_group_switch(_cmd, int(block_type), True)
|
||||
group_name = (await bot.get_group_info(group_id=int(block_type)))[
|
||||
"group_name"
|
||||
]
|
||||
await switch_rule_matcher.send(
|
||||
f"已禁用群聊 {group_name}({block_type}) 的 {_cmd[2:]} 功能"
|
||||
)
|
||||
elif block_type in ["all", "private", "group", "a", "p", "g"]:
|
||||
block_type = "all" if block_type == "a" else block_type
|
||||
block_type = "private" if block_type == "p" else block_type
|
||||
block_type = "group" if block_type == "g" else block_type
|
||||
set_plugin_status(_cmd, block_type)
|
||||
if block_type == 'all':
|
||||
await switch_rule.send(f'已{_cmd[:2]}功能:{_cmd[2:]}')
|
||||
elif block_type == 'private':
|
||||
await switch_rule.send(f'已在私聊中{_cmd[:2]}功能:{_cmd[2:]}')
|
||||
if block_type == "all":
|
||||
await switch_rule_matcher.send(f"已{_cmd[:2]}功能:{_cmd[2:]}")
|
||||
elif block_type == "private":
|
||||
await switch_rule_matcher.send(f"已在私聊中{_cmd[:2]}功能:{_cmd[2:]}")
|
||||
else:
|
||||
await switch_rule.send(f'已在群聊中{_cmd[:2]}功能:{_cmd[2:]}')
|
||||
await switch_rule_matcher.send(f"已在群聊中{_cmd[:2]}功能:{_cmd[2:]}")
|
||||
else:
|
||||
await switch_rule.finish('格式错误:关闭[功能] [group]/[p/g]')
|
||||
logger.info(
|
||||
f'USER {event.user_id} 使用功能管理命令 {state["_prefix"]["raw_command"]} | {block_type}'
|
||||
)
|
||||
await switch_rule_matcher.finish("格式错误:关闭[功能] [group]/[p/g]")
|
||||
logger.info(f"USER {event.user_id} 使用功能管理命令 {_cmd} | {block_type}")
|
||||
|
||||
|
||||
@plugins_status.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
await plugins_status.send(await get_plugin_status())
|
||||
|
||||
|
||||
@group_task_status.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
await group_task_status.send(await group_current_status(event.group_id))
|
||||
|
||||
@@ -5,6 +5,13 @@ from models.group_info import GroupInfo
|
||||
from asyncpg.exceptions import ConnectionDoesNotExistError
|
||||
|
||||
|
||||
__zx_plugin_name__ = '管理方面定时任务 [Hidden]'
|
||||
__plugin_usage__ = '无'
|
||||
__plugin_des__ = '成员信息和管理权限的定时更新'
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = 'HibiKier'
|
||||
|
||||
|
||||
# 自动更新群员信息
|
||||
@scheduler.scheduled_job(
|
||||
"cron",
|
||||
@@ -13,14 +20,15 @@ from asyncpg.exceptions import ConnectionDoesNotExistError
|
||||
)
|
||||
async def _():
|
||||
bot = get_bot()
|
||||
gl = await bot.get_group_list(self_id=bot.self_id)
|
||||
gl = [g["group_id"] for g in gl]
|
||||
for g in gl:
|
||||
try:
|
||||
await update_member_info(g)
|
||||
logger.info(f"更新群组 g:{g} 成功")
|
||||
except Exception as e:
|
||||
logger.error(f"更新群组错误 g:{g} e:{e}")
|
||||
if bot:
|
||||
gl = await bot.get_group_list()
|
||||
gl = [g["group_id"] for g in gl]
|
||||
for g in gl:
|
||||
try:
|
||||
await update_member_info(g)
|
||||
logger.info(f"更新群组 g:{g} 成功")
|
||||
except Exception as e:
|
||||
logger.error(f"更新群组错误 g:{g} e:{e}")
|
||||
|
||||
|
||||
# 快速更新群员信息以及管理员权限
|
||||
@@ -31,12 +39,13 @@ async def _():
|
||||
async def _():
|
||||
try:
|
||||
bot = get_bot()
|
||||
gl = await bot.get_group_list(self_id=bot.self_id)
|
||||
gl = [g["group_id"] for g in gl]
|
||||
all_group = [x.group_id for x in await GroupInfo.get_all_group()]
|
||||
for g in gl:
|
||||
if g not in all_group:
|
||||
await update_member_info(g)
|
||||
logger.info(f"快速更新群信息以及权限:{g}")
|
||||
if bot:
|
||||
gl = await bot.get_group_list()
|
||||
gl = [g["group_id"] for g in gl]
|
||||
all_group = [x.group_id for x in await GroupInfo.get_all_group()]
|
||||
for g in gl:
|
||||
if g not in all_group:
|
||||
await update_member_info(g)
|
||||
logger.info(f"快速更新群信息以及权限:{g}")
|
||||
except (IndexError, ConnectionDoesNotExistError):
|
||||
pass
|
||||
|
||||
@@ -3,14 +3,20 @@ from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, GROUP, GroupIncreaseNoticeEvent
|
||||
from .data_source import update_member_info
|
||||
|
||||
__plugin_name__ = "更新群组成员列表"
|
||||
|
||||
__zx_plugin_name__ = "更新群组成员列表 [Admin]"
|
||||
__plugin_usage__ = """
|
||||
说明:
|
||||
更新群组成员的基本信息
|
||||
示例:
|
||||
更新群组成员列表
|
||||
"""
|
||||
usage:
|
||||
更新群组成员的基本信息
|
||||
指令:
|
||||
更新群组成员列表/更新群组成员信息
|
||||
""".strip()
|
||||
__plugin_des__ = '更新群组成员列表'
|
||||
__plugin_cmd__ = ['更新群组成员列表']
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = 'HibiKier'
|
||||
__plugin_settings__ = {
|
||||
"admin_level": 1,
|
||||
}
|
||||
|
||||
|
||||
refresh_member_group = on_command(
|
||||
|
||||
Reference in New Issue
Block a user