update code

This commit is contained in:
hibiki 2021-09-09 10:47:26 +08:00
parent 754a0c111c
commit 8d0b0e5505
10 changed files with 104 additions and 54 deletions

View File

@ -10,6 +10,10 @@ except ModuleNotFoundError:
# 是否使用配置文件 # 是否使用配置文件
# 使用配置文件在每次启动时 plugins2info_dict, plugins2cd_dict, plugins2exists_dict 将从本地读取
# 除了 plugins2info_dict 新增内容键值会写入 plugins2info_file
# 其他修改或新增在 configs.config.py中对 plugins2info_dict, plugins2cd_dict, plugins2exists_dict 的配置无效
# 目录data/configs/
USE_CONFIG_FILE: bool = False USE_CONFIG_FILE: bool = False
# 回复消息名称 # 回复消息名称
@ -55,12 +59,12 @@ MAXINFO_PRIVATE_ANIME: int = 20 # 私聊搜索动漫返回的最大数量
MAXINFO_GROUP_ANIME: int = 5 # 群搜索动漫返回的最大数量 MAXINFO_GROUP_ANIME: int = 5 # 群搜索动漫返回的最大数量
MAX_FIND_IMG_COUNT: int = 3 # 识图最大返回数 MAX_FIND_IMG_COUNT: int = 3 # 识图最大返回数
# 参1延迟撤回色图时间(秒)0 为关闭 | 参2监控聊天类型0(私聊) 1(群聊) 2(群聊+私聊) # 参1延迟撤回色图时间(秒)0 为关闭 | 参2监控聊天类型0(私聊) 1(群聊) 2(群聊+私聊)
WITHDRAW_SETU_TIME: Tuple[int, int] = (0, 1) WITHDRAW_SETU_TIME: Tuple[int, int] = (90, 1)
# 参1延迟撤回PIX图片时间(秒)0 为关闭 | 参2监控聊天类型0(私聊) 1(群聊) 2(群聊+私聊) # 参1延迟撤回PIX图片时间(秒)0 为关闭 | 参2监控聊天类型0(私聊) 1(群聊) 2(群聊+私聊)
WITHDRAW_PIX_TIME: Tuple[int, int] = (0, 1) WITHDRAW_PIX_TIME: Tuple[int, int] = (0, 1)
# PIX图库 与 额外图库OmegaPixivIllusts 混合搜索的比例 参1PIX图库 参2OmegaPixivIllusts扩展图库没有此图库请设置为0 # PIX图库 与 额外图库OmegaPixivIllusts 混合搜索的比例 参1PIX图库 参2OmegaPixivIllusts扩展图库没有此图库请设置为0
PIX_OMEGA_PIXIV_RATIO: Tuple[int, int] = (10, 0) PIX_OMEGA_PIXIV_RATIO: Tuple[int, int] = (2, 8)
# 各种卡池的开关 # 各种卡池的开关
PRTS_FLAG = True # 明日方舟 PRTS_FLAG = True # 明日方舟
@ -92,7 +96,7 @@ CHECK_NOTICE_INFO_CD = 300 # 群检测,个人权限检测等各种检测提
# 注:即在 MALICIOUS_CHECK_TIME 时间内触发相同命令 MALICIOUS_BAN_COUNT 将被ban MALICIOUS_BAN_TIME 分钟 # 注:即在 MALICIOUS_CHECK_TIME 时间内触发相同命令 MALICIOUS_BAN_COUNT 将被ban MALICIOUS_BAN_TIME 分钟
MALICIOUS_BAN_TIME: int = 30 # 恶意命令触发检测触发后ban的时长分钟 MALICIOUS_BAN_TIME: int = 30 # 恶意命令触发检测触发后ban的时长分钟
MALICIOUS_BAN_COUNT: int = 8 # 恶意命令触发检测最大触发次数 MALICIOUS_BAN_COUNT: int = 3 # 恶意命令触发检测最大触发次数
MALICIOUS_CHECK_TIME: int = 5 # 恶意命令触发检测规定时间内(秒) MALICIOUS_CHECK_TIME: int = 5 # 恶意命令触发检测规定时间内(秒)
# LEVEL # LEVEL
@ -102,6 +106,7 @@ UPLOAD_LEVEL: int = 6 # 上传图片权限
BAN_LEVEL: int = 5 # BAN权限 BAN_LEVEL: int = 5 # BAN权限
OC_LEVEL: int = 2 # 开关群功能权限 OC_LEVEL: int = 2 # 开关群功能权限
MUTE_LEVEL: int = 5 # 更改禁言设置权限 MUTE_LEVEL: int = 5 # 更改禁言设置权限
MEMBER_ACTIVITY_LEVEL = 5 # 群员活跃检测设置权限
GROUP_BILIBILI_SUB_LEVEL = 5 # 群内bilibili订阅需要的权限 GROUP_BILIBILI_SUB_LEVEL = 5 # 群内bilibili订阅需要的权限
DEFAULT_GROUP_LEVEL = 5 # 默认群等级 DEFAULT_GROUP_LEVEL = 5 # 默认群等级
@ -140,6 +145,7 @@ admin_plugins_auth = {
"upload_img": UPLOAD_LEVEL, "upload_img": UPLOAD_LEVEL,
"admin_help": 1, "admin_help": 1,
"mute": MUTE_LEVEL, "mute": MUTE_LEVEL,
"member_activity_handle": MEMBER_ACTIVITY_LEVEL,
} }
# 需要cd的功能方便管理[秒] # 需要cd的功能方便管理[秒]
@ -307,10 +313,40 @@ HIBIAPI = HIBIAPI[:-1] if HIBIAPI[-1] == "/" else HIBIAPI
RSSHUBAPP = RSSHUBAPP[:-1] if RSSHUBAPP[-1] == "/" else RSSHUBAPP RSSHUBAPP = RSSHUBAPP[:-1] if RSSHUBAPP[-1] == "/" else RSSHUBAPP
# plugins2info_file = Path(DATA_PATH) / 'configs' / 'plugins2info.json' if USE_CONFIG_FILE:
# plugins2info_file.parent.mkdir(exist_ok=True, parents=True) # 读取配置文件
# plugins2info_file = Path(DATA_PATH) / 'configs' / 'plugins2info.json'
# with open(f'{DATA_PATH}/configs/') plugins2info_file.parent.mkdir(exist_ok=True, parents=True)
if plugins2info_file.exists():
with open(plugins2info_file, 'r') as f:
_data = json.load(f)
for p in plugins2info_dict:
if not _data.get(p):
_data[p] = plugins2info_dict[p]
with open(plugins2info_file, 'w') as wf:
json.dump(_data, wf, ensure_ascii=False, indent=4)
plugins2info_dict = _data
else:
with open(plugins2info_file, 'w', encoding='utf8') as wf:
json.dump(plugins2info_dict, wf, ensure_ascii=False, indent=4)
plugins2cd_file = Path(DATA_PATH) / 'configs' / 'plugins2cd.json'
if plugins2cd_file.exists():
with open(plugins2cd_file, 'r', encoding='utf8') as f:
plugins2cd_dict = json.load(f)
else:
with open(plugins2cd_file, 'w', encoding='utf8') as wf:
json.dump(plugins2cd_dict, wf, ensure_ascii=False, indent=4)
plugins2exists_file = Path(DATA_PATH) / 'configs' / 'plugins2exists.json'
if plugins2exists_file.exists():
with open(plugins2exists_file, 'r', encoding='utf8') as f:
plugins2exists_dict = json.load(f)
else:
with open(plugins2exists_file, 'w', encoding='utf8') as wf:
json.dump(plugins2exists_dict, wf, ensure_ascii=False, indent=4)
# 配置文件应用 # 配置文件应用
# if USE_CONFIG_FILE: # if USE_CONFIG_FILE:

View File

@ -24,6 +24,7 @@ class GroupInfoUser(db.Model):
belonging_group: int, belonging_group: int,
user_name: str, user_name: str,
user_join_time: datetime, user_join_time: datetime,
uid: Optional[int] = None,
) -> bool: ) -> bool:
""" """
说明 说明
@ -33,6 +34,7 @@ class GroupInfoUser(db.Model):
:param belonging_group: 群号 :param belonging_group: 群号
:param user_name: 用户名称 :param user_name: 用户名称
:param user_join_time: 入群时间 :param user_join_time: 入群时间
:param uid: 用户唯一 id自动生成
""" """
query = cls.query.where( query = cls.query.where(
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group) (cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
@ -44,6 +46,7 @@ class GroupInfoUser(db.Model):
user_name=user_name, user_name=user_name,
belonging_group=belonging_group, belonging_group=belonging_group,
user_join_time=user_join_time, user_join_time=user_join_time,
uid=uid
) )
return True return True
except Exception: except Exception:

View File

@ -1,6 +1,6 @@
from nonebot import on_command, export from nonebot import on_command, on_notice
from nonebot.typing import T_State from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, GROUP from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, GROUP, GroupIncreaseNoticeEvent
from .data_source import update_member_info from .data_source import update_member_info
__plugin_name__ = "更新群组成员列表" __plugin_name__ = "更新群组成员列表"
@ -12,8 +12,6 @@ __plugin_usage__ = """
更新群组成员列表 更新群组成员列表
""" """
export = export()
export.update_member_info = update_member_info
refresh_member_group = on_command( refresh_member_group = on_command(
"更新群组成员列表", aliases={"更新群组成员信息"}, permission=GROUP, priority=5, block=True "更新群组成员列表", aliases={"更新群组成员信息"}, permission=GROUP, priority=5, block=True
@ -26,3 +24,12 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await refresh_member_group.finish("更新群员信息成功!", at_sender=True) await refresh_member_group.finish("更新群员信息成功!", at_sender=True)
else: else:
await refresh_member_group.finish("更新群员信息失败!", at_sender=True) await refresh_member_group.finish("更新群员信息失败!", at_sender=True)
group_increase_handle = on_notice(priority=1, block=False)
@group_increase_handle.handle()
async def _(bot: Bot, event: GroupIncreaseNoticeEvent, state: dict):
if event.user_id == int(bot.self_id):
await update_member_info(event.group_id)

View File

@ -19,6 +19,10 @@ __plugin_usage__ = f'''[权限等级]管理帮助:
\t\t/设置检测次数/设置禁言时长 \t\t/设置检测次数/设置禁言时长
[5]7.群订阅相关 -> 指令添加订阅 [主播/up/番剧] [id/番名/链接] [5]7.群订阅相关 -> 指令添加订阅 [主播/up/番剧] [id/番名/链接]
\t\t/删除订阅 [id]/ 查看订阅 \t\t/删除订阅 [id]/ 查看订阅
[5]8.群员活跃度相关 --> 指令:群员活跃检测设置
设置群员活跃检测时长()
添加群员活跃检测白名单[at]...
查看群员活跃检测白名单
[6]8.上传图片/连续上传图片(6) [6]8.上传图片/连续上传图片(6)
[7]9.移动图片(7) [7]9.移动图片(7)
[7]10.删除图片(7) [7]10.删除图片(7)

View File

@ -279,9 +279,13 @@ async def _get_season_status(id_) -> Optional[str]:
_idx = (await BilibiliSub.get_sub(id_)).season_current_episode _idx = (await BilibiliSub.get_sub(id_)).season_current_episode
new_ep = season_info["media"]["new_ep"]["index"] new_ep = season_info["media"]["new_ep"]["index"]
if new_ep != _idx: if new_ep != _idx:
await BilibiliSub.update_sub_info(id_, season_current_episode=new_ep, season_update_time=datetime.now()) await BilibiliSub.update_sub_info(
id_, season_current_episode=new_ep, season_update_time=datetime.now()
)
return ( return (
f'{image(season_info["media"]["cover"])}\n' f"[{title}]更新啦\n" f"最新集数:{new_ep}" f'{image(season_info["media"]["cover"])}\n'
f"[{title}]更新啦\n"
f"最新集数:{new_ep}"
) )
return None return None
@ -363,6 +367,8 @@ class SubManager:
:return: :return:
""" """
sub = None sub = None
if not self.live_data and not self.up_data and not self.season_data:
return sub
self.current_index += 1 self.current_index += 1
if self.current_index == 0: if self.current_index == 0:
if self.live_data: if self.live_data:
@ -382,5 +388,3 @@ class SubManager:
return sub return sub
await self.reload_sub_data() await self.reload_sub_data()
return await self.random_sub_data() return await self.random_sub_data()

View File

@ -19,7 +19,7 @@ coser = on_command(
) )
url = "http://81.70.100.130/api/cosplay.php" url = "http://api520.ltd/api/cosplay.php"
@coser.handle() @coser.handle()
@ -29,20 +29,22 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
for _ in range(3): for _ in range(3):
try: try:
async with session.get(url, timeout=2) as response: async with session.get(url, timeout=2) as response:
r = re.search(r'±img=(.*)±', await response.text()) _url = await response.text()
if r: async with session.get(_url, timeout=5, verify_ssl=False) as res:
async with session.get(r.group(1), timeout=5, verify_ssl=False) as res: if res.status == 200:
async with aiofiles.open(f'{IMAGE_PATH}/temp/{event.user_id}_coser.jpg', 'wb') as f: async with aiofiles.open(f'{IMAGE_PATH}/temp/{event.user_id}_coser.jpg', 'wb') as f:
await f.write(await res.read()) await f.write(await res.read())
logger.info( logger.info(
f"(USER {event.user_id}, " f"(USER {event.user_id}, "
f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})" f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送COSER" f" 发送COSER"
) )
await coser.send(image(f'{event.user_id}_coser.jpg', 'temp')) await coser.send(image(f'{event.user_id}_coser.jpg', 'temp'))
break break
except TimeoutError: except TimeoutError:
pass pass
else:
await coser.send('你cos给我看')
except Exception as e: except Exception as e:
await coser.send('发生了预料之外的错误..请稍后再试或联系管理员修复...') await coser.send('发生了预料之外的错误..请稍后再试或联系管理员修复...')
logger.error(f'coser 发送了未知错误 {type(e)}{e}') logger.error(f'coser 发送了未知错误 {type(e)}{e}')

View File

@ -116,15 +116,10 @@ async def _(matcher: Matcher, bot: Bot, event: GroupMessageEvent, state: T_State
return return
if matcher.type == "message" and matcher.priority not in [1, 9]: if matcher.type == "message" and matcher.priority not in [1, 9]:
if state["_prefix"]["raw_command"]: if state["_prefix"]["raw_command"]:
# print(state["_prefix"]["raw_command"])
if _blmt.check(f'{event.user_id}{state["_prefix"]["raw_command"]}'): if _blmt.check(f'{event.user_id}{state["_prefix"]["raw_command"]}'):
if await BanUser.ban(event.user_id, 9, MALICIOUS_BAN_TIME * 60): if await BanUser.ban(event.user_id, 9, MALICIOUS_BAN_TIME * 60):
logger.info(f"USER {event.user_id} 触发了恶意触发检测") logger.info(f"USER {event.user_id} 触发了恶意触发检测")
# await update_img.finish('检测到恶意触发命令,您将被封禁 30 分钟', at_sender=True) if isinstance(event, GroupMessageEvent):
if event.message_type == "group":
if not static_flmt.check(event.user_id):
return
static_flmt.start_cd(event.user_id)
try: try:
await bot.send_group_msg( await bot.send_group_msg(
group_id=event.group_id, group_id=event.group_id,
@ -133,9 +128,6 @@ async def _(matcher: Matcher, bot: Bot, event: GroupMessageEvent, state: T_State
except ActionFailed: except ActionFailed:
pass pass
else: else:
if not static_flmt.check(event.user_id):
return
static_flmt.start_cd(event.user_id)
try: try:
await bot.send_private_msg( await bot.send_private_msg(
user_id=event.user_id, user_id=event.user_id,

View File

@ -31,7 +31,10 @@ driver: Driver = nonebot.get_driver()
@driver.on_startup @driver.on_startup
async def init_image(): async def init_image():
SIGN_RESOURCE_PATH.mkdir(parents=True, exist_ok=True) SIGN_RESOURCE_PATH.mkdir(parents=True, exist_ok=True)
await GroupInfoUser.add_member_info(114514, 114514, "", datetime.min) await GroupInfoUser.add_member_info(114514, 114514, "", datetime.min, 0)
_u = await GroupInfoUser.get_member_info(114514, 114514)
if _u.uid is None:
await _u.update(uid=0).apply()
generate_progress_bar_pic() generate_progress_bar_pic()
clear_sign_data_pic() clear_sign_data_pic()

View File

@ -15,16 +15,17 @@ yiqing = on_command("疫情", aliases={"查询疫情", "疫情查询"}, priority
@yiqing.handle() @yiqing.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State): async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json()) msg = get_message_text(event.json())
result = await get_yiqing_data(msg) if msg:
if result: result = await get_yiqing_data(msg)
await yiqing.send(result) if result:
logger.info( await yiqing.send(result)
f"(USER {event.user_id}, GROUP " logger.info(
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情: {msg}" f"(USER {event.user_id}, GROUP "
) f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情: {msg}"
else: )
await yiqing.send("查询失败!!!!", at_sender=True) else:
logger.info( await yiqing.send("查询失败!!!!", at_sender=True)
f"(USER {event.user_id}, GROUP " logger.info(
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败" f"(USER {event.user_id}, GROUP "
) f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败"
)

View File

@ -7,8 +7,7 @@
"models/pixiv.py", "models/pixiv.py",
"models/russian_user.py", "models/russian_user.py",
"models/setu.py", "models/setu.py",
"plugins/admin_bot_manage/data_source.py", "plugins/admin_bot_manage",
"plugins/admin_bot_manage/switch_rule.py",
"plugins/admin_help/__init__.py", "plugins/admin_help/__init__.py",
"plugins/ai/__init__.py", "plugins/ai/__init__.py",
"plugins/ai/data_source.py", "plugins/ai/data_source.py",
@ -65,9 +64,7 @@
"utils/static_data/__init__.py", "utils/static_data/__init__.py",
"utils/static_data/data_class.py", "utils/static_data/data_class.py",
"utils/static_data/group_manager.py", "utils/static_data/group_manager.py",
"utils/utils.py" "utils/utils.py",
],
"add_file": [
"models/omega_pixiv_illusts.py", "models/omega_pixiv_illusts.py",
"models/sign_group_user.py", "models/sign_group_user.py",
"plugins/bilibili_sub", "plugins/bilibili_sub",
@ -79,5 +76,6 @@
"plugins/withdraw.py", "plugins/withdraw.py",
"resources/img/sign" "resources/img/sign"
], ],
"add_file": [],
"delete_file": ["plugins/nonebot_plugin_withdraw", "models/sigin_group_user.py"] "delete_file": ["plugins/nonebot_plugin_withdraw", "models/sigin_group_user.py"]
} }