update 0.0.6.0

This commit is contained in:
HibiKier
2021-11-04 16:11:50 +08:00
parent 21c1950898
commit 19d650c35d
217 changed files with 8213 additions and 5697 deletions
View File
-3
View File
@@ -1,3 +0,0 @@
import nonebot
nonebot.load_plugins("plugins/admin_bot_manage")
@@ -1,51 +0,0 @@
from nonebot import on_command
from utils.utils import get_message_text, get_message_imgs
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
__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(
"自定义进群欢迎消息",
aliases={"自定义欢迎消息", "自定义群欢迎消息", "设置群欢迎消息"},
permission=GROUP,
priority=5,
block=True,
)
@custom_welcome.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
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("发生了一些未知错误...")
-273
View File
@@ -1,273 +0,0 @@
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
from utils.utils import get_local_proxy, get_bot
from pathlib import Path
from models.group_member_info import GroupInfoUser
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.manager import group_manager, plugins2settings_manager
from utils.image_utils import CreateImg
import aiofiles
import aiohttp
import asyncio
import time
import os
try:
import ujson as json
except ModuleNotFoundError:
import json
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 = (
Path() / "data" / "custom_welcome_msg" / "custom_welcome_msg.json"
)
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")
if not custom_welcome_msg_json.exists():
custom_welcome_msg_json.parent.mkdir(parents=True, exist_ok=True)
data = {}
else:
try:
data = json.load(open(custom_welcome_msg_json, "r"))
except FileNotFoundError:
data = {}
try:
if msg:
data[str(group_id)] = str(msg)
json.dump(
data, open(custom_welcome_msg_json, "w"), indent=4, ensure_ascii=False
)
logger.info(f"USER {user_id} GROUP {group_id} 更换群欢迎消息 {msg}")
result += msg
if img:
async with aiohttp.ClientSession() as session:
async with session.get(img, proxy=get_local_proxy()) as response:
async with aiofiles.open(
DATA_PATH + f"custom_welcome_msg/{group_id}.jpg", "wb"
) as f:
await f.write(await response.read())
img_result = image(abspath=DATA_PATH + f"custom_welcome_msg/{group_id}.jpg")
logger.info(f"USER {user_id} GROUP {group_id} 更换群欢迎消息图片")
except Exception as e:
logger.error(f"GROUP {group_id} 替换群消息失败 e:{e}")
return "替换群消息失败.."
return f"替换群欢迎消息成功:\n{result}" + img_result
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"
status = cmd[:2]
cmd = cmd[2:]
type_ = 'plugin'
modules = plugins2settings_manager.get_plugin_module(cmd, True)
if cmd == '全部被动':
for task in task_data:
if status == "开启":
if not await group_manager.check_group_task_status(group_id, task):
await group_manager.open_group_task(group_id, task)
else:
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(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:]
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() -> 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)
b.text((10, 10), flag_str)
A = CreateImg(380, height)
A.paste(a)
A.paste(b, (150, 0))
return image(b64=A.pic2bs4())
async def update_member_info(group_id: int, remind_superuser: bool = False) -> bool:
"""
更新群成员信息
:param group_id: 群号
:param remind_superuser: 失败信息提醒超级用户
"""
bot = get_bot()
_group_user_list = await bot.get_group_member_list(group_id=group_id)
_error_member_list = []
_exist_member_list = []
# try:
for user_info in _group_user_list:
if user_info["card"] == "":
nickname = user_info["nickname"]
else:
nickname = user_info["card"]
async with db.transaction():
# 更新权限
if (
user_info["role"]
in [
"owner",
"admin",
]
and not await LevelUser.is_group_flag(user_info["user_id"], group_id)
):
await LevelUser.set_level(
user_info["user_id"], user_info["group_id"], ADMIN_DEFAULT_AUTH
)
if str(user_info["user_id"]) in bot.config.superusers:
await LevelUser.set_level(
user_info["user_id"], user_info["group_id"], 9
)
user = await GroupInfoUser.get_member_info(
user_info["user_id"], user_info["group_id"]
)
if user:
if user.user_name != nickname:
await user.update(user_name=nickname).apply()
logger.info(
f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新群昵称成功"
)
_exist_member_list.append(int(user_info["user_id"]))
continue
join_time = datetime.strptime(
time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime(user_info["join_time"])
),
"%Y-%m-%d %H:%M:%S",
)
if await GroupInfoUser.add_member_info(
user_info["user_id"],
user_info["group_id"],
nickname,
join_time,
):
_exist_member_list.append(int(user_info["user_id"]))
logger.info(f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新成功")
else:
_error_member_list.append(
f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新失败\n"
)
_del_member_list = list(
set(_exist_member_list).difference(
set(await GroupInfoUser.get_group_member_id_list(group_id))
)
)
if _del_member_list:
for del_user in _del_member_list:
if await GroupInfoUser.delete_member_info(del_user, group_id):
logger.info(f"退群用户{del_user} 所属{group_id} 已删除")
else:
logger.info(f"退群用户{del_user} 所属{group_id} 删除失败")
if _error_member_list and remind_superuser:
result = ""
for error_user in _error_member_list:
result += error_user
await bot.send_private_msg(
user_id=int(list(bot.config.superusers)[0]), message=result[:-1]
)
return True
-42
View File
@@ -1,42 +0,0 @@
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
-106
View File
@@ -1,106 +0,0 @@
from nonebot import on_command, on_message
from nonebot.typing import T_State
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 NICKNAME, OC_LEVEL
from utils.utils import get_message_text, is_number
from nonebot.permission import SUPERUSER
from .rule import switch_rule
__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)
@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_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 = " ".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_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_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_matcher.send(f"已在群聊中{_cmd[:2]}功能:{_cmd[2:]}")
else:
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))
-51
View File
@@ -1,51 +0,0 @@
from utils.utils import scheduler, get_bot
from .data_source import update_member_info
from services.log import logger
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",
hour=2,
minute=1,
)
async def _():
bot = get_bot()
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}")
# 快速更新群员信息以及管理员权限
@scheduler.scheduled_job(
"interval",
minutes=5,
)
async def _():
try:
bot = get_bot()
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, False)
logger.info(f"快速更新群信息以及权限:{g}")
except (IndexError, ConnectionDoesNotExistError):
pass
@@ -1,41 +0,0 @@
from nonebot import on_command, on_notice
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, GROUP, GroupIncreaseNoticeEvent
from .data_source import update_member_info
__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(
"更新群组成员列表", aliases={"更新群组成员信息"}, permission=GROUP, priority=5, block=True
)
@refresh_member_group.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
if await update_member_info(event.group_id):
await refresh_member_group.finish("更新群员信息成功!", at_sender=True)
else:
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)
-31
View File
@@ -1,31 +0,0 @@
from nonebot import on_notice
from services.log import logger
from nonebot.adapters.cqhttp import Bot, GroupAdminNoticeEvent
from nonebot.typing import T_State
from models.level_user import LevelUser
from models.group_member_info import GroupInfoUser
from configs.config import ADMIN_DEFAULT_AUTH
__zx_plugin_name__ = "群管理员变动监测 [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
admin_notice = on_notice(priority=5)
@admin_notice.handle()
async def _(bot: Bot, event: GroupAdminNoticeEvent, state: T_State):
try:
nickname = (
await GroupInfoUser.get_member_info(event.user_id, event.group_id)
).user_name
except AttributeError:
nickname = event.user_id
if event.sub_type == "set":
await LevelUser.set_level(event.user_id, event.group_id, ADMIN_DEFAULT_AUTH)
logger.info(f"为新晋管理员 {nickname}({event.user_id}) 添加权限等级:{ADMIN_DEFAULT_AUTH}")
elif event.sub_type == "unset":
await LevelUser.delete_level(event.user_id, event.group_id)
logger.info(f"将非管理员 {nickname}({event.user_id}) 取消权限等级")
-27
View File
@@ -1,27 +0,0 @@
from nonebot import on_command
from nonebot.typing import T_State
from nonebot.adapters import Bot
from nonebot.adapters.cqhttp import GroupMessageEvent
from utils.message_builder import image
from .data_source import create_help_image, admin_help_image
__zx_plugin_name__ = '管理帮助 [Admin]'
__plugin_usage__ = '管理员帮助,在群内回复“管理员帮助”'
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
__plugin_settings__ = {
"admin_level": 1,
}
admin_help = on_command("管理员帮助", aliases={"管理帮助"}, priority=5, block=True)
if admin_help_image.exists():
admin_help_image.unlink()
@admin_help.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
if not admin_help_image.exists():
await create_help_image()
await admin_help.send(image('admin_help_img.png'))
-91
View File
@@ -1,91 +0,0 @@
from utils.image_utils import CreateImg
from configs.path_config import IMAGE_PATH
from services.log import logger
from utils.utils import get_matchers
from utils.manager import group_manager
from nonebot.adapters.cqhttp import Bot
from pathlib import Path
from nonebot import Driver
import asyncio
import nonebot
driver: Driver = nonebot.get_driver()
background = Path(IMAGE_PATH) / "background" / "0.png"
admin_help_image = Path(IMAGE_PATH) / 'admin_help_img.png'
@driver.on_bot_connect
async def create_help_image(bot: Bot = None):
"""
创建管理员帮助图片
"""
if not group_manager.get_task_data():
await group_manager.init_group_task()
logger.info(f'已成功加载 {len(group_manager.get_task_data())} 个被动技能.')
await asyncio.get_event_loop().run_in_executor(
None, _create_help_image
)
def _create_help_image():
"""
创建管理员帮助图片
"""
_matchers = get_matchers()
_plugin_name_list = []
width = 0
_plugin_level = {}
for matcher in _matchers:
_plugin = nonebot.plugin.get_plugin(matcher.module)
_module = _plugin.module
try:
plugin_name = _module.__getattribute__("__zx_plugin_name__")
except AttributeError:
continue
try:
if (
"[admin]" in plugin_name.lower()
and plugin_name not in _plugin_name_list
and plugin_name != "管理帮助 [Admin]"
):
_plugin_name_list.append(plugin_name)
plugin_settings = _module.__getattribute__("__plugin_settings__")
plugin_des = _module.__getattribute__("__plugin_des__")
plugin_cmd = _module.__getattribute__("__plugin_cmd__")
plugin_cmd = [x for x in plugin_cmd if "[_superuser]" not in x]
admin_level = int(plugin_settings["admin_level"])
if _plugin_level.get(admin_level):
_plugin_level[admin_level].append(
f"[{admin_level}] {plugin_des} -> " + " / ".join(plugin_cmd)
)
else:
_plugin_level[admin_level] = [
f"[{admin_level}] {plugin_des} -> " + " / ".join(plugin_cmd)
]
x = len(f"[{admin_level}] {plugin_des} -> " + " / ".join(plugin_cmd)) * 23
width = width if width > x else x
except AttributeError:
logger.warning(f"获取管理插件 {matcher.module}: {plugin_name} 设置失败...")
help_str = "* 注: ‘*’ 代表可有多个相同参数 ‘?’ 代表可省略该参数 *\n\n" \
"[权限等级] 管理员帮助:\n\n"
x = list(_plugin_level.keys())
x.sort()
for level in x:
for help_ in _plugin_level[level]:
help_str += f"\t{help_}\n\n"
help_str += '-----[被动技能开关]-----\n\n'
task_data = group_manager.get_task_data()
for i, x in enumerate(task_data.keys()):
help_str += f'{i+1}.开启/关闭{task_data[x]}\n\n'
height = len(help_str.split("\n")) * 33
A = CreateImg(width, height, font_size=24)
_background = CreateImg(width, height, background=background)
A.text((150, 110), help_str)
A.paste(_background, alpha=True)
A.save(admin_help_image)
logger.info(f'已成功加载 {len(_plugin_name_list)} 条管理员命令')
+19 -2
View File
@@ -13,7 +13,7 @@ from models.group_member_info import GroupInfoUser
from services.log import logger
from utils.utils import get_message_text, get_message_imgs
from .data_source import get_chat_result, hello, no_result
from configs.config import NICKNAME
from configs.config import NICKNAME, Config
__zx_plugin_name__ = "AI"
__plugin_usage__ = f"""
@@ -28,6 +28,23 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["Ai", "ai", "AI", "aI"],
}
__plugin_configs__ = {
"TL_KEY": {
"value": [],
"help": "图灵Key"
},
"ALAPI_AI_CHECK": {
"value": False,
"help": "是否检测青云客骂娘回复",
"default_value": False
}
}
Config.add_plugin_config(
"alapi",
"ALAPI_TOKEN",
None,
help_="在https://admin.alapi.cn/user/login登录后获取token"
)
ai = on_message(rule=to_me(), priority=8)
@@ -36,7 +53,7 @@ ai = on_message(rule=to_me(), priority=8)
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
imgs = get_message_imgs(event.json())
if "CQ:xml" in msg:
if "CQ:xml" in str(event.get_message()):
return
# 打招呼
if (not msg and not imgs) or msg in [
+5 -5
View File
@@ -4,11 +4,10 @@ import re
import aiohttp
from aiohttp.client import ClientSession
from configs.config import TL_KEY, ALAPI_TOKEN, ALAPI_AI_CHECK, NICKNAME
from configs.path_config import IMAGE_PATH, DATA_PATH
from services.log import logger
from utils.message_builder import image, face
from configs.config import Config, NICKNAME
try:
import ujson as json
@@ -70,6 +69,7 @@ async def tu_ling(text: str, img_url: str, user_id: int, sess: ClientSession) ->
:return: 图灵回复
"""
global index
TL_KEY = Config.get_config("ai", "TL_KEY")
try:
if text:
req = {
@@ -149,7 +149,7 @@ async def xie_ai(text: str, sess: ClientSession) -> str:
break
return (
content
if not content and not ALAPI_AI_CHECK
if not content and not Config.get_config("ai", "ALAPI_AI_CHECK")
else await check_text(content, sess)
)
@@ -200,9 +200,9 @@ async def check_text(text: str, sess: ClientSession) -> str:
:param text: 回复
:param sess: AIOHTTP SESSION
"""
if not ALAPI_TOKEN:
if not Config.get_config("alapi", "ALAPI_TOKEN"):
return text
params = {"token": ALAPI_TOKEN, "text": text}
params = {"token": Config.get_config("alapi", "ALAPI_TOKEN"), "text": text}
try:
async with sess.get(check_url, timeout=2, params=params) as response:
data = await response.json()
+8
View File
@@ -1,3 +1,11 @@
from configs.config import Config
import nonebot
nonebot.load_plugins("plugins/alapi")
Config.add_plugin_config(
"alapi",
"ALAPI_TOKEN",
None,
help_="在https://admin.alapi.cn/user/login登录后获取token"
)
+1 -3
View File
@@ -1,7 +1,6 @@
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
from configs.config import ALAPI_TOKEN
from .data_source import get_data
from services.log import logger
@@ -34,8 +33,7 @@ comments_163_url = "https://v2.alapi.cn/api/comment"
@comments_163.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
params = {"token": ALAPI_TOKEN}
data, code = await get_data(comments_163_url, params)
data, code = await get_data(comments_163_url)
if code != 200:
await comments_163.finish(data, at_sender=True)
data = data["data"]
+18 -23
View File
@@ -1,53 +1,48 @@
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot, MessageEvent, Message, GroupMessageEvent
from nonebot.typing import T_State
from configs.config import ALAPI_TOKEN
from utils.message_builder import image
from utils.utils import get_message_text
from .data_source import get_data
from services.log import logger
__zx_plugin_name__ = 'b封面'
__plugin_usage__ = """usage:
__zx_plugin_name__ = "b封面"
__plugin_usage__ = """
usage:
b封面 [链接/av/bv/cv/直播id]
示例:b封面 av86863038
"""
__plugin_des__ = '快捷的b站视频封面获取方式'
__plugin_cmd__ = ['b封面/B封面']
__plugin_type__ = ('一些工具',)
""".strip()
__plugin_des__ = "快捷的b站视频封面获取方式"
__plugin_cmd__ = ["b封面/B封面"]
__plugin_type__ = ("一些工具",)
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["b封面", 'B封面'],
"cmd": ["b封面", "B封面"],
}
cover = on_command('b封面', aliases={'B封面'}, priority=5, block=True)
cover = on_command("b封面", aliases={"B封面"}, priority=5, block=True)
cover_url = 'https://v2.alapi.cn/api/bilibili/cover'
cover_url = "https://v2.alapi.cn/api/bilibili/cover"
@cover.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
params = {
'token': ALAPI_TOKEN,
'c': msg
}
params = {"c": msg}
data, code = await get_data(cover_url, params)
if code != 200:
await cover.finish(data, at_sender=True)
data = data['data']
title = data['title']
img = data['cover']
await cover.send(Message(f'title:{title}\n{image(img)}'))
data = data["data"]
title = data["title"]
img = data["cover"]
await cover.send(Message(f"title:{title}\n{image(img)}"))
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 获取b站封面: {title} url:{img}")
f" 获取b站封面: {title} url:{img}"
)
+11 -9
View File
@@ -2,21 +2,23 @@ from nonebot.adapters.cqhttp import MessageSegment
from utils.image_utils import CreateImg
from utils.message_builder import image
from configs.path_config import IMAGE_PATH
from typing import Union
from typing import Optional
from configs.config import Config
import aiohttp
async def get_data(url: str, params: dict) -> 'Union[dict, str], int':
async def get_data(url: str, params: Optional[dict] = None) -> "Union[dict, str], int":
"""
获取ALAPI数据
:param url: 请求链接
:param params: 参数
"""
if not params:
params = {}
params["token"] = Config.get_config("alapi", "ALAPI_TOKEN")
async with aiohttp.ClientSession() as session:
try:
async with session.get(
url, timeout=2, params=params
) as response:
async with session.get(url, timeout=2, params=params) as response:
data = await response.json()
if data["code"] == 200:
if not data["data"]:
@@ -33,13 +35,13 @@ def gen_wbtop_pic(data: dict) -> MessageSegment:
生成微博热搜图片
:param data: 微博热搜数据
"""
bk = CreateImg(700, 32 * 50 + 280, 700, 32, color='#797979')
wbtop_bk = CreateImg(700, 280, background=f'{IMAGE_PATH}/other/webtop.png')
bk = CreateImg(700, 32 * 50 + 280, 700, 32, color="#797979")
wbtop_bk = CreateImg(700, 280, background=f"{IMAGE_PATH}/other/webtop.png")
bk.paste(wbtop_bk)
text_bk = CreateImg(700, 32 * 50, 700, 32, color='#797979')
text_bk = CreateImg(700, 32 * 50, 700, 32, color="#797979")
for i, data in enumerate(data):
title = f"{i+1}. {data['hot_word']}"
hot = data['hot_word_num']
hot = data["hot_word_num"]
img = CreateImg(700, 30, font_size=20)
w, h = img.getsize(title)
img.text((10, int((30 - h) / 2)), title)
+15 -21
View File
@@ -1,48 +1,42 @@
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
from configs.config import ALAPI_TOKEN
from services.log import logger
from .data_source import get_data
__zx_plugin_name__ = '古诗'
__zx_plugin_name__ = "古诗"
__plugin_usage__ = """usage:
平白无故念首诗
示例:念诗/来首诗/念首诗
"""
__plugin_des__ = '为什么突然文艺起来了!'
__plugin_cmd__ = ['念诗/来首诗/念首诗']
__plugin_des__ = "为什么突然文艺起来了!"
__plugin_cmd__ = ["念诗/来首诗/念首诗"]
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ['念诗', '来首诗', '念首诗'],
"cmd": ["念诗", "来首诗", "念首诗"],
}
poetry = on_command("念诗", aliases={'来首诗', '念首诗'}, priority=5, block=True)
poetry = on_command("念诗", aliases={"来首诗", "念首诗"}, priority=5, block=True)
poetry_url = 'https://v2.alapi.cn/api/shici'
poetry_url = "https://v2.alapi.cn/api/shici"
@poetry.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
params = {
'token': ALAPI_TOKEN
}
data, code = await get_data(poetry_url, params)
data, code = await get_data(poetry_url)
if code != 200:
await poetry.finish(data, at_sender=True)
data = data['data']
content = data['content']
title = data['origin']
author = data['author']
await poetry.send(f'{content}\n\t——{author}《{title}》')
data = data["data"]
content = data["content"]
title = data["origin"]
author = data["author"]
await poetry.send(f"{content}\n\t——{author}《{title}》")
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送古诗: f'{content}\n\t--{author}《{title}》'")
f" 发送古诗: f'{content}\n\t--{author}《{title}》'"
)
+2 -5
View File
@@ -1,7 +1,6 @@
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
from configs.config import ALAPI_TOKEN
from services.log import logger
from .data_source import get_data, gen_wbtop_pic
from utils.browser import get_browser
@@ -43,10 +42,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
global wbtop_data
msg = get_message_text(event.json())
if not wbtop_data or not msg:
params = {
'token': ALAPI_TOKEN
}
data, code = await get_data(wbtop_url, params)
data, code = await get_data(wbtop_url)
if code != 200:
await wbtop.finish(data, at_sender=True)
wbtop_data = data['data']
@@ -67,6 +63,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
page = await browser.new_page()
await page.goto(url, wait_until='networkidle', timeout=10000)
await page.set_viewport_size({"width": 2560, "height": 1080})
await asyncio.sleep(5)
div = await page.query_selector("#pl_feedlist_index")
await div.screenshot(path=f'{IMAGE_PATH}/temp/wbtop_{event.user_id}.png', timeout=100000)
await page.close()
-87
View File
@@ -1,87 +0,0 @@
from nonebot import on_request
from nonebot.adapters.cqhttp import Bot, FriendRequestEvent, GroupRequestEvent
from models.friend_user import FriendUser
from datetime import datetime
from configs.config import AUTO_ADD_FRIEND, NICKNAME
from nonebot.adapters.cqhttp.exception import ActionFailed
from utils.utils import scheduler
import time
__zx_plugin_name__ = "好友群聊处理请求 [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
friend_req = on_request(priority=5)
exists_data = {"private": {}, "group": {}}
@friend_req.handle()
async def _(bot: Bot, event: FriendRequestEvent, state: dict):
global exists_data
if exists_data["private"].get(event.user_id):
if time.time() - exists_data["private"][event.user_id] < 60 * 5:
return
exists_data["private"][event.user_id] = time.time()
user = await bot.get_stranger_info(user_id=event.user_id)
nickname = user["nickname"]
await bot.send_private_msg(
user_id=int(list(bot.config.superusers)[0]),
message=f"*****一份好友申请*****\n"
f"昵称:{nickname}({event.user_id})\n"
f"自动同意:{'√' if AUTO_ADD_FRIEND else '×'}\n"
f"日期:{str(datetime.now()).split('.')[0]}\n"
f"备注:{event.comment}",
)
if AUTO_ADD_FRIEND:
await bot.set_friend_add_request(flag=event.flag, approve=True)
await FriendUser.add_friend_info(user["user_id"], user["nickname"])
group_req = on_request(priority=5, block=True)
@group_req.handle()
async def _(bot: Bot, event: GroupRequestEvent, state: dict):
global exists_data
if event.sub_type == "invite":
if str(event.user_id) in bot.config.superusers:
try:
await bot.set_group_add_request(
flag=event.flag, sub_type="invite", approve=True
)
except ActionFailed:
pass
else:
if exists_data["group"].get(f"{event.user_id}:{event.group_id}"):
if (
time.time()
- exists_data["group"][f"{event.user_id}:{event.group_id}"]
< 60 * 5
):
return
exists_data["group"][f"{event.user_id}:{event.group_id}"] = time.time()
nickname = await FriendUser.get_user_name(event.user_id)
await bot.send_private_msg(
user_id=int(list(bot.config.superusers)[0]),
message=f"*****一份入群申请*****\n"
f"申请人:{nickname}({event.user_id})\n"
f"群聊:{event.group_id}\n"
f"邀请日期:{str(datetime.now()).split('.')[0]}",
)
await bot.send_private_msg(
user_id=event.user_id,
message=f"想要邀请我偷偷入群嘛~已经提醒{NICKNAME}的管理员大人了\n"
"请确保已经群主或群管理沟通过!\n"
"等待管理员处理吧!",
)
@scheduler.scheduled_job(
"interval",
minutes=5,
)
async def _():
global exists_data
exists_data = {"private": {}, "group": {}}
-189
View File
@@ -1,189 +0,0 @@
from nonebot import on_command
from models.ban_user import BanUser
from models.level_user import LevelUser
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot
from nonebot.adapters.cqhttp import GroupMessageEvent, PrivateMessageEvent
from utils.utils import get_message_at, get_message_text, is_number
from configs.config import NICKNAME, BAN_LEVEL
from nonebot.permission import SUPERUSER
from services.log import logger
__zx_plugin_name__ = "封禁Ban用户 [Admin]"
__plugin_usage__ = """
usage:
将用户拉入或拉出黑名单
指令:
.ban [at] ?[小时] ?[分钟]
.unban
示例:.ban @user
示例:.ban @user 6
示例:.ban @user 3 10
示例:.unban @user
""".strip()
__plugin_superuser_usage__ = """
usage:
屏蔽用户消息,相当于最上级.ban
指令:
b了 [at]
示例:b了 @user
""".strip()
__plugin_des__ = '你被逮捕了!丢进小黑屋!'
__plugin_cmd__ = ['.ban [at] ?[小时] ?[分钟]', '.unban [at]', 'b了 [at] [_superuser]']
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
__plugin_settings__ = {
"admin_level": BAN_LEVEL,
}
ban = on_command(
".ban",
aliases={".unban", "/ban", "/unban"},
priority=5,
block=True,
)
super_ban = on_command('b了', permission=SUPERUSER, priority=5, block=True)
@ban.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
result = ""
qq = get_message_at(event.json())
if qq:
qq = qq[0]
user_name = await bot.get_group_member_info(group_id=event.group_id, user_id=qq)
user_name = user_name['card'] if user_name['card'] else user_name['nickname']
msg = get_message_text(event.json())
if msg:
msg = msg.split()
if len(msg) == 2:
if not is_number(msg[0].strip()) or not is_number(msg[1].strip()):
await ban.finish("参数必须是数字!", at_sender=True)
time = int(msg[0]) * 60 * 60 + int(msg[1]) * 60
else:
if not is_number(msg[0].strip()):
await ban.finish("参数必须是数字!", at_sender=True)
time = int(msg[0]) * 60 * 60
else:
time = -1
if state["_prefix"]["raw_command"] in [".ban", "/ban"]:
if (
await LevelUser.get_user_level(event.user_id, event.group_id)
<= await LevelUser.get_user_level(qq, event.group_id)
and str(event.user_id) not in bot.config.superusers
):
await ban.finish(
f"您的权限等级比对方低或相等, {NICKNAME}不能为您使用此功能!",
at_sender=True,
)
if await BanUser.ban(
qq, await LevelUser.get_user_level(event.user_id, event.group_id), time
):
logger.info(
f"USER {event.user_id} GROUP {event.group_id} 将 USER {qq} 封禁 时长 {time/60} 分钟"
)
result = f"已经将 {user_name} 加入{NICKNAME}的黑名单了!"
if time != -1:
result += f"将在 {time/60} 分钟后解封"
else:
time = await BanUser.check_ban_time(qq)
if is_number(time):
time = abs(int(time))
if time < 60:
time = str(time) + " 秒"
else:
time = str(int(time / 60)) + " 分钟"
else:
time += " 分钟"
result = f"{user_name} 已在黑名单!预计 {time}后解封"
else:
if (
await BanUser.check_ban_level(
qq, await LevelUser.get_user_level(event.user_id, event.group_id)
)
and str(event.user_id) not in bot.config.superusers
):
await ban.finish(
f"ban掉 {user_name} 的管理员权限比您高,无法进行unban", at_sender=True
)
if await BanUser.unban(qq):
logger.info(
f"USER {event.user_id} GROUP {event.group_id} 将 USER {qq} 解禁"
)
result = f"已经把 {user_name} 从黑名单中删除了!"
else:
result = f"{user_name} 不在黑名单!"
else:
await ban.finish("艾特人了吗??", at_sender=True)
await ban.finish(result, at_sender=True)
@ban.handle()
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
if str(event.user_id) in bot.config.superusers:
msg = get_message_text(event.json())
msg = msg.split()
if is_number(msg[0]):
qq = int(msg[0])
if state["_prefix"]["raw_command"] in [".ban", "/ban"]:
hour = 0
minute = 0
if len(msg) > 1 and is_number(msg[1]):
hour = int(msg[1])
if len(msg) > 2 and is_number(msg[2]):
minute = int(msg[2])
time = hour * 60 * 60 + minute * 60
time = time if time else -1
if await BanUser.ban(
qq, 9, time
):
logger.info(
f"USER {event.user_id} 将 USER {qq} 封禁 时长 {time/60} 分钟"
)
result = f"已经将 {qq} 加入{NICKNAME}的黑名单了!"
if time != -1:
result += f"将在 {time/60} 分钟后解封"
else:
result += f"将在 ∞ 分钟后解封"
await ban.send(result)
else:
time = await BanUser.check_ban_time(qq)
if is_number(time):
time = abs(int(time))
if time < 60:
time = str(time) + " 秒"
else:
time = str(int(time / 60)) + " 分钟"
else:
time += " 分钟"
await ban.send(f"{qq} 已在黑名单!预计 {time}后解封")
else:
if await BanUser.unban(qq):
logger.info(
f"USER {event.user_id} 将 USER {qq} 解禁"
)
result = f"已经把 {qq} 从黑名单中删除了!"
else:
result = f"{qq} 不在黑名单!"
await ban.send(result)
else:
await ban.finish('qq号必须是数字!\n格式:.ban [qq] [hour]? [minute]?', at_sender=True)
@super_ban.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
qq = get_message_at(event.json())
if qq:
qq = qq[0]
user = await bot.get_group_member_info(group_id=event.group_id, user_id=qq)
user_name = user['card'] if user['card'] else user['nickname']
if not await BanUser.ban(qq, 10, 99999999):
await BanUser.unban(qq)
await BanUser.ban(qq, 10, 99999999)
await ban.send(f"已将 {user_name} 拉入黑名单!")
else:
await super_ban.send('需要艾特被super ban的对象..')
+51 -33
View File
@@ -9,11 +9,11 @@ from .data_source import (
get_media_id,
get_sub_status,
SubManager,
BilibiliSub
)
from models.level_user import LevelUser
from configs.config import GROUP_BILIBILI_SUB_LEVEL
from configs.config import Config
from utils.utils import get_message_text, is_number, scheduler, get_bot
from models.bilibili_sub import BilibiliSub
from typing import Optional
from services.log import logger
from nonebot import Driver
@@ -34,20 +34,27 @@ usage:
示例:添加订阅番剧 125344 <-(番剧id)
示例:删除订阅 2324344 <-(任意id,通过查看订阅获取)
""".strip()
__plugin_des__ = '非常便利的B站订阅通知'
__plugin_cmd__ = ['添加订阅 [主播/UP/番剧] [id/链接/番名]', '删除订阅 [id]', '查看订阅']
__plugin_des__ = "非常便利的B站订阅通知"
__plugin_cmd__ = ["添加订阅 [主播/UP/番剧] [id/链接/番名]", "删除订阅 [id]", "查看订阅"]
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["B站订阅", 'b站订阅', '添加订阅', '删除订阅', '查看订阅'],
"cmd": ["B站订阅", "b站订阅", "添加订阅", "删除订阅", "查看订阅"],
}
__plugin_configs__ = {
"GROUP_BILIBILI_SUB_LEVEL": {
"value": 5,
"help": "群内bilibili订阅需要管理的权限",
"default_value": 5,
}
}
add_sub = on_command("添加订阅", priority=5, block=True)
del_sub = on_command("删除订阅", priority=5, block=True)
show_sub_info = on_command('查看订阅', priority=5, block=True)
show_sub_info = on_command("查看订阅", priority=5, block=True)
driver: Driver = nonebot.get_driver()
@@ -79,10 +86,13 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
id_ = ""
if isinstance(event, GroupMessageEvent):
if not await LevelUser.check_level(
event.user_id, event.group_id, GROUP_BILIBILI_SUB_LEVEL
event.user_id,
event.group_id,
Config.get_config("bilibili_sub", "GROUP_BILIBILI_SUB_LEVEL"),
):
await add_sub.finish(
f"您的权限不足,群内订阅的需要 {GROUP_BILIBILI_SUB_LEVEL} 级权限..", at_sender=True
f"您的权限不足,群内订阅的需要 {Config.get_config('bilibili_sub', 'GROUP_BILIBILI_SUB_LEVEL')} 级权限..",
at_sender=True,
)
sub_user = f"{event.user_id}:{event.group_id}"
else:
@@ -134,44 +144,52 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
if not is_number(msg):
await del_sub.finish('Id必须为数字!', at_sender=True)
id_ = f'{event.user_id}:{event.group_id}' if isinstance(event, GroupMessageEvent) else f'{event.user_id}'
await del_sub.finish("Id必须为数字!", at_sender=True)
id_ = (
f"{event.user_id}:{event.group_id}"
if isinstance(event, GroupMessageEvent)
else f"{event.user_id}"
)
if await BilibiliSub.delete_bilibili_sub(int(msg), id_):
await del_sub.send(f'删除订阅id:{msg} 成功...')
await del_sub.send(f"删除订阅id:{msg} 成功...")
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 删除订阅 {id_}"
)
else:
await del_sub.send(f'删除订阅id:{msg} 失败...')
await del_sub.send(f"删除订阅id:{msg} 失败...")
@show_sub_info.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
id_ = f'{event.user_id}:{event.group_id}' if isinstance(event, GroupMessageEvent) else f'{event.user_id}'
id_ = (
f"{event.user_id}:{event.group_id}"
if isinstance(event, GroupMessageEvent)
else f"{event.user_id}"
)
data = await BilibiliSub.get_sub_data(id_)
live_rst = ''
up_rst = ''
season_rst = ''
live_rst = ""
up_rst = ""
season_rst = ""
for x in data:
if x.sub_type == 'live':
live_rst += f'\t直播间id:{x.sub_id}\n' \
f'\t名称:{x.uname}\n' \
f'------------------\n'
if x.sub_type == 'up':
up_rst += f'\tUP:{x.uname}\n' \
f'\tuid:{x.uid}\n' \
f'------------------\n'
if x.sub_type == 'season':
season_rst += f'\t番名:{x.season_name}\n' \
f'\t当前集数:{x.season_current_episode}\n' \
f'------------------\n'
live_rst = '当前订阅的直播:\n' + live_rst if live_rst else live_rst
up_rst = '当前订阅的UP:\n' + up_rst if up_rst else up_rst
season_rst = '当前订阅的番剧:\n' + season_rst if season_rst else season_rst
if x.sub_type == "live":
live_rst += (
f"\t直播间id:{x.sub_id}\n" f"\t名称:{x.uname}\n" f"------------------\n"
)
if x.sub_type == "up":
up_rst += f"\tUP:{x.uname}\n" f"\tuid:{x.uid}\n" f"------------------\n"
if x.sub_type == "season":
season_rst += (
f"\t番名:{x.season_name}\n"
f"\t当前集数:{x.season_current_episode}\n"
f"------------------\n"
)
live_rst = "当前订阅的直播:\n" + live_rst if live_rst else live_rst
up_rst = "当前订阅的UP:\n" + up_rst if up_rst else up_rst
season_rst = "当前订阅的番剧:\n" + season_rst if season_rst else season_rst
if not live_rst and not up_rst and not season_rst:
live_rst = '您目前没有任何订阅...'
live_rst = "您目前没有任何订阅..."
await show_sub_info.send(live_rst + up_rst + season_rst)
+5 -1
View File
@@ -1,6 +1,7 @@
from bilibili_api.exceptions.ResponseCodeException import ResponseCodeException
from utils.manager import resources_manager
from asyncio.exceptions import TimeoutError
from models.bilibili_sub import BilibiliSub
from .model import BilibiliSub
from bilibili_api.live import LiveRoom
from bilibili_api import bangumi
from utils.message_builder import image
@@ -23,6 +24,9 @@ dynamic_path = Path(IMAGE_PATH) / "bilibili_sub" / "dynamic"
dynamic_path.mkdir(exist_ok=True, parents=True)
resources_manager.add_temp_dir(dynamic_path)
async def add_live_sub(live_id: int, sub_user: str) -> str:
"""
添加直播订阅
+249
View File
@@ -0,0 +1,249 @@
from services.log import logger
from services.db_context import db
from datetime import datetime
from typing import Optional, List
class BilibiliSub(db.Model):
__tablename__ = "bilibili_sub"
id = db.Column(db.Integer(), primary_key=True)
sub_id = db.Column(db.Integer(), nullable=False)
sub_type = db.Column(db.String(), nullable=False)
# 订阅用户
sub_users = db.Column(db.String(), nullable=False)
# 直播
live_short_id = db.Column(db.Integer())
live_status = db.Column(db.Integer)
# 主播/UP
uid = db.Column(db.BigInteger())
uname = db.Column(db.String())
latest_video_created = db.Column(db.BigInteger()) # 视频上传时间
dynamic_upload_time = db.Column(db.BigInteger(), default=0) # 动态发布时间
# 番剧
season_name = db.Column(db.String())
season_id = db.Column(db.Integer())
season_current_episode = db.Column(db.String())
season_update_time = db.Column(db.DateTime())
_idx1 = db.Index("bilibili_sub_idx1", "sub_id", "sub_type", unique=True)
@classmethod
async def add_bilibili_sub(
cls,
sub_id: int,
sub_type: str,
sub_user: str,
*,
live_short_id: Optional[int] = None,
live_status: Optional[int] = None,
dynamic_upload_time: Optional[int] = None,
uid: Optional[int] = None,
uname: Optional[str] = None,
latest_video_created: Optional[int] = None,
season_name: Optional[str] = None,
season_id: Optional[int] = None,
season_current_episode: Optional[str] = None,
season_update_time: Optional[datetime] = None,
) -> bool:
"""
说明:
添加订阅
参数:
:param sub_id: 订阅名称,房间号,番剧号等
:param sub_type: 订阅类型
:param sub_user: 订阅此条目的用户
:param live_short_id: 直接短 id
:param live_status: 主播开播状态
:param dynamic_upload_time: 主播/UP最新动态时间
:param uid: 主播/UP uid
:param uname: 用户名称
:param latest_video_created: 最新视频上传时间
:param season_name: 番剧名称
:param season_id: 番剧 season_id
:param season_current_episode: 番剧最新集数
:param season_update_time: 番剧更新时间
"""
try:
async with db.transaction():
query = (
await cls.query.where(cls.sub_id == sub_id)
.with_for_update()
.gino.first()
)
sub_user = sub_user if sub_user[-1] == "," else f"{sub_user},"
if query:
if sub_user not in query.sub_users:
sub_users = query.sub_users + sub_user
await query.update(sub_users=sub_users).apply()
else:
sub = await cls.create(
sub_id=sub_id, sub_type=sub_type, sub_users=sub_user
)
await sub.update(
live_short_id=live_short_id
if live_short_id
else sub.live_short_id,
live_status=live_status if live_status else sub.live_status,
dynamic_upload_time=dynamic_upload_time
if dynamic_upload_time
else sub.dynamic_upload_time,
uid=uid if uid else sub.uid,
uname=uname if uname else sub.uname,
latest_video_created=latest_video_created
if latest_video_created
else sub.latest_video_created,
season_update_time=season_update_time
if season_update_time
else sub.season_update_time,
season_current_episode=season_current_episode
if season_current_episode
else sub.season_current_episode,
season_id=season_id if season_id else sub.season_id,
season_name=season_name if season_name else sub.season_name,
).apply()
return True
except Exception as e:
logger.info(f"bilibili_sub 添加订阅错误 {type(e)}: {e}")
return False
@classmethod
async def delete_bilibili_sub(cls, sub_id: int, sub_user: str) -> bool:
"""
说明:
删除订阅
参数:
:param sub_id: 订阅名称
:param sub_user: 删除此条目的用户
"""
try:
async with db.transaction():
query = (
await cls.query.where(
(cls.sub_id == sub_id) & (cls.sub_users.contains(sub_user))
)
.with_for_update()
.gino.first()
)
if not query:
return False
await query.update(
sub_users=query.sub_users.replace(f"{sub_user},", "")
).apply()
if not query.sub_users.strip():
await query.delete()
return True
except Exception as e:
logger.info(f"bilibili_sub 删除订阅错误 {type(e)}: {e}")
return False
@classmethod
async def get_sub(cls, sub_id: int) -> Optional["BilibiliSub"]:
"""
说明:
获取订阅对象
参数:
:param sub_id: 订阅 id
"""
return await cls.query.where(cls.sub_id == sub_id).gino.first()
@classmethod
async def get_sub_data(cls, id_: str) -> List["BilibiliSub"]:
"""
获取 id_ 订阅的所有内容
:param id_: id
"""
query = cls.query.where(cls.sub_users.contains(id_))
return await query.gino.all()
@classmethod
async def update_sub_info(
cls,
sub_id: int,
*,
live_short_id: Optional[int] = None,
live_status: Optional[int] = None,
dynamic_upload_time: Optional[int] = None,
uid: Optional[int] = None,
uname: Optional[str] = None,
latest_video_created: Optional[int] = None,
season_name: Optional[str] = None,
season_id: Optional[int] = None,
season_current_episode: Optional[str] = None,
season_update_time: Optional[datetime] = None,
) -> bool:
"""
说明:
更新订阅信息
参数:
:param sub_id: 订阅名称,房间号,番剧号等
:param live_short_id: 直接短 id
:param live_status: 主播开播状态
:param dynamic_upload_time: 主播/UP最新动态时间
:param uid: 主播/UP uid
:param uname: 用户名称
:param latest_video_created: 最新视频上传时间
:param season_name: 番剧名称
:param season_id: 番剧 season_id
:param season_current_episode: 番剧最新集数
:param season_update_time: 番剧更新时间
"""
try:
async with db.transaction():
sub = (
await cls.query.where(cls.sub_id == sub_id)
.with_for_update()
.gino.first()
)
if sub:
await sub.update(
live_short_id=live_short_id
if live_short_id is not None
else sub.live_short_id,
live_status=live_status
if live_status is not None
else sub.live_status,
dynamic_upload_time=dynamic_upload_time
if dynamic_upload_time is not None
else sub.dynamic_upload_time,
uid=uid if uid is not None else sub.uid,
uname=uname if uname is not None else sub.uname,
latest_video_created=latest_video_created
if latest_video_created is not None
else sub.latest_video_created,
season_update_time=season_update_time
if season_update_time is not None
else sub.season_update_time,
season_current_episode=season_current_episode
if season_current_episode is not None
else sub.season_current_episode,
season_id=season_id if season_id is not None else sub.season_id,
season_name=season_name
if season_name is not None
else sub.season_name,
).apply()
return True
except Exception as e:
logger.info(f"bilibili_sub 更新订阅错误 {type(e)}: {e}")
return False
@classmethod
async def get_all_sub_data(
cls,
) -> "List[BilibiliSub], List[BilibiliSub], List[BilibiliSub]":
"""
说明:
分类获取所有数据
"""
live_data = []
up_data = []
season_data = []
query = await cls.query.gino.all()
for x in query:
if x.sub_type == "live":
live_data.append(x)
if x.sub_type == "up":
up_data.append(x)
if x.sub_type == "season":
season_data.append(x)
return live_data, up_data, season_data
-59
View File
@@ -1,59 +0,0 @@
from nonebot import on_command
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
from nonebot.permission import SUPERUSER
import asyncio
from utils.utils import get_message_text, get_message_imgs
from services.log import logger
from utils.message_builder import image
from utils.manager import group_manager
__zx_plugin_name__ = "广播 [Superuser]"
__plugin_usage__ = """
usage:
指令:
广播- ?[消息] ?[图片]
示例:广播- 你们好!
""".strip()
__plugin_des__ = "昭告天下!"
__plugin_cmd__ = ["广播-"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_task__ = {"broadcast": "广播"}
broadcast = on_command("广播-", priority=1, permission=SUPERUSER, block=True)
@broadcast.handle()
async def _(bot: Bot, event: Event, state: T_State):
msg = get_message_text(event.json())
imgs = get_message_imgs(event.json())
rst = ""
for img in imgs:
rst += image(img)
sid = bot.self_id
gl = await bot.get_group_list(self_id=sid)
gl = [
g["group_id"]
for g in gl
if await group_manager.check_group_task_status(g["group_id"], "broadcast")
]
g_cnt = len(gl)
cnt = 0
error = ""
x = 0.25
for g in gl:
cnt += 1
if cnt / g_cnt > x:
await broadcast.send(f"已播报至 {int(cnt / g_cnt * 100)}% 的群聊")
x += 0.25
try:
await bot.send_group_msg(self_id=sid, group_id=g, message=msg + rst)
logger.info(f"GROUP {g} 投递广播成功")
except Exception as e:
logger.error(f"GROUP {g} 投递广播失败:{type(e)}")
error += f"GROUP {g} 投递广播失败:{type(e)}\n"
await asyncio.sleep(0.5)
await broadcast.send(f"已播报至 100% 的群聊")
if error:
await broadcast.send(f"播报时错误:{error}")
+7
View File
@@ -32,6 +32,13 @@ __plugin_settings__ = {
__plugin_block_limit__ = {
"rst": "您有bt任务正在进行,请等待结束."
}
__plugin_configs__ = {
"BT_MAX_NUM": {
"value": 10,
"help": "单次BT搜索返回最大消息数量",
"default_value": 10,
}
}
bt = on_command("bt", permission=PRIVATE, priority=5, block=True)
+4 -2
View File
@@ -1,6 +1,6 @@
from utils.user_agent import get_user_agent
import aiohttp
from configs.config import MAXINFO_BT
from configs.config import Config
from bs4 import BeautifulSoup
from utils.utils import get_local_proxy
import platform
@@ -24,7 +24,9 @@ async def get_bt_info(keyword: str, page: str):
return
soup = BeautifulSoup(text, "lxml")
item_lst = soup.find_all("div", {"class": "search-item"})
for item in item_lst[:MAXINFO_BT]:
bt_max_num = Config.get_config("bt", "BT_MAX_NUM")
bt_max_num = bt_max_num if bt_max_num < len(item_lst) else len(item_lst)
for item in item_lst[:bt_max_num]:
divs = item.find_all("div")
title = (
str(divs[0].find("a").text)
+2 -1
View File
@@ -4,6 +4,7 @@ from nonebot.adapters.cqhttp import Bot, Event
from nonebot.typing import T_State
from nonebot.rule import to_me
from nonebot.permission import SUPERUSER
from utils.message_builder import image
__zx_plugin_name__ = "服务器自我检查 [Superuser]"
@@ -29,4 +30,4 @@ check_ = on_command(
@check_.handle()
async def _(bot: Bot, event: Event, state: T_State):
await check_.send(await check.show())
await check_.send(image(b64=await check.show()))
+18 -1
View File
@@ -6,6 +6,9 @@ from utils.user_agent import get_user_agent
from asyncio.exceptions import TimeoutError
from aiohttp.client_exceptions import ClientConnectorError
from utils.utils import get_local_proxy
from utils.image_utils import CreateImg
from configs.path_config import IMAGE_PATH
from pathlib import Path
import asyncio
from services.log import logger
@@ -57,6 +60,7 @@ class Check:
async def show(self):
await self.check_all()
A = CreateImg(0, 0, font_size=24)
rst = (
f'[Time] {str(datetime.now()).split(".")[0]}\n'
f"-----System-----\n"
@@ -69,4 +73,17 @@ class Check:
)
if self.user:
rst += "-----User-----\n" + self.user
return rst
width = 0
height = 0
for x in rst.split('\n'):
w, h = A.getsize(x)
if w > width:
width = w
height += 30
A = CreateImg(width + 50, height + 10, font_size=24, font="HWZhongSong.ttf")
A.transparent(1)
A.text((10, 10), rst)
_x = max(width, height)
bk = CreateImg(_x + 100, _x + 100, background=Path(IMAGE_PATH) / "background" / "check" / "0.jpg")
bk.paste(A, alpha=True, center_type='center')
return bk.pic2bs4()
+9 -2
View File
@@ -6,7 +6,7 @@ from .data_source import check_update, get_latest_version_data
from services.log import logger
from utils.utils import scheduler, get_bot
from pathlib import Path
from configs.config import AUTO_UPDATE_ZHENXUN
from configs.config import Config
from nonebot.rule import to_me
import platform
import os
@@ -24,6 +24,13 @@ __plugin_des__ = "就算是真寻也会成长的"
__plugin_cmd__ = ["检查更新真寻", "重启"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_configs__ = {
"AUTO_UPDATE_ZHENXUN": {
"value": False,
"help": "真寻是否自动检查更新",
"default": False,
}
}
update_zhenxun = on_command("检查更新真寻", permission=SUPERUSER, priority=1, block=True)
@@ -82,7 +89,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
minute=0,
)
async def _():
if AUTO_UPDATE_ZHENXUN:
if Config.get_config("check_zhenxun_update", "AUTO_UPDATE_ZHENXUN"):
_version = "v0.0.0"
_version_file = Path() / "__version__"
if _version_file.exists():
+1 -1
View File
@@ -41,7 +41,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
try:
for _ in range(3):
try:
async with session.get(url, proxy=get_local_proxy(), timeout=2) as response:
async with session.get(url, proxy=get_local_proxy(), timeout=2, verify_ssl=False) as response:
_url = (await response.json())['text']
async with session.get(
_url, timeout=5, proxy=get_local_proxy(), verify_ssl=False
+69
View File
@@ -0,0 +1,69 @@
from nonebot import on_command
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, MessageEvent
from utils.utils import get_message_text, is_number
from .data_source import get_csgola_data, get_5e_data
from services.log import logger
__zx_plugin_name__ = "cs国服/平台信息查找"
__plugin_usage__ = """
usage:
快速查询csgo战绩和数据
指令:
cs国服查询 [steam主页个人id]
5e查询 [5e战绩个人名称]
示例:cs国服查询 23848238483
示例:5e查询 poster
"""
__plugin_des__ = "什么?你也是rush B玩家?"
__plugin_cmd__ = ["cs国服查询 [steam主页个人id]", "5e查询 [5e战绩个人名称]"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["csgo战绩查询", "cs国服查询", "5e查询"],
}
csgola = on_command("cs国服查询", priority=5, block=True)
csgo5e = on_command("5e查询", priority=5, block=True)
@csgola.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
if "http" in msg:
msg = msg[:-1] if msg[-1] == "/" else msg
msg = msg.split("/")[-1]
if not is_number(msg):
await csgola.finish("Id必须为数字!", at_sender=True)
await csgola.send("开始查找...")
img, code = await get_csgola_data(int(msg))
if code == 200:
await csgola.send(img, at_sender=True)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查询csgo国服战绩:{msg}"
)
else:
await csgola.send(img, at_sender=True)
@csgo5e.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
await csgola.send("开始查找...")
img, code = await get_5e_data(msg)
if code == 200:
await csgo5e.send(img, at_sender=True)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查询csgo国服战绩:{msg}"
)
else:
await csgo5e.send(img, at_sender=True)
+130
View File
@@ -0,0 +1,130 @@
from configs.path_config import IMAGE_PATH
from utils.image_utils import CreateImg
from utils.message_builder import image
from services.log import logger
from utils.browser import get_browser
from playwright._impl._api_types import TimeoutError
csgola_url = "https://www.csgola.com/player/"
_5e_url = "https://arena.5eplay.com/data/player/"
async def get_csgola_data(uid: int) -> "str, int":
page = None
try:
browser = await get_browser()
if not browser:
return "", 997
page = await browser.new_page()
for _ in range(3):
try:
await page.goto(f"{csgola_url}{uid}", wait_until="networkidle", timeout=10000)
break
except TimeoutError:
pass
else:
return '连接超时...', 995
await page.set_viewport_size({"width": 2560, "height": 1080})
data = await page.query_selector_all(".panel-body")
if not data:
return "未查询到该Id....", 999
await data[0].screenshot(path=f"{IMAGE_PATH}/temp/{uid}_1.png", timeout=100000)
await data[3].screenshot(path=f"{IMAGE_PATH}/temp/{uid}_2.png", timeout=100000)
await data[5].screenshot(path=f"{IMAGE_PATH}/temp/{uid}_3.png", timeout=100000)
await data[7].screenshot(path=f"{IMAGE_PATH}/temp/{uid}_5.png", timeout=100000)
ava = await page.query_selector("div.container:nth-child(4) > div:nth-child(1)")
await ava.screenshot(path=f"{IMAGE_PATH}/temp/{uid}_0.png", timeout=100000)
weapon_data = await page.query_selector(".gun-stats-sec")
await weapon_data.screenshot(
path=f"{IMAGE_PATH}/temp/{uid}_4.png", timeout=100000
)
ava = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/{uid}_0.png")
statistical_data = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/{uid}_1.png")
combined_data = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/{uid}_2.png")
detailed_data = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/{uid}_3.png")
weapon_data = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/{uid}_4.png")
map_data = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/{uid}_5.png")
if statistical_data.h > 300:
statistical_data.crop((0, 0, statistical_data.w, 300))
if combined_data.h > 260:
combined_data.crop((0, 0, combined_data.w, 260))
if detailed_data.h > 400:
detailed_data.crop((0, 0, detailed_data.w, 400))
weapon_data.crop((0, 100, weapon_data.w, weapon_data.h))
map_data.crop((0, 310, map_data.w, map_data.h))
height = (
ava.h
+ statistical_data.h
+ combined_data.h
+ detailed_data.h
+ weapon_data.h
+ map_data.h
)
bk = CreateImg(1168, height)
current_h = 0
for img in [
ava,
statistical_data,
combined_data,
detailed_data,
weapon_data,
map_data,
]:
bk.paste(img, (0, current_h))
current_h += img.h
bk.save(f"{IMAGE_PATH}/temp/csgo_{uid}.png")
except Exception as e:
logger.error(f"生成csgola图片错误 {type(e)}:{e}")
if page:
await page.close()
return "发生了错误....", 998
if page:
await page.close()
return image(f"csgo_{uid}.png", "temp"), 200
async def get_5e_data(uname: str) -> "str, int":
page = None
try:
browser = await get_browser()
if not browser:
return "", 997
page = await browser.new_page()
await page.goto(f"{_5e_url}{uname}", wait_until="networkidle", timeout=10000)
if "HTTP ERROR 404" in await page.content():
return "未查询到该玩家...", 999
await page.set_viewport_size({"width": 2560, "height": 1080})
body = await page.query_selector("body")
await body.screenshot(
path=f"{IMAGE_PATH}/temp/csgo_{uname}_0.png", timeout=100000
)
await page.click("a.match-tab-item:nth-child(2)")
body = await page.query_selector("body")
await body.screenshot(
path=f"{IMAGE_PATH}/temp/csgo_{uname}_1.png", timeout=100000
)
await page.click("a.match-tab-item:nth-child(1)")
body = await page.query_selector("body")
await body.screenshot(
path=f"{IMAGE_PATH}/temp/csgo_{uname}_2.png", timeout=100000
)
bk = CreateImg(1344 * 3, 2307)
current_w = 0
for i in range(3):
body = CreateImg(0, 0, background=f"{IMAGE_PATH}/temp/csgo_{uname}_{i}.png")
body.crop((600, 90, body.w - 600, body.h - 410))
bk.paste(body, (current_w, 0))
current_w += 1344
bk.save(f"{IMAGE_PATH}/temp/csgo_{uname}.png")
except Exception as e:
logger.error(f"生成5e图片错误 {type(e)}:{e}")
if page:
await page.close()
return "发生了错误...", 998
if page:
await page.close()
return image(f"csgo_{uname}.png", "temp"), 200
+9 -7
View File
@@ -4,6 +4,7 @@ from nonebot.adapters.cqhttp import Bot, MessageEvent, Message, GroupMessageEven
from nonebot.permission import SUPERUSER
from utils.utils import get_message_text, is_number, get_message_imgs
from utils.message_builder import image
from utils.message_builder import text as _text
from services.log import logger
from utils.message_builder import at
@@ -52,7 +53,7 @@ __plugin_settings__ = {
dialogue_data = {}
dialogue = on_command("[滴滴滴]", aliases={"滴滴滴-"}, priority=1, block=True)
dialogue = on_command("[滴滴滴]", aliases={"滴滴滴-"}, priority=5, block=True)
reply = on_command("/t", priority=1, permission=SUPERUSER, block=True)
@@ -61,7 +62,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
uid = event.user_id
coffee = int(list(bot.config.superusers)[0])
text = get_message_text(event.json())
img_msg = ""
img_msg = _text("")
for img in get_message_imgs(event.json()):
img_msg += image(img)
if not text or text in ["帮助"]:
@@ -78,15 +79,16 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
nickname = event.sender.card if event.sender.card else event.sender.nickname
await bot.send_private_msg(
user_id=coffee,
message=Message(
message=_text(
f"*****一份交流报告*****\n"
f"昵称:{nickname}({uid})\n"
f"群聊:{group_name}({group_id})\n"
f"消息:{text} {img_msg}"
),
f"消息:{text}"
)
+ img_msg,
)
await dialogue.send(
Message(f"您的话已发送至管理员!\n======\n{text}{img_msg}"), at_sender=True
_text(f"您的话已发送至管理员!\n======\n{text}") + img_msg, at_sender=True
)
nickname = event.sender.nickname if event.sender.nickname else event.sender.card
dialogue_data[len(dialogue_data)] = {
@@ -94,7 +96,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
"user_id": event.user_id,
"group_id": group_id,
"group_name": group_name,
"msg": f"{text} {img_msg}",
"msg": _text(text) + img_msg,
}
# print(dialogue_data)
logger.info(f"Q{uid}@群{group_id} 联系管理员:{coffee} text:{text}")
+278 -207
View File
@@ -1,31 +1,56 @@
import nonebot
from pathlib import Path
from configs.path_config import DATA_PATH
from configs.config import FGO_FLAG, PCR_FLAG, AZUR_FLAG, PRTS_FLAG,\
PRETTY_FLAG, GUARDIAN_FLAG, GENSHIN_FLAG, ONMYOJI_FLAG, PCR_TAI, SEMAPHORE
from configs.config import Config
try:
import ujson as json
except ModuleNotFoundError:
import json
DRAW_PATH = DATA_PATH + '/draw_card/'
DRAW_PATH = DATA_PATH + "/draw_card/"
_draw_config = Path(rf"{DRAW_PATH}/draw_card_config/draw_card_config.json")
# 开关
PRTS_FLAG = PRTS_FLAG
GENSHIN_FLAG = GENSHIN_FLAG
PRETTY_FLAG = PRETTY_FLAG
GUARDIAN_FLAG = GUARDIAN_FLAG
PCR_FLAG = PCR_FLAG
AZUR_FLAG = AZUR_FLAG
FGO_FLAG = FGO_FLAG
ONMYOJI_FLAG = ONMYOJI_FLAG
for game_flag, game_name in zip(
[
"PRTS_FLAG",
"GENSHIN_FLAG",
"PRETTY_FLAG",
"GUARDIAN_FLAG",
"PCR_FLAG",
"AZUR_FLAG",
"FGO_FLAG",
"ONMYOJI_FLAG",
"PCR_TAI",
],
["明日方舟", "原神", "赛马娘", "坎公骑冠剑", "公主连结", "碧蓝航线", "命运-冠位指定(FGO)", "阴阳师", "pcr台服卡池"],
):
Config.add_plugin_config(
"draw_card",
game_flag,
True,
name="游戏抽卡",
help_=f"{game_name} 抽卡开关",
default_value=True,
)
Config.add_plugin_config(
"draw_card", "SEMAPHORE", 5, help_=f"异步数据下载数量限制", default_value=5
)
PRTS_FLAG = Config.get_config("draw_card", "PRTS_FLAG")
GENSHIN_FLAG = Config.get_config("draw_card", "GENSHIN_FLAG")
PRETTY_FLAG = Config.get_config("draw_card", "PRETTY_FLAG")
GUARDIAN_FLAG = Config.get_config("draw_card", "GUARDIAN_FLAG")
PCR_FLAG = Config.get_config("draw_card", "PCR_FLAG")
AZUR_FLAG = Config.get_config("draw_card", "AZUR_FLAG")
FGO_FLAG = Config.get_config("draw_card", "FGO_FLAG")
ONMYOJI_FLAG = Config.get_config("draw_card", "ONMYOJI_FLAG")
PCR_TAI = Config.get_config("draw_card", "PCR_TAI")
SEMAPHORE = Config.get_config("draw_card", "SEMAPHORE")
PCR_TAI = PCR_TAI
SEMAPHORE = SEMAPHORE
# 方舟概率
PRTS_SIX_P = 0.02
@@ -97,244 +122,290 @@ ONMYOJI_R = 0.7875
path_dict = {
'genshin': '原神',
'prts': '明日方舟',
'pretty': '赛马娘',
'guardian': '坎公骑冠剑',
'pcr': '公主连结',
'azur': '碧蓝航线',
'fgo': '命运-冠位指定',
'onmyoji': '阴阳师',
"genshin": "原神",
"prts": "明日方舟",
"pretty": "赛马娘",
"guardian": "坎公骑冠剑",
"pcr": "公主连结",
"azur": "碧蓝航线",
"fgo": "命运-冠位指定",
"onmyoji": "阴阳师",
}
driver: nonebot.Driver = nonebot.get_driver()
config_default_data = {
'path_dict': {
'genshin': '原神',
'prts': '明日方舟',
'pretty': '赛马娘',
'guardian': '坎公骑冠剑',
'pcr': '公主连结',
'azur': '碧蓝航线',
'fgo': '命运-冠位指定',
'onmyoji': '阴阳师',
"path_dict": {
"genshin": "原神",
"prts": "明日方舟",
"pretty": "赛马娘",
"guardian": "坎公骑冠剑",
"pcr": "公主连结",
"azur": "碧蓝航线",
"fgo": "命运-冠位指定",
"onmyoji": "阴阳师",
},
'prts': {
'PRTS_SIX_P': 0.02,
'PRTS_FIVE_P': 0.08,
'PRTS_FOUR_P': 0.48,
'PRTS_THREE_P': 0.42,
"prts": {
"PRTS_SIX_P": 0.02,
"PRTS_FIVE_P": 0.08,
"PRTS_FOUR_P": 0.48,
"PRTS_THREE_P": 0.42,
},
'genshin': {
'GENSHIN_FIVE_P': 0.006,
'GENSHIN_FOUR_P': 0.051,
'GENSHIN_THREE_P': 0.43,
'GENSHIN_G_FIVE_P': 0.13,
'GENSHIN_G_FOUR_P': 0.016,
'I72_ADD': 0.0585,
"genshin": {
"GENSHIN_FIVE_P": 0.006,
"GENSHIN_FOUR_P": 0.051,
"GENSHIN_THREE_P": 0.43,
"GENSHIN_G_FIVE_P": 0.13,
"GENSHIN_G_FOUR_P": 0.016,
"I72_ADD": 0.0585,
},
'pretty': {
'PRETTY_THREE_P': 0.03,
'PRETTY_TWO_P': 0.18,
'PRETTY_ONE_P': 0.79,
"pretty": {
"PRETTY_THREE_P": 0.03,
"PRETTY_TWO_P": 0.18,
"PRETTY_ONE_P": 0.79,
},
'guardian': {
'GUARDIAN_THREE_CHAR_P': 0.0275,
'GUARDIAN_TWO_CHAR_P': 0.19,
'GUARDIAN_ONE_CHAR_P': 0.7825,
'GUARDIAN_THREE_CHAR_UP_P': 0.01375,
'GUARDIAN_THREE_CHAR_OTHER_P': 0.01375,
'GUARDIAN_EXCLUSIVE_ARMS_P': 0.03,
'GUARDIAN_FIVE_ARMS_P': 0.03,
'GUARDIAN_FOUR_ARMS_P': 0.09,
'GUARDIAN_THREE_ARMS_P': 0.27,
'GUARDIAN_TWO_ARMS_P': 0.58,
'GUARDIAN_EXCLUSIVE_ARMS_UP_P': 0.01,
'GUARDIAN_EXCLUSIVE_ARMS_OTHER_P': 0.02,
"guardian": {
"GUARDIAN_THREE_CHAR_P": 0.0275,
"GUARDIAN_TWO_CHAR_P": 0.19,
"GUARDIAN_ONE_CHAR_P": 0.7825,
"GUARDIAN_THREE_CHAR_UP_P": 0.01375,
"GUARDIAN_THREE_CHAR_OTHER_P": 0.01375,
"GUARDIAN_EXCLUSIVE_ARMS_P": 0.03,
"GUARDIAN_FIVE_ARMS_P": 0.03,
"GUARDIAN_FOUR_ARMS_P": 0.09,
"GUARDIAN_THREE_ARMS_P": 0.27,
"GUARDIAN_TWO_ARMS_P": 0.58,
"GUARDIAN_EXCLUSIVE_ARMS_UP_P": 0.01,
"GUARDIAN_EXCLUSIVE_ARMS_OTHER_P": 0.02,
},
'pcr': {
'PCR_THREE_P': 0.025,
'PCR_TWO_P': 0.18,
'PCR_ONE_P': 0.795,
"pcr": {
"PCR_THREE_P": 0.025,
"PCR_TWO_P": 0.18,
"PCR_ONE_P": 0.795,
},
'azur': {
'AZUR_FIVE_P': 0.012,
'AZUR_FOUR_P': 0.07,
'AZUR_THREE_P': 0.12,
'AZUR_TWO_P': 0.51,
'AZUR_ONE_P': 0.3,
"azur": {
"AZUR_FIVE_P": 0.012,
"AZUR_FOUR_P": 0.07,
"AZUR_THREE_P": 0.12,
"AZUR_TWO_P": 0.51,
"AZUR_ONE_P": 0.3,
},
'fgo': {
'FGO_SERVANT_FIVE_P': 0.01,
'FGO_SERVANT_FOUR_P': 0.03,
'FGO_SERVANT_THREE_P': 0.4,
'FGO_CARD_FIVE_P': 0.04,
'FGO_CARD_FOUR_P': 0.12,
'FGO_CARD_THREE_P': 0.4,
"fgo": {
"FGO_SERVANT_FIVE_P": 0.01,
"FGO_SERVANT_FOUR_P": 0.03,
"FGO_SERVANT_THREE_P": 0.4,
"FGO_CARD_FIVE_P": 0.04,
"FGO_CARD_FOUR_P": 0.12,
"FGO_CARD_THREE_P": 0.4,
},
"onmyoji": {
"ONMYOJI_SP": 0.0025,
"ONMYOJI_SSR": 0.01,
"ONMYOJI_SR": 0.2,
"ONMYOJI_R": 0.7875,
},
'onmyoji': {
'ONMYOJI_SP': 0.0025,
'ONMYOJI_SSR': 0.01,
'ONMYOJI_SR': 0.2,
'ONMYOJI_R': 0.7875,
}
}
@driver.on_startup
def check_config():
global PRTS_SIX_P, PRTS_FOUR_P, PRTS_FIVE_P, PRTS_THREE_P, GENSHIN_G_FIVE_P, config_default_data, \
GENSHIN_G_FOUR_P, GENSHIN_FOUR_P, GENSHIN_FIVE_P, I72_ADD, path_dict, PRETTY_THREE_P, \
PRETTY_ONE_P, PRETTY_TWO_P, GENSHIN_THREE_P, GUARDIAN_THREE_CHAR_P, GUARDIAN_TWO_CHAR_P, GUARDIAN_ONE_CHAR_P, \
GUARDIAN_THREE_CHAR_UP_P, GUARDIAN_THREE_CHAR_OTHER_P, GUARDIAN_EXCLUSIVE_ARMS_P, GUARDIAN_FIVE_ARMS_P, \
GUARDIAN_FOUR_ARMS_P, GUARDIAN_THREE_ARMS_P, GUARDIAN_TWO_ARMS_P, GENSHIN_FLAG, PRTS_FLAG, \
PRETTY_FLAG, GUARDIAN_FLAG, GUARDIAN_EXCLUSIVE_ARMS_UP_P, GUARDIAN_EXCLUSIVE_ARMS_OTHER_P, DRAW_PATH, \
PCR_THREE_P, PCR_TWO_P, PCR_ONE_P, AZUR_FOUR_P, AZUR_THREE_P, AZUR_TWO_P, AZUR_ONE_P, AZUR_FIVE_P, FGO_CARD_FIVE_P,\
FGO_CARD_FOUR_P, FGO_CARD_THREE_P, FGO_SERVANT_THREE_P, FGO_SERVANT_FOUR_P, FGO_SERVANT_FIVE_P, ONMYOJI_R, ONMYOJI_SP, \
ONMYOJI_SSR, ONMYOJI_SR
global PRTS_SIX_P, PRTS_FOUR_P, PRTS_FIVE_P, PRTS_THREE_P, GENSHIN_G_FIVE_P, config_default_data, GENSHIN_G_FOUR_P, GENSHIN_FOUR_P, GENSHIN_FIVE_P, I72_ADD, path_dict, PRETTY_THREE_P, PRETTY_ONE_P, PRETTY_TWO_P, GENSHIN_THREE_P, GUARDIAN_THREE_CHAR_P, GUARDIAN_TWO_CHAR_P, GUARDIAN_ONE_CHAR_P, GUARDIAN_THREE_CHAR_UP_P, GUARDIAN_THREE_CHAR_OTHER_P, GUARDIAN_EXCLUSIVE_ARMS_P, GUARDIAN_FIVE_ARMS_P, GUARDIAN_FOUR_ARMS_P, GUARDIAN_THREE_ARMS_P, GUARDIAN_TWO_ARMS_P, GENSHIN_FLAG, PRTS_FLAG, PRETTY_FLAG, GUARDIAN_FLAG, GUARDIAN_EXCLUSIVE_ARMS_UP_P, GUARDIAN_EXCLUSIVE_ARMS_OTHER_P, DRAW_PATH, PCR_THREE_P, PCR_TWO_P, PCR_ONE_P, AZUR_FOUR_P, AZUR_THREE_P, AZUR_TWO_P, AZUR_ONE_P, AZUR_FIVE_P, FGO_CARD_FIVE_P, FGO_CARD_FOUR_P, FGO_CARD_THREE_P, FGO_SERVANT_THREE_P, FGO_SERVANT_FOUR_P, FGO_SERVANT_FIVE_P, ONMYOJI_R, ONMYOJI_SP, ONMYOJI_SSR, ONMYOJI_SR
_draw_config.parent.mkdir(parents=True, exist_ok=True)
try:
data = json.load(open(_draw_config, 'r', encoding='utf8'))
data = json.load(open(_draw_config, "r", encoding="utf8"))
except (FileNotFoundError, ValueError):
_draw_config.parent.mkdir(parents=True, exist_ok=True)
json.dump(config_default_data, open(_draw_config, 'w', encoding='utf8'), indent=4, ensure_ascii=False)
print('draw_card:配置文件不存在或格式错误,已重新生成配置文件.....')
json.dump(
config_default_data,
open(_draw_config, "w", encoding="utf8"),
indent=4,
ensure_ascii=False,
)
print("draw_card:配置文件不存在或格式错误,已重新生成配置文件.....")
else:
try:
PRTS_SIX_P = float(data['prts']['PRTS_SIX_P'])
PRTS_FIVE_P = float(data['prts']['PRTS_FIVE_P'])
PRTS_FOUR_P = float(data['prts']['PRTS_FOUR_P'])
PRTS_THREE_P = float(data['prts']['PRTS_THREE_P'])
PRTS_SIX_P = float(data["prts"]["PRTS_SIX_P"])
PRTS_FIVE_P = float(data["prts"]["PRTS_FIVE_P"])
PRTS_FOUR_P = float(data["prts"]["PRTS_FOUR_P"])
PRTS_THREE_P = float(data["prts"]["PRTS_THREE_P"])
except KeyError:
data['prts'] = {}
data['prts']['PRTS_SIX_P'] = config_default_data['prts']['PRTS_SIX_P']
data['prts']['PRTS_FIVE_P'] = config_default_data['prts']['PRTS_FIVE_P']
data['prts']['PRTS_FOUR_P'] = config_default_data['prts']['PRTS_FOUR_P']
data['prts']['PRTS_THREE_P'] = config_default_data['prts']['PRTS_THREE_P']
data["prts"] = {}
data["prts"]["PRTS_SIX_P"] = config_default_data["prts"]["PRTS_SIX_P"]
data["prts"]["PRTS_FIVE_P"] = config_default_data["prts"]["PRTS_FIVE_P"]
data["prts"]["PRTS_FOUR_P"] = config_default_data["prts"]["PRTS_FOUR_P"]
data["prts"]["PRTS_THREE_P"] = config_default_data["prts"]["PRTS_THREE_P"]
try:
GENSHIN_FIVE_P = float(data['genshin']['GENSHIN_FIVE_P'])
GENSHIN_FOUR_P = float(data['genshin']['GENSHIN_FOUR_P'])
GENSHIN_THREE_P = float(data['genshin']['GENSHIN_THREE_P'])
GENSHIN_G_FIVE_P = float(data['genshin']['GENSHIN_G_FIVE_P'])
GENSHIN_G_FOUR_P = float(data['genshin']['GENSHIN_G_FOUR_P'])
I72_ADD = float(data['genshin']['I72_ADD'])
GENSHIN_FIVE_P = float(data["genshin"]["GENSHIN_FIVE_P"])
GENSHIN_FOUR_P = float(data["genshin"]["GENSHIN_FOUR_P"])
GENSHIN_THREE_P = float(data["genshin"]["GENSHIN_THREE_P"])
GENSHIN_G_FIVE_P = float(data["genshin"]["GENSHIN_G_FIVE_P"])
GENSHIN_G_FOUR_P = float(data["genshin"]["GENSHIN_G_FOUR_P"])
I72_ADD = float(data["genshin"]["I72_ADD"])
except KeyError:
data['genshin'] = {}
data['genshin']['GENSHIN_FIVE_P'] = config_default_data['genshin']['GENSHIN_FIVE_P']
data['genshin']['GENSHIN_FOUR_P'] = config_default_data['genshin']['GENSHIN_FOUR_P']
data['genshin']['GENSHIN_THREE_P'] = config_default_data['genshin']['GENSHIN_THREE_P']
data['genshin']['GENSHIN_G_FIVE_P'] = config_default_data['genshin']['GENSHIN_G_FIVE_P']
data['genshin']['GENSHIN_G_FOUR_P'] = config_default_data['genshin']['GENSHIN_G_FOUR_P']
data['genshin']['I72_ADD'] = config_default_data['genshin']['I72_ADD']
data["genshin"] = {}
data["genshin"]["GENSHIN_FIVE_P"] = config_default_data["genshin"][
"GENSHIN_FIVE_P"
]
data["genshin"]["GENSHIN_FOUR_P"] = config_default_data["genshin"][
"GENSHIN_FOUR_P"
]
data["genshin"]["GENSHIN_THREE_P"] = config_default_data["genshin"][
"GENSHIN_THREE_P"
]
data["genshin"]["GENSHIN_G_FIVE_P"] = config_default_data["genshin"][
"GENSHIN_G_FIVE_P"
]
data["genshin"]["GENSHIN_G_FOUR_P"] = config_default_data["genshin"][
"GENSHIN_G_FOUR_P"
]
data["genshin"]["I72_ADD"] = config_default_data["genshin"]["I72_ADD"]
try:
PRETTY_THREE_P = float(data['pretty']['PRETTY_THREE_P'])
PRETTY_TWO_P = float(data['pretty']['PRETTY_TWO_P'])
PRETTY_ONE_P = float(data['pretty']['PRETTY_ONE_P'])
PRETTY_THREE_P = float(data["pretty"]["PRETTY_THREE_P"])
PRETTY_TWO_P = float(data["pretty"]["PRETTY_TWO_P"])
PRETTY_ONE_P = float(data["pretty"]["PRETTY_ONE_P"])
except KeyError:
data['pretty'] = {}
data['pretty']['PRETTY_THREE_P'] = config_default_data['pretty']['PRETTY_THREE_P']
data['pretty']['PRETTY_TWO_P'] = config_default_data['pretty']['PRETTY_TWO_P']
data['pretty']['PRETTY_ONE_P'] = config_default_data['pretty']['PRETTY_ONE_P']
data["pretty"] = {}
data["pretty"]["PRETTY_THREE_P"] = config_default_data["pretty"][
"PRETTY_THREE_P"
]
data["pretty"]["PRETTY_TWO_P"] = config_default_data["pretty"][
"PRETTY_TWO_P"
]
data["pretty"]["PRETTY_ONE_P"] = config_default_data["pretty"][
"PRETTY_ONE_P"
]
try:
GUARDIAN_THREE_CHAR_P = float(data['guardian']['GUARDIAN_THREE_CHAR_P'])
GUARDIAN_TWO_CHAR_P = float(data['guardian']['GUARDIAN_TWO_CHAR_P'])
GUARDIAN_ONE_CHAR_P = float(data['guardian']['GUARDIAN_ONE_CHAR_P'])
GUARDIAN_THREE_CHAR_UP_P = float(data['guardian']['GUARDIAN_THREE_CHAR_UP_P'])
GUARDIAN_THREE_CHAR_OTHER_P = float(data['guardian']['GUARDIAN_THREE_CHAR_OTHER_P'])
GUARDIAN_EXCLUSIVE_ARMS_P = float(data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_P'])
GUARDIAN_FIVE_ARMS_P = float(data['guardian']['GUARDIAN_FIVE_ARMS_P'])
GUARDIAN_FOUR_ARMS_P = float(data['guardian']['GUARDIAN_FOUR_ARMS_P'])
GUARDIAN_THREE_ARMS_P = float(data['guardian']['GUARDIAN_THREE_ARMS_P'])
GUARDIAN_TWO_ARMS_P = float(data['guardian']['GUARDIAN_TWO_ARMS_P'])
GUARDIAN_EXCLUSIVE_ARMS_UP_P = float(data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_UP_P'])
GUARDIAN_EXCLUSIVE_ARMS_OTHER_P = float(data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_OTHER_P'])
GUARDIAN_THREE_CHAR_P = float(data["guardian"]["GUARDIAN_THREE_CHAR_P"])
GUARDIAN_TWO_CHAR_P = float(data["guardian"]["GUARDIAN_TWO_CHAR_P"])
GUARDIAN_ONE_CHAR_P = float(data["guardian"]["GUARDIAN_ONE_CHAR_P"])
GUARDIAN_THREE_CHAR_UP_P = float(
data["guardian"]["GUARDIAN_THREE_CHAR_UP_P"]
)
GUARDIAN_THREE_CHAR_OTHER_P = float(
data["guardian"]["GUARDIAN_THREE_CHAR_OTHER_P"]
)
GUARDIAN_EXCLUSIVE_ARMS_P = float(
data["guardian"]["GUARDIAN_EXCLUSIVE_ARMS_P"]
)
GUARDIAN_FIVE_ARMS_P = float(data["guardian"]["GUARDIAN_FIVE_ARMS_P"])
GUARDIAN_FOUR_ARMS_P = float(data["guardian"]["GUARDIAN_FOUR_ARMS_P"])
GUARDIAN_THREE_ARMS_P = float(data["guardian"]["GUARDIAN_THREE_ARMS_P"])
GUARDIAN_TWO_ARMS_P = float(data["guardian"]["GUARDIAN_TWO_ARMS_P"])
GUARDIAN_EXCLUSIVE_ARMS_UP_P = float(
data["guardian"]["GUARDIAN_EXCLUSIVE_ARMS_UP_P"]
)
GUARDIAN_EXCLUSIVE_ARMS_OTHER_P = float(
data["guardian"]["GUARDIAN_EXCLUSIVE_ARMS_OTHER_P"]
)
except KeyError:
data['guardian'] = {}
data['guardian']['GUARDIAN_THREE_CHAR_P'] = config_default_data['guardian']['GUARDIAN_THREE_CHAR_P']
data['guardian']['GUARDIAN_TWO_CHAR_P'] = config_default_data['guardian']['GUARDIAN_TWO_CHAR_P']
data['guardian']['GUARDIAN_ONE_CHAR_P'] = config_default_data['guardian']['GUARDIAN_ONE_CHAR_P']
data['guardian']['GUARDIAN_THREE_CHAR_UP_P'] = config_default_data['guardian']['GUARDIAN_THREE_CHAR_UP_P']
data['guardian']['GUARDIAN_THREE_CHAR_OTHER_P'] = config_default_data['guardian']['GUARDIAN_THREE_CHAR_OTHER_P']
data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_P'] = config_default_data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_P']
data['guardian']['GUARDIAN_FIVE_ARMS_P'] = config_default_data['guardian']['GUARDIAN_FIVE_ARMS_P']
data['guardian']['GUARDIAN_FOUR_ARMS_P'] = config_default_data['guardian']['GUARDIAN_FOUR_ARMS_P']
data['guardian']['GUARDIAN_THREE_ARMS_P'] = config_default_data['guardian']['GUARDIAN_THREE_ARMS_P']
data['guardian']['GUARDIAN_TWO_ARMS_P'] = config_default_data['guardian']['GUARDIAN_TWO_ARMS_P']
data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_UP_P'] = config_default_data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_UP_P']
data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_OTHER_P'] = config_default_data['guardian']['GUARDIAN_EXCLUSIVE_ARMS_OTHER_P']
data["guardian"] = {}
data["guardian"]["GUARDIAN_THREE_CHAR_P"] = config_default_data["guardian"][
"GUARDIAN_THREE_CHAR_P"
]
data["guardian"]["GUARDIAN_TWO_CHAR_P"] = config_default_data["guardian"][
"GUARDIAN_TWO_CHAR_P"
]
data["guardian"]["GUARDIAN_ONE_CHAR_P"] = config_default_data["guardian"][
"GUARDIAN_ONE_CHAR_P"
]
data["guardian"]["GUARDIAN_THREE_CHAR_UP_P"] = config_default_data[
"guardian"
]["GUARDIAN_THREE_CHAR_UP_P"]
data["guardian"]["GUARDIAN_THREE_CHAR_OTHER_P"] = config_default_data[
"guardian"
]["GUARDIAN_THREE_CHAR_OTHER_P"]
data["guardian"]["GUARDIAN_EXCLUSIVE_ARMS_P"] = config_default_data[
"guardian"
]["GUARDIAN_EXCLUSIVE_ARMS_P"]
data["guardian"]["GUARDIAN_FIVE_ARMS_P"] = config_default_data["guardian"][
"GUARDIAN_FIVE_ARMS_P"
]
data["guardian"]["GUARDIAN_FOUR_ARMS_P"] = config_default_data["guardian"][
"GUARDIAN_FOUR_ARMS_P"
]
data["guardian"]["GUARDIAN_THREE_ARMS_P"] = config_default_data["guardian"][
"GUARDIAN_THREE_ARMS_P"
]
data["guardian"]["GUARDIAN_TWO_ARMS_P"] = config_default_data["guardian"][
"GUARDIAN_TWO_ARMS_P"
]
data["guardian"]["GUARDIAN_EXCLUSIVE_ARMS_UP_P"] = config_default_data[
"guardian"
]["GUARDIAN_EXCLUSIVE_ARMS_UP_P"]
data["guardian"]["GUARDIAN_EXCLUSIVE_ARMS_OTHER_P"] = config_default_data[
"guardian"
]["GUARDIAN_EXCLUSIVE_ARMS_OTHER_P"]
try:
PCR_THREE_P = float(data['pcr']['PCR_THREE_P'])
PCR_TWO_P = float(data['pcr']['PCR_TWO_P'])
PCR_ONE_P = float(data['pcr']['PCR_ONE_P'])
PCR_THREE_P = float(data["pcr"]["PCR_THREE_P"])
PCR_TWO_P = float(data["pcr"]["PCR_TWO_P"])
PCR_ONE_P = float(data["pcr"]["PCR_ONE_P"])
except KeyError:
data['pcr'] = {}
data['pcr']['PCR_THREE_P'] = config_default_data['pcr']['PCR_THREE_P']
data['pcr']['PCR_TWO_P'] = config_default_data['pcr']['PCR_TWO_P']
data['pcr']['PCR_ONE_P'] = config_default_data['pcr']['PCR_ONE_P']
data["pcr"] = {}
data["pcr"]["PCR_THREE_P"] = config_default_data["pcr"]["PCR_THREE_P"]
data["pcr"]["PCR_TWO_P"] = config_default_data["pcr"]["PCR_TWO_P"]
data["pcr"]["PCR_ONE_P"] = config_default_data["pcr"]["PCR_ONE_P"]
try:
AZUR_FIVE_P = float(data['azur']['AZUR_FIVE_P'])
AZUR_FOUR_P = float(data['azur']['AZUR_FOUR_P'])
AZUR_THREE_P = float(data['azur']['AZUR_THREE_P'])
AZUR_TWO_P = float(data['azur']['AZUR_TWO_P'])
AZUR_ONE_P = float(data['azur']['AZUR_ONE_P'])
AZUR_FIVE_P = float(data["azur"]["AZUR_FIVE_P"])
AZUR_FOUR_P = float(data["azur"]["AZUR_FOUR_P"])
AZUR_THREE_P = float(data["azur"]["AZUR_THREE_P"])
AZUR_TWO_P = float(data["azur"]["AZUR_TWO_P"])
AZUR_ONE_P = float(data["azur"]["AZUR_ONE_P"])
except KeyError:
data['azur'] = {}
data['azur']['AZUR_FIVE_P'] = config_default_data['azur']['AZUR_FIVE_P']
data['azur']['AZUR_FOUR_P'] = config_default_data['azur']['AZUR_FOUR_P']
data['azur']['AZUR_THREE_P'] = config_default_data['azur']['AZUR_THREE_P']
data['azur']['AZUR_TWO_P'] = config_default_data['azur']['AZUR_TWO_P']
data['azur']['AZUR_ONE_P'] = config_default_data['azur']['AZUR_ONE_P']
data["azur"] = {}
data["azur"]["AZUR_FIVE_P"] = config_default_data["azur"]["AZUR_FIVE_P"]
data["azur"]["AZUR_FOUR_P"] = config_default_data["azur"]["AZUR_FOUR_P"]
data["azur"]["AZUR_THREE_P"] = config_default_data["azur"]["AZUR_THREE_P"]
data["azur"]["AZUR_TWO_P"] = config_default_data["azur"]["AZUR_TWO_P"]
data["azur"]["AZUR_ONE_P"] = config_default_data["azur"]["AZUR_ONE_P"]
try:
FGO_SERVANT_FIVE_P = float(data['fgo']['FGO_SERVANT_FIVE_P'])
FGO_SERVANT_FOUR_P = float(data['fgo']['FGO_SERVANT_FOUR_P'])
FGO_SERVANT_THREE_P = float(data['fgo']['FGO_SERVANT_THREE_P'])
FGO_CARD_FIVE_P = float(data['fgo']['FGO_CARD_FIVE_P'])
FGO_CARD_FOUR_P = float(data['fgo']['FGO_CARD_FOUR_P'])
FGO_CARD_THREE_P = float(data['fgo']['FGO_CARD_THREE_P'])
FGO_SERVANT_FIVE_P = float(data["fgo"]["FGO_SERVANT_FIVE_P"])
FGO_SERVANT_FOUR_P = float(data["fgo"]["FGO_SERVANT_FOUR_P"])
FGO_SERVANT_THREE_P = float(data["fgo"]["FGO_SERVANT_THREE_P"])
FGO_CARD_FIVE_P = float(data["fgo"]["FGO_CARD_FIVE_P"])
FGO_CARD_FOUR_P = float(data["fgo"]["FGO_CARD_FOUR_P"])
FGO_CARD_THREE_P = float(data["fgo"]["FGO_CARD_THREE_P"])
except KeyError:
data['fgo'] = {}
data['fgo']['FGO_SERVANT_FIVE_P'] = config_default_data['fgo']['FGO_SERVANT_FIVE_P']
data['fgo']['FGO_SERVANT_FOUR_P'] = config_default_data['fgo']['FGO_SERVANT_FOUR_P']
data['fgo']['FGO_SERVANT_THREE_P'] = config_default_data['fgo']['FGO_SERVANT_THREE_P']
data['fgo']['FGO_CARD_FIVE_P'] = config_default_data['fgo']['FGO_CARD_FIVE_P']
data['fgo']['FGO_CARD_FOUR_P'] = config_default_data['fgo']['FGO_CARD_FOUR_P']
data['fgo']['FGO_CARD_THREE_P'] = config_default_data['fgo']['FGO_CARD_THREE_P']
data["fgo"] = {}
data["fgo"]["FGO_SERVANT_FIVE_P"] = config_default_data["fgo"][
"FGO_SERVANT_FIVE_P"
]
data["fgo"]["FGO_SERVANT_FOUR_P"] = config_default_data["fgo"][
"FGO_SERVANT_FOUR_P"
]
data["fgo"]["FGO_SERVANT_THREE_P"] = config_default_data["fgo"][
"FGO_SERVANT_THREE_P"
]
data["fgo"]["FGO_CARD_FIVE_P"] = config_default_data["fgo"][
"FGO_CARD_FIVE_P"
]
data["fgo"]["FGO_CARD_FOUR_P"] = config_default_data["fgo"][
"FGO_CARD_FOUR_P"
]
data["fgo"]["FGO_CARD_THREE_P"] = config_default_data["fgo"][
"FGO_CARD_THREE_P"
]
try:
ONMYOJI_SP = float(data['onmyoji']['ONMYOJI_SP'])
ONMYOJI_SSR = float(data['onmyoji']['ONMYOJI_SSR'])
ONMYOJI_SR = float(data['onmyoji']['ONMYOJI_SR'])
ONMYOJI_R = float(data['onmyoji']['ONMYOJI_R'])
ONMYOJI_SP = float(data["onmyoji"]["ONMYOJI_SP"])
ONMYOJI_SSR = float(data["onmyoji"]["ONMYOJI_SSR"])
ONMYOJI_SR = float(data["onmyoji"]["ONMYOJI_SR"])
ONMYOJI_R = float(data["onmyoji"]["ONMYOJI_R"])
except KeyError:
data['onmyoji'] = {}
data['onmyoji']['ONMYOJI_SP'] = config_default_data['onmyoji']['ONMYOJI_SP']
data['onmyoji']['ONMYOJI_SSR'] = config_default_data['onmyoji']['ONMYOJI_SSR']
data['onmyoji']['ONMYOJI_SR'] = config_default_data['onmyoji']['ONMYOJI_SR']
data['onmyoji']['ONMYOJI_R'] = config_default_data['onmyoji']['ONMYOJI_R']
json.dump(data, open(_draw_config, 'w', encoding='utf8'), indent=4, ensure_ascii=False)
data["onmyoji"] = {}
data["onmyoji"]["ONMYOJI_SP"] = config_default_data["onmyoji"]["ONMYOJI_SP"]
data["onmyoji"]["ONMYOJI_SSR"] = config_default_data["onmyoji"][
"ONMYOJI_SSR"
]
data["onmyoji"]["ONMYOJI_SR"] = config_default_data["onmyoji"]["ONMYOJI_SR"]
data["onmyoji"]["ONMYOJI_R"] = config_default_data["onmyoji"]["ONMYOJI_R"]
json.dump(
data, open(_draw_config, "w", encoding="utf8"), indent=4, ensure_ascii=False
)
+10 -6
View File
@@ -9,9 +9,9 @@ from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
import aiohttp
import aiofiles
from asyncio.exceptions import TimeoutError
from configs.config import FUDU_PROBABILITY
from configs.config import Config
from utils.manager import group_manager
from services.log import logger
__zx_plugin_name__ = "复读"
@@ -24,6 +24,9 @@ __plugin_type__ = ("被动相关",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_task__ = {"fudu": "复读"}
__plugin_configs__ = {
"FUDU_PROBABILITY": {"value": 0.7, "help": "复读概率", "default_value": 0.7}
}
class Fudu:
@@ -98,9 +101,9 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
_fudu_list.clear(event.group_id)
_fudu_list.append(event.group_id, add_msg)
if _fudu_list.size(event.group_id) > 2:
if random.random() < FUDU_PROBABILITY and not _fudu_list.is_repeater(
event.group_id
):
if random.random() < Config.get_config(
"fudu", "FUDU_PROBABILITY"
) and not _fudu_list.is_repeater(event.group_id):
if random.random() < 0.2:
await fudu.finish("打断施法!")
_fudu_list.set_repeater(event.group_id)
@@ -126,5 +129,6 @@ async def get_fudu_img_hash(url, group_id):
await f.write(await response.read())
img_hash = get_img_hash(IMAGE_PATH + f"temp/compare_{group_id}_img.jpg")
return str(img_hash)
except TimeoutError:
except Exception as e:
logger.warning(f"复读读取图片Hash出错 {type(e)}:{e}")
return ""
-195
View File
@@ -1,195 +0,0 @@
from utils.message_builder import image
from utils.utils import scheduler, get_bot
from nonebot import on_message
from services.log import logger
from models.group_info import GroupInfo
from models.friend_user import FriendUser
from nonebot.adapters.cqhttp.exception import ActionFailed
from configs.config import NICKNAME
from utils.manager import group_manager
__zx_plugin_name__ = "群定时任务相关 [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_task__ = {'zwa': '早晚安'}
x = on_message(priority=9, block=False)
# 早上好
@scheduler.scheduled_job(
"cron",
hour=6,
minute=1,
)
async def _():
try:
bot = get_bot()
gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl]
for g in gl:
if await group_manager.check_group_task_status(g, 'zwa'):
result = image("zao.jpg", "zhenxun")
try:
await bot.send_group_msg(group_id=g, message="早上好" + result)
except ActionFailed:
logger.warning(f"{g} 群被禁言中,无法发送早安")
except Exception as e:
logger.error(f"早晚安错误 e:{e}")
# 睡觉了
@scheduler.scheduled_job(
"cron",
hour=23,
minute=59,
)
async def _():
try:
bot = get_bot()
gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl]
for g in gl:
if await group_manager.check_group_task_status(g, 'zwa'):
result = image("sleep.jpg", "zhenxun")
try:
await bot.send_group_msg(
group_id=g, message=f"{NICKNAME}要睡觉了,你们也要早点睡呀" + result
)
except ActionFailed:
logger.warning(f"{g} 群被禁言中,无法发送晚安")
except Exception as e:
logger.error(f"早晚安错误 e:{e}")
# 自动更新群组信息
@scheduler.scheduled_job(
"cron",
hour=3,
minute=1,
)
async def _():
try:
bot = get_bot()
gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl]
for g in gl:
group_info = await bot.get_group_info(group_id=g)
await GroupInfo.add_group_info(
group_info["group_id"],
group_info["group_name"],
group_info["max_member_count"],
group_info["member_count"],
)
logger.info(f"自动更新群组 {g} 信息成功")
except Exception as e:
logger.error(f"自动更新群组信息错误 e:{e}")
# 自动更新好友信息
@scheduler.scheduled_job(
"cron",
hour=3,
minute=1,
)
async def _():
try:
bot = get_bot()
fl = await bot.get_friend_list()
for f in fl:
if await FriendUser.add_friend_info(f["user_id"], f["nickname"]):
logger.info(f'自动更新好友 {f["user_id"]} 信息成功')
else:
logger.warning(f'自动更新好友 {f["user_id"]} 信息失败')
except Exception as e:
logger.error(f"自动更新群组信息错误 e:{e}")
# 一次性任务
# 固定时间触发,仅触发一次:
#
# from datetime import datetime
#
# @nonebot.scheduler.scheduled_job(
# 'date',
# run_date=datetime(2021, 1, 1, 0, 0),
# # timezone=None,
# )
# async def _():
# await bot.send_group_msg(group_id=123456,
# message="2021,新年快乐!")
# 定期任务
# 从 start_date 开始到 end_date 结束,根据类似 Cron
#
# 的规则触发任务:
#
# @nonebot.scheduler.scheduled_job(
# 'cron',
# # year=None,
# # month=None,
# # day=None,
# # week=None,
# day_of_week="mon,tue,wed,thu,fri",
# hour=7,
# # minute=None,
# # second=None,
# # start_date=None,
# # end_date=None,
# # timezone=None,
# )
# async def _():
# await bot.send_group_msg(group_id=123456,
# message="起床啦!")
# 间隔任务
#
# interval 触发器
#
# 从 start_date 开始,每间隔一段时间触发,到 end_date 结束:
#
# @nonebot.scheduler.scheduled_job(
# 'interval',
# # weeks=0,
# # days=0,
# # hours=0,
# minutes=5,
# # seconds=0,
# # start_date=time.now(),
# # end_date=None,
# )
# async def _():
# has_new_item = check_new_item()
# if has_new_item:
# await bot.send_group_msg(group_id=123456,
# message="XX有更新啦!")
# 动态的计划任务
# import datetime
#
# from apscheduler.triggers.date import DateTrigger # 一次性触发器
# # from apscheduler.triggers.cron import CronTrigger # 定期触发器
# # from apscheduler.triggers.interval import IntervalTrigger # 间隔触发器
# from nonebot import on_command, scheduler
#
# @on_command('赖床')
# async def _(session: CommandSession):
# await session.send('我会在5分钟后再喊你')
#
# # 制作一个“5分钟后”触发器
# delta = datetime.timedelta(minutes=5)
# trigger = DateTrigger(
# run_date=datetime.datetime.now() + delta
# )
#
# # 添加任务
# scheduler.add_job(
# func=session.send, # 要添加任务的函数,不要带参数
# trigger=trigger, # 触发器
# args=('不要再赖床啦!',), # 函数的参数列表,注意:只有一个值时,不能省略末尾的逗号
# # kwargs=None,
# misfire_grace_time=60, # 允许的误差时间,建议不要省略
# # jobstore='default', # 任务储存库,在下一小节中说明
# )
-141
View File
@@ -1,141 +0,0 @@
from nonebot import on_notice, on_request
from configs.path_config import IMAGE_PATH, DATA_PATH
from utils.message_builder import image
from models.group_member_info import GroupInfoUser
from datetime import datetime
from services.log import logger
from nonebot.adapters.cqhttp import (
Bot,
GroupIncreaseNoticeEvent,
GroupDecreaseNoticeEvent,
)
from nonebot.adapters.cqhttp.exception import ActionFailed
from utils.manager import group_manager, plugins2settings_manager
from models.group_info import GroupInfo
from pathlib import Path
import random
import os
try:
import ujson as json
except ModuleNotFoundError:
import json
__zx_plugin_name__ = "群事件处理 [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_task__ = {
'group_welcome': '进群欢迎',
'refund_group_remind': '退群提醒'
}
# 群员增加处理
group_increase_handle = on_notice(priority=1, block=False)
# 群员减少处理
group_decrease_handle = on_notice(priority=1, block=False)
# (群管理)加群同意请求
add_group = on_request(priority=1, block=False)
@group_increase_handle.handle()
async def _(bot: Bot, event: GroupIncreaseNoticeEvent, state: dict):
if event.user_id == int(bot.self_id):
if event.group_id not in group_manager["group_manager"].keys():
data = plugins2settings_manager.get_data()
for plugin in data.keys():
if not data[plugin]["default_status"]:
group_manager.block_plugin(plugin, event.group_id)
else:
join_time = datetime.now()
user_info = await bot.get_group_member_info(
group_id=event.group_id, user_id=event.user_id
)
if await GroupInfoUser.add_member_info(
user_info["user_id"],
user_info["group_id"],
user_info["nickname"],
join_time,
):
logger.info(f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新成功")
else:
logger.info(f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新失败")
# 群欢迎消息
if await group_manager.check_group_task_status(event.group_id, 'group_welcome'):
msg = ""
img = ""
at_flag = False
custom_welcome_msg_json = (
Path() / "data" / "custom_welcome_msg" / "custom_welcome_msg.json"
)
if custom_welcome_msg_json.exists():
data = json.load(open(custom_welcome_msg_json, "r"))
if data.get(str(event.group_id)):
msg = data[str(event.group_id)]
if msg.find("[at]") != -1:
msg = msg.replace("[at]", "")
at_flag = True
if os.path.exists(DATA_PATH + f"custom_welcome_msg/{event.group_id}.jpg"):
img = image(
abspath=DATA_PATH + f"custom_welcome_msg/{event.group_id}.jpg"
)
if msg or img:
await group_increase_handle.send(
"\n" + msg.strip() + img, at_sender=at_flag
)
else:
await group_increase_handle.send(
"新人快跑啊!!本群现状↓(快使用自定义!)"
+ image(random.choice(os.listdir(IMAGE_PATH + "qxz/")), "qxz")
)
@group_decrease_handle.handle()
async def _(bot: Bot, event: GroupDecreaseNoticeEvent, state: dict):
# 被踢出群
if event.sub_type == "kick_me":
group_id = event.group_id
operator_id = event.operator_id
try:
operator_name = (
await GroupInfoUser.get_member_info(event.operator_id, event.group_id)
).user_name
except AttributeError:
operator_name = "None"
group = await GroupInfo.get_group_info(group_id)
group_name = group.group_name if group else ""
coffee = int(list(bot.config.superusers)[0])
await bot.send_private_msg(
user_id=coffee,
message=f"****呜..一份踢出报告****\n"
f"我被 {operator_name}({operator_id})\n"
f"踢出了 {group_name}({group_id})\n"
f"日期:{str(datetime.now()).split('.')[0]}",
)
return
try:
user_name = (
await GroupInfoUser.get_member_info(event.user_id, event.group_id)
).user_name
except AttributeError:
user_name = str(event.user_id)
if await GroupInfoUser.delete_member_info(event.user_id, event.group_id):
logger.info(f"用户{user_name}, qq={event.user_id} 所属{event.group_id} 删除成功")
else:
logger.info(f"用户{user_name}, qq={event.user_id} 所属{event.group_id} 删除失败")
if await group_manager.check_group_task_status(event.group_id, 'refund_group_remind'):
rst = ""
if event.sub_type == "leave":
rst = f"{user_name}离开了我们..."
if event.sub_type == "kick":
operator = await bot.get_group_member_info(
user_id=event.operator_id, group_id=event.group_id
)
operator_name = operator["card"] if operator["card"] else operator["nickname"]
rst = f"{user_name} 被 {operator_name} 送走了."
try:
await group_decrease_handle.send(f"{rst}")
except ActionFailed:
return
-132
View File
@@ -1,132 +0,0 @@
from nonebot import on_command, on_regex
from utils.utils import get_message_text, is_number
from nonebot.rule import to_me
from services.log import logger
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, MessageEvent, GROUP
from nonebot.typing import T_State
from nonebot.permission import SUPERUSER
from configs.config import NICKNAME
from utils.manager import group_manager, plugins2settings_manager
try:
import ujson as json
except ModuleNotFoundError:
import json
__zx_plugin_name__ = "群权限操作 [Superuser]"
__plugin_usage__ = """
usage:
对群权限 | 群白名单 的操作
指令:
修改群权限 [group] [等级]
添加群白名单 *[group]
删除群白名单 *[group]
查看群白名单
""".strip()
__plugin_des__ = "对群权限 | 群白名单 的操作"
__plugin_cmd__ = ["修改群权限 [group] [等级]", "添加群白名单 *[group]", "删除群白名单 *[group]", "查看群白名单"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
add_group_level = on_command("修改群权限", priority=1, permission=SUPERUSER, block=True)
my_group_level = on_command(
"查看群权限", aliases={"群权限"}, priority=5, permission=GROUP, block=True
)
what_up_group_level = on_regex(
".*?(提高|提升|升高|增加|加上)(.*?)群权限.*?",
rule=to_me(),
priority=5,
permission=GROUP,
block=True,
)
manager_group_whitelist = on_command(
"添加群白名单", aliases={"删除群白名单"}, priority=1, permission=SUPERUSER, block=True
)
show_group_whitelist = on_command(
"查看群白名单", priority=1, permission=SUPERUSER, block=True
)
@add_group_level.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
group_id = 0
level = 0
if not msg:
await add_group_level.finish("用法:修改群权限 [group] [level]")
msg = msg.split(" ")
if len(msg) < 2:
await add_group_level.finish("参数不完全..[group] [level]")
if is_number(msg[0]) and is_number(msg[1]):
group_id = msg[0]
level = int(msg[1])
else:
await add_group_level.finish("参数错误...group和level必须是数字..")
old_level = group_manager.get_group_level(group_id)
group_manager.set_group_level(group_id, level)
await add_group_level.send("修改成功...", at_sender=True)
if level > -1:
await bot.send_group_msg(
group_id=int(group_id), message=f"管理员修改了此群权限:{old_level} -> {level}"
)
logger.info(f"{event.user_id} 修改了 {group_id} 的权限:{level}")
@my_group_level.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
level = group_manager.get_group_level(event.group_id)
tmp = ""
data = plugins2settings_manager.get_data()
for module in data:
if data[module]["level"] > level:
plugin_name = data[module]["cmd"][0]
if plugin_name == "pixiv":
plugin_name = "搜图 p站排行"
tmp += f"{plugin_name}\n"
if tmp:
tmp = "\n目前无法使用的功能:\n" + tmp
await my_group_level.finish(f"当前群权限:{level}{tmp}")
@what_up_group_level.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await what_up_group_level.finish(
f"[此功能用于防止内鬼,如果引起不便那真是抱歉了]\n" f"目前提高群权限的方法:\n" f"\t1.管理员修改权限"
)
@manager_group_whitelist.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json()).split()
all_group = [
g["group_id"] for g in await bot.get_group_list(self_id=int(bot.self_id))
]
group_list = []
for group in msg:
if is_number(group) and int(group) in all_group:
group_list.append(int(group))
if group_list:
for group in group_list:
if state["_prefix"]["raw_command"] in ["添加群白名单"]:
group_manager.add_group_white_list(group)
else:
group_manager.delete_group_white_list(group)
group_list = [str(x) for x in group_list]
await manager_group_whitelist.send(
"已成功将 " + "\n".join(group_list) + " " + state["_prefix"]["raw_command"]
)
else:
await manager_group_whitelist.send(f"添加失败,请检查{NICKNAME}是否已加入这些群聊或重复添加/删除群白单名")
@show_group_whitelist.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
x = group_manager.get_group_white_list()
x = [str(g) for g in x]
if x:
await show_group_whitelist.send("目前的群白名单:\n" + "\n".join(x))
else:
await show_group_whitelist.send("没有任何群在群白名单...")
-61
View File
@@ -1,61 +0,0 @@
from nonebot import on_command
from nonebot.adapters.cqhttp import (
Bot,
MessageEvent,
)
from nonebot.typing import T_State
from nonebot.rule import to_me
from configs.path_config import IMAGE_PATH
from utils.message_builder import image
from .data_source import create_help_img, get_plugin_help
from utils.utils import get_message_text
from pathlib import Path
__zx_plugin_name__ = "帮助"
help_image = Path(IMAGE_PATH) / "help.png"
simple_help_image = Path(IMAGE_PATH) / "simple_help.png"
if help_image.exists():
help_image.unlink()
if simple_help_image.exists():
simple_help_image.unlink()
_help = on_command("详细功能", rule=to_me(), aliases={"详细帮助"}, priority=1, block=True)
simple_help = on_command("功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True)
@_help.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if not help_image.exists():
if help_image.exists():
help_image.unlink()
if simple_help_image.exists():
simple_help_image.unlink()
await create_help_img(help_image, simple_help_image)
await _help.finish(image("help.png"))
@simple_help.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
is_super = False
if msg:
if '-super' in msg:
if str(event.user_id) in bot.config.superusers:
is_super = True
msg = msg.replace('-super', '')
msg = get_plugin_help(msg, is_super)
if msg:
await _help.send(image(b64=msg))
else:
await _help.send("没有此功能的帮助信息...")
else:
if not simple_help_image.exists():
if help_image.exists():
help_image.unlink()
if simple_help_image.exists():
simple_help_image.unlink()
await create_help_img(help_image, simple_help_image)
await _help.finish(image("simple_help.png"))
-289
View File
@@ -1,289 +0,0 @@
from utils.image_utils import CreateImg
from configs.path_config import IMAGE_PATH
from utils.manager import plugins2settings_manager
from typing import Optional
from services.log import logger
from pathlib import Path
from utils.utils import get_matchers
import random
import asyncio
import nonebot
import os
random_bk_path = Path(IMAGE_PATH) / "background" / "help" / "simple_help"
background = Path(IMAGE_PATH) / "background" / "0.png"
async def create_help_img(help_image: Path, simple_help_image: Path):
"""
生成帮助图片
:param help_image: 图片路径
:param simple_help_image: 简易帮助图片路径
"""
return await asyncio.get_event_loop().run_in_executor(
None, _create_help_img, help_image, simple_help_image
)
def _create_help_img(help_image: Path, simple_help_image: Path):
"""
生成帮助图片
:param help_image: 图片路径
:param simple_help_image: 简易帮助图片路径
"""
_matchers = get_matchers()
width = 0
matchers_data = {}
_des_tmp = {}
_plugin_name_tmp = []
_tmp = []
tmp_img = CreateImg(0, 0, plain_text="1", font_size=24)
font_height = tmp_img.h
for matcher in _matchers:
plugin_name = None
_plugin = nonebot.plugin.get_plugin(matcher.module)
_module = _plugin.module
try:
plugin_name = _module.__getattribute__("__zx_plugin_name__")
try:
plugin_des = _module.__getattribute__("__plugin_des__")
except AttributeError:
plugin_des = "_"
if (
"[hidden]" in plugin_name.lower()
or "[admin]" in plugin_name.lower()
or "[superuser]" in plugin_name.lower()
or plugin_name in _plugin_name_tmp
or plugin_name == "帮助"
):
continue
plugin_type = ("normal",)
text_type = 0
if plugins2settings_manager.get(
matcher.module
) and plugins2settings_manager[matcher.module].get("plugin_type"):
plugin_type = tuple(
plugins2settings_manager.get_plugin_data(matcher.module)[
"plugin_type"
]
)
else:
try:
plugin_type = _module.__getattribute__("__plugin_type__")
except AttributeError:
pass
if len(plugin_type) > 1:
try:
text_type = int(plugin_type[1])
except ValueError as e:
logger.warning(f"生成列向帮助排列失败 {plugin_name}: {type(e)}: {e}")
plugin_type = plugin_type[0]
else:
plugin_type = plugin_type[0]
try:
plugin_cmd = _module.__getattribute__("__plugin_cmd__")
plugin_cmd = [x for x in plugin_cmd if "[_superuser]" not in x]
except AttributeError:
plugin_cmd = []
if plugin_type not in matchers_data.keys():
matchers_data[plugin_type] = {}
if plugin_des in _des_tmp.keys():
try:
matchers_data[plugin_type][_des_tmp[plugin_des]]["cmd"] = (
matchers_data[plugin_type][_des_tmp[plugin_des]]["cmd"]
+ plugin_cmd
)
except KeyError as e:
logger.warning(f"{type(e)}: {e}")
else:
matchers_data[plugin_type][plugin_name] = {
"des": plugin_des,
"cmd": plugin_cmd,
"text_type": text_type,
}
try:
if text_type == 0:
x = tmp_img.getsize(
f'{plugin_name}: {matchers_data[plugin_type][plugin_name]["des"]} ->'
+ " / ".join(matchers_data[plugin_type][plugin_name]["cmd"])
)[0]
width = width if width > x else x
except KeyError:
pass
if plugin_des not in _des_tmp:
_des_tmp[plugin_des] = plugin_name
except AttributeError as e:
if plugin_name not in _plugin_name_tmp:
logger.warning(f"获取功能 {matcher.module}: {plugin_name} 设置失败...e:{e}")
if plugin_name not in _plugin_name_tmp:
_plugin_name_tmp.append(plugin_name)
help_img_list = []
simple_help_img_list = []
types = list(matchers_data.keys())
types.sort()
ix = 0
for type_ in types:
keys = list(matchers_data[type_].keys())
keys.sort()
help_str = f"{type_ if type_ != 'normal' else '功能'}:\n\n"
simple_help_str = f"{type_ if type_ != 'normal' else '功能'}:\n\n"
for i, k in enumerate(keys):
simple_help_str += f"{i+1}.{k}\n"
if matchers_data[type_][k]["text_type"] == 1:
_x = tmp_img.getsize(
f"{i+1}".rjust(5)
+ f'.{k}: {matchers_data[type_][k]["des"]} {"->" if matchers_data[type_][k]["cmd"] else ""} '
)[0]
_str = (
f"{i+1}".rjust(5)
+ f'.{k}: {matchers_data[type_][k]["des"]} {"->" if matchers_data[type_][k]["cmd"] else ""} '
)
_str += matchers_data[type_][k]["cmd"][0] + "\n"
for c in matchers_data[type_][k]["cmd"][1:]:
_str += "".rjust(int(_x * 0.125) + 1) + f"{c}\n"
help_str += _str
else:
help_str += (
f"{i+1}".rjust(5)
+ f'.{k}: {matchers_data[type_][k]["des"]} {"->" if matchers_data[type_][k]["cmd"] else ""} '
+ " / ".join(matchers_data[type_][k]["cmd"])
+ "\n"
)
height = len(help_str.split("\n")) * (font_height + 5)
simple_height = len(simple_help_str.split("\n")) * (font_height + 5)
A = CreateImg(
width + 150, height, font_size=24, color="white" if not ix % 2 else "black"
)
A.text((10, 10), help_str, (255, 255, 255) if ix % 2 else (0, 0, 0))
simple_width = 0
for x in [tmp_img.getsize(x)[0] for x in simple_help_str.split("\n")]:
simple_width = simple_width if simple_width > x else x
bk = CreateImg(
simple_width + 20, simple_height, font_size=24, color="#6495ED"
)
B = CreateImg(
simple_width + 20,
simple_height,
font_size=24,
color="white" if not ix % 2 else "black",
)
B.text((10, 10), simple_help_str, (255, 255, 255) if ix % 2 else (0, 0, 0))
bk.paste(B, center_type="center")
bk.transparent(2)
ix += 1
help_img_list.append(A)
simple_help_img_list.append(bk)
height = 0
for img in help_img_list:
height += img.h
A = CreateImg(width + 150, height + 50, font_size=24)
A.text((10, 10), '* 注: ‘*’ 代表可有多个相同参数 ‘?’ 代表可省略该参数 *\n\n" "功能名: 功能简介 -> 指令\n\n')
current_height = 50
for img in help_img_list:
A.paste(img, (0, current_height))
current_height += img.h
A.save(help_image)
height = 0
width = 0
for img in simple_help_img_list:
if img.h > height:
height = img.h
width += img.w + 10
B = CreateImg(width + 100, height + 250, font_size=24)
width, _ = get_max_width_or_paste(simple_help_img_list, B)
bk = None
random_bk = os.listdir(random_bk_path)
if random_bk:
bk = random.choice(random_bk)
x = max(width + 50, height + 250)
B = CreateImg(
x,
x,
font_size=24,
color="#FFEFD5",
background=random_bk_path / bk,
)
B.filter("GaussianBlur", 10)
_, B = get_max_width_or_paste(simple_help_img_list, B, True)
w = 10
h = 10
for msg in ['目前支持的功能列表:', '可以通过 ‘帮助[功能名称]’ 来获取对应功能的使用方法', '或者使用 ‘详细帮助’ 来获取所有功能方法']:
text = CreateImg(
0,
0,
plain_text=msg,
font_size=24,
color=(255, 255, 255, 0),
font='yuanshen.ttf'
)
B.paste(text, (w, h), True)
h += 50
if msg == '目前支持的功能列表:':
w += 50
B.save(simple_help_image)
def get_max_width_or_paste(
simple_help_img_list: list, B: CreateImg = None, is_paste: bool = False
) -> "int, CreateImg":
"""
获取最大宽度,或直接贴图
:param simple_help_img_list: 简单帮助图片列表
:param B: 背景图
:param is_paste: 是否直接贴图
"""
current_width = 50
current_height = 180
max_width = simple_help_img_list[0].w
for i in range(len(simple_help_img_list)):
try:
if is_paste and B:
B.paste(simple_help_img_list[i], (current_width, current_height), True)
current_height += simple_help_img_list[i].h + 40
if current_height + simple_help_img_list[i + 1].h > B.h - 10:
current_height = 180
current_width += max_width + 30
max_width = 0
elif simple_help_img_list[i].w > max_width:
max_width = simple_help_img_list[i].w
except IndexError:
pass
if current_width > simple_help_img_list[0].w + 50:
current_width += simple_help_img_list[-1].w
return current_width, B
def get_plugin_help(msg: str, is_super: bool = False) -> Optional[str]:
"""
获取功能的帮助信息
:param msg: 功能cmd
:param is_super: 是否为超级用户
"""
module = plugins2settings_manager.get_plugin_module(msg)
if module:
try:
plugin = nonebot.plugin.get_plugin(module)
if plugin:
if is_super:
result = plugin.module.__getattribute__(
"__plugin_superuser_usage__"
)
else:
result = plugin.module.__getattribute__("__plugin_usage__")
width = 0
for x in result.split("\n"):
_width = len(x) * 24
width = width if width > _width else _width
height = len(result.split("\n")) * 45
A = CreateImg(width, height, font_size=24)
bk = CreateImg(
width, height, background=Path(IMAGE_PATH) / "background" / "1.png"
)
A.paste(bk, alpha=True)
A.text((int(width * 0.048), int(height * 0.21)), result)
return A.pic2bs4()
except AttributeError:
pass
return None
-467
View File
@@ -1,467 +0,0 @@
from nonebot.matcher import Matcher
from nonebot.message import run_preprocessor, run_postprocessor, IgnoredException
from nonebot.adapters.cqhttp.exception import ActionFailed
from models.group_member_info import GroupInfoUser
from utils.manager import (
plugins2cd_manager,
plugins2block_manager,
plugins2settings_manager,
admin_manager
)
from models.friend_user import FriendUser
from typing import Optional
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import (
Bot,
Event,
MessageEvent,
PrivateMessageEvent,
GroupMessageEvent,
PokeNotifyEvent,
Message,
)
from configs.config import (
BAN_RESULT,
MALICIOUS_BAN_TIME,
MALICIOUS_CHECK_TIME,
MALICIOUS_BAN_COUNT,
CHECK_NOTICE_INFO_CD,
)
from models.ban_user import BanUser
from utils.utils import (
is_number,
static_flmt,
BanCheckLimiter,
FreqLimiter,
)
from utils.manager import withdraw_message_manager
from utils.message_builder import at
from services.log import logger
from models.level_user import LevelUser
from utils.manager import group_manager
import asyncio
try:
import ujson as json
except ModuleNotFoundError:
import json
# 检查是否被ban
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: MessageEvent, state: T_State):
try:
if (
await BanUser.is_super_ban(event.user_id)
and str(event.user_id) not in bot.config.superusers
):
raise IgnoredException("用户处于超级黑名单中")
except AttributeError:
pass
if not isinstance(event, MessageEvent):
return
if matcher.type == "message" and matcher.priority not in [1, 9]:
if (
await BanUser.is_ban(event.user_id)
and str(event.user_id) not in bot.config.superusers
):
time = await BanUser.check_ban_time(event.user_id)
if is_number(time):
time = abs(int(time))
if time < 60:
time = str(time) + " 秒"
else:
time = str(int(time / 60)) + " 分钟"
else:
time = str(time) + " 分钟"
if isinstance(event, GroupMessageEvent):
if not static_flmt.check(event.user_id):
raise IgnoredException("用户处于黑名单中")
static_flmt.start_cd(event.user_id)
if matcher.priority != 9:
try:
await bot.send_group_msg(
group_id=event.group_id,
message=at(event.user_id)
+ BAN_RESULT
+ f" 在..在 {time} 后才会理你喔",
)
except ActionFailed:
pass
else:
if not static_flmt.check(event.user_id):
raise IgnoredException("用户处于黑名单中")
static_flmt.start_cd(event.user_id)
if matcher.priority != 9:
try:
await bot.send_private_msg(
user_id=event.user_id,
message=at(event.user_id)
+ BAN_RESULT
+ f" 在..在 {time}后才会理你喔",
)
except ActionFailed:
pass
raise IgnoredException("用户处于黑名单中")
_blmt = BanCheckLimiter(MALICIOUS_CHECK_TIME, MALICIOUS_BAN_COUNT)
# 恶意触发命令检测
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: GroupMessageEvent, state: T_State):
if not isinstance(event, MessageEvent):
return
if matcher.type == "message" and matcher.priority not in [1, 9]:
if 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):
logger.info(f"USER {event.user_id} 触发了恶意触发检测")
if isinstance(event, GroupMessageEvent):
try:
await bot.send_group_msg(
group_id=event.group_id,
message=at(event.user_id) + "检测到恶意触发命令,您将被封禁 30 分钟",
)
except ActionFailed:
pass
else:
try:
await bot.send_private_msg(
user_id=event.user_id,
message=at(event.user_id) + "检测到恶意触发命令,您将被封禁 30 分钟",
)
except ActionFailed:
pass
raise IgnoredException("检测到恶意触发命令")
_blmt.add(f'{event.user_id}{state["_prefix"]["raw_command"]}')
_flmt = FreqLimiter(CHECK_NOTICE_INFO_CD)
_flmt_g = FreqLimiter(CHECK_NOTICE_INFO_CD)
_flmt_s = FreqLimiter(CHECK_NOTICE_INFO_CD)
_flmt_c = FreqLimiter(CHECK_NOTICE_INFO_CD)
_exists_msg = {}
ignore_rst_module = ["ai", "poke"]
# 权限检测
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: MessageEvent, state: T_State):
global _exists_msg
module = matcher.module
plugins2info_dict = plugins2settings_manager.get_data()
if (
(not isinstance(event, MessageEvent) and module != "poke")
or await BanUser.is_ban(event.user_id)
and str(event.user_id) not in bot.config.superusers
) or (
str(event.user_id) in bot.config.superusers
and plugins2info_dict.get(module)
and not plugins2info_dict[module]["limit_superuser"]
):
return
# 黑名单检测
if isinstance(event, GroupMessageEvent):
if group_manager.get_group_level(event.group_id) < 0:
raise IgnoredException("群黑名单")
if module in admin_manager.keys() and matcher.priority not in [1, 9]:
if isinstance(event, GroupMessageEvent):
# 个人权限
if not await LevelUser.check_level(
event.user_id, event.group_id, admin_manager.get_plugin_level(module)
):
try:
if _flmt.check(event.user_id):
_flmt.start_cd(event.user_id)
await bot.send_group_msg(
group_id=event.group_id,
message=f"{at(event.user_id)}你的权限不足喔,该功能需要的权限等级:"
f"{admin_manager.get_plugin_level(module)}",
)
except ActionFailed:
pass
raise IgnoredException("权限不足")
else:
if not await LevelUser.check_level(
event.user_id, 0, admin_manager.get_plugin_level(module)
):
try:
await bot.send_private_msg(
user_id=event.user_id,
message=f"你的权限不足喔,该功能需要的权限等级:{admin_manager.get_plugin_level(module)}",
)
except ActionFailed:
pass
raise IgnoredException("权限不足")
if module in plugins2info_dict.keys() and matcher.priority not in [1, 9]:
# 戳一戳单独判断
if isinstance(event, GroupMessageEvent) or (
isinstance(event, PokeNotifyEvent) and event.group_id
):
if _exists_msg.get(event.group_id) is None:
_exists_msg[event.group_id] = False
# 群权限
if plugins2info_dict[module]["level"] > group_manager.get_group_level(
event.group_id
):
try:
if _flmt_g.check(event.user_id) and module not in ignore_rst_module:
_flmt_g.start_cd(event.user_id)
await bot.send_group_msg(
group_id=event.group_id, message="群权限不足..."
)
except ActionFailed:
pass
_exists_msg[event.group_id] = True
raise IgnoredException("群权限不足")
# 插件状态
if not group_manager.get_plugin_status(module, event.group_id):
try:
if module not in ignore_rst_module and _flmt_s.check(
event.group_id
):
_flmt_s.start_cd(event.group_id)
await bot.send_group_msg(
group_id=event.group_id, message="该群未开启此功能.."
)
except ActionFailed:
pass
_exists_msg[event.group_id] = True
print(123123)
raise IgnoredException("未开启此功能...")
# 管理员禁用
if not group_manager.get_plugin_status(f"{module}:super", event.group_id):
try:
if (
_flmt_s.check(event.group_id)
and module not in ignore_rst_module
):
_flmt_s.start_cd(event.group_id)
await bot.send_group_msg(
group_id=event.group_id, message="管理员禁用了此群该功能..."
)
except ActionFailed:
pass
_exists_msg[event.group_id] = True
raise IgnoredException("管理员禁用了此群该功能...")
# 群聊禁用
if not group_manager.get_plugin_status(module, block_type="group"):
try:
if (
_flmt_c.check(event.group_id)
and module not in ignore_rst_module
):
_flmt_c.start_cd(event.group_id)
await bot.send_group_msg(
group_id=event.group_id, message="该功能在群聊中已被禁用..."
)
except ActionFailed:
pass
_exists_msg[event.group_id] = True
raise IgnoredException("该插件在群聊中已被禁用...")
else:
# 私聊禁用
if not group_manager.get_plugin_status(module, block_type="private"):
try:
if _flmt_c.check(event.user_id):
_flmt_c.start_cd(event.user_id)
await bot.send_private_msg(
user_id=event.user_id, message="该功能在私聊中已被禁用..."
)
except ActionFailed:
pass
raise IgnoredException("该插件在私聊中已被禁用...")
# 维护
if not group_manager.get_plugin_status(module, block_type="all"):
if isinstance(
event, GroupMessageEvent
) and group_manager.check_group_is_white(event.group_id):
return
try:
if isinstance(event, GroupMessageEvent):
if (
_flmt_c.check(event.group_id)
and module not in ignore_rst_module
):
_flmt_c.start_cd(event.group_id)
await bot.send_group_msg(
group_id=event.group_id, message="此功能正在维护..."
)
else:
await bot.send_private_msg(
user_id=event.user_id, message="此功能正在维护..."
)
except ActionFailed:
pass
if isinstance(event, GroupMessageEvent):
_exists_msg[event.group_id] = True
raise IgnoredException("此功能正在维护...")
# 命令cd 和 命令阻塞
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: MessageEvent, state: T_State):
global _exists_msg
if not isinstance(event, MessageEvent) and matcher.module != "poke":
return
module = matcher.module
if isinstance(event, GroupMessageEvent) and _exists_msg.get(event.group_id) is None:
_exists_msg[event.group_id] = False
if plugins2cd_manager.check_plugin_cd_status(module):
plugin_cd_data = plugins2cd_manager.get_plugin_cd_data(module)
check_type = plugin_cd_data["check_type"]
limit_type = plugin_cd_data["limit_type"]
rst = plugin_cd_data["rst"]
if (
(isinstance(event, PrivateMessageEvent) and check_type == "private")
or (isinstance(event, GroupMessageEvent) and check_type == "group")
or plugins2cd_manager.get_plugin_data(module).get("check_type") == "all"
):
cd_type_ = event.user_id
if limit_type == "group" and isinstance(event, GroupMessageEvent):
cd_type_ = event.group_id
if not plugins2cd_manager.check(module, cd_type_):
if rst:
rst = await init_rst(rst, event)
await send_msg(rst, bot, event)
raise IgnoredException(f"{module} 正在cd中...")
else:
plugins2cd_manager.start_cd(module, cd_type_)
if plugins2block_manager.check_plugin_block_status(module):
plugin_block_data = plugins2block_manager.get_plugin_block_data(module)
check_type = plugin_block_data["check_type"]
limit_type = plugin_block_data["limit_type"]
rst = plugin_block_data["rst"]
if (
(isinstance(event, PrivateMessageEvent) and check_type == "private")
or (isinstance(event, GroupMessageEvent) and check_type == "group")
or check_type == "all"
):
block_type_ = event.user_id
if limit_type == "group" and isinstance(event, GroupMessageEvent):
block_type_ = event.group_id
if plugins2block_manager.check(block_type_, module):
if rst:
rst = await init_rst(rst, event)
await send_msg(rst, bot, event)
raise IgnoredException(f"{event.user_id}正在调用{module}....")
else:
plugins2block_manager.set_true(block_type_, module)
async def send_msg(rst: str, bot: Bot, event: MessageEvent):
"""
发送信息
:param rst: pass
:param bot: pass
:param event: pass
"""
global _exists_msg
rst = await init_rst(rst, event)
try:
if isinstance(event, GroupMessageEvent):
_exists_msg[event.group_id] = True
await bot.send_group_msg(group_id=event.group_id, message=Message(rst))
else:
_exists_msg[event.user_id] = True
await bot.send_private_msg(user_id=event.user_id, message=Message(rst))
except ActionFailed:
pass
@run_postprocessor
async def _(
matcher: Matcher,
exception: Optional[Exception],
bot: Bot,
event: Event,
state: T_State,
):
if not isinstance(event, MessageEvent) and matcher.module != "poke":
return
module = matcher.module
if plugins2block_manager.check_plugin_block_status(module):
plugin_block_data = plugins2block_manager.get_plugin_block_data(module)
check_type = plugin_block_data["check_type"]
limit_type = plugin_block_data["limit_type"]
if not (
(isinstance(event, GroupMessageEvent) and check_type == "private")
or (isinstance(event, PrivateMessageEvent) and check_type == "group")
):
block_type_ = event.user_id
if limit_type == "group" and isinstance(event, GroupMessageEvent):
block_type_ = event.group_id
plugins2block_manager.set_false(block_type_, module)
async def init_rst(rst: str, event: MessageEvent):
if "[uname]" in rst:
uname = event.sender.card if event.sender.card else event.sender.nickname
rst = rst.replace("[uname]", uname)
if "[nickname]" in rst:
if isinstance(event, GroupMessageEvent):
nickname = await GroupInfoUser.get_group_member_nickname(
event.user_id, event.group_id
)
else:
nickname = await FriendUser.get_friend_nickname(event.user_id)
rst = rst.replace("[nickname]", nickname)
if "[at]" in rst and isinstance(event, GroupMessageEvent):
rst = rst.replace("[at]", str(at(event.user_id)))
return rst
# 消息撤回
@run_postprocessor
async def _(
matcher: Matcher,
exception: Optional[Exception],
bot: Bot,
event: Event,
state: T_State,
):
tasks = []
for id_, time in withdraw_message_manager.data:
tasks.append(asyncio.ensure_future(_withdraw_message(bot, id_, time)))
withdraw_message_manager.remove((id_, time))
await asyncio.gather(*tasks)
async def _withdraw_message(bot: Bot, id_: int, time: int):
await asyncio.sleep(time)
await bot.delete_msg(message_id=id_, self_id=int(bot.self_id))
# 为什么AI会自己和自己聊天
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: PrivateMessageEvent, state: T_State):
if not isinstance(event, MessageEvent):
return
if event.user_id == int(bot.self_id):
raise IgnoredException("为什么AI会自己和自己聊天")
# 有命令就别说话了
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: MessageEvent, state: T_State):
global _exists_msg
if not isinstance(event, MessageEvent):
return
if matcher.type == "message":
if matcher.module == "ai":
if (
isinstance(event, GroupMessageEvent)
and _exists_msg.get(event.group_id) is True
):
_exists_msg[event.group_id] = False
raise IgnoredException("有命令就别说话了")
elif (
isinstance(event, PrivateMessageEvent)
and _exists_msg.get(event.user_id) is True
):
_exists_msg[event.user_id] = False
raise IgnoredException("有命令就别说话了")
+45
View File
@@ -1,3 +1,48 @@
from configs.config import Config
import nonebot
Config.add_plugin_config(
"image_management",
"IMAGE_DIR_LIST",
["美图", "萝莉", "壁纸"],
name="图库操作",
help_="公开图库列表,可自定义添加 [如果含有send_setu插件,请不要添加色图库]",
default_value=[],
)
Config.add_plugin_config(
"image_management",
"WITHDRAW_IMAGE_MESSAGE",
(0, 1),
name="图库操作",
help_="自动撤回,参1:延迟撤回发送图库图片的时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
default_value=(0, 1),
)
Config.add_plugin_config(
"image_management:delete_img",
"DELETE_IMAGE_LEVEL [LEVEL]",
7,
help_="删除图库图片需要的管理员等级",
default_value=7,
)
Config.add_plugin_config(
"image_management:move_img",
"MOVE_IMAGE_LEVEL [LEVEL]",
7,
help_="移动图库图片需要的管理员等级",
default_value=7,
)
Config.add_plugin_config(
"image_management:upload_img",
"UPLOAD_IMAGE_LEVEL [LEVEL]",
6,
help_="上传图库图片需要的管理员等级",
default_value=6,
)
nonebot.load_plugins("plugins/image_management")
@@ -5,9 +5,8 @@ from nonebot import on_command
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from configs.config import DELETE_IMG_LEVEL
from configs.config import IMAGE_DIR_LIST
from utils.utils import is_number, cn2py, get_message_text
from configs.config import Config
from pathlib import Path
import os
@@ -25,7 +24,7 @@ __plugin_cmd__ = ["删除图片 [图库] [id]", "查看公开图库"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"admin_level": DELETE_IMG_LEVEL
"admin_level": Config.get_config("image_management", "DELETE_IMAGE_LEVEL")
}
@@ -37,7 +36,7 @@ async def parse(bot: Bot, event: MessageEvent, state: T_State):
if get_message_text(event.json()) in ["取消", "算了"]:
await delete_img.finish("已取消操作..", at_sender=True)
if state["_current_key"] in ["path"]:
if get_message_text(event.json()) not in IMAGE_DIR_LIST:
if get_message_text(event.json()) not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
await delete_img.reject("此目录不正确,请重新输入目录!")
state[state["_current_key"]] = get_message_text(event.json())
if state["_current_key"] == "id":
@@ -53,7 +52,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
args = raw_arg.split(" ")
if args[0] in ["帮助"]:
await delete_img.finish(__plugin_usage__)
if len(args) >= 2 and args[0] in IMAGE_DIR_LIST and is_number(args[1]):
if len(args) >= 2 and args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST") and is_number(args[1]):
state["path"] = args[0]
state["id"] = args[1]
@@ -4,7 +4,7 @@ from nonebot import on_command
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from configs.config import IMAGE_DIR_LIST, MOVE_IMG_LEVEL
from configs.config import Config
from utils.utils import is_number, cn2py
from configs.path_config import IMAGE_PATH
from pathlib import Path
@@ -24,7 +24,7 @@ __plugin_cmd__ = ["移动图片 [源图库] [目标图库] [id]", "查看公开
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"admin_level": MOVE_IMG_LEVEL
"admin_level": Config.get_config("image_management", "MOVE_IMAGE_LEVEL")
}
@@ -36,7 +36,9 @@ async def parse(bot: Bot, event: MessageEvent, state: T_State):
if str(event.get_message()) in ["取消", "算了"]:
await move_img.finish("已取消操作..", at_sender=True)
if state["_current_key"] in ["source_path", "destination_path"]:
if str(event.get_message()) not in IMAGE_DIR_LIST:
if str(event.get_message()) not in Config.get_config(
"image_management", "IMAGE_DIR_LIST"
):
await move_img.reject("此目录不正确,请重新输入目录!")
state[state["_current_key"]] = str(event.get_message())
if state["_current_key"] == "id":
@@ -54,8 +56,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
await move_img.finish(__plugin_usage__)
if (
len(args) >= 3
and args[0] in IMAGE_DIR_LIST
and args[1] in IMAGE_DIR_LIST
and args[0] in Config.get_config("image_management", "IMAGE_DIR_LIST")
and args[1] in Config.get_config("image_management", "IMAGE_DIR_LIST")
and is_number(args[2])
):
state["source_path"] = args[0]
@@ -78,9 +80,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
if int(img_id) > max_id or int(img_id) < 0:
await move_img.finish(f"Id超过上下限,上限:{max_id}", at_sender=True)
try:
os.rename(
source_path / f"{img_id}.jpg", destination_path / f"{des_max_id}.jpg"
)
os.rename(source_path / f"{img_id}.jpg", destination_path / f"{des_max_id}.jpg")
logger.info(
f"移动 {source_path}/{img_id}.jpg ---> {destination_path}/{des_max_id} 移动成功"
)
@@ -1,135 +1,124 @@
from nonebot import on_command, on_keyword, on_regex
from configs.path_config import IMAGE_PATH
from utils.message_builder import image
from utils.utils import get_message_text, is_number
import os
import random
from services.log import logger
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from utils.utils import FreqLimiter, cn2py
from configs.config import IMAGE_DIR_LIST
from utils.manager import group_manager
try:
import ujson as json
except ModuleNotFoundError:
import json
if "色图" in IMAGE_DIR_LIST:
IMAGE_DIR_LIST.remove("色图")
__zx_plugin_name__ = "发送本地图库图片"
__plugin_usage__ = f"""
usage:
发送指定图库下的随机或指定id图片
指令:
{IMAGE_DIR_LIST} ?[id]
示例:美图
示例: 萝莉 2
""".strip()
__plugin_des__ = "让看看我的私藏,指[图片]"
__plugin_cmd__ = IMAGE_DIR_LIST
__plugin_type__ = ("来点好康的",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["发送图片"] + IMAGE_DIR_LIST,
}
__plugin_task__ = {"pa": "丢人爬"}
_flmt = FreqLimiter(1)
cmd = set(IMAGE_DIR_LIST)
# print(cmd)
send_img = on_command("img", aliases=cmd, priority=5, block=True)
pa = on_keyword({"丢人爬", "爪巴"}, priority=5, block=True)
pa_reg = on_regex("^爬$", priority=5, block=True)
search_url = "https://api.fantasyzone.cc/tu/search.php"
@send_img.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
img_id = get_message_text(event.json())
path = cn2py(state["_prefix"]["raw_command"]) + "/"
if state["_prefix"]["raw_command"] in IMAGE_DIR_LIST:
if not os.path.exists(f"{IMAGE_PATH}/{path}/"):
os.mkdir(f"{IMAGE_PATH}/{path}/")
length = len(os.listdir(IMAGE_PATH + path)) - 1
if length < 1:
await send_img.finish("该图库中没有图片噢")
logger.warning(f"图库 {path} 为空,调用取消!")
return
index = img_id if img_id else str(random.randint(0, length))
if not is_number(index):
await send_img.finish("id错误!")
if int(index) > length or int(index) < 0:
await send_img.finish(f"超过当前上下限!({length - 1})")
result = image(f"{index}.jpg", path)
if result:
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送{path}:"
+ result
)
await send_img.finish(f"id:{index}" + result)
else:
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送 {path} 失败"
)
await send_img.finish(f"不想给你看Ov|")
@pa.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if (
isinstance(event, GroupMessageEvent)
and not await group_manager.check_group_task_status(event.group_id, "pa")
or get_message_text(event.json()).startswith("开启")
or get_message_text(event.json()).startswith("关闭")
):
return
msg = get_message_text(event.json())
if not msg or str(event.get_message()[:2]) in ["开启", "关闭"]:
return
if _flmt.check(event.user_id):
_flmt.start_cd(event.user_id)
await pa.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
@pa_reg.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if (
(
isinstance(event, GroupMessageEvent)
and not await group_manager.check_group_task_status(event.group_id, "pa")
or get_message_text(event.json()).startswith("开启")
or get_message_text(event.json()).startswith("关闭")
)
):
return
if _flmt.check(event.user_id):
_flmt.start_cd(event.user_id)
await pa.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
num_key = {
"一": 1,
"二": 2,
"两": 2,
"双": 2,
"三": 3,
"四": 4,
"五": 5,
"六": 6,
"七": 7,
"八": 8,
"九": 9,
}
from nonebot import on_command, on_keyword, on_regex
from configs.path_config import IMAGE_PATH
from utils.message_builder import image
from utils.utils import get_message_text, is_number
from services.log import logger
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from utils.utils import FreqLimiter, cn2py
from configs.config import Config
from utils.manager import group_manager, withdraw_message_manager
import random
import os
try:
import ujson as json
except ModuleNotFoundError:
import json
__zx_plugin_name__ = "发送本地图库图片"
__plugin_usage__ = f"""
usage:
发送指定图库下的随机或指定id图片
指令:
{Config.get_config("image_management", "IMAGE_DIR_LIST")} ?[id]
示例:美图
示例: 萝莉 2
""".strip()
__plugin_des__ = "让看看我的私藏,指[图片]"
__plugin_cmd__ = Config.get_config("image_management", "IMAGE_DIR_LIST")
__plugin_type__ = ("来点好康的",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["发送图片"] + Config.get_config("image_management", "IMAGE_DIR_LIST"),
}
__plugin_task__ = {"pa": "丢人爬"}
__plugin_resources__ = {
"pa": IMAGE_PATH
}
_flmt = FreqLimiter(1)
cmd = set(Config.get_config("image_management", "IMAGE_DIR_LIST"))
# print(cmd)
send_img = on_command("img", aliases=cmd, priority=5, block=True)
pa = on_keyword({"丢人爬", "爪巴"}, priority=5, block=True)
pa_reg = on_regex("^爬$", priority=5, block=True)
search_url = "https://api.fantasyzone.cc/tu/search.php"
@send_img.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
img_id = get_message_text(event.json())
path = cn2py(state["_prefix"]["raw_command"]) + "/"
if state["_prefix"]["raw_command"] in Config.get_config(
"image_management", "IMAGE_DIR_LIST"
):
if not os.path.exists(f"{IMAGE_PATH}/{path}/"):
os.mkdir(f"{IMAGE_PATH}/{path}/")
length = len(os.listdir(IMAGE_PATH + path))
if length == 0:
logger.warning(f"图库 {path} 为空,调用取消!")
await send_img.finish("该图库中没有图片噢")
index = img_id if img_id else str(random.randint(0, length))
if not is_number(index):
return
if int(index) > length - 1 or int(index) < 0:
await send_img.finish(f"超过当前上下限!({length - 1})")
result = image(f"{index}.jpg", path)
if result:
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送{path}:"
+ result
)
msg_id = await send_img.send(f"id:{index}" + result)
withdraw_message_manager.withdraw_message(
event,
msg_id,
Config.get_config("image_management", "WITHDRAW_IMAGE_MESSAGE"),
)
else:
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送 {path} 失败"
)
await send_img.finish(f"不想给你看Ov|")
@pa.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if (
isinstance(event, GroupMessageEvent)
and not await group_manager.check_group_task_status(event.group_id, "pa")
or get_message_text(event.json()).startswith("开启")
or get_message_text(event.json()).startswith("关闭")
):
return
msg = get_message_text(event.json())
if not msg or str(event.get_message()[:2]) in ["开启", "关闭"]:
return
if _flmt.check(event.user_id):
_flmt.start_cd(event.user_id)
await pa.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
@pa_reg.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if (
isinstance(event, GroupMessageEvent)
and not await group_manager.check_group_task_status(event.group_id, "pa")
or get_message_text(event.json()).startswith("开启")
or get_message_text(event.json()).startswith("关闭")
):
return
if _flmt.check(event.user_id):
_flmt.start_cd(event.user_id)
await pa.finish(image(random.choice(os.listdir(IMAGE_PATH + "pa")), "pa"))
@@ -3,7 +3,7 @@ from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from configs.config import IMAGE_DIR_LIST, UPLOAD_IMG_LEVEL
from configs.config import Config
from utils.utils import get_message_imgs, get_message_text
from .data_source import upload_image_to_local
@@ -23,7 +23,7 @@ __plugin_des__ = "指定图库图片上传"
__plugin_cmd__ = ["上传图片 [图库] [图片]", "连续上传图片 [图库]", "查看公开图库"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {"admin_level": UPLOAD_IMG_LEVEL}
__plugin_settings__ = {"admin_level": Config.get_config("image_management", "DELETE_IMAGE_LEVEL")}
upload_img = on_command("上传图片", rule=to_me(), priority=5, block=True)
@@ -35,7 +35,7 @@ show_gallery = on_command("查看公开图库", priority=1, block=True)
@show_gallery.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
x = '公开图库列表:\n'
for i, e in enumerate(IMAGE_DIR_LIST):
for i, e in enumerate(Config.get_config("image_management", "IMAGE_DIR_LIST")):
x += f'\t{i+1}.{e}\n'
await show_gallery.send(x[:-1])
@@ -46,7 +46,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
if msg in ["取消", "算了"]:
await upload_img.finish("已取消操作..", at_sender=True)
if state["_current_key"] in ["path"]:
if msg not in IMAGE_DIR_LIST:
if msg not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
await upload_img.reject("此目录不正确,请重新输入目录!")
state["path"] = msg
if state["_current_key"] in ["imgs"]:
@@ -60,7 +60,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
raw_arg = get_message_text(event.json())
img_list = get_message_imgs(event.json())
if raw_arg:
if raw_arg in IMAGE_DIR_LIST:
if raw_arg in Config.get_config("image_management", "IMAGE_DIR_LIST"):
state["path"] = raw_arg
if img_list:
state["imgs"] = img_list
@@ -88,7 +88,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
if str(event.get_message()) in ["取消", "算了"]:
await continuous_upload_img.finish("已取消操作..", at_sender=True)
if state["_current_key"] in ["path"]:
if str(event.get_message()) not in IMAGE_DIR_LIST:
if str(event.get_message()) not in Config.get_config("image_management", "IMAGE_DIR_LIST"):
await continuous_upload_img.reject("此目录不正确,请重新输入目录!")
state[state["_current_key"]] = str(event.get_message())
else:
@@ -104,7 +104,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
@continuous_upload_img.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
path = get_message_imgs(event.json())
if path in IMAGE_DIR_LIST:
if path in Config.get_config("image_management", "IMAGE_DIR_LIST"):
state["path"] = path
await continuous_upload_img.send("图来!!")
state["tmp"] = []
-36
View File
@@ -1,36 +0,0 @@
from .data_source import (
init_plugins_settings,
init_plugins_cd_limit,
init_plugins_block_limit,
init_group_manager,
)
from nonebot.adapters.cqhttp import Bot
from configs.path_config import DATA_PATH
from services.log import logger
from nonebot import Driver
import nonebot
__zx_plugin_name__ = "初始化插件数据 [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
driver: Driver = nonebot.get_driver()
@driver.on_startup
def _():
"""
初始化数据
"""
init_plugins_settings(DATA_PATH)
init_plugins_cd_limit(DATA_PATH)
init_plugins_block_limit(DATA_PATH)
logger.info("初始化数据完成...")
@driver.on_bot_connect
async def _(bot: Bot):
await init_group_manager()
-289
View File
@@ -1,289 +0,0 @@
from pathlib import Path
from ruamel.yaml import YAML, round_trip_load, round_trip_dump
from utils.manager import (
plugins2settings_manager,
plugins2cd_manager,
plugins2block_manager,
group_manager,
admin_manager
)
from services.db_context import db
from asyncpg.exceptions import DuplicateColumnError
from services.log import logger
from utils.utils import get_matchers
import nonebot
try:
import ujson as json
except ModuleNotFoundError:
import json
try:
from models.group_remind import GroupRemind
except ModuleNotFoundError:
pass
yaml = YAML(typ="safe")
def init_plugins_settings(data_path: str):
"""
初始化插件设置,从插件中获取 __zx_plugin_name__,__plugin_cmd__,__plugin_settings__
"""
plugins2config_file = Path(data_path) / "configs" / "plugins2settings.yaml"
plugins2config_file.parent.mkdir(exist_ok=True, parents=True)
_matchers = get_matchers()
_data = {}
if plugins2config_file.exists():
with open(plugins2config_file, "r", encoding="utf8") as f:
_data = yaml.load(f)
_data = _data["PluginSettings"] if _data else {}
_tmp_module = {}
_tmp = []
for matcher in _matchers:
if matcher.module in _data.keys():
plugins2settings_manager.add_plugin_settings(
matcher.module,
plugin_type=_data[matcher.module]["plugin_type"],
data_dict=_data[matcher.module],
)
if _data[matcher.module]['cmd']:
_tmp_module[matcher.module] = _data[matcher.module]['cmd'][0]
else:
_plugin = nonebot.plugin.get_plugin(matcher.module)
_module = _plugin.module
try:
plugin_name = _module.__getattribute__("__zx_plugin_name__")
if "[admin]" in plugin_name.lower():
try:
level = (_module.__getattribute__("__plugin_settings__"))['admin_level']
except (AttributeError, KeyError):
level = 5
admin_manager.add_admin_command(matcher.module, level)
if (
"[hidden]" in plugin_name.lower()
or "[admin]" in plugin_name.lower()
or "[superuser]" in plugin_name.lower()
or matcher.module in plugins2settings_manager.keys()
):
continue
except AttributeError:
if matcher.module not in _tmp:
logger.warning(
f"获取插件 {matcher.module} __zx_plugin_name__ 失败...,插件控制未加载."
)
else:
try:
_tmp_module[matcher.module] = plugin_name
plugin_settings = _module.__getattribute__("__plugin_settings__")
if plugin_settings['cmd'] and plugin_name not in plugin_settings['cmd']:
plugin_settings['cmd'].append(plugin_name)
if plugins2settings_manager.get(
matcher.module
) and plugins2settings_manager[matcher.module].get("plugin_type"):
plugin_type = tuple(
plugins2settings_manager.get_plugin_data(matcher.module)[
"plugin_type"
]
)
else:
try:
plugin_type = _module.__getattribute__("__plugin_type__")
except AttributeError:
plugin_type = ("normal",)
if plugin_settings and matcher.module:
plugins2settings_manager.add_plugin_settings(
matcher.module,
plugin_type=plugin_type,
data_dict=plugin_settings,
)
except AttributeError:
pass
_tmp.append(matcher.module)
_tmp_data = {"PluginSettings": plugins2settings_manager.get_data()}
with open(plugins2config_file, "w", encoding="utf8") as wf:
yaml.dump(_tmp_data, wf)
_data = round_trip_load(open(plugins2config_file, encoding="utf8"))
_data["PluginSettings"].yaml_set_start_comment(
"""# 模块与对应命令和对应群权限
# 用于生成帮助图片 和 开关功能
# key:模块名称
# level:需要的群等级
# default_status:加入群时功能的默认开关状态
# limit_superuser: 功能状态是否限制超级用户
# cmd: 关闭[cmd] 都会触发命令 关闭对应功能,cmd列表第一个词为统计的功能名称
# plugin_type: 帮助类别 示例:('原神相关',) 或 ('原神相关', 1),1代表帮助命令列向排列,否则为横向排列""",
indent=2,
)
for plugin in _data["PluginSettings"].keys():
_data["PluginSettings"][plugin].yaml_set_start_comment(
f"{plugin}:{_tmp_module[plugin]}", indent=2
)
with open(plugins2config_file, "w", encoding="utf8") as wf:
round_trip_dump(_data, wf)
logger.info(f"已成功加载 {len(plugins2settings_manager.get_data())} 个非限制插件.")
def init_plugins_cd_limit(data_path):
"""
加载 cd 限制
"""
plugins2cd_file = Path(data_path) / "configs" / "plugins2cd.yaml"
plugins2cd_file.parent.mkdir(exist_ok=True, parents=True)
_data = {}
_matchers = get_matchers()
for matcher in _matchers:
if not plugins2cd_manager.get_plugin_cd_data(matcher.module):
_plugin = nonebot.plugin.get_plugin(matcher.module)
_module = _plugin.module
try:
plugin_cd_limit = _module.__getattribute__("__plugin_cd_limit__")
plugins2cd_manager.add_cd_limit(
matcher.module, data_dict=plugin_cd_limit
)
except AttributeError:
pass
if plugins2cd_file.exists():
with open(plugins2cd_file, "r", encoding="utf8") as f:
_data = yaml.load(f)
_data = _data if _data else {}
if _data.get("PluginCdLimit"):
for plugin in _data["PluginCdLimit"].keys():
plugins2cd_manager.add_cd_limit(
plugin, data_dict=_data["PluginCdLimit"][plugin]
)
_tmp_data = {"PluginCdLimit": plugins2cd_manager.get_data()}
with open(plugins2cd_file, "w", encoding="utf8") as wf:
yaml.dump(_tmp_data, wf)
_data = round_trip_load(open(plugins2cd_file, encoding="utf8"))
_data["PluginCdLimit"].yaml_set_start_comment(
"""# 需要cd的功能
# 自定义的功能需要cd也可以在此配置
# key:模块名称
# cd:cd 时长(秒)
# status:此限制的开关状态
# check_type:'private'/'group'/'all',限制私聊/群聊/全部
# limit_type:监听对象,以user_id或group_id作为键来限制,'user':用户id,'group':群id
# 示例:'user':用户N秒内触发1次,'group':群N秒内触发1次
# rst:回复的话,可以添加[at],[uname],[nickname]来对应艾特,用户群名称,昵称系统昵称
# rst 为 "" 或 None 时则不回复
# rst示例:"[uname]你冲的太快了,[nickname]先生,请稍后再冲[at]"
# rst回复:"老色批你冲的太快了,欧尼酱先生,请稍后再冲@老色批"
# 用户昵称↑ 昵称系统的昵称↑ 艾特用户↑""",
indent=2,
)
with open(plugins2cd_file, "w", encoding="utf8") as wf:
round_trip_dump(_data, wf)
plugins2cd_manager.reload_cd_limit()
def init_plugins_block_limit(data_path):
"""
加载阻塞限制
"""
plugins2block_file = Path(data_path) / "configs" / "plugins2block.yaml"
plugins2block_file.parent.mkdir(exist_ok=True, parents=True)
_data = {}
_matchers = get_matchers()
for matcher in _matchers:
if not plugins2block_manager.get_plugin_block_data(matcher.module):
_plugin = nonebot.plugin.get_plugin(matcher.module)
_module = _plugin.module
try:
plugin_block_limit = _module.__getattribute__("__plugin_block_limit__")
plugins2block_manager.add_block_limit(
matcher.module, data_dict=plugin_block_limit
)
except AttributeError:
pass
if plugins2block_file.exists():
with open(plugins2block_file, "r", encoding="utf8") as f:
_data = yaml.load(f)
_data = _data if _data else {}
if _data.get("PluginBlockLimit"):
for plugin in _data["PluginBlockLimit"].keys():
plugins2block_manager.add_block_limit(
plugin, data_dict=_data["PluginBlockLimit"][plugin]
)
_tmp_data = {"PluginBlockLimit": plugins2block_manager.get_data()}
with open(plugins2block_file, "w", encoding="utf8") as wf:
yaml.dump(_tmp_data, wf)
_data = round_trip_load(open(plugins2block_file, encoding="utf8"))
_data["PluginBlockLimit"].yaml_set_start_comment(
"""# 用户调用阻塞
# 即 当用户调用此功能还未结束时
# 用发送消息阻止用户重复调用此命令直到该命令结束
# key:模块名称
# cd:cd 时长(秒)
# status:此限制的开关状态
# check_type:'private'/'group'/'all',限制私聊/群聊/全部
# limit_type:监听对象,以user_id或group_id作为键来限制,'user':用户id,'group':群id
# 示例:'user':用户N秒内触发1次,'group':群N秒内触发1次
# rst:回复的话,可以添加[at],[uname],[nickname]来对应艾特,用户群名称,昵称系统昵称
# rst 为 "" 或 None 时则不回复
# rst示例:"[uname]你冲的太快了,[nickname]先生,请稍后再冲[at]"
# rst回复:"老色批你冲的太快了,欧尼酱先生,请稍后再冲@老色批"
# 用户昵称↑ 昵称系统的昵称↑ 艾特用户↑""",
indent=2,
)
with open(plugins2block_file, "w", encoding="utf8") as wf:
round_trip_dump(_data, wf)
plugins2block_manager.reload_block_limit()
async def init_group_manager():
"""
旧数据格式替换为新格式
初始化数据
"""
old_group_level_file = Path() / "data" / "manager" / "group_level.json"
old_plugin_list_file = Path() / "data" / "manager" / "plugin_list.json"
if old_group_level_file.exists():
data = json.load(open(old_group_level_file, "r", encoding="utf8"))
for key in data.keys():
group = key
level = data[key]
group_manager.set_group_level(group, level)
old_group_level_file.unlink()
group_manager.save()
if old_plugin_list_file.exists():
data = json.load(open(old_plugin_list_file, "r", encoding="utf8"))
for plugin in data.keys():
for group in data[plugin].keys():
if group == "default" and not data[plugin]["default"]:
group_manager.block_plugin(plugin)
elif not data[plugin][group]:
group_manager.block_plugin(plugin, group)
old_plugin_list_file.unlink()
old_data_table = Path() / "models" / "group_remind.py"
try:
if old_data_table.exists():
b = {
"hy": "group_welcome",
"kxcz": "open_case_reset_remind",
"zwa": "zwa",
"blpar": "bilibili_parse",
"epic": "epic_free_game",
"pa": "pa",
"almanac": "genshin_alc",
}
for group in group_manager.get_data()["group_manager"]:
for remind in b:
try:
status = await GroupRemind.get_status(int(group), remind)
if status is not None:
if status:
await group_manager.open_group_task(group, b[remind])
logger.info(f"读取旧数据-->{group} 开启 {b[remind]}")
else:
await group_manager.close_group_task(group, b[remind])
logger.info(f"读取旧数据-->{group} 关闭 {b[remind]}")
except Exception as e:
pass
query = db.text("DROP TABLE group_reminds;")
await db.first(query)
old_data_table.unlink()
logger.info("旧数据读取完毕,删除了舍弃表 group_reminds...")
except (ModuleNotFoundError, DuplicateColumnError):
pass
group_manager.save()
+27 -11
View File
@@ -9,15 +9,9 @@ from nonebot.adapters.cqhttp.exception import ActionFailed
from configs.path_config import DATA_PATH, IMAGE_PATH
from utils.image_utils import get_img_hash
from services.log import logger
from configs.config import MUTE_LEVEL
from configs.config import NICKNAME, Config
import aiohttp
import aiofiles
from configs.config import (
MUTE_DEFAULT_COUNT,
MUTE_DEFAULT_TIME,
MUTE_DEFAULT_DURATION,
NICKNAME,
)
try:
import ujson as json
@@ -40,7 +34,29 @@ __plugin_des__ = "刷屏禁言相关操作"
__plugin_cmd__ = ["设置刷屏检测时间 [秒]", "设置刷屏检测次数 [次数]", "设置刷屏禁言时长 [分钟]", "刷屏检测设置"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {"admin_level": MUTE_LEVEL}
__plugin_settings__ = {"admin_level": Config.get_config("mute", "MUTE_LEVEL")}
__plugin_configs__ = {
"MUTE_LEVEL [LEVEL]": {
"value": 5,
"help": "更改禁言设置的管理权限",
"default_value": 5
},
"MUTE_DEFAULT_COUNT": {
"value": 10,
"help": "刷屏禁言默认检测次数",
"default_value": 10
},
"MUTE_DEFAULT_TIME": {
"value": 7,
"help": "刷屏检测默认规定时间",
"default_value": 7
},
"MUTE_DEFAULT_DURATION": {
"value": 10,
"help": "刷屏检测默禁言时长(分钟)",
"default_value": 10
},
}
mute = on_message(priority=1, block=False)
@@ -98,9 +114,9 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
msg += img_hash
if not mute_data.get(group_id):
mute_data[group_id] = {
"count": MUTE_DEFAULT_COUNT,
"time": MUTE_DEFAULT_TIME,
"duration": MUTE_DEFAULT_DURATION,
"count": Config.get_config("mute", "MUTE_DEFAULT_COUNT"),
"time": Config.get_config("mute", "MUTE_DEFAULT_TIME"),
"duration": Config.get_config("mute", "MUTE_DEFAULT_DURATION"),
}
if not mute_dict.get(event.user_id):
mute_dict[event.user_id] = {"time": time.time(), "count": 1, "msg": msg}
-194
View File
@@ -1,194 +0,0 @@
from nonebot import on_command
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, PrivateMessageEvent
from nonebot.rule import to_me
from utils.utils import get_message_text
from models.group_member_info import GroupInfoUser
from models.friend_user import FriendUser
import random
from models.ban_user import BanUser
from services.log import logger
from configs.config import NICKNAME
__zx_plugin_name__ = "昵称系统"
__plugin_usage__ = f"""
usage:
个人昵称系统,群聊 与 私聊 昵称相互独立
指令:
以后叫我 [昵称]
{NICKNAME}我是谁
""".strip()
__plugin_des__ = "区区昵称,才不想叫呢!"
__plugin_cmd__ = ["以后叫我 [昵称]", f"{NICKNAME}我是谁"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
nickname = on_command(
"nickname",
aliases={"以后叫我", "以后请叫我", "称呼我", "以后请称呼我", "以后称呼我", "叫我", "请叫我"},
rule=to_me(),
priority=5,
block=True,
)
my_nickname = on_command(
"my_name", aliases={"我叫什么", "我是谁", "我的名字"}, rule=to_me(), priority=5, block=True
)
cancel_nickname = on_command("取消昵称", rule=to_me(), priority=5, block=True)
@nickname.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
msg = get_message_text(event.json())
if not msg:
await nickname.finish("叫你空白?叫你虚空?叫你无名??", at_sender=True)
if len(msg) > 10:
await nickname.finish("昵称可不能超过10个字!", at_sender=True)
if await GroupInfoUser.set_group_member_nickname(
event.user_id, event.group_id, msg
):
if len(msg) < 5:
if random.random() < 0.5:
msg = "~".join(msg)
await nickname.send(
random.choice(
[
f"好啦好啦,我知道啦,{msg},以后就这么叫你吧",
f"嗯嗯,{NICKNAME}记住你的昵称了哦,{msg}",
f"好突然,突然要叫你昵称什么的...{msg}..",
f"{NICKNAME}会好好记住的{msg}的,放心吧",
f"好..好.,那窝以后就叫你{msg}了.",
]
)
)
logger.info(f"USER {event.user_id} GROUP {event.group_id} 设置群昵称 {msg}")
else:
await nickname.send("设置昵称失败,请更新群组成员信息!", at_sender=True)
logger.warning(f"USER {event.user_id} GROUP {event.group_id} 设置群昵称 {msg} 失败")
@nickname.handle()
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
msg = get_message_text(event.json())
if not msg:
await nickname.finish("叫你空白?叫你虚空?叫你无名??", at_sender=True)
if len(msg) > 10:
await nickname.finish("不要超过10个字!", at_sender=True)
if await FriendUser.set_friend_nickname(event.user_id, msg):
await nickname.send(
random.choice(
[
f"好啦好啦,我知道啦,{msg},以后就这么叫你吧",
f"嗯嗯,{NICKNAME}记住你的昵称了哦,{msg}",
f"好突然,突然要叫你昵称什么的...{msg}..",
f"{NICKNAME}会好好记住的{msg}的,放心吧",
f"好..好.,那窝以后就叫你{msg}了.",
]
)
)
logger.info(f"USER {event.user_id} 设置昵称 {msg}")
else:
await nickname.send("设置昵称失败了,明天再来试一试!或联系管理员更新好友!", at_sender=True)
logger.warning(f"USER {event.user_id} 设置昵称 {msg} 失败")
@my_nickname.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
try:
nickname_ = await GroupInfoUser.get_group_member_nickname(
event.user_id, event.group_id
)
except AttributeError:
nickname_ = ""
if nickname_:
await my_nickname.send(
random.choice(
[
f"我肯定记得你啊,你是{nickname_}啊",
f"我不会忘记你的,你也不要忘记我!{nickname_}",
f"哼哼,{NICKNAME}记忆力可是很好的,{nickname_}",
f"嗯?你是失忆了嘛...{nickname_}..",
f"不要小看{NICKNAME}的记忆力啊!笨蛋{nickname_}!QAQ",
f"哎?{nickname_}..怎么了吗..突然这样问..",
]
)
)
else:
nickname_ = event.sender.card if event.sender.card else event.sender.nickname
await my_nickname.send(
random.choice(
["没..没有昵称嘛,{}", "啊,你是{}啊,我想叫你的昵称!", "是{}啊,有什么事吗?", "你是{}?"]
).format(nickname_)
)
@my_nickname.handle()
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
nickname_ = await FriendUser.get_friend_nickname(event.user_id)
if nickname_:
await my_nickname.send(
random.choice(
[
f"我肯定记得你啊,你是{nickname_}啊",
f"我不会忘记你的,你也不要忘记我!{nickname_}",
f"哼哼,{NICKNAME}记忆力可是很好的,{nickname_}",
f"嗯?你是失忆了嘛...{nickname_}..",
f"不要小看{NICKNAME}的记忆力啊!笨蛋{nickname_}!QAQ",
f"哎?{nickname_}..怎么了吗..突然这样问..",
]
)
)
else:
nickname_ = (await bot.get_stranger_info(user_id=event.user_id))["nickname"]
await my_nickname.send(
random.choice(
["没..没有昵称嘛,{}", "啊,你是{}啊,我想叫你的昵称!", "是{}啊,有什么事吗?", "你是{}?"]
).format(nickname_)
)
@cancel_nickname.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
nickname_ = await GroupInfoUser.get_group_member_nickname(
event.user_id, event.group_id
)
if nickname_:
await cancel_nickname.send(
random.choice(
[
f"呜..{NICKNAME}睡一觉就会忘记的..和梦一样..{nickname_}",
f"窝知道了..{nickname_}..",
f"是{NICKNAME}哪里做的不好嘛..好吧..晚安{nickname_}",
f"呃,{nickname_},下次我绝对绝对绝对不会再忘记你!",
f"可..可恶!{nickname_}!太可恶了!呜",
]
)
)
await GroupInfoUser.set_group_member_nickname(event.user_id, event.group_id, "")
await BanUser.ban(event.user_id, 9, 60)
else:
await cancel_nickname.send("你在做梦吗?你没有昵称啊", at_sender=True)
@cancel_nickname.handle()
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
nickname_ = await FriendUser.get_friend_nickname(event.user_id)
if nickname_:
await cancel_nickname.send(
random.choice(
[
f"呜..{NICKNAME}睡一觉就会忘记的..和梦一样..{nickname_}",
f"窝知道了..{nickname_}..",
f"是{NICKNAME}哪里做的不好嘛..好吧..晚安{nickname_}",
f"呃,{nickname_},下次我绝对绝对绝对不会再忘记你!",
f"可..可恶!{nickname_}!太可恶了!呜",
]
)
)
await FriendUser.get_user_name(event.user_id)
await BanUser.ban(event.user_id, 9, 60)
else:
await cancel_nickname.send("你在做梦吗?你没有昵称啊", at_sender=True)
+11 -5
View File
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import traceback
from typing import Dict
from aiohttp.client_exceptions import ClientError
@@ -8,7 +7,7 @@ from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
from services.log import logger
from utils.utils import get_message_text, get_message_imgs
from configs.config import MAX_FIND_IMG_COUNT
from configs.config import Config
from nonebot.rule import to_me
from .ex import get_des as get_des_ex
@@ -37,6 +36,9 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["识图"],
}
__plugin_configs__ = {
"MAX_FIND_IMAGE_COUNT": {"value": 3, "help": "识图返回的最大结果数", "default_value": 3}
}
async def get_des(url: str, mode: str, user_id: int):
@@ -109,11 +111,13 @@ async def get_setu(bot: Bot, event: MessageEvent, state: T_State):
async for msg in get_des(url, mod, event.user_id):
if msg:
await bot.send(event=event, message=msg)
if idx == MAX_FIND_IMG_COUNT:
if idx == Config.get_config(
"nonebot_plugin_picsearcher", "MAX_FIND_IMAGE_COUNT"
):
break
idx += 1
if id == 1:
await bot.send(event=event, message='没找着.')
await bot.send(event=event, message="没找着.")
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 识图:{url}"
@@ -163,7 +167,9 @@ async def handle_previous(bot: Bot, event: GroupMessageEvent, state: T_State):
idx = 1
async for msg in get_des(url, "nao", event.user_id):
await bot.send(event=event, message=msg)
if idx == MAX_FIND_IMG_COUNT:
if idx == Config.get_config(
"nonebot_plugin_picsearcher", "MAX_FIND_IMAGE_COUNT"
):
break
idx += 1
except IndexError:
+4 -18
View File
@@ -1,14 +1,12 @@
import aiohttp
from io import BytesIO
from random import choice
from nonebot import on_regex
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
from utils.utils import get_message_text, get_message_at
from utils.utils import get_message_text, get_message_at, get_user_avatar
from utils.message_builder import image
import re
from utils.image_utils import CreateImg
from asyncio.exceptions import TimeoutError
__zx_plugin_name__ = "我有一个朋友"
__plugin_usage__ = """
@@ -35,18 +33,6 @@ one_friend = on_regex(
)
async def get_pic(qq):
url = f"http://q1.qlogo.cn/g?b=qq&nk={qq}&s=100"
async with aiohttp.ClientSession() as session:
for _ in range(3):
try:
async with session.get(url, timeout=5) as response:
return await response.read()
except TimeoutError:
pass
return None
@one_friend.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
msg = get_message_text(event.json())
@@ -72,11 +58,11 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
if not msg:
msg = "都不知道问什么"
msg = msg.replace("他", "我").replace("她", "我").replace("它", "我")
x = await get_pic(qq)
x = await get_user_avatar(qq)
if x:
ava = CreateImg(100, 100, background=BytesIO(await get_pic(qq)))
ava = CreateImg(200, 100, background=BytesIO(x))
else:
ava = CreateImg(100, 100, color=(0, 0, 0))
ava = CreateImg(200, 100, color=(0, 0, 0))
ava.circle()
text = CreateImg(300, 30, font_size=30)
text.text((0, 0), user_name)
+15
View File
@@ -8,6 +8,7 @@ from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, MessageEvent
from nonebot.permission import SUPERUSER
import random
from nonebot.plugin import MatcherGroup
from configs.path_config import IMAGE_PATH
import re
from .open_cases_c import (
open_case,
@@ -68,6 +69,20 @@ __plugin_settings__ = {
}
__plugin_task__ = {"open_case_reset_remind": "每日开箱重置提醒"}
__plugin_cd_limit__ = {"rst": "着什么急啊,慢慢来!"}
__plugin_resources__ = {f"cases": IMAGE_PATH}
__plugin_configs__ = {
"INITIAL_OPEN_CASE_COUNT": {"value": 20, "help": "初始每日开箱次数", "default_value": 20},
"EACH_IMPRESSION_ADD_COUNT": {
"value": 3,
"help": "每 * 点好感度额外增加开箱次数",
"default_value": 3,
},
"COOKIE": {
"value": None,
"help": "BUFF的cookie",
},
"BUFF_PROXY": {"value": None, "help": "使用代理访问BUFF"},
}
cases_name = ["狂牙大行动", "突围大行动", "命悬一线", "裂空", "光谱"]
+2
View File
@@ -0,0 +1,2 @@
from .open_cases_user import *
from .buff_prices import *
+35
View File
@@ -0,0 +1,35 @@
from datetime import datetime
from services.db_context import db
# 1.狂牙武器箱
class BuffPrice(db.Model):
__tablename__ = 'buff_prices'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
case_id = db.Column(db.Integer(), nullable=False)
skin_name = db.Column(db.Unicode(), nullable=False)
skin_price = db.Column(db.Float(), nullable=False)
update_date = db.Column(db.DateTime(), nullable=False)
_idx1 = db.Index('buff_price_idx1', 'skin_name', unique=True)
@classmethod
async def ensure(cls, skin_name: str, for_update: bool = False) -> 'BuffPrice':
query = cls.query.where(
(cls.skin_name == skin_name)
)
if for_update:
query = query.with_for_update()
user = await query.gino.first()
return user or await cls.create(
case_id=1,
skin_name=skin_name,
skin_price=0,
update_date=datetime.min,
)
@@ -0,0 +1,60 @@
from datetime import datetime
from services.db_context import db
class OpenCasesUser(db.Model):
__tablename__ = 'open_cases_users'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
user_qq = db.Column(db.BigInteger(), nullable=False)
belonging_group = db.Column(db.BigInteger(), nullable=False)
total_count = db.Column(db.Integer(), nullable=False, default=0)
blue_count = db.Column(db.Integer(), nullable=False, default=0)
blue_st_count = db.Column(db.Integer(), nullable=False, default=0)
purple_count = db.Column(db.Integer(), nullable=False, default=0)
purple_st_count = db.Column(db.Integer(), nullable=False, default=0)
pink_count = db.Column(db.Integer(), nullable=False, default=0)
pink_st_count = db.Column(db.Integer(), nullable=False, default=0)
red_count = db.Column(db.Integer(), nullable=False, default=0)
red_st_count = db.Column(db.Integer(), nullable=False, default=0)
knife_count = db.Column(db.Integer(), nullable=False, default=0)
knife_st_count = db.Column(db.Integer(), nullable=False, default=0)
spend_money = db.Column(db.Integer(), nullable=False, default=0)
make_money = db.Column(db.Float(), nullable=False, default=0)
today_open_total = db.Column(db.Integer(), nullable=False, default=0)
open_cases_time_last = db.Column(db.DateTime(timezone=True), nullable=False, default=datetime.now())
knifes_name = db.Column(db.Unicode(), nullable=False, default="")
_idx1 = db.Index('open_cases_group_users_idx1', 'user_qq', 'belonging_group', unique=True)
@classmethod
async def ensure(cls, user_qq: int, belonging_group: int, for_update: bool = False) -> 'OpenCasesUser':
query = cls.query.where(
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
)
if for_update:
query = query.with_for_update()
user = await query.gino.first()
return user or await cls.create(
user_qq=user_qq,
belonging_group=belonging_group,
)
@classmethod
async def get_user_all(cls, group_id: int = None) -> 'list':
user_list = []
if not group_id:
query = await cls.query.gino.all()
else:
query = await cls.query.where(
(cls.belonging_group == group_id)
).gino.all()
for user in query:
user_list.append(user)
return user_list
+165 -115
View File
@@ -2,39 +2,40 @@ from datetime import datetime, timedelta
from .config import *
from services.log import logger
from services.db_context import db
from models.open_cases_user import OpenCasesUser
from .models.open_cases_user import OpenCasesUser
from models.sign_group_user import SignGroupUser
from utils.message_builder import image
import pypinyin
import random
from .utils import get_price
from models.buff_price import BuffPrice
from .models.buff_prices import BuffPrice
from PIL import Image
from utils.image_utils import alpha2white_pil, CreateImg
from configs.path_config import IMAGE_PATH
import asyncio
from utils.utils import cn2py
from configs.config import INITIAL_OPEN_CASE_COUNT
MAX_COUNT = INITIAL_OPEN_CASE_COUNT
from configs.config import Config
async def open_case(user_qq: int, group: int, case_name: str = "狂牙大行动") -> str:
if case_name not in ["狂牙大行动", "突围大行动", "命悬一线", '裂空', '光谱']:
if case_name not in ["狂牙大行动", "突围大行动", "命悬一线", "裂空", "光谱"]:
return "武器箱未收录"
knifes_flag = False
# lan zi fen hong jin price
uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0]
case = ""
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += ''.join(i)
case += "".join(i)
impression = (await SignGroupUser.ensure(user_qq, group)).impression
rand = random.random()
async with db.transaction():
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
# 一天次数上限
if user.today_open_total == int(MAX_COUNT + int(impression) / 3):
if user.today_open_total == int(
Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
+ int(impression)
/ Config.get_config("open_cases", "EACH_IMPRESSION_ADD_COUNT")
):
return _handle_is_MAX_COUNT()
skin, mosun = get_color_quality(rand, case_name)
# 调侃
@@ -43,51 +44,49 @@ async def open_case(user_qq: int, group: int, case_name: str = "狂牙大行动"
uplist[0] = 1
else:
uplist[1] = 1
ridicule_result = random.choice(['这样看着才舒服',
'是自己人,大伙把刀收好',
'非常舒适~'])
ridicule_result = random.choice(["这样看着才舒服", "是自己人,大伙把刀收好", "非常舒适~"])
if skin[:2] == "受限":
if skin.find("StatTrak") == -1:
uplist[2] = 1
else:
uplist[3] = 1
ridicule_result = random.choice(['还行吧,勉强接受一下下',
'居然不是蓝色,太假了',
'运气-1-1-1-1-1...'])
ridicule_result = random.choice(
["还行吧,勉强接受一下下", "居然不是蓝色,太假了", "运气-1-1-1-1-1..."]
)
if skin[:2] == "保密":
if skin.find("StatTrak") == -1:
uplist[4] = 1
else:
uplist[5] = 1
ridicule_result = random.choice(['开始不适....',
'你妈妈买菜必涨价!涨三倍!',
'你最近不适合出门,真的'])
ridicule_result = random.choice(
["开始不适....", "你妈妈买菜必涨价!涨三倍!", "你最近不适合出门,真的"]
)
if skin[:2] == "隐秘":
if skin.find("StatTrak") == -1:
uplist[6] = 1
else:
uplist[7] = 1
ridicule_result = random.choice(['已经非常不适',
'好兄弟你开的什么箱子啊,一般箱子不是只有蓝色的吗',
'开始拿阳寿开箱子了?'])
ridicule_result = random.choice(
["已经非常不适", "好兄弟你开的什么箱子啊,一般箱子不是只有蓝色的吗", "开始拿阳寿开箱子了?"]
)
if skin[:2] == "罕见":
knifes_flag = True
if skin.find("StatTrak") == -1:
uplist[8] = 1
else:
uplist[9] = 1
ridicule_result = random.choice(['你的好运我收到了,你可以去喂鲨鱼了',
'最近该吃啥就迟点啥吧,哎,好好的一个人怎么就....哎',
'众所周知,欧皇寿命极短.'])
ridicule_result = random.choice(
["你的好运我收到了,你可以去喂鲨鱼了", "最近该吃啥就迟点啥吧,哎,好好的一个人怎么就....哎", "众所周知,欧皇寿命极短."]
)
if skin.find("(") != -1:
cskin = skin.split("(")
skin = cskin[0].strip() + "(" + cskin[1].strip()
skin = skin.split("|")[0].strip() + " | " + skin.split("|")[1].strip()
# 价格
if skin.find('无涂装') == -1:
if skin.find("无涂装") == -1:
dbprice = await BuffPrice.ensure(skin[9:])
else:
dbprice = await BuffPrice.ensure(skin[9: skin.rfind('(')].strip())
dbprice = await BuffPrice.ensure(skin[9 : skin.rfind("(")].strip())
if dbprice.skin_price != 0:
price_result = dbprice.skin_price
print("数据库查询到价格: ", dbprice.skin_price)
@@ -114,38 +113,55 @@ async def open_case(user_qq: int, group: int, case_name: str = "狂牙大行动"
# cskin_word = sp[1][:sp[1].find("(") - 1].strip()
if knifes_flag:
await user.update(
knifes_name=user.knifes_name + f"{case}||{skin.split(':')[1].strip()} 磨损:{str(mosun)[:11]}, 价格:{uplist[10]},"
knifes_name=user.knifes_name
+ f"{case}||{skin.split(':')[1].strip()} 磨损:{str(mosun)[:11]}, 价格:{uplist[10]},"
).apply()
cskin_word = skin.split(':')[1].replace('|', '-').replace('(StatTrak™)', '')
cskin_word = cskin_word[: cskin_word.rfind('(')].strip()
skin_name = cn2py(cskin_word.replace('|', '-').replace('(StatTrak™)', '').strip())
img = image(f'{skin_name}.png', "cases/" + case)
cskin_word = skin.split(":")[1].replace("|", "-").replace("(StatTrak™)", "")
cskin_word = cskin_word[: cskin_word.rfind("(")].strip()
skin_name = cn2py(
cskin_word.replace("|", "-").replace("(StatTrak™)", "").strip()
)
img = image(f"{skin_name}.png", "cases/" + case)
# if knifes_flag:
# await user.update(
# knifes_name=user.knifes_name + f"{skin} 磨损:{mosun}, 价格:{uplist[10]}"
# ).apply()
if await update_user_total(user, uplist):
logger.info(f"qq:{user_qq} 群:{group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}, 数据更新成功")
logger.info(
f"qq:{user_qq} 群:{group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}, 数据更新成功"
)
else:
logger.warning(f"qq:{user_qq} 群:{group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}, 数据更新失败")
logger.warning(
f"qq:{user_qq} 群:{group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}, 数据更新失败"
)
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
over_count = int(MAX_COUNT + int(impression) / 3) - user.today_open_total
return f"开启{case_name}武器箱.\n剩余开箱次数:{over_count}.\n" \
+ img + "\n" + \
f"皮肤:{skin}\n" \
f"磨损:{mosun:.9f}\n" \
f"价格:{price_result}\n" \
f"{ridicule_result}"
over_count = int(
Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
+ int(impression)
/ Config.get_config("open_cases", "EACH_IMPRESSION_ADD_COUNT")
) - user.today_open_total
return (
f"开启{case_name}武器箱.\n剩余开箱次数:{over_count}.\n" + img + "\n" + f"皮肤:{skin}\n"
f"磨损:{mosun:.9f}\n"
f"价格:{price_result}\n"
f"{ridicule_result}"
)
async def open_shilian_case(user_qq: int, group: int, case_name: str, num: int = 10):
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
impression = (await SignGroupUser.ensure(user_qq, group)).impression
if user.today_open_total == int(MAX_COUNT + int(impression) / 3):
max_count = int(
Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
+ int(impression) / Config.get_config("open_cases", "EACH_IMPRESSION_ADD_COUNT")
)
if user.today_open_total == max_count:
return _handle_is_MAX_COUNT()
if int(MAX_COUNT + int(impression) / 3) - user.today_open_total < num:
return f"今天开箱次数不足{num}次噢,请单抽试试看(也许单抽运气更好?)" \
f"\n剩余开箱次数:{int(MAX_COUNT + int(impression) / 3) - user.today_open_total}"
if max_count - user.today_open_total < num:
return (
f"今天开箱次数不足{num}次噢,请单抽试试看(也许单抽运气更好?)"
f"\n剩余开箱次数:{max_count - user.today_open_total}"
)
await user.update(
total_count=user.total_count + num,
spend_money=user.spend_money + 17 * num,
@@ -163,7 +179,7 @@ async def open_shilian_case(user_qq: int, group: int, case_name: str, num: int =
# lan zi fen hong jin price
uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0]
img_list = []
name_list = ['蓝', '蓝(暗金)', '紫', '紫(暗金)', '粉', '粉(暗金)', '红', '红(暗金)', '金', '金(暗金)']
name_list = ["蓝", "蓝(暗金)", "紫", "紫(暗金)", "粉", "粉(暗金)", "红", "红(暗金)", "金", "金(暗金)"]
async with db.transaction():
for _ in range(num):
knifes_flag = False
@@ -200,49 +216,71 @@ async def open_shilian_case(user_qq: int, group: int, case_name: str, num: int =
skin = cskin[0].strip() + "(" + cskin[1].strip()
skin = skin.split("|")[0].strip() + " | " + skin.split("|")[1].strip()
# 价格
if skin.find('无涂装') == -1:
if skin.find("无涂装") == -1:
dbprice = await BuffPrice.ensure(skin[9:])
else:
dbprice = await BuffPrice.ensure(skin[9: skin.rfind('(')].strip())
dbprice = await BuffPrice.ensure(skin[9 : skin.rfind("(")].strip())
if dbprice.skin_price != 0:
price_result = dbprice.skin_price
uplist[10] += price_result
else:
price_result = '未查询到'
price_result = "未查询到"
if knifes_flag:
await user.update(
knifes_name=user.knifes_name + f"{case}||{skin.split(':')[1].strip()} 磨损:{str(mosun)[:11]}, 价格:{dbprice.skin_price},"
knifes_name=user.knifes_name
+ f"{case}||{skin.split(':')[1].strip()} 磨损:{str(mosun)[:11]}, 价格:{dbprice.skin_price},"
).apply()
cskin_word = skin.split(':')[1].replace('|', '-').replace('(StatTrak™)', '')
cskin_word = cskin_word[: cskin_word.rfind('(')].strip()
cskin_word = skin.split(":")[1].replace("|", "-").replace("(StatTrak™)", "")
cskin_word = cskin_word[: cskin_word.rfind("(")].strip()
skin_name = ""
for i in pypinyin.pinyin(cskin_word.replace('|', '-').replace('(StatTrak™)', '').strip(),
style=pypinyin.NORMAL):
skin_name += ''.join(i)
for i in pypinyin.pinyin(
cskin_word.replace("|", "-").replace("(StatTrak™)", "").strip(),
style=pypinyin.NORMAL,
):
skin_name += "".join(i)
# img = image(skin_name, "cases/" + case, "png")
wImg = CreateImg(200, 270, 200, 200)
wImg.paste(alpha2white_pil(Image.open(IMAGE_PATH + f'cases/{case}/{skin_name}.png').resize((200, 200), Image.ANTIALIAS)), (0, 0))
wImg.paste(
alpha2white_pil(
Image.open(IMAGE_PATH + f"cases/{case}/{skin_name}.png").resize(
(200, 200), Image.ANTIALIAS
)
),
(0, 0),
)
wImg.text((5, 200), skin)
wImg.text((5, 220), f'磨损:{str(mosun)[:9]}')
wImg.text((5, 240), f'价格:{price_result}')
wImg.text((5, 220), f"磨损:{str(mosun)[:9]}")
wImg.text((5, 240), f"价格:{price_result}")
img_list.append(wImg)
logger.info(f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}")
logger.info(
f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}"
)
if await update_user_total(user, uplist, 0):
logger.info(f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 {num} 次, 数据更新成功")
logger.info(
f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 {num} 次, 数据更新成功"
)
else:
logger.warning(f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 {num} 次, 价格:{uplist[10]}, 数据更新失败")
logger.warning(
f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 {num} 次, 价格:{uplist[10]}, 数据更新失败"
)
# markImg = CreateImg(1000, h, 200, 270)
# for img in img_list:
# markImg.paste(img)
markImg = await asyncio.get_event_loop().run_in_executor(None, paste_markImg, h, img_list)
over_count = int(MAX_COUNT + int(impression) / 3) - user.today_open_total
result = ''
markImg = await asyncio.get_event_loop().run_in_executor(
None, paste_markImg, h, img_list
)
over_count = max_count - user.today_open_total
result = ""
for i in range(len(name_list)):
if uplist[i]:
result += f'[{name_list[i]}:{uplist[i]}] '
return f"开启{case_name}武器箱\n剩余开箱次数:{over_count}\n" \
+ image(b64=markImg.pic2bs4()) + \
'\n' + result[:-1] + f'\n总获取金额:{uplist[-1]:.2f}\n总花费:{17 * num}'
result += f"[{name_list[i]}:{uplist[i]}] "
return (
f"开启{case_name}武器箱\n剩余开箱次数:{over_count}\n"
+ image(b64=markImg.pic2bs4())
+ "\n"
+ result[:-1]
+ f"\n总获取金额:{uplist[-1]:.2f}\n总花费:{17 * num}"
)
def paste_markImg(h: int, img_list: list):
@@ -273,7 +311,7 @@ async def update_user_total(user: OpenCasesUser, up_list: list, num: int = 1) ->
spend_money=user.spend_money + 17 * num,
make_money=user.make_money + up_list[10],
today_open_total=user.today_open_total + num,
open_cases_time_last=datetime.now()
open_cases_time_last=datetime.now(),
).apply()
return True
except:
@@ -283,21 +321,23 @@ async def update_user_total(user: OpenCasesUser, up_list: list, num: int = 1) ->
async def total_open_statistics(user_qq: int, group: int) -> str:
async with db.transaction():
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
return f"开箱总数:{user.total_count}\n" \
f"今日开箱:{user.today_open_total}\n" \
f"蓝色军规:{user.blue_count}\n" \
f"蓝色暗金:{user.blue_st_count}\n" \
f"紫色受限:{user.purple_count}\n" \
f"紫色暗金:{user.purple_st_count}\n" \
f"粉色保密:{user.pink_count}\n" \
f"粉色暗金:{user.pink_st_count}\n" \
f"红色隐秘:{user.red_count}\n" \
f"红色暗金:{user.red_st_count}\n" \
f"金色罕见:{user.knife_count}\n" \
f"金色暗金:{user.knife_st_count}\n" \
f"花费金额:{user.spend_money}\n" \
f"获取金额:{user.make_money:.2f}\n" \
f"最后开箱日期:{(user.open_cases_time_last + timedelta(hours=8)).date()}"
return (
f"开箱总数:{user.total_count}\n"
f"今日开箱:{user.today_open_total}\n"
f"蓝色军规:{user.blue_count}\n"
f"蓝色暗金:{user.blue_st_count}\n"
f"紫色受限:{user.purple_count}\n"
f"紫色暗金:{user.purple_st_count}\n"
f"粉色保密:{user.pink_count}\n"
f"粉色暗金:{user.pink_st_count}\n"
f"红色隐秘:{user.red_count}\n"
f"红色暗金:{user.red_st_count}\n"
f"金色罕见:{user.knife_count}\n"
f"金色暗金:{user.knife_st_count}\n"
f"花费金额:{user.spend_money}\n"
f"获取金额:{user.make_money:.2f}\n"
f"最后开箱日期:{(user.open_cases_time_last + timedelta(hours=8)).date()}"
)
async def group_statistics(group: int):
@@ -318,20 +358,22 @@ async def group_statistics(group: int):
uplist[10] += user.make_money
uplist[11] += user.total_count
uplist[12] += user.today_open_total
return f"群开箱总数:{uplist[11]}\n" \
f"群今日开箱:{uplist[12]}\n" \
f"蓝色军规:{uplist[0]}\n" \
f"蓝色暗金:{uplist[1]}\n" \
f"紫色受限:{uplist[2]}\n" \
f"紫色暗金:{uplist[3]}\n" \
f"粉色保密:{uplist[4]}\n" \
f"粉色暗金:{uplist[5]}\n" \
f"红色隐秘:{uplist[6]}\n" \
f"红色暗金:{uplist[7]}\n" \
f"金色罕见:{uplist[8]}\n" \
f"金色暗金:{uplist[9]}\n" \
f"花费金额:{uplist[11] * 17}\n" \
f"获取金额:{uplist[10]:.2f}"
return (
f"群开箱总数:{uplist[11]}\n"
f"群今日开箱:{uplist[12]}\n"
f"蓝色军规:{uplist[0]}\n"
f"蓝色暗金:{uplist[1]}\n"
f"紫色受限:{uplist[2]}\n"
f"紫色暗金:{uplist[3]}\n"
f"粉色保密:{uplist[4]}\n"
f"粉色暗金:{uplist[5]}\n"
f"红色隐秘:{uplist[6]}\n"
f"红色暗金:{uplist[7]}\n"
f"金色罕见:{uplist[8]}\n"
f"金色暗金:{uplist[9]}\n"
f"花费金额:{uplist[11] * 17}\n"
f"获取金额:{uplist[10]:.2f}"
)
async def my_knifes_name(user_id: int, group: int):
@@ -348,7 +390,9 @@ async def my_knifes_name(user_id: int, group: int):
else:
h = 600 * int(length / 5) + 600
w = 540 * 5
A = await asyncio.get_event_loop().run_in_executor(None, _pst_my_knife, w, h, knifes_list)
A = await asyncio.get_event_loop().run_in_executor(
None, _pst_my_knife, w, h, knifes_list
)
return image(b64=A.pic2bs4())
else:
return "您木有开出金色级别的皮肤喔"
@@ -357,30 +401,36 @@ async def my_knifes_name(user_id: int, group: int):
def _pst_my_knife(w, h, knifes_list):
A = CreateImg(w, h, 540, 600)
for knife in knifes_list:
case = knife.split('||')[0]
knife = knife.split('||')[1]
name = knife[:knife.find('(')].strip()
itype = knife[knife.find('(')+1: knife.find(')')].strip()
mosun = knife[knife.find('磨损:')+3: knife.rfind('价格:')].strip()
if mosun[-1] == ',' or mosun[-1] == ',':
case = knife.split("||")[0]
knife = knife.split("||")[1]
name = knife[: knife.find("(")].strip()
itype = knife[knife.find("(") + 1 : knife.find(")")].strip()
mosun = knife[knife.find("磨损:") + 3 : knife.rfind("价格:")].strip()
if mosun[-1] == "," or mosun[-1] == ",":
mosun = mosun[:-1]
price = knife[knife.find('价格:')+3:]
price = knife[knife.find("价格:") + 3 :]
skin_name = ""
for i in pypinyin.pinyin(name.replace('|', '-').replace('(StatTrak™)', '').strip(),
style=pypinyin.NORMAL):
skin_name += ''.join(i)
for i in pypinyin.pinyin(
name.replace("|", "-").replace("(StatTrak™)", "").strip(),
style=pypinyin.NORMAL,
):
skin_name += "".join(i)
knife_img = CreateImg(470, 600, 470, 470, font_size=20)
knife_img.paste(alpha2white_pil(
Image.open(IMAGE_PATH + f'cases/{case}/{skin_name}.png').resize((470, 470), Image.ANTIALIAS)), (0, 0))
knife_img.text((5, 500), f'\t{name}({itype})')
knife_img.text((5, 530), f'\t磨损:{mosun}')
knife_img.text((5, 560), f'\t价格:{price}')
knife_img.paste(
alpha2white_pil(
Image.open(IMAGE_PATH + f"cases/{case}/{skin_name}.png").resize(
(470, 470), Image.ANTIALIAS
)
),
(0, 0),
)
knife_img.text((5, 500), f"\t{name}({itype})")
knife_img.text((5, 530), f"\t磨损:{mosun}")
knife_img.text((5, 560), f"\t价格:{price}")
A.paste(knife_img)
return A
# G3SG1(StatTrak™) | 血腥迷彩 (战痕累累)
# G3SG1(StatTrak™) | 血腥迷彩 (战痕累累)
# G3SG1(StatTrak™) | 血腥迷彩 (战痕累累)
+135 -93
View File
@@ -1,19 +1,18 @@
from models.buff_price import BuffPrice
from .models.buff_prices import BuffPrice
from services.db_context import db
from datetime import datetime, timedelta
from utils.user_agent import get_user_agent
from configs.path_config import IMAGE_PATH
import aiohttp
import aiofiles
from models.open_cases_user import OpenCasesUser
from .models.open_cases_user import OpenCasesUser
import os
from services.log import logger
from utils.utils import get_bot
from utils.utils import get_cookie_text
from asyncio.exceptions import TimeoutError
import pypinyin
from nonebot.adapters.cqhttp.exception import ActionFailed
from configs.config import BUFF_PROXY
from configs.config import Config
from utils.manager import group_manager
url = "https://buff.163.com/api/market/goods"
@@ -21,20 +20,20 @@ url = "https://buff.163.com/api/market/goods"
async def util_get_buff_price(case_name: str = "狂牙大行动") -> str:
cookie = {'session': get_cookie_text('buff')}
cookie = {"session": Config.get_config("open_cases", "COOKIE")}
failed_list = []
case = ""
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += ''.join(i)
case += "".join(i)
if case_name == "狂牙大行动":
case_id = 1
elif case_name == "突围大行动":
case_id = 2
elif case_name == "命悬一线":
case_id = 3
elif case_name == '裂空':
elif case_name == "裂空":
case_id = 4
elif case_name == '光谱':
elif case_name == "光谱":
case_id = 5
else:
return "未查询到武器箱"
@@ -44,47 +43,63 @@ async def util_get_buff_price(case_name: str = "狂牙大行动") -> str:
CASE_PINK = eval(case + "_CASE_PINK")
CASE_PURPLE = eval(case + "_CASE_PURPLE")
CASE_BLUE = eval(case + "_CASE_BLUE")
async with aiohttp.ClientSession(cookies=cookie, headers=get_user_agent()) as session:
async with aiohttp.ClientSession(
cookies=cookie, headers=get_user_agent()
) as session:
for total_list in [CASE_KNIFE, CASE_RED, CASE_PINK, CASE_PURPLE, CASE_BLUE]:
print("----------------------------------")
for skin in total_list:
print(skin)
if skin in ["蝴蝶刀 | 无涂装", '求生匕首 | 无涂装', '流浪者匕首 | 无涂装', '系绳匕首 | 无涂装', '骷髅匕首 | 无涂装']:
skin = skin.split('|')[0].strip()
if skin in [
"蝴蝶刀 | 无涂装",
"求生匕首 | 无涂装",
"流浪者匕首 | 无涂装",
"系绳匕首 | 无涂装",
"骷髅匕首 | 无涂装",
]:
skin = skin.split("|")[0].strip()
async with db.transaction():
name_list = []
price_list = []
parameter = {
"game": "csgo",
"page_num": "1",
"search": skin
}
parameter = {"game": "csgo", "page_num": "1", "search": skin}
try:
async with session.get(url, proxy=BUFF_PROXY, params=parameter, timeout=20) as response:
async with session.get(
url,
proxy=Config.get_config("open_cases", "BUFF_PROXY"),
params=parameter,
timeout=20,
) as response:
if response.status == 200:
data = (await response.json())["data"]
total_page = data["total_page"]
data = data["items"]
flag = False
if skin.find('|') == -1: # in ['蝴蝶刀', '求生匕首', '流浪者匕首', '系绳匕首', '骷髅匕首']:
if (
skin.find("|") == -1
): # in ['蝴蝶刀', '求生匕首', '流浪者匕首', '系绳匕首', '骷髅匕首']:
for i in range(1, total_page + 1):
name_list = []
price_list = []
parameter = {
"game": "csgo",
"page_num": f"{i}",
"search": skin
"search": skin,
}
async with session.get(url, params=parameter, timeout=20) as res:
data = (await response.json())["data"]["items"]
async with session.get(
url, params=parameter, timeout=20
) as res:
data = (await response.json())["data"][
"items"
]
for j in range(len(data)):
if data[j]['name'] in [f'{skin}(★)']:
if data[j]["name"] in [f"{skin}(★)"]:
name = data[j]["name"]
price = data[j]["sell_reference_price"]
name_list.append(name.split('(')[0].strip() + ' | 无涂装')
price = data[j][
"sell_reference_price"
]
name_list.append(
name.split("(")[0].strip()
+ " | 无涂装"
)
price_list.append(price)
print(name_list[-1])
print(price_list[-1])
flag = True
break
if flag:
@@ -99,38 +114,56 @@ async def util_get_buff_price(case_name: str = "狂牙大行动") -> str:
price_list.append(price)
except Exception as e:
failed_list.append(skin)
print(f"{skin}更新失败")
logger.warning(f"{skin}更新失败")
else:
failed_list.append(skin)
print(f"{skin}更新失败")
logger.warning(f"{skin}更新失败")
except Exception:
failed_list.append(skin)
print(f"{skin}更新失败")
logger.warning(f"{skin}更新失败")
continue
for i in range(len(name_list)):
name = name_list[i].strip()
price = float(price_list[i])
if name.find("(★)") != -1:
name = name[: name.find("(")] + name[name.find(")") + 1:]
name = name[: name.find("(")] + name[name.find(")") + 1 :]
if name.find("消音") != -1 and name.find("(S") != -1:
name = name.split("(")[0][:-4] + "(" + name.split("(")[1]
name = name.split("|")[0].strip() + " | " + name.split("|")[1].strip()
name = (
name.split("|")[0].strip()
+ " | "
+ name.split("|")[1].strip()
)
elif name.find("消音") != -1:
name = name.split("|")[0][:-5].strip() + " | " + name.split("|")[1].strip()
name = (
name.split("|")[0][:-5].strip()
+ " | "
+ name.split("|")[1].strip()
)
if name.find(" 18 ") != -1 and name.find("(S") != -1:
name = name.split("(")[0][:-5] + "(" + name.split("(")[1]
name = name.split("|")[0].strip() + " | " + name.split("|")[1].strip()
name = (
name.split("|")[0].strip()
+ " | "
+ name.split("|")[1].strip()
)
elif name.find(" 18 ") != -1:
name = name.split("|")[0][:-6].strip() + " | " + name.split("|")[1].strip()
name = (
name.split("|")[0][:-6].strip()
+ " | "
+ name.split("|")[1].strip()
)
dbskin = await BuffPrice.ensure(name, True)
if (dbskin.update_date + timedelta(8)).date() == datetime.now().date():
if (
dbskin.update_date + timedelta(8)
).date() == datetime.now().date():
continue
await dbskin.update(
case_id=case_id,
skin_price=price,
update_date=datetime.now(),
).apply()
print(f"{name_list[i]}---------->成功更新")
logger.info(f"{name_list[i]}---------->成功更新")
result = None
if failed_list:
result = ""
@@ -140,11 +173,11 @@ async def util_get_buff_price(case_name: str = "狂牙大行动") -> str:
async def util_get_buff_img(case_name: str = "狂牙大行动") -> str:
cookie = {'session': get_cookie_text('buff')}
cookie = {"session": Config.get_config("open_cases", "COOKIE")}
error_list = []
case = ""
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += ''.join(i)
case += "".join(i)
path = "cases/" + case + "/"
if not os.path.exists(IMAGE_PATH + path):
os.mkdir(IMAGE_PATH + path)
@@ -154,63 +187,75 @@ async def util_get_buff_img(case_name: str = "狂牙大行动") -> str:
CASE_PINK = eval(case + "_CASE_PINK")
CASE_PURPLE = eval(case + "_CASE_PURPLE")
CASE_BLUE = eval(case + "_CASE_BLUE")
async with aiohttp.ClientSession(cookies=cookie, headers=get_user_agent()) as session:
async with aiohttp.ClientSession(
cookies=cookie, headers=get_user_agent()
) as session:
for total_list in [CASE_KNIFE, CASE_RED, CASE_PINK, CASE_PURPLE, CASE_BLUE]:
for skin in total_list:
parameter = {
"game": "csgo",
"page_num": "1",
"search": skin
}
if skin in ["蝴蝶刀 | 无涂装", '求生匕首 | 无涂装', '流浪者匕首 | 无涂装', '系绳匕首 | 无涂装', '骷髅匕首 | 无涂装']:
skin = skin.split('|')[0].strip()
print("开始更新----->", skin)
print(skin)
skin_name = ''
parameter = {"game": "csgo", "page_num": "1", "search": skin}
if skin in [
"蝴蝶刀 | 无涂装",
"求生匕首 | 无涂装",
"流浪者匕首 | 无涂装",
"系绳匕首 | 无涂装",
"骷髅匕首 | 无涂装",
]:
skin = skin.split("|")[0].strip()
logger.info(f"开始更新----->{skin}")
skin_name = ""
# try:
async with session.get(url, proxy=BUFF_PROXY, params=parameter, timeout=20) as response:
async with session.get(
url,
proxy=Config.get_config("open_cases", "BUFF_PROXY"),
params=parameter,
timeout=20,
) as response:
if response.status == 200:
data = (await response.json())["data"]
total_page = data["total_page"]
flag = False
if skin.find('|') == -1: # in ['蝴蝶刀', '求生匕首', '流浪者匕首', '系绳匕首', '骷髅匕首']:
if (
skin.find("|") == -1
): # in ['蝴蝶刀', '求生匕首', '流浪者匕首', '系绳匕首', '骷髅匕首']:
for i in range(1, total_page + 1):
async with session.get(url, params=parameter, timeout=20) as res:
async with session.get(
url, params=parameter, timeout=20
) as res:
data = (await response.json())["data"]["items"]
for j in range(len(data)):
if data[j]['name'] in [f'{skin}(★)']:
img_url = data[j]['goods_info']['icon_url']
for k in pypinyin.pinyin(skin + '无涂装', style=pypinyin.NORMAL):
skin_name += ''.join(k)
async with aiofiles.open(IMAGE_PATH + path + skin_name + ".png", 'wb') as f:
print("------->开始写入 ", skin)
async with session.get(img_url, timeout=7) as res:
if data[j]["name"] in [f"{skin}(★)"]:
img_url = data[j]["goods_info"]["icon_url"]
for k in pypinyin.pinyin(
skin + "无涂装", style=pypinyin.NORMAL
):
skin_name += "".join(k)
async with aiofiles.open(
IMAGE_PATH + path + skin_name + ".png",
"wb",
) as f:
logger.info(f"------->开始写入{skin}")
async with session.get(
img_url, timeout=7
) as res:
await f.write(await res.read())
flag = True
break
if flag:
break
else:
img_url = (await response.json())["data"]['items'][0]['goods_info']['icon_url']
for i in pypinyin.pinyin(skin.replace('|', '-').strip(), style=pypinyin.NORMAL):
skin_name += ''.join(i)
async with aiofiles.open(IMAGE_PATH + path + skin_name + ".png", 'wb') as f:
print("------->开始写入 ", skin)
img_url = (await response.json())["data"]["items"][0][
"goods_info"
]["icon_url"]
for i in pypinyin.pinyin(
skin.replace("|", "-").strip(), style=pypinyin.NORMAL
):
skin_name += "".join(i)
async with aiofiles.open(
IMAGE_PATH + path + skin_name + ".png", "wb"
) as f:
logger.info(f"------->开始写入 {skin}")
async with session.get(img_url, timeout=7) as res:
await f.write(await res.read())
# async with session.get(url, params=parameter, timeout=7) as response:
# if response.status == 200:
# img_url = (await response.json())["data"]['items'][0]['goods_info']['icon_url']
# skin_name = ''
# for i in pypinyin.pinyin(skin.split("|")[1].strip(), style=pypinyin.NORMAL):
# skin_name += ''.join(i)
# async with aiofiles.open(IMAGE_PATH + path + skin_name + ".png", 'wb') as f:
# print("------->开始写入 ", skin)
# async with session.get(img_url, timeout=7) as res:
# await f.write(await res.read())
# except Exception:
# print("图片更新失败 ---->", skin)
# error_list.append(skin)
result = None
if error_list:
result = ""
@@ -220,16 +265,14 @@ async def util_get_buff_img(case_name: str = "狂牙大行动") -> str:
async def get_price(dname):
cookie = {'session': get_cookie_text('buff')}
cookie = {"session": Config.get_config("open_cases", "COOKIE")}
name_list = []
price_list = []
parameter = {
"game": "csgo",
"page_num": "1",
"search": dname
}
parameter = {"game": "csgo", "page_num": "1", "search": dname}
try:
async with aiohttp.ClientSession(cookies=cookie, headers=get_user_agent()) as session:
async with aiohttp.ClientSession(
cookies=cookie, headers=get_user_agent()
) as session:
async with session.get(url, params=parameter, timeout=7) as response:
if response.status == 200:
try:
@@ -262,22 +305,21 @@ async def update_count_daily():
for user in users:
await user.update(
today_open_total=0,
).apply()
).apply()
bot = get_bot()
gl = await bot.get_group_list()
gl = [g['group_id'] for g in gl]
gl = [g["group_id"] for g in gl]
for g in gl:
if await group_manager.check_group_task_status(g, 'open_case_reset_remind'):
if await group_manager.check_group_task_status(g, "open_case_reset_remind"):
try:
await bot.send_group_msg(group_id=g, message="今日开箱次数重置成功")
except ActionFailed:
logger.warning(f'{g} 群被禁言,无法发送 开箱重置提醒')
logger.warning(f"{g} 群被禁言,无法发送 开箱重置提醒")
logger.info("今日开箱次数重置成功")
except Exception as e:
logger.error(f'开箱重置错误 e:{e}')
logger.error(f"开箱重置错误 e:{e}")
# 蝴蝶刀(★) | 噩梦之夜 (久经沙场)
if __name__ == '__main__':
if __name__ == "__main__":
print(util_get_buff_img("xxxx/"))
+2 -1
View File
@@ -104,7 +104,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
)
)
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f"(USER {event.user_id}, "
f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查询图片 PID:{pid}"
)
if isinstance(event, GroupMessageEvent):
+53 -3
View File
@@ -1,6 +1,6 @@
from configs.config import HIBIAPI
from configs.config import Config
from services.log import logger
from models.omega_pixiv_illusts import OmegaPixivIllusts
from .model.omega_pixiv_illusts import OmegaPixivIllusts
from pathlib import Path
from nonebot import Driver
from typing import List
@@ -14,10 +14,60 @@ __zx_plugin_name__ = "更新扩展图库Omega [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
Config.add_plugin_config(
"hibiapi",
"HIBIAPI",
"https://api.obfs.dev",
help_="如果没有自建或其他hibiapi请不要修改",
default_value="https://api.obfs.dev",
)
Config.add_plugin_config(
"pixiv",
"PIXIV_NGINX_URL",
"i.pixiv.re",
help_="Pixiv反向代理"
)
Config.add_plugin_config(
"pix",
"PIX_IMAGE_SIZE",
"master",
name="PIX图库",
help_="PIX图库下载的画质 可能的值:original:原图,master:缩略图(加快发送速度)",
default_value="master"
)
Config.add_plugin_config(
"pix",
"SEARCH_HIBIAPI_BOOKMARKS",
5000,
help_="最低收藏,PIX使用HIBIAPI搜索图片时达到最低收藏才会添加至图库",
default_value=5000
)
Config.add_plugin_config(
"pix",
"WITHDRAW_PIX_MESSAGE",
(0, 1),
help_="自动撤回,参1:延迟撤回色图时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
default_value=(0, 1)
)
Config.add_plugin_config(
"pix",
"PIX_OMEGA_PIXIV_RATIO",
(10, 0),
help_="PIX图库 与 额外图库OmegaPixivIllusts 混合搜索的比例 参1:PIX图库 参2:OmegaPixivIllusts扩展图库(没有此图库请设置为0)",
default_value=(10, 0)
)
Config.add_plugin_config(
"pix",
"TIMEOUT",
10,
help_="下载图片超时限制(秒)",
default_value=10
)
nonebot.load_plugins("plugins/pix_gallery")
driver: Driver = nonebot.get_driver()
illust_url = f"{HIBIAPI}/api/pixiv/illust"
@driver.on_startup
+103 -42
View File
@@ -4,17 +4,17 @@ from aiohttp.client_exceptions import (
ClientConnectorError,
)
from asyncpg.exceptions import UniqueViolationError
from models.omega_pixiv_illusts import OmegaPixivIllusts
from .model.omega_pixiv_illusts import OmegaPixivIllusts
from asyncio.locks import Semaphore
from aiohttp import ClientPayloadError
from aiohttp.client import ClientSession
from asyncio.exceptions import TimeoutError
from models.pixiv import Pixiv
from .model.pixiv import Pixiv
from typing import List
from utils.utils import get_local_proxy, change_picture_links
from utils.image_utils import CreateImg
from services.log import logger
from configs.config import HIBIAPI_BOOKMARKS, HIBIAPI, PIX_IMAGE_SIZE
from configs.config import Config
from configs.path_config import TEMP_PATH
import platform
import aiohttp
@@ -31,36 +31,45 @@ if str(platform.system()).lower() == "windows":
policy = asyncio.WindowsSelectorEventLoopPolicy()
asyncio.set_event_loop_policy(policy)
search_url = f"{HIBIAPI}/api/pixiv/search"
member_illust_url = f"{HIBIAPI}/api/pixiv/member_illust"
illust_url = f"{HIBIAPI}/api/pixiv/illust"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
HIBIAPI = None
# 开始更新
async def start_update_image_url(current_keyword: List[str], black_pid: List[str]):
async def start_update_image_url(
current_keyword: List[str], black_pid: List[str]
) -> "int, int":
"""
开始更新图片url
:param current_keyword: 关键词
:param black_pid: 黑名单pid
:return: pid数量和图片数量
"""
global HIBIAPI
pid_count = 0
pic_count = 0
tasks = []
semaphore = asyncio.Semaphore(10)
if not HIBIAPI:
HIBIAPI = Config.get_config("hibiapi", "HIBIAPI")
HIBIAPI = HIBIAPI[:-1] if HIBIAPI[-1] else HIBIAPI
async with aiohttp.ClientSession(headers=headers) as session:
for keyword in current_keyword:
for page in range(1, 110):
if keyword.startswith("uid:"):
url = member_illust_url
url = f"{HIBIAPI}/api/pixiv/member_illust"
params = {"id": keyword[4:], "page": page}
if page == 30:
break
elif keyword.startswith("pid:"):
url = illust_url
url = f"{HIBIAPI}/api/pixiv/illust"
params = {"id": keyword[4:]}
else:
url = search_url
url = f"{HIBIAPI}/api/pixiv/search"
params = {"word": keyword, "page": page}
tasks.append(
asyncio.ensure_future(
@@ -86,7 +95,18 @@ async def search_image(
session: ClientSession,
page: int = 1,
black: List[str] = None,
):
) -> "int, int":
"""
搜索图片
:param url: 搜索url
:param keyword: 关键词
:param params: params参数
:param semaphore: semaphore
:param session: session
:param page: 页面
:param black: pid黑名单
:return: pid数量和图片数量
"""
tmp_pid = []
pic_count = 0
pid_count = 0
@@ -104,7 +124,7 @@ async def search_image(
or (not data.get("illusts") and not data.get("illust"))
):
return 0, 0
if url != illust_url:
if url != f"{HIBIAPI}/api/pixiv/illust":
logger.info(f'{keyword}: 获取数据成功...数据总量:{len(data["illusts"])}')
data = data["illusts"]
else:
@@ -133,9 +153,13 @@ async def search_image(
img_urls.append(urls["image_urls"]["original"])
if (
(
bookmarks >= HIBIAPI_BOOKMARKS
or (url == member_illust_url and bookmarks >= 1500)
or (url == illust_url)
bookmarks
>= Config.get_config("pix", "SEARCH_HIBIAPI_BOOKMARKS")
or (
url == f"{HIBIAPI}/api/pixiv/member_illust"
and bookmarks >= 1500
)
or (url == f"{HIBIAPI}/api/pixiv/illust")
)
and len(img_urls) < 10
and _check_black(img_urls, black)
@@ -177,13 +201,8 @@ async def search_image(
tmp_pid.append(data["pid"])
pic_count += 1
logger.info(f'存储图片PID:{data["pid"]} IMG_P:{img_p}')
# await download_image(img_url, session)
except UniqueViolationError:
logger.warning(f'{data["pid"]} | {img_url} 已存在...')
# 下载图片
# if not os.path.exists(f'{image_path}/
# {img_url[img_url.rfind("/") + 1:]}'):
# await download_image(img_url, session)
except (ServerDisconnectedError, ClientConnectorError, ClientOSError):
logger.warning("搜索图片服务被关闭,再次调用....")
await search_image(url, keyword, params, semaphore, session, page, black)
@@ -192,22 +211,26 @@ async def search_image(
# 下载图片
async def download_image(img_url: str, session: ClientSession, _count: int = 1):
"""
下载图片
:param img_url: 图片url
:param session: session
:param _count: 次数
"""
try:
async with session.get(img_url, proxy=get_local_proxy()) as response:
logger.info(f"下载图片 --> {img_url}")
async with aiofiles.open(f'tmp/{img_url.split("/")[-1]}', "wb") as f:
await f.write(await response.read())
# async with semaphore:
# await asyncio.get_event_loop().run_in_executor(None,
# upload_image, img_url[img_url.rfind("/")+1:])
except ServerDisconnectedError:
logger.warning(f"下载图片服务被关闭,第 {_count} 次调用....")
await download_image(img_url, session, _count + 1)
except ClientOSError:
logger.warning(f"远程连接被关闭,第 {_count} 次调用....")
await download_image(
img_url.replace("i.pximg.net", "i.pixiv.cat"), session, _count + 1
)
ws_url = Config.get_config("pixiv", "PIXIV_NGINX_URL")
if ws_url:
img_url = img_url.replace("i.pximg.net", ws_url)
await download_image(img_url, session, _count + 1)
except TimeoutError:
logger.warning(f"下载或写入超时,第 {_count} 次调用....")
await download_image(img_url, session, _count + 1)
@@ -216,34 +239,47 @@ async def download_image(img_url: str, session: ClientSession, _count: int = 1):
async def get_image(img_url: str, user_id: int) -> str:
"""
下载图片
:param img_url:
:param user_id:
:return: 图片名称
"""
async with aiohttp.ClientSession(headers=headers) as session:
if 'https://www.pixiv.net/artworks' in img_url:
pid = img_url.rsplit('/', maxsplit=1)[-1]
if "https://www.pixiv.net/artworks" in img_url:
pid = img_url.rsplit("/", maxsplit=1)[-1]
params = {"id": pid}
for _ in range(3):
try:
async with session.get(
illust_url,
f"{HIBIAPI}/api/pixiv/illust",
params=params,
proxy=get_local_proxy(),
) as response:
if response.status == 200:
data = await response.json()
if data.get('illust'):
if data['illust']['page_count'] == 1:
img_url = data['illust']['meta_single_page']['original_image_url']
if data.get("illust"):
if data["illust"]["page_count"] == 1:
img_url = data["illust"]["meta_single_page"][
"original_image_url"
]
else:
img_url = data['illust']["meta_pages"][0]["image_urls"]["original"]
img_url = data["illust"]["meta_pages"][0][
"image_urls"
]["original"]
break
except (ClientConnectorError, TimeoutError):
pass
old_img_url = img_url
img_url = change_picture_links(img_url, PIX_IMAGE_SIZE)
img_url = change_picture_links(
img_url, Config.get_config("pix", "PIX_IMAGE_SIZE")
)
for _ in range(3):
try:
async with session.get(
img_url,
proxy=get_local_proxy(),
timeout=Config.get_config("pix", "TIMEOUT"),
) as response:
if response.status == 404:
img_url = old_img_url
@@ -257,12 +293,15 @@ async def get_image(img_url: str, user_id: int) -> str:
pass
# 检测UID或PID是否有效
async def uid_pid_exists(id_: str) -> bool:
"""
检测 pid/uid 是否有效
:param id_: pid/uid
"""
if id_.startswith("uid:"):
url = f"{HIBIAPI}/api/pixiv/member"
elif id_.startswith("pid:"):
url = illust_url
url = f"{HIBIAPI}/api/pixiv/illust"
else:
return False
params = {"id": int(id_[4:])}
@@ -274,13 +313,24 @@ async def uid_pid_exists(id_: str) -> bool:
return True
async def get_keyword_num(keyword: str) -> "int , int":
async def get_keyword_num(keyword: str) -> "int, int, int, int, int":
"""
查看图片相关 tag 数量
:param keyword: 关键词tag
"""
count, r18_count = await Pixiv.get_keyword_num(keyword.split())
count_, setu_count, r18_count_ = await OmegaPixivIllusts.get_keyword_num(keyword.split())
count_, setu_count, r18_count_ = await OmegaPixivIllusts.get_keyword_num(
keyword.split()
)
return count, r18_count, count_, setu_count, r18_count_
async def remove_image(pid: int, img_p: str) -> bool:
"""
删除置顶图片
:param pid: pid
:param img_p: 图片 p 如 p0,p1 等
"""
if img_p:
if "p" not in img_p:
img_p = f"p{img_p}"
@@ -290,6 +340,12 @@ async def remove_image(pid: int, img_p: str) -> bool:
def gen_keyword_pic(
_pass_keyword: List[str], not_pass_keyword: List[str], is_superuser: bool
):
"""
已通过或未通过的所有关键词/uid/pid
:param _pass_keyword: 通过列表
:param not_pass_keyword: 未通过列表
:param is_superuser: 是否超级用户
"""
_keyword = [
x
for x in _pass_keyword
@@ -373,10 +429,15 @@ def gen_keyword_pic(
return A.pic2bs4()
def _check_black(img_urls: List[str], black: List[str]):
def _check_black(img_urls: List[str], black: List[str]) -> bool:
"""
检测pid是否在黑名单中
:param img_urls: 图片img列表
:param black: 黑名单
:return:
"""
for b in black:
for img_url in img_urls:
# img_url = img_url[img_url.rfind('/')+1: img_url.rfind('.')]
if b in img_url:
return False
return True
+3
View File
@@ -0,0 +1,3 @@
from .pixiv_keyword_user import *
from .omega_pixiv_illusts import *
from .pixiv import *
@@ -0,0 +1,141 @@
from typing import Optional, List
from datetime import datetime
from services.db_context import db
class OmegaPixivIllusts(db.Model):
__tablename__ = "omega_pixiv_illusts"
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
pid = db.Column(db.BigInteger(), nullable=False)
uid = db.Column(db.BigInteger(), nullable=False)
title = db.Column(db.String(), nullable=False)
uname = db.Column(db.String(), nullable=False)
nsfw_tag = db.Column(db.Integer(), nullable=False)
width = db.Column(db.Integer(), nullable=False)
height = db.Column(db.Integer(), nullable=False)
tags = db.Column(db.String(), nullable=False)
url = db.Column(db.String(), nullable=False)
created_at = db.Column(db.DateTime(timezone=True))
updated_at = db.Column(db.DateTime(timezone=True))
_idx1 = db.Index("omega_pixiv_illusts_idx1", "pid", "url", unique=True)
@classmethod
async def add_image_data(
cls,
pid: int,
title: str,
width: int,
height: int,
url: str,
uid: int,
uname: str,
nsfw_tag: int,
tags: str,
created_at: datetime,
updated_at: datetime,
):
"""
说明:
添加图片信息
参数:
:param pid: pid
:param title: 标题
:param width: 宽度
:param height: 长度
:param url: url链接
:param uid: 作者uid
:param uname: 作者名称
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
:param tags: 相关tag
:param created_at: 创建日期
:param updated_at: 更新日期
"""
if not await cls.check_exists(pid):
await cls.create(
pid=pid,
title=title,
width=width,
height=height,
url=url,
uid=uid,
uname=uname,
nsfw_tag=nsfw_tag,
tags=tags,
)
return True
return False
@classmethod
async def query_images(
cls,
keywords: Optional[List[str]] = None,
uid: Optional[int] = None,
pid: Optional[int] = None,
nsfw_tag: Optional[int] = 0,
num: int = 100
) -> List[Optional["OmegaPixivIllusts"]]:
"""
说明:
查找符合条件的图片
参数:
:param keywords: 关键词
:param uid: 画师uid
:param pid: 图片pid
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
:param num: 获取图片数量
"""
if nsfw_tag is not None:
query = cls.query.where(cls.nsfw_tag == nsfw_tag)
else:
query = cls.query
if keywords:
for keyword in keywords:
query = query.where(cls.tags.contains(keyword))
elif uid:
query = query.where(cls.uid == uid)
elif pid:
query = query.where(cls.uid == pid)
query = query.order_by(db.func.random()).limit(num)
return await query.gino.all()
@classmethod
async def check_exists(cls, pid: int) -> bool:
"""
说明:
检测pid是否已存在
参数:
:param pid: 图片PID
"""
query = await cls.query.where(cls.pid == pid).gino.all()
return bool(query)
@classmethod
async def get_keyword_num(cls, tags: List[str] = None) -> "int, int, int":
"""
说明:
获取相关关键词(keyword, tag)在图库中的数量
参数:
:param tags: 关键词/Tag
"""
setattr(OmegaPixivIllusts, 'count', db.func.count(cls.pid).label('count'))
query = cls.select('count')
if tags:
for tag in tags:
query = query.where(cls.tags.contains(tag))
count = await query.where(cls.nsfw_tag == 0).gino.first()
setu_count = await query.where(cls.nsfw_tag == 1).gino.first()
r18_count = await query.where(cls.nsfw_tag == 2).gino.first()
return count[0], setu_count[0], r18_count[0]
@classmethod
async def get_all_pid(cls) -> List[int]:
"""
说明:
获取所有图片PID
"""
data = await cls.select('pid').gino.all()
return [x[0] for x in data]
+170
View File
@@ -0,0 +1,170 @@
from typing import Optional, List
from services.db_context import db
class Pixiv(db.Model):
__tablename__ = "pixiv"
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
pid = db.Column(db.BigInteger(), nullable=False)
title = db.Column(db.String(), nullable=False)
width = db.Column(db.Integer(), nullable=False)
height = db.Column(db.Integer(), nullable=False)
view = db.Column(db.Integer(), nullable=False)
bookmarks = db.Column(db.Integer(), nullable=False)
img_url = db.Column(db.String(), nullable=False)
img_p = db.Column(db.String(), nullable=False)
uid = db.Column(db.BigInteger(), nullable=False)
author = db.Column(db.String(), nullable=False)
is_r18 = db.Column(db.Boolean(), nullable=False)
tags = db.Column(db.String(), nullable=False)
_idx1 = db.Index("pixiv_idx1", "pid", "img_url", unique=True)
@classmethod
async def add_image_data(
cls,
pid: int,
title: str,
width: int,
height: int,
view: int,
bookmarks: int,
img_url: str,
img_p: str,
uid: int,
author: str,
tags: str,
):
"""
说明:
添加图片信息
参数:
:param pid: pid
:param title: 标题
:param width: 宽度
:param height: 长度
:param view: 被查看次数
:param bookmarks: 收藏数
:param img_url: url链接
:param img_p: 张数
:param uid: 作者uid
:param author: 作者名称
:param tags: 相关tag
"""
if not await cls.check_exists(pid, img_p):
await cls.create(
pid=pid,
title=title,
width=width,
height=height,
view=view,
bookmarks=bookmarks,
img_url=img_url,
img_p=img_p,
uid=uid,
author=author,
is_r18=True if "R-18" in tags else False,
tags=tags,
)
return True
return False
@classmethod
async def remove_image_data(cls, pid: int, img_p: str) -> bool:
"""
说明:
删除图片数据
参数:
:param pid: 图片pid
:param img_p: 图片pid的张数,如:p0,p1
"""
try:
if img_p:
await cls.delete.where(
(cls.pid == pid) & (cls.img_p == img_p)
).gino.status()
else:
await cls.delete.where(cls.pid == pid).gino.status()
return True
except Exception:
return False
@classmethod
async def get_all_pid(cls) -> List[int]:
"""
说明:
获取所有PID
"""
query = await cls.query.select("pid").gino.first()
pid = [x[0] for x in query]
return list(set(pid))
# 0:非r18 1:r18 2:混合
@classmethod
async def query_images(
cls,
keywords: Optional[List[str]] = None,
uid: Optional[int] = None,
pid: Optional[int] = None,
r18: Optional[int] = 0,
num: int = 100
) -> List[Optional["Pixiv"]]:
"""
说明:
查找符合条件的图片
参数:
:param keywords: 关键词
:param uid: 画师uid
:param pid: 图片pid
:param r18: 是否r18,0:非r18 1:r18 2:混合
:param num: 查找图片的数量
"""
if r18 == 0:
query = cls.query.where(cls.is_r18 == False)
elif r18 == 1:
query = cls.query.where(cls.is_r18 == True)
else:
query = cls.query
if keywords:
for keyword in keywords:
query = query.where(cls.tags.contains(keyword))
elif uid:
query = query.where(cls.uid == uid)
elif pid:
query = query.where(cls.pid == pid)
query = query.order_by(db.func.random()).limit(num)
return await query.gino.all()
@classmethod
async def check_exists(cls, pid: int, img_p: str) -> bool:
"""
说明:
检测pid是否已存在
参数:
:param pid: 图片PID
:param img_p: 张数
"""
query = await cls.query.where(
(cls.pid == pid) & (cls.img_p == img_p)
).gino.all()
return bool(query)
@classmethod
async def get_keyword_num(cls, tags: List[str] = None) -> "int, int":
"""
说明:
获取相关关键词(keyword, tag)在图库中的数量
参数:
:param tags: 关键词/Tag
"""
setattr(Pixiv, 'count', db.func.count(cls.pid).label('count'))
query = cls.select('count')
if tags:
for tag in tags:
query = query.where(cls.tags.contains(tag))
count = await query.where(cls.is_r18 == False).gino.first()
r18_count = await query.where(cls.is_r18 == True).gino.first()
return count[0], r18_count[0]
@@ -0,0 +1,127 @@
from services.db_context import db
from typing import Set, List
class PixivKeywordUser(db.Model):
__tablename__ = "pixiv_keyword_users"
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
user_qq = db.Column(db.BigInteger(), nullable=False)
group_id = db.Column(db.BigInteger(), nullable=False)
keyword = db.Column(db.String(), nullable=False)
is_pass = db.Column(db.Boolean(), default=False)
_idx1 = db.Index("pixiv_keyword_users_idx1", "keyword", unique=True)
@classmethod
async def add_keyword(
cls, user_qq: int, group_id: int, keyword: str, superusers: Set[str]
) -> bool:
"""
说明:
添加搜图的关键词
参数:
:param user_qq: qq号
:param group_id: 群号
:param keyword: 关键词
:param superusers: 是否为超级用户
"""
is_pass = True if str(user_qq) in superusers else False
if not await cls._check_keyword_exists(keyword):
await cls.create(
user_qq=user_qq, group_id=group_id, keyword=keyword, is_pass=is_pass
)
return True
return False
@classmethod
async def delete_keyword(cls, keyword: str) -> bool:
"""
说明:
删除关键词
参数:
:param keyword: 关键词
"""
if await cls._check_keyword_exists(keyword):
query = cls.query.where(cls.keyword == keyword).with_for_update()
query = await query.gino.first()
await query.delete()
return True
return False
@classmethod
async def set_keyword_pass(cls, keyword: str, is_pass: bool) -> "int, int":
"""
说明:
通过或禁用关键词
参数:
:param keyword: 关键词
:param is_pass: 通过状态
"""
if await cls._check_keyword_exists(keyword):
query = cls.query.where(cls.keyword == keyword).with_for_update()
query = await query.gino.first()
await query.update(
is_pass=is_pass,
).apply()
return query.user_qq, query.group_id
return 0, 0
@classmethod
async def get_all_user_dict(cls) -> dict:
"""
说明:
获取关键词数据库各个用户贡献的关键词字典
"""
tmp = {}
query = await cls.query.gino.all()
for user in query:
if not tmp.get(user.user_qq):
tmp[user.user_qq] = {"keyword": []}
tmp[user.user_qq]["keyword"].append(user.keyword)
return tmp
@classmethod
async def get_current_keyword(cls) -> "List[str], List[str]":
"""
说明:
获取当前通过与未通过的关键词
"""
pass_keyword = []
not_pass_keyword = []
query = await cls.query.gino.all()
for user in query:
if user.is_pass:
pass_keyword.append(user.keyword)
else:
not_pass_keyword.append(user.keyword)
return pass_keyword, not_pass_keyword
@classmethod
async def get_black_pid(cls) -> List[str]:
"""
说明:
获取黑名单PID
"""
black_pid = []
query = await cls.query.where(cls.user_qq == 114514).gino.all()
for image in query:
black_pid.append(image.keyword[6:])
return black_pid
@classmethod
async def _check_keyword_exists(cls, keyword: str) -> bool:
"""
说明:
检测关键词是否已存在
参数:
:param keyword: 关键词
"""
current_keyword = []
query = await cls.query.gino.all()
for user in query:
current_keyword.append(user.keyword)
if keyword in current_keyword:
return True
return False
+50 -50
View File
@@ -1,19 +1,18 @@
from nonebot.adapters.cqhttp.message import Message
from utils.utils import get_message_text, is_number
from configs.config import PIX_OMEGA_PIXIV_RATIO, WITHDRAW_PIX_TIME
from models.omega_pixiv_illusts import OmegaPixivIllusts
from configs.config import Config
from .model.omega_pixiv_illusts import OmegaPixivIllusts
from utils.message_builder import image
from utils.manager import withdraw_message_manager
from services.log import logger
from nonebot.adapters.cqhttp import (
Bot,
MessageEvent,
GroupMessageEvent,
PrivateMessageEvent,
)
from utils.manager import withdraw_message_manager
from nonebot.typing import T_State
from .data_source import get_image
from models.pixiv import Pixiv
from .model.pixiv import Pixiv
from nonebot import on_command
import random
@@ -55,54 +54,66 @@ __plugin_block_limit__ = {"rst": "您有PIX图片正在处理,请稍等..."}
pix = on_command("pix", aliases={"PIX", "Pix"}, priority=5, block=True)
PIX_RATIO = PIX_OMEGA_PIXIV_RATIO[0] / (
PIX_OMEGA_PIXIV_RATIO[0] + PIX_OMEGA_PIXIV_RATIO[1]
)
OMEGA_RATIO = 1 - PIX_RATIO
PIX_RATIO = None
OMEGA_RATIO = None
@pix.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
global PIX_RATIO, OMEGA_RATIO
if PIX_RATIO is None:
pix_omega_pixiv_ratio = Config.get_config("pix", "PIX_OMEGA_PIXIV_RATIO")
PIX_RATIO = pix_omega_pixiv_ratio[0] / (
pix_omega_pixiv_ratio[0] + pix_omega_pixiv_ratio[1]
)
OMEGA_RATIO = 1 - PIX_RATIO
num = 1
keyword = get_message_text(event.json())
x = keyword.split(" ")
if "-s" in x:
x.remove("-s")
nsfw_tag = 1
elif "-r" in x:
x.remove("-r")
nsfw_tag = 2
else:
nsfw_tag = 0
if nsfw_tag != 0 and str(event.user_id) not in bot.config.superusers:
await pix.finish("你不能看这些噢,这些都是是留给管理员看的...")
if len(x) > 1:
if is_number(x[-1]):
num = int(x[-1])
if num > 10:
if str(event.user_id) not in bot.config.superusers or (
str(event.user_id) in bot.config.superusers and num > 30
):
num = random.randint(1, 10)
await pix.send(f"太贪心了,就给你发 {num}张 好了")
x = x[:-1]
keyword = " ".join(x)
pix_num = int(num * PIX_RATIO) + 15 if PIX_RATIO != 0 else 0
omega_num = num - pix_num + 15
if is_number(keyword):
all_image = await Pixiv.query_images(uid=int(keyword))
if num == 1:
pix_num = 15
omega_num = 15
all_image = await Pixiv.query_images(
uid=int(keyword), num=pix_num, r18=1 if nsfw_tag == 2 else 0
) + await OmegaPixivIllusts.query_images(
uid=int(keyword), num=omega_num, nsfw_tag=nsfw_tag
)
elif keyword.lower().startswith("pid"):
pid = keyword.replace("pid", "").replace(":", "")
pid = keyword.replace("pid", "").replace(":", "").replace(":", "")
if not is_number(pid):
await pix.finish("PID必须是数字...", at_sender=True)
isr18 = 0 if isinstance(event, GroupMessageEvent) else 2
nsfw_tag = 0 if isinstance(event, GroupMessageEvent) else None
all_image = await Pixiv.query_images(pid=int(pid), r18=isr18)
all_image = await Pixiv.query_images(
pid=int(pid), r18=1 if nsfw_tag == 2 else 0
)
if not all_image:
all_image = await OmegaPixivIllusts.query_images(
pid=int(pid), nsfw_tag=nsfw_tag
)
else:
x = keyword.split()
if "-s" in x:
x.remove("-s")
nsfw_tag = 1
elif "-r" in x:
x.remove("-r")
nsfw_tag = 2
else:
nsfw_tag = 0
if nsfw_tag != 0 and str(event.user_id) not in bot.config.superusers:
await pix.finish("你不能看这些噢,这些都是是留给管理员看的...")
if len(x) > 1:
if is_number(x[-1]):
num = int(x[-1])
if num > 10:
if str(event.user_id) not in bot.config.superusers or (
str(event.user_id) in bot.config.superusers and num > 30
):
num = random.randint(1, 10)
await pix.send(f"太贪心了,就给你发 {num}张 好了")
x = x[:-1]
keyword = " ".join(x)
pix_num = int(num * PIX_RATIO) + 15 if PIX_RATIO != 0 else 0
omega_num = num - pix_num + 15
tmp = await Pixiv.query_images(
x, r18=1 if nsfw_tag == 2 else 0, num=pix_num
) + await OmegaPixivIllusts.query_images(x, nsfw_tag=nsfw_tag, num=omega_num)
@@ -124,14 +135,12 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
if isinstance(img, OmegaPixivIllusts):
img_url = img.url
author = img.uname
print(img.nsfw_tag)
elif isinstance(img, Pixiv):
img_url = img.img_url
author = img.author
pid = img.pid
title = img.title
uid = img.uid
# tags = img.tags
_img = await get_image(img_url, event.user_id)
if _img:
msg_id = await pix.send(
@@ -152,14 +161,5 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查看PIX图库PID: {pid},下载图片出错"
)
withdraw_message(event, msg_id["message_id"])
withdraw_message_manager.withdraw_message(event, msg_id, Config.get_config("pix", "WITHDRAW_PIX_MESSAGE"))
def withdraw_message(event: MessageEvent, id_: int):
if WITHDRAW_PIX_TIME[0]:
if (
(WITHDRAW_PIX_TIME[1] == 0 and isinstance(event, PrivateMessageEvent))
or (WITHDRAW_PIX_TIME[1] == 1 and isinstance(event, GroupMessageEvent))
or WITHDRAW_PIX_TIME[1] == 2
):
withdraw_message_manager.append((id_, WITHDRAW_PIX_TIME[0]))
+2 -2
View File
@@ -4,8 +4,8 @@ from services.log import logger
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
from .data_source import uid_pid_exists
from models.pixiv_keyword_user import PixivKeywordUser
from models.pixiv import Pixiv
from .model.pixiv_keyword_user import PixivKeywordUser
from .model.pixiv import Pixiv
from nonebot.permission import SUPERUSER
__zx_plugin_name__ = "PIX关键词/UID/PID添加管理 [Superuser]"
+2 -2
View File
@@ -7,8 +7,8 @@ from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from .data_source import remove_image
from models.pixiv_keyword_user import PixivKeywordUser
from models.pixiv import Pixiv
from .model.pixiv_keyword_user import PixivKeywordUser
from .model.pixiv import Pixiv
__zx_plugin_name__ = "PIX关键词/UID/PID删除管理 [Superuser]"
+1 -1
View File
@@ -4,7 +4,7 @@ from utils.message_builder import image
from nonebot.adapters.cqhttp import Bot, MessageEvent
from nonebot.typing import T_State
from .data_source import gen_keyword_pic, get_keyword_num
from models.pixiv_keyword_user import PixivKeywordUser
from .model.pixiv_keyword_user import PixivKeywordUser
import asyncio
+2 -2
View File
@@ -3,8 +3,8 @@ from utils.utils import get_message_text, is_number
from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from .data_source import start_update_image_url
from models.pixiv_keyword_user import PixivKeywordUser
from models.pixiv import Pixiv
from .model.pixiv_keyword_user import PixivKeywordUser
from .model.pixiv import Pixiv
from nonebot.adapters.cqhttp import Bot, MessageEvent
import time
@@ -1,204 +1,199 @@
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.matcher import Matcher
from nonebot import on_command
from utils.utils import get_message_text, is_number
from .data_source import get_pixiv_urls, download_pixiv_imgs, search_pixiv_urls
from services.log import logger
from nonebot.adapters.cqhttp.exception import NetworkError
from asyncio.exceptions import TimeoutError
from aiohttp.client_exceptions import ClientConnectorError
from configs.config import NICKNAME
from typing import Type
from nonebot.rule import to_me
import time
__zx_plugin_name__ = "P站排行/搜图"
__plugin_usage__ = """
usage:
P站排行:
可选参数:
类型:
1. 日排行
2. 周排行
3. 月排行
4. 原创排行
5. 新人排行
6. R18日排行
7. R18周排行
8. R18受男性欢迎排行
9. R18重口排行【慎重!】
【使用时选择参数序号即可,R18仅可私聊】
p站排行 ?[参数] ?[数量] ?[日期]
示例:
p站排行榜 [无参数默认为日榜]
p站排行榜 1
p站排行榜 1 5
p站排行榜 1 5 2018-4-25
【注意空格!!】【在线搜索会较慢】
---------------------------------
P站搜图:
搜图 [关键词] ?[数量] ?[页数=1] ?[r18](不屏蔽R-18)
示例:
搜图 樱岛麻衣
搜图 樱岛麻衣 5
搜图 樱岛麻衣 5 r18
【默认为 热度排序】
【注意空格!!】【在线搜索会较慢】【数量可能不符?可能该页数量不够,也可能被R-18屏蔽】
""".strip()
__plugin_des__ = "P站排行榜直接冲,P站搜图跟着冲"
__plugin_cmd__ = ["p站排行 ?[参数] ?[数量] ?[日期]", "搜图 [关键词] ?[数量] ?[页数=1] ?[r18](不屏蔽R-18)"]
__plugin_type__ = ("来点好康的",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 9,
"default_status": True,
"limit_superuser": False,
"cmd": ["pixiv", "p站排行", "搜图", "p站搜图", "P站搜图"],
}
__plugin_block_limit__ = {
"rst": "P站排行榜或搜图正在搜索,请不要重复触发命令..."
}
rank_dict = {
"1": "day",
"2": "week",
"3": "month",
"4": "week_original",
"5": "week_rookie",
"6": "day_r18",
"7": "week_r18",
"8": "day_male_r18",
"9": "week_r18g",
}
pixiv_rank = on_command(
"p站排行",
aliases={"P站排行榜", "p站排行榜", "P站排行榜", "P站排行"},
priority=5,
block=True,
rule=to_me(),
)
pixiv_keyword = on_command("搜图", priority=5, block=True, rule=to_me())
@pixiv_rank.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json()).strip()
msg = msg.split(" ")
msg = [m for m in msg if m]
code = 0
info_list = []
if not msg:
msg = ["1"]
if msg[0] in ["6", "7", "8", "9"]:
if event.message_type == "group":
await pixiv_rank.finish("羞羞脸!私聊里自己看!", at_sender=True)
if (n := len(msg)) == 0 or msg[0] == "":
info_list, code = await get_pixiv_urls(rank_dict.get("1"))
elif n == 1:
if msg[0] not in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
await pixiv_rank.finish("要好好输入要看什么类型的排行榜呀!", at_sender=True)
info_list, code = await get_pixiv_urls(rank_dict.get(msg[0]))
elif n == 2:
info_list, code = await get_pixiv_urls(rank_dict.get(msg[0]), int(msg[1]))
elif n == 3:
if not check_date(msg[2]):
await pixiv_rank.finish("日期格式错误了", at_sender=True)
info_list, code = await get_pixiv_urls(
rank_dict.get(msg[0]), int(msg[1]), date=msg[2]
)
else:
await pixiv_rank.finish("格式错了噢,参数不够?看看帮助?", at_sender=True)
if code != 200 and info_list:
await pixiv_rank.finish(info_list[0])
if not info_list:
await pixiv_rank.finish("没有找到啊,等等再试试吧~V", at_sender=True)
await send_image(info_list, pixiv_rank, bot, event)
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查看了P站排行榜 code:{msg[0]}"
)
@pixiv_keyword.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
if isinstance(event, GroupMessageEvent):
if "r18" in msg.lower():
await pixiv_keyword.finish("(脸红#) 你不会害羞的 八嘎!", at_sender=True)
r18 = 0 if "r18" in msg else 1
msg = msg.replace("r18", "").strip().split()
msg = [m.strip() for m in msg if m]
keyword = None
info_list = None
num = 10
page = 1
if (n := len(msg)) == 1:
keyword = msg[0]
if n > 1:
if not is_number(msg[1]):
await pixiv_keyword.finish("图片数量必须是数字!", at_sender=True)
num = int(msg[1])
if n > 2:
if not is_number(msg[2]):
await pixiv_keyword.finish("页数数量必须是数字!", at_sender=True)
page = int(msg[2])
if keyword:
info_list, code = await search_pixiv_urls(keyword, num, page, r18)
if code != 200:
await pixiv_keyword.finish(info_list[0])
if not info_list:
await pixiv_keyword.finish("没有找到啊,等等再试试吧~V", at_sender=True)
await send_image(info_list, pixiv_keyword, bot, event)
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查看了搜索 {keyword} R18:{r18}"
)
def check_date(date):
try:
time.strptime(date, "%Y-%m-%d")
return True
except:
return False
async def send_image(
info_list: list, matcher: Type[Matcher], bot: Bot, event: MessageEvent
):
if isinstance(event, GroupMessageEvent):
await pixiv_rank.send("开始下载整理数据...")
idx = 0
mes_list = []
for title, author, urls in info_list:
_message = (
f"title: {title}\nauthor: {author}\n"
+ await download_pixiv_imgs(urls, event.user_id, idx)
)
data = {
"type": "node",
"data": {
"name": f"这里是{NICKNAME}酱",
"uin": f"{bot.self_id}",
"content": _message,
},
}
mes_list.append(data)
idx += 1
await bot.send_group_forward_msg(group_id=event.group_id, messages=mes_list)
else:
for title, author, urls in info_list:
try:
await matcher.send(
f"title: {title}\n"
f"author: {author}\n"
+ await download_pixiv_imgs(urls, event.user_id)
)
except (NetworkError, TimeoutError, ClientConnectorError):
await matcher.send("这张图网络直接炸掉了!", at_sender=True)
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.matcher import Matcher
from nonebot import on_command
from utils.utils import get_message_text, is_number
from .data_source import get_pixiv_urls, download_pixiv_imgs, search_pixiv_urls
from services.log import logger
from nonebot.adapters.cqhttp.exception import NetworkError
from asyncio.exceptions import TimeoutError
from aiohttp.client_exceptions import ClientConnectorError
from utils.message_builder import custom_forward_msg
from configs.config import Config
from typing import Type
from nonebot.rule import to_me
import time
__zx_plugin_name__ = "P站排行/搜图"
__plugin_usage__ = """
usage:
P站排行:
可选参数:
类型:
1. 日排行
2. 周排行
3. 月排行
4. 原创排行
5. 新人排行
6. R18日排行
7. R18周排行
8. R18受男性欢迎排行
9. R18重口排行【慎重!】
【使用时选择参数序号即可,R18仅可私聊】
p站排行 ?[参数] ?[数量] ?[日期]
示例:
p站排行榜 [无参数默认为日榜]
p站排行榜 1
p站排行榜 1 5
p站排行榜 1 5 2018-4-25
【注意空格!!】【在线搜索会较慢】
---------------------------------
P站搜图:
搜图 [关键词] ?[数量] ?[页数=1] ?[r18](不屏蔽R-18)
示例:
搜图 樱岛麻衣
搜图 樱岛麻衣 5
搜图 樱岛麻衣 5 r18
【默认为 热度排序】
【注意空格!!】【在线搜索会较慢】【数量可能不符?可能该页数量不够,也可能被R-18屏蔽】
""".strip()
__plugin_des__ = "P站排行榜直接冲,P站搜图跟着冲"
__plugin_cmd__ = ["p站排行 ?[参数] ?[数量] ?[日期]", "搜图 [关键词] ?[数量] ?[页数=1] ?[r18](不屏蔽R-18)"]
__plugin_type__ = ("来点好康的",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 9,
"default_status": True,
"limit_superuser": False,
"cmd": ["p站排行", "搜图", "p站搜图", "P站搜图"],
}
__plugin_block_limit__ = {"rst": "P站排行榜或搜图正在搜索,请不要重复触发命令..."}
Config.add_plugin_config(
"hibiapi",
"HIBIAPI",
"https://api.obfs.dev",
help_="如果没有自建或其他hibiapi请不要修改",
default_value="https://api.obfs.dev",
)
rank_dict = {
"1": "day",
"2": "week",
"3": "month",
"4": "week_original",
"5": "week_rookie",
"6": "day_r18",
"7": "week_r18",
"8": "day_male_r18",
"9": "week_r18g",
}
pixiv_rank = on_command(
"p站排行",
aliases={"P站排行榜", "p站排行榜", "P站排行榜", "P站排行"},
priority=5,
block=True,
rule=to_me(),
)
pixiv_keyword = on_command("搜图", priority=5, block=True, rule=to_me())
@pixiv_rank.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json()).strip()
msg = msg.split(" ")
msg = [m for m in msg if m]
code = 0
info_list = []
if not msg:
msg = ["1"]
if msg[0] in ["6", "7", "8", "9"]:
if event.message_type == "group":
await pixiv_rank.finish("羞羞脸!私聊里自己看!", at_sender=True)
if (n := len(msg)) == 0 or msg[0] == "":
info_list, code = await get_pixiv_urls(rank_dict.get("1"))
elif n == 1:
if msg[0] not in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
await pixiv_rank.finish("要好好输入要看什么类型的排行榜呀!", at_sender=True)
info_list, code = await get_pixiv_urls(rank_dict.get(msg[0]))
elif n == 2:
info_list, code = await get_pixiv_urls(rank_dict.get(msg[0]), int(msg[1]))
elif n == 3:
if not check_date(msg[2]):
await pixiv_rank.finish("日期格式错误了", at_sender=True)
info_list, code = await get_pixiv_urls(
rank_dict.get(msg[0]), int(msg[1]), date=msg[2]
)
else:
await pixiv_rank.finish("格式错了噢,参数不够?看看帮助?", at_sender=True)
if code != 200 and info_list:
await pixiv_rank.finish(info_list[0])
if not info_list:
await pixiv_rank.finish("没有找到啊,等等再试试吧~V", at_sender=True)
await send_image(info_list, pixiv_rank, bot, event)
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查看了P站排行榜 code:{msg[0]}"
)
@pixiv_keyword.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
if isinstance(event, GroupMessageEvent):
if "r18" in msg.lower():
await pixiv_keyword.finish("(脸红#) 你不会害羞的 八嘎!", at_sender=True)
r18 = 0 if "r18" in msg else 1
msg = msg.replace("r18", "").strip().split()
msg = [m.strip() for m in msg if m]
keyword = None
info_list = None
num = 10
page = 1
if (n := len(msg)) == 1:
keyword = msg[0]
if n > 1:
if not is_number(msg[1]):
await pixiv_keyword.finish("图片数量必须是数字!", at_sender=True)
num = int(msg[1])
if n > 2:
if not is_number(msg[2]):
await pixiv_keyword.finish("页数数量必须是数字!", at_sender=True)
page = int(msg[2])
if keyword:
info_list, code = await search_pixiv_urls(keyword, num, page, r18)
if code != 200:
await pixiv_keyword.finish(info_list[0])
if not info_list:
await pixiv_keyword.finish("没有找到啊,等等再试试吧~V", at_sender=True)
await send_image(info_list, pixiv_keyword, bot, event)
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查看了搜索 {keyword} R18:{r18}"
)
def check_date(date):
try:
time.strptime(date, "%Y-%m-%d")
return True
except:
return False
async def send_image(
info_list: list, matcher: Type[Matcher], bot: Bot, event: MessageEvent
):
if isinstance(event, GroupMessageEvent):
await pixiv_rank.send("开始下载整理数据...")
idx = 0
mes_list = []
for title, author, urls in info_list:
_message = f"title: {title}\nauthor: {author}\n" + await download_pixiv_imgs(urls, event.user_id, idx)
mes_list.append(_message)
idx += 1
mes_list = custom_forward_msg(mes_list, bot.self_id)
await bot.send_group_forward_msg(group_id=event.group_id, messages=mes_list)
else:
for title, author, urls in info_list:
try:
await matcher.send(
f"title: {title}\n"
f"author: {author}\n"
+ await download_pixiv_imgs(urls, event.user_id)
)
except (NetworkError, TimeoutError, ClientConnectorError):
await matcher.send("这张图网络直接炸掉了!", at_sender=True)
@@ -1,131 +1,161 @@
from configs.path_config import IMAGE_PATH
from utils.utils import get_local_proxy
from utils.message_builder import image
from asyncio.exceptions import TimeoutError
from configs.config import HIBIAPI
from aiohttp.client_exceptions import ClientConnectorError
from typing import Optional
from pathlib import Path
import aiohttp
import aiofiles
import platform
if platform.system() == "Windows":
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
rank_url = f"{HIBIAPI}/api/pixiv/rank"
search_url = f"{HIBIAPI}/api/pixiv/search"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
async def get_pixiv_urls(
mode: str, num: int = 10, page: int = 1, date: Optional[str] = None
) -> "list, int":
params = {"mode": mode, "page": page}
if date:
params["date"] = date
return await parser_data(rank_url, num, params, 'rank')
async def search_pixiv_urls(
keyword: str, num: int, page: int, r18: int
) -> "list, list":
params = {"word": keyword, 'page': page}
return await parser_data(search_url, num, params, 'search', r18)
async def parser_data(url: str, num: int, params: dict, type_: str, r18: int = 0) -> "list, int":
info_list = []
async with aiohttp.ClientSession() as session:
for _ in range(3):
try:
async with session.get(
url, params=params, proxy=get_local_proxy(), timeout=5
) as response:
if response.status == 200:
data = await response.json()
if data.get("illusts"):
data = data["illusts"]
break
except (TimeoutError, ClientConnectorError):
pass
else:
return ["网络不太好?没有该页数?也许过一会就好了..."], 998
num = num if num < 30 else 30
data = data[:num]
for x in data:
if type_ == 'search' and r18 == 1:
if 'R-18' in str(x['tags']):
continue
title = x["title"]
author = x["user"]["name"]
urls = []
if x["page_count"] == 1:
urls.append(x["image_urls"]["large"])
else:
for j in x["meta_pages"]:
urls.append(j["image_urls"]["large"])
info_list.append((title, author, urls))
return info_list, 200
async def download_pixiv_imgs(
urls: list, user_id: int, forward_msg_index: int = None
) -> str:
result = ""
index = 0
for url in urls:
url = url.replace('_webp', '')
async with aiohttp.ClientSession(headers=headers) as session:
for _ in range(3):
try:
async with session.get(
url, proxy=get_local_proxy(), timeout=3
) as response:
if response.status == 200:
try:
file = (
f"{IMAGE_PATH}/temp/{user_id}_{forward_msg_index}_{index}_pixiv.jpg"
if forward_msg_index is not None
else f"{IMAGE_PATH}/temp/{user_id}_{index}_pixiv.jpg"
)
file = Path(file)
if forward_msg_index is not None:
async with aiofiles.open(
file,
"wb",
) as f:
await f.write(await response.read())
result += image(
f"{user_id}_{forward_msg_index}_{index}_pixiv.jpg",
"temp",
)
else:
async with aiofiles.open(
file,
"wb",
) as f:
await f.write(await response.read())
result += image(
f"{user_id}_{index}_pixiv.jpg", "temp"
)
index += 1
break
except OSError:
file.unlink()
except (TimeoutError, ClientConnectorError):
# result += '\n这张图下载失败了..\n'
pass
else:
result += "\n这张图下载失败了..\n"
return result
from configs.path_config import IMAGE_PATH
from utils.utils import get_local_proxy
from utils.message_builder import image
from asyncio.exceptions import TimeoutError
from configs.config import Config
from aiohttp.client_exceptions import ClientConnectorError
from typing import Optional
from pathlib import Path
import aiohttp
import aiofiles
import platform
if platform.system() == "Windows":
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
async def get_pixiv_urls(
mode: str, num: int = 10, page: int = 1, date: Optional[str] = None
) -> "list, int":
"""
拿到pixiv rank图片url
:param mode: 模式
:param num: 数量
:param page: 页数
:param date: 日期
"""
params = {"mode": mode, "page": page}
if date:
params["date"] = date
hibiapi = Config.get_config("hibiapi", "HIBIAPI")
hibiapi = hibiapi[:-1] if hibiapi[-1] == '/' else hibiapi
rank_url = f"{hibiapi}/api/pixiv/rank"
return await parser_data(rank_url, num, params, 'rank')
async def search_pixiv_urls(
keyword: str, num: int, page: int, r18: int
) -> "list, list":
"""
搜图图片的url
:param keyword: 关键词
:param num: 数量
:param page: 页数
:param r18: 是否r18
"""
params = {"word": keyword, 'page': page}
hibiapi = Config.get_config("hibiapi", "HIBIAPI")
hibiapi = hibiapi[:-1] if hibiapi[-1] == '/' else hibiapi
search_url = f"{hibiapi}/api/pixiv/search"
return await parser_data(search_url, num, params, 'search', r18)
async def parser_data(url: str, num: int, params: dict, type_: str, r18: int = 0) -> "list, int":
"""
解析数据
:param url: hibiapi搜索url
:param num: 数量
:param params: 参数
:param type_: 类型,rank或search
:param r18: 是否r18
"""
info_list = []
async with aiohttp.ClientSession() as session:
for _ in range(3):
try:
async with session.get(
url, params=params, proxy=get_local_proxy(), timeout=5
) as response:
if response.status == 200:
data = await response.json()
if data.get("illusts"):
data = data["illusts"]
break
except (TimeoutError, ClientConnectorError):
pass
else:
return ["网络不太好?没有该页数?也许过一会就好了..."], 998
num = num if num < 30 else 30
data = data[:num]
for x in data:
if type_ == 'search' and r18 == 1:
if 'R-18' in str(x['tags']):
continue
title = x["title"]
author = x["user"]["name"]
urls = []
if x["page_count"] == 1:
urls.append(x["image_urls"]["large"])
else:
for j in x["meta_pages"]:
urls.append(j["image_urls"]["large"])
info_list.append((title, author, urls))
return info_list, 200
async def download_pixiv_imgs(
urls: list, user_id: int, forward_msg_index: int = None
) -> str:
"""
下载图片
:param urls: 图片链接
:param user_id: 用户id
:param forward_msg_index: 转发消息中的图片排序
"""
result = ""
index = 0
for url in urls:
url = url.replace('_webp', '')
async with aiohttp.ClientSession(headers=headers) as session:
for _ in range(3):
try:
async with session.get(
url, proxy=get_local_proxy(), timeout=3
) as response:
if response.status == 200:
try:
file = (
f"{IMAGE_PATH}/temp/{user_id}_{forward_msg_index}_{index}_pixiv.jpg"
if forward_msg_index is not None
else f"{IMAGE_PATH}/temp/{user_id}_{index}_pixiv.jpg"
)
file = Path(file)
if forward_msg_index is not None:
async with aiofiles.open(
file,
"wb",
) as f:
await f.write(await response.read())
result += image(
f"{user_id}_{forward_msg_index}_{index}_pixiv.jpg",
"temp",
)
else:
async with aiofiles.open(
file,
"wb",
) as f:
await f.write(await response.read())
result += image(
f"{user_id}_{index}_pixiv.jpg", "temp"
)
index += 1
break
except OSError:
file.unlink()
except (TimeoutError, ClientConnectorError):
# result += '\n这张图下载失败了..\n'
pass
else:
result += "\n这张图下载失败了..\n"
return result
-98
View File
@@ -1,98 +0,0 @@
from nonebot import on_command
from nonebot.adapters.cqhttp.permission import PRIVATE
from .data_source import from_reimu_get_info
from services.log import logger
from nonebot.adapters.cqhttp import Bot, PrivateMessageEvent
from nonebot.typing import T_State
from utils.utils import is_number, get_message_text, UserBlockLimiter, scheduler
from models.count_user import UserCount
from configs.config import COUNT_PER_DAY_REIMU, NICKNAME
__zx_plugin_name__ = "上车"
__plugin_usage__ = """
usage:
* 请各位使用后不要转发 *
* 大部分解压密码是⑨ *
/ 并不推荐小色批使用此功能[主要是不够色,目的不够明确] /
指令:
上车 ?[page] [目的地]
示例:上车 萝莉
示例:上车 5 萝莉: 该目的地第5页停车场
ps: 请尽量提供具体的目的地名称
""".strip()
__plugin_des__ = "都坐稳了,老司机焊死了车门![仅限私聊]"
__plugin_cmd__ = ["上车 ?[page] [目的地]"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["上车"],
}
_ulmt = UserBlockLimiter()
reimu = on_command("上车", permission=PRIVATE, block=True, priority=1)
@reimu.args_parser
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
if get_message_text(event.json()) in ["取消", "算了"]:
await reimu.finish("已取消操作..", at_sender=True)
if not get_message_text(event.json()):
await reimu.reject("没时间等了!快说你要去哪里?", at_sender=True)
state["keyword"] = get_message_text(event.json())
state["page"] = 1
@reimu.handle()
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
if str(event.get_message()) in ["帮助"]:
await reimu.finish(__plugin_usage__)
if await UserCount.check_count(event.user_id, "reimu", COUNT_PER_DAY_REIMU):
await reimu.finish("今天已经没车了,请明天再来...", at_sender=True)
if _ulmt.check(event.user_id):
await reimu.finish("您还没下车呢,请稍等...", at_sender=True)
_ulmt.set_true(event.user_id)
msg = get_message_text(event.json())
args = msg.split(" ")
if msg in ["!", "!", "?", "?", ",", ",", ".", "。"]:
await reimu.finish(__plugin_usage__)
if msg:
if len(args) > 1 and is_number(args[0]):
state["keyword"] = args[1]
state["page"] = args[0]
else:
state["keyword"] = msg
state["page"] = 1
@reimu.got("keyword", "你的目的地是哪?")
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
try:
keyword = state["keyword"]
page = state["page"]
await UserCount.add_count(event.user_id, "reimu")
await reimu.send(
f"已经帮你关好车门了,请等待发车(不加{NICKNAME}好友的话是欣赏不到旅途的风景的)", at_sender=True
)
reimu_report = await from_reimu_get_info(keyword, page)
if reimu_report:
await reimu.send(reimu_report)
else:
logger.error("Not found reimuInfo")
await reimu.send("没找着")
_ulmt.set_false(event.user_id)
except:
_ulmt.set_false(event.user_id)
@scheduler.scheduled_job(
"cron",
hour=0,
minute=1,
)
async def _():
await UserCount.reset_count()
-112
View File
@@ -1,112 +0,0 @@
from lxml import etree
import time
import aiohttp
from services.log import logger
from configs.config import MAXINFO_REIMU
from utils.user_agent import get_user_agent
from utils.utils import get_local_proxy
from asyncio.exceptions import TimeoutError
async def from_reimu_get_info(key_word: str, page: int) -> str:
if "miku" in key_word.lower():
logger.warning("Taboo words are being triggered")
return ''
repass = ""
url = f"https://blog.reimu.net/search/{key_word}/page/{page}"
url_s = "https://blog.reimu.net/"
# try:
# if key_word == "最近的存档":
# logger.debug("Now starting get the {}".format(url_s))
# repass = await get_repass(url_s)
# else:
# logger.debug("Now starting get the {}".format(url))
# repass = await get_repass(url)
# except TimeoutError as e:
# logger.error("Timeout! {}".format(e))
#
# return repass
# async def get_repass(url: str) -> str:
# repass = ""
# info = "[Note]注意大部分资源解压密码为⑨\n"
# fund = None
# print(url)
# async with aiohttp.ClientSession(headers=get_user_agent()) as session:
# async with session.get(url, proxy=get_local_proxy(), timeout=15) as response:
# html = etree.HTML(await response.text())
#
# fund_l = html.xpath('//h1[@class="page-title"]/text()')
# if fund_l:
# fund = fund_l[0]
# if fund == "未找到":
# return "老司机也找不到路了……"
# else:
# pass
#
# headers = html.xpath("//article/header/h2/a/text()")
# urls = html.xpath("//article/header/h2/a/@href")
# logger.debug("Now get {} post from search page".format(len(headers)))
#
# headers_d = []
# urls_d = []
# for i, header in enumerate(headers):
# if check_need_list(header):
# headers_d.append(headers[i])
# urls_d.append(urls[i])
# else:
# logger.debug(
# "This title {} does not meet the requirements".format(header)
# )
#
# header_len = len(headers_d)
# logger.debug("Get {} post after processing".format(header_len))
# if header_len > MAXINFO_REIMU:
# headers_d = headers_d[:MAXINFO_REIMU]
# urls_d = urls_d[:MAXINFO_REIMU]
#
# for h_s, url_s in zip(headers_d, urls_d):
# if h_s != "审核结果存档":
# time.sleep(1.5)
# putline = await get_son_html_info(h_s, url_s)
# if putline:
# if repass:
# repass = "\n\n- - - - - - - - \n".join([repass, putline])
# else:
# repass = putline
# else:
# logger.info("审核归档页面已跳过")
#
# if repass:
# repass = info + repass
# return repass
#
#
# async def get_son_html_info(h_s, url_s) -> str:
# repass = ""
# logger.debug("Now starting get the {}".format(url_s))
# async with aiohttp.ClientSession(headers=get_user_agent()) as session:
# async with session.get(url_s, proxy=get_local_proxy(), timeout=15) as response:
# html = etree.HTML(await response.text())
# pres = html.xpath('//div[@class="entry-content"]/pre/text()')
# a_texts = html.xpath('//div[@class="entry-content"]/pre//a/text()')
# a_hrefs = html.xpath('//div[@class="entry-content"]/pre//a/@href')
#
# if pres and a_texts and a_hrefs:
# while "" in pres:
# pres.remove("")
#
# repass = "【资源名称】 {}\n\n{}".format(h_s, pres[0].strip())
# for i, (a_t_s, a_h_s) in enumerate(zip(a_texts, a_hrefs)):
# a = "\n {} {} {} ".format(a_t_s, a_h_s, pres[i + 1].strip())
# repass += a
# else:
# logger.warning("Not get putline from {}".format(url_s))
#
# return repass
+37 -15
View File
@@ -5,13 +5,13 @@ from nonebot.adapters.cqhttp import GROUP, Bot, GroupMessageEvent, Message
from nonebot.typing import T_State
from utils.utils import get_message_text, is_number, get_message_at
from models.group_member_info import GroupInfoUser
from utils.message_builder import at
from models.russian_user import RussianUser
from utils.message_builder import at, image
from .model import RussianUser
from models.bag_user import BagUser
from services.log import logger
import time
from .data_source import rank
from configs.config import MAX_RUSSIAN_BET_GOLD, NICKNAME
from configs.config import NICKNAME, Config
__zx_plugin_name__ = "俄罗斯轮盘"
__plugin_usage__ = """
@@ -47,6 +47,13 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["俄罗斯轮盘", "装弹"],
}
__plugin_configs__ = {
"MAX_RUSSIAN_BET_GOLD": {
"value": 1000,
"help": "俄罗斯轮盘最大赌注金额",
"default_value": 1000,
}
}
rs_player = {}
@@ -228,7 +235,7 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
and rs_player[event.group_id][2]
and time.time() - rs_player[event.group_id]["time"] > 30
):
await shot.send("决斗已过时,强行结算...")
await russian.send("决斗已过时,强行结算...")
await end_game(bot, event)
if (
not rs_player[event.group_id][2]
@@ -250,11 +257,15 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
msg = msg[0].strip()
if is_number(msg) and not (int(msg) < 1 or int(msg) > 6):
state["bullet_num"] = int(msg)
if is_number(money) and 0 < int(money) <= MAX_RUSSIAN_BET_GOLD:
if is_number(money) and 0 < int(money) <= Config.get_config(
"russian", "MAX_RUSSIAN_BET_GOLD"
):
state["money"] = int(money)
else:
state["money"] = 200
await russian.send(f"赌注金额超过限制({MAX_RUSSIAN_BET_GOLD}),已改为200(默认)")
await russian.send(
f"赌注金额超过限制({Config.get_config('russian', 'MAX_RUSSIAN_BET_GOLD')}),已改为200(默认)"
)
state["at"] = get_message_at(event.json())
@@ -267,8 +278,11 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
user_money = await BagUser.get_gold(event.user_id, event.group_id)
if bullet_num < 0 or bullet_num > 6:
await russian.reject("子弹数量必须大于0小于7!速速重新装弹!")
if money > MAX_RUSSIAN_BET_GOLD:
await russian.finish(f"太多了!单次金额不能超过{MAX_RUSSIAN_BET_GOLD}!", at_sender=True)
if money > Config.get_config("russian", "MAX_RUSSIAN_BET_GOLD"):
await russian.finish(
f"太多了!单次金额不能超过{Config.get_config('russian', 'MAX_RUSSIAN_BET_GOLD')}!",
at_sender=True,
)
if money > user_money:
await russian.finish("你没有足够的钱支撑起这场挑战", at_sender=True)
@@ -433,6 +447,7 @@ async def end_game(bot: Bot, event: GroupMessageEvent):
for x in rs_player[event.group_id]["bullet"]:
bullet_str += "__ " if x == 0 else "| "
logger.info(f"俄罗斯轮盘:胜者:{win_name} - 败者:{lose_name} - 金币:{money}")
rs_player[event.group_id] = {}
await bot.send(
event,
message=f"结算:\n"
@@ -449,7 +464,6 @@ async def end_game(bot: Bot, event: GroupMessageEvent):
f"哼哼,{NICKNAME}从中收取了 {float(rand)}%({fee}金币) 作为手续费!\n"
f"子弹排列:{bullet_str[:-1]}",
)
rs_player[event.group_id] = {}
@record.handle()
@@ -471,18 +485,26 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
@russian_rank.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
num = get_message_text(event.json())
if is_number(num) and 51 > int(num) > 10:
num = int(num)
else:
num = 10
rank_image = None
if state["_prefix"]["raw_command"] in ["胜场排行", "胜利排行"]:
await russian_rank.finish(await rank(event.group_id, "win_rank"))
rank_image = await rank(event.group_id, "win_rank", num)
if state["_prefix"]["raw_command"] in ["败场排行", "失败排行"]:
await russian_rank.finish(await rank(event.group_id, "lose_rank"))
rank_image = await rank(event.group_id, "lose_rank", num)
if state["_prefix"]["raw_command"] == "欧洲人排行":
await russian_rank.finish(await rank(event.group_id, "make_money"))
rank_image = await rank(event.group_id, "make_money", num)
if state["_prefix"]["raw_command"] == "慈善家排行":
await russian_rank.finish(await rank(event.group_id, "spend_money"))
rank_image = await rank(event.group_id, "spend_money", num)
if state["_prefix"]["raw_command"] == "最高连胜排行":
await russian_rank.finish(await rank(event.group_id, "max_winning_streak"))
rank_image = await rank(event.group_id, "max_winning_streak", num)
if state["_prefix"]["raw_command"] == "最高连败排行":
await russian_rank.finish(await rank(event.group_id, "max_losing_streak"))
rank_image = await rank(event.group_id, "max_losing_streak", num)
if rank_image:
await russian_rank.send(image(b64=rank_image.pic2bs4()))
# 随机子弹排列
+13 -11
View File
@@ -1,32 +1,34 @@
from models.russian_user import RussianUser
from .model import RussianUser
from typing import Optional
from utils.data_utils import init_rank
from utils.image_utils import CreateMat
async def rank(group_id: int, itype) -> str:
async def rank(group_id: int, itype: str, num: int) -> Optional[CreateMat]:
all_users = await RussianUser.get_all_user(group_id)
all_user_id = [user.user_qq for user in all_users]
if itype == 'win_rank':
rank_name = '\t胜场排行榜\n'
rank_name = '胜场排行榜'
all_user_data = [user.win_count for user in all_users]
elif itype == 'lose_rank':
rank_name = '\t败场排行榜\n'
rank_name = '败场排行榜'
all_user_data = [user.fail_count for user in all_users]
elif itype == 'make_money':
rank_name = '\t赢取金币排行榜\n'
rank_name = '赢取金币排行榜'
all_user_data = [user.make_money for user in all_users]
elif itype == 'spend_money':
rank_name = '\t输掉金币排行榜\n'
rank_name = '输掉金币排行榜'
all_user_data = [user.lose_money for user in all_users]
elif itype == 'max_winning_streak':
rank_name = '\t最高连胜排行榜\n'
rank_name = '最高连胜排行榜'
all_user_data = [user.max_winning_streak for user in all_users]
else:
rank_name = '\t最高连败排行榜\n'
rank_name = '最高连败排行榜'
all_user_data = [user.max_losing_streak for user in all_users]
rst = ''
rst = None
if all_users:
rst = await init_rank(all_user_id, all_user_data, group_id)
return rank_name + rst
rst = await init_rank(rank_name, all_user_id, all_user_data, group_id, num)
return rst
+129
View File
@@ -0,0 +1,129 @@
from services.db_context import db
from typing import List
class RussianUser(db.Model):
__tablename__ = "russian_users"
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
user_qq = db.Column(db.BigInteger(), nullable=False)
group_id = db.Column(db.BigInteger(), nullable=False)
win_count = db.Column(db.Integer(), default=0)
fail_count = db.Column(db.Integer(), default=0)
make_money = db.Column(db.Integer(), default=0)
lose_money = db.Column(db.Integer(), default=0)
winning_streak = db.Column(db.Integer(), default=0)
losing_streak = db.Column(db.Integer(), default=0)
max_winning_streak = db.Column(db.Integer(), default=0)
max_losing_streak = db.Column(db.Integer(), default=0)
_idx1 = db.Index("russian_group_users_idx1", "user_qq", "group_id", unique=True)
@classmethod
async def ensure(cls, user_qq: int, group_id: int) -> "RussianUser":
"""
说明:
获取用户对象
参数:
:param user_qq: qq号
:param group_id: 群号
"""
user = (
await cls.query.where((cls.user_qq == user_qq) & (cls.group_id == group_id))
.with_for_update()
.gino.first()
)
return user or await cls.create(user_qq=user_qq, group_id=group_id)
@classmethod
async def add_count(cls, user_qq: int, group_id: int, itype: str) -> bool:
"""
说明:
添加用户输赢次数
说明:
:param user_qq: qq号
:param group_id: 群号
:param itype: 输或赢 'win' or 'lose'
"""
try:
user = (
await cls.query.where(
(cls.user_qq == user_qq) & (cls.group_id == group_id)
)
.with_for_update()
.gino.first()
)
if not user:
user = await cls.create(user_qq=user_qq, group_id=group_id)
if itype == "win":
_max = (
user.max_winning_streak
if user.max_winning_streak > user.winning_streak + 1
else user.winning_streak + 1
)
await user.update(
win_count=user.win_count + 1,
winning_streak=user.winning_streak + 1,
losing_streak=0,
max_winning_streak=_max
).apply()
elif itype == "lose":
_max = (
user.max_losing_streak
if user.max_losing_streak > user.losing_streak + 1
else user.losing_streak + 1
)
await user.update(
fail_count=user.fail_count + 1,
losing_streak=user.losing_streak + 1,
winning_streak=0,
max_losing_streak=_max,
).apply()
return True
except Exception:
return False
@classmethod
async def money(cls, user_qq: int, group_id: int, itype: str, count: int) -> bool:
"""
说明:
添加用户输赢金钱
参数:
:param user_qq: qq号
:param group_id: 群号
:param itype: 输或赢 'win' or 'lose'
:param count: 金钱数量
"""
try:
user = (
await cls.query.where(
(cls.user_qq == user_qq) & (cls.group_id == group_id)
)
.with_for_update()
.gino.first()
)
if not user:
user = await cls.create(user_qq=user_qq, group_id=group_id)
if itype == "win":
await user.update(
make_money=user.make_money + count,
).apply()
elif itype == "lose":
await user.update(
lose_money=user.lose_money + count,
).apply()
return True
except Exception:
return False
@classmethod
async def get_all_user(cls, group_id: int) -> List["RussianUser"]:
"""
说明:
获取该群所有用户对象
参数:
:param group_id: 群号
"""
users = await cls.query.where((cls.group_id == group_id)).gino.all()
return users
+11 -8
View File
@@ -3,15 +3,15 @@ from .data_source import from_anime_get_info
from services.log import logger
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
from configs.config import MAXINFO_GROUP_ANIME, MAXINFO_PRIVATE_ANIME
from configs.config import Config
from utils.utils import get_message_text
from utils.message_builder import custom_forward_msg
__zx_plugin_name__ = "搜番"
__plugin_usage__ = f"""
usage:
搜索动漫资源
普通的搜番群内使用此功能只返还 {MAXINFO_GROUP_ANIME} 个结果,私聊返还 {MAXINFO_PRIVATE_ANIME} 个结果(绝不能打扰老色批们看色图!)
指令:
搜番 [番剧名称或者关键词]
示例:搜番 刀剑神域
@@ -27,8 +27,9 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["搜番"],
}
__plugin_block_limit__ = {
"rst": "搜索还未完成,不要重复触发!"
__plugin_block_limit__ = {"rst": "搜索还未完成,不要重复触发!"}
__plugin_configs__ = {
"SEARCH_ANIME_MAX_INFO": {"value": 20, "help": "搜索动漫返回的最大数量", "default_value": 20}
}
search_anime = on_command("搜番", aliases={"搜动漫"}, priority=5, block=True)
@@ -54,12 +55,14 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
await search_anime.send(f"开始搜番 {key_word}", at_sender=True)
anime_report = await from_anime_get_info(
key_word,
MAXINFO_GROUP_ANIME
if isinstance(event, GroupMessageEvent)
else MAXINFO_PRIVATE_ANIME,
Config.get_config("search_anime", "SEARCH_ANIME_MAX_INFO"),
)
if anime_report:
await search_anime.send(anime_report)
if isinstance(event, GroupMessageEvent):
mes_list = custom_forward_msg(anime_report, bot.self_id)
await bot.send_group_forward_msg(group_id=event.group_id, messages=mes_list)
else:
await search_anime.send("\n\n".join(anime_report))
logger.info(
f"USER {event.user_id} GROUP"
f" {event.group_id if isinstance(event, GroupMessageEvent) else 'private'} 搜索番剧 {key_word} 成功"
+9 -11
View File
@@ -2,12 +2,13 @@ from lxml import etree
import feedparser
from urllib import parse
from services.log import logger
from typing import List
import aiohttp
import time
from utils.utils import get_local_proxy
async def from_anime_get_info(key_word: str, max_: int) -> str:
async def from_anime_get_info(key_word: str, max_: int) -> List[str]:
s_time = time.time()
repass = ""
url = "https://share.dmhy.org/topics/rss/rss.xml?keyword=" + parse.quote(key_word)
@@ -15,15 +16,16 @@ async def from_anime_get_info(key_word: str, max_: int) -> str:
repass = await get_repass(url, max_)
except Exception as e:
logger.error("Timeout! {}".format(e))
return f"搜索 {key_word} 结果(耗时 {int(time.time() - s_time)} 秒):\n" + repass
repass.insert(0, f"搜索 {key_word} 结果(耗时 {int(time.time() - s_time)} 秒):\n")
return repass
async def get_repass(url: str, max_: int) -> str:
putline = []
async def get_repass(url: str, max_: int) -> List[str]:
put_line = []
async with aiohttp.ClientSession() as session:
async with session.get(url, proxy=get_local_proxy(), timeout=20) as response:
d = feedparser.parse(await response.text())
max_ = max_ if max_ < len([e.link for e in d.entries]) else len([e.link for e in d.entries])
url_list = [e.link for e in d.entries][:max_]
for u in url_list:
try:
@@ -44,15 +46,11 @@ async def get_repass(url: str, max_: int) -> str:
.replace("\t", "")
)
size = item[3].xpath("string(.)")[5:].strip()
putline.append(
put_line.append(
"【{}】| {}\n【{}】| {}".format(class_a, title, size, magent)
)
except Exception as e:
logger.warning(f"搜番超时 e:{e}")
repass = "\n\n".join(putline)
return repass
return put_line
# print(asyncio.get_event_loop().run_until_complete(from_anime_get_info('进击的巨人', 1234556)))
+13 -6
View File
@@ -28,6 +28,19 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["查询皮肤"],
}
__plugin_block_limit__ = {
"rst": "您有皮肤正在搜索,请稍等..."
}
__plugin_configs__ = {
"BUFF_PROXY": {
"value": None,
"help": "BUFF代理,有些厂ip可能被屏蔽"
},
"COOKIE": {
"value": None,
"help": "BUFF的账号cookie"
}
}
search_skin = on_command("查询皮肤", aliases={"皮肤查询"}, priority=5, block=True)
@@ -45,8 +58,6 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
if str(event.get_message()) in ["帮助"]:
await search_skin.finish(__plugin_usage__)
raw_arg = get_message_text(event.json())
if _ulmt.check(event.user_id):
await search_skin.finish("您有皮肤正在搜索,请稍等...", at_sender=True)
if raw_arg:
args = raw_arg.split(" ")
if len(args) >= 2:
@@ -58,7 +69,6 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
@search_skin.got("skin", prompt="要查询该武器的什么皮肤呢?")
async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
result = ""
_ulmt.set_true(event.user_id)
if state["name"] in ["ak", "ak47"]:
state["name"] = "ak-47"
name = state["name"] + " | " + state["skin"]
@@ -67,7 +77,6 @@ async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
except FileNotFoundError:
await search_skin.finish(f'请先对{NICKNAME}说"设置cookie"来设置cookie!')
if status_code in [996, 997, 998]:
_ulmt.set_false(event.user_id)
await search_skin.finish(result)
if result:
logger.info(
@@ -75,7 +84,6 @@ async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询皮肤:"
+ name
)
_ulmt.set_false(event.user_id)
await search_skin.finish(result)
else:
logger.info(
@@ -83,7 +91,6 @@ async def arg_handle(bot: Bot, event: MessageEvent, state: T_State):
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}"
f" 查询皮肤:{name} 没有查询到"
)
_ulmt.set_false(event.user_id)
await search_skin.finish("没有查询到哦,请检查格式吧")
+8 -20
View File
@@ -1,18 +1,14 @@
from utils.user_agent import get_user_agent
import aiohttp
from utils.utils import get_cookie_text
from configs.path_config import TEXT_PATH
from asyncio.exceptions import TimeoutError
from configs.config import BUFF_PROXY
from pathlib import Path
from services.log import logger
from configs.config import Config
url = "https://buff.163.com/api/market/goods"
async def get_price(dname):
cookie = {"session": get_cookie_text("buff")}
cookie = {"session": Config.get_config("search_buff_skin_price", "COOKIE")}
name_list = []
price_list = []
parameter = {"game": "csgo", "page_num": "1", "search": dname}
@@ -21,7 +17,7 @@ async def get_price(dname):
cookies=cookie, headers=get_user_agent()
) as session:
async with session.get(
url, proxy=BUFF_PROXY, params=parameter, timeout=5
url, proxy=Config.get_config("search_buff_skin_price", "BUFF_PROXY"), params=parameter, timeout=5
) as response:
if response.status == 200:
try:
@@ -36,29 +32,21 @@ async def get_price(dname):
price = data[i]["sell_reference_price"]
name_list.append(name)
price_list.append(price)
except Exception as e:
except Exception:
return "没有查询到...", 998
else:
return "访问失败!", response.status
except TimeoutError as e:
except TimeoutError:
return "访问超时! 请重试或稍后再试!", 997
result = f"皮肤: {dname}({len(name_list)})\n"
# result = "皮肤: " + dname + "\n"
for i in range(len(name_list)):
result += name_list[i] + ": " + price_list[i] + "\n"
return result[:-1], 999
def update_buff_cookie(cookie: str):
_cookie = Path(TEXT_PATH + "cookie/buff.txt")
try:
_cookie.parent.mkdir(parents=True, exist_ok=True)
with open(_cookie, "w") as f:
f.write(cookie)
return "更新cookie成功"
except Exception as e:
logger.error(f"更新cookie失败 e:{e}")
return "更新cookie失败"
def update_buff_cookie(cookie: str) -> str:
Config.set_config("search_buff_skin_price", "COOKIE", cookie)
return "更新cookie成功"
if __name__ == "__main__":
+14 -16
View File
@@ -3,7 +3,6 @@ from utils.message_builder import record
from configs.path_config import VOICE_PATH
import random
from services.log import logger
from utils.utils import FreqLimiter
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
from nonebot.rule import to_me
@@ -26,8 +25,10 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["骂老子", "骂我"],
}
_flmt = FreqLimiter(3)
__plugin_cd_limit__ = {
"cd": 3,
"rst": "就...就算求我骂你也得慢慢来..."
}
dg_voice = on_keyword({"骂"}, rule=to_me(), priority=5, block=True)
@@ -35,16 +36,13 @@ dg_voice = on_keyword({"骂"}, rule=to_me(), priority=5, block=True)
@dg_voice.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if len(str((event.get_message()))) == 1:
return
if not _flmt.check(event.user_id):
await dg_voice.finish("就...就算求我骂你也得慢慢来...", at_sender=True)
_flmt.start_cd(event.user_id)
voice = random.choice(os.listdir(VOICE_PATH + "dinggong/"))
result = record(voice, "dinggong")
await dg_voice.send(result)
await dg_voice.send(voice.split("_")[1])
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送钉宫骂人:"
+ result
)
if len(str((event.get_message()))) > 1:
voice = random.choice(os.listdir(VOICE_PATH + "dinggong/"))
result = record(voice, "dinggong")
await dg_voice.send(result)
await dg_voice.send(voice.split("_")[1])
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送钉宫骂人:"
+ result
)
+4
View File
@@ -0,0 +1,4 @@
import nonebot
nonebot.load_plugins("plugins/send_setu_")
+177
View File
@@ -0,0 +1,177 @@
from services.db_context import db
from typing import List, Optional
class Setu(db.Model):
__tablename__ = "setu"
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer(), primary_key=True)
local_id = db.Column(db.Integer(), nullable=False)
title = db.Column(db.String(), nullable=False)
author = db.Column(db.String(), nullable=False)
pid = db.Column(db.BigInteger(), nullable=False)
img_hash = db.Column(db.String(), nullable=False)
img_url = db.Column(db.String(), nullable=False)
is_r18 = db.Column(db.Boolean(), nullable=False)
tags = db.Column(db.String())
_idx1 = db.Index("setu_pid_img_url_idx1", "pid", "img_url", unique=True)
@classmethod
async def add_setu_data(
cls,
local_id: int,
title: str,
author: str,
pid: int,
img_hash: str,
img_url: str,
tags: str,
):
"""
说明:
添加一份色图数据
参数:
:param local_id: 本地存储id
:param title: 标题
:param author: 作者
:param pid: 图片pid
:param img_hash: 图片hash值
:param img_url: 图片链接
:param tags: 图片标签
"""
if not await cls._check_exists(pid, img_url):
await cls.create(
local_id=local_id,
title=title,
author=author,
pid=pid,
img_hash=img_hash,
img_url=img_url,
is_r18=True if "R-18" in tags else False,
tags=tags,
)
@classmethod
async def query_image(
cls,
local_id: Optional[int] = None,
tags: Optional[List[str]] = None,
r18: int = 0,
limit: int = 50,
):
"""
说明:
通过tag查找色图
参数:
:param local_id: 本地色图 id
:param tags: tags
:param r18: 是否 r18,0:非r18 1:r18 2:混合
:param limit: 获取数量
"""
if local_id:
flag = True if r18 == 1 else False
return await cls.query.where(
(cls.local_id == local_id) & (cls.is_r18 == flag)
).gino.first()
if r18 == 0:
query = cls.query.where(cls.is_r18 == False)
elif r18 == 1:
query = cls.query.where(cls.is_r18 == True)
else:
query = cls.query
if tags:
for tag in tags:
query = query.where(cls.tags.contains(tag) | cls.title.contains(tag) | cls.author.contains(tag))
query = query.order_by(db.func.random()).limit(limit)
return await query.gino.all()
@classmethod
async def get_image_count(cls, r18: int = 0) -> int:
"""
说明:
查询图片数量
"""
flag = False if r18 == 0 else True
setattr(Setu, 'count', db.func.count(cls.local_id).label('count'))
count = await cls.select('count').where(cls.is_r18 == flag).gino.first()
return count[0]
@classmethod
async def get_image_in_hash(cls, img_hash: str) -> "Setu":
"""
说明:
通过图像hash获取图像信息
参数:
:param img_hash: = 图像hash值
"""
query = await cls.query.where(cls.img_hash == img_hash).gino.first()
return query
@classmethod
async def _check_exists(cls, pid: int, img_url: str) -> bool:
"""
说明:
检测图片是否存在
参数:
:param pid: 图片pid
:param img_url: 图片链接
"""
return bool(
await cls.query.where(
(cls.pid == pid) & (cls.img_url == img_url)
).gino.first()
)
@classmethod
async def update_setu_data(
cls,
pid: int,
*,
local_id: Optional[int] = None,
title: Optional[str] = None,
author: Optional[str] = None,
img_hash: Optional[str] = None,
img_url: Optional[str] = None,
tags: Optional[str] = None,
) -> bool:
"""
说明:
根据PID修改图片数据
参数:
:param local_id: 本地id
:param pid: 图片pid
:param title: 标题
:param author: 作者
:param img_hash: 图片hash值
:param img_url: 图片链接
:param tags: 图片标签
"""
query = cls.query.where(cls.pid == pid).with_for_update()
image_list = await query.gino.all()
if image_list:
for image in image_list:
if local_id:
await image.update(local_id=local_id).apply()
if title:
await image.update(title=title).apply()
if author:
await image.update(author=author).apply()
if img_hash:
await image.update(img_hash=img_hash).apply()
if img_url:
await image.update(img_url=img_url).apply()
if tags:
await image.update(tags=tags).apply()
return True
return False
@classmethod
async def get_all_setu(cls) -> List["Setu"]:
"""
说明:
获取所有图片对象
"""
return await cls.query.gino.all()
@@ -1,330 +1,368 @@
import random
from nonebot import on_command, on_regex
from services.log import logger
from models.sign_group_user import SignGroupUser
from nonebot.message import run_postprocessor
from nonebot.matcher import Matcher
from typing import Optional, Type
from gino.exceptions import UninitializedError
from utils.utils import (
is_number,
get_message_text,
get_message_imgs,
)
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import (
Bot,
MessageEvent,
GroupMessageEvent,
PrivateMessageEvent,
Message,
Event,
)
from .data_source import (
get_setu_list,
get_luoxiang,
search_online_setu,
get_setu_urls,
find_img_index,
gen_message,
check_local_exists_or_download,
add_data_to_database,
get_setu_count
)
from nonebot.adapters.cqhttp.exception import ActionFailed
from configs.config import ONLY_USE_LOCAL_SETU, WITHDRAW_SETU_TIME, NICKNAME
from utils.manager import withdraw_message_manager
import re
try:
import ujson as json
except ModuleNotFoundError:
import json
__zx_plugin_name__ = "色图"
__plugin_usage__ = f"""
usage:
搜索 lolicon 图库,每日色图time...
指令:
色图: 随机本地色图
色图r: 随机在线十张r18涩图
色图 [id]: 本地指定id色图
色图 *[tags]: 在线搜索指定tag色图
色图r *[tags]: 同上
[1-9]张涩图: 本地随机色图连发
[1-9]张[tags]的涩图: 指定tag色图连发
示例:色图 萝莉|少女 白丝|黑丝
示例:色图 萝莉 猫娘
注:
tag至多取前20项,| 为或,萝莉|少女=萝莉或者少女
""".strip()
__plugin_des__ = "不要小看涩图啊混蛋!"
__plugin_cmd__ = ["色图 ?[id]", "色图 ?[tags]", "色图r ?[tags]", "[1-9]张?[tags]色图"]
__plugin_type__ = ("来点好康的",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 9,
"default_status": True,
"limit_superuser": False,
"cmd": ["色图", "涩图", "瑟图"],
}
__plugin_block_limit__ = {}
__plugin_cd_limit__ = {
'rst': '您冲的太快了,请稍后再冲.',
}
setu_data_list = []
@run_postprocessor
async def do_something(
matcher: Matcher,
exception: Optional[Exception],
bot: Bot,
event: Event,
state: T_State,
):
global setu_data_list
if isinstance(event, MessageEvent):
if matcher.module == "send_setu":
# 添加数据至数据库
try:
await add_data_to_database(setu_data_list)
logger.info("色图数据自动存储数据库成功...")
setu_data_list = []
except UninitializedError:
pass
setu = on_command(
"色图", aliases={"涩图", "不够色", "来一发", "再来点", "色图r"}, priority=5, block=True
)
setu_reg = on_regex("(.*)[份|发|张|个|次|点](.*)[瑟|色|涩]图$", priority=5, block=True)
find_setu = on_command("查色图", priority=5, block=True)
@setu.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
if isinstance(event, GroupMessageEvent):
impression = (
await SignGroupUser.ensure(event.user_id, event.group_id)
).impression
luox = get_luoxiang(impression)
if luox:
await setu.finish(luox)
r18 = 0
num = 1
# 是否看r18
if state["_prefix"]["raw_command"] == "色图r" and isinstance(
event, PrivateMessageEvent
):
r18 = 1
num = 10
elif state["_prefix"]["raw_command"] == "色图r" and isinstance(
event, GroupMessageEvent
):
await setu.finish(
random.choice(["这种不好意思的东西怎么可能给这么多人看啦", "羞羞脸!给我滚出克私聊!", "变态变态变态变态大变态!"])
)
# 有 数字 的话先尝试本地色图id
if msg and is_number(msg):
setu_list, code = await get_setu_list(int(msg), r18=r18)
if code != 200:
await setu.finish(setu_list[0], at_sender=True)
setu_img, code = await check_local_exists_or_download(setu_list[0])
msg_id = await setu.send(gen_message(setu_list[0]) + setu_img, at_sender=True)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送色图 {setu_list[0].local_id}.png"
)
if msg_id:
withdraw_message(event, msg_id["message_id"])
return
await send_setu_handle(setu, event, state["_prefix"]["raw_command"], msg, num, r18)
num_key = {
"一": 1,
"二": 2,
"两": 2,
"双": 2,
"三": 3,
"四": 4,
"五": 5,
"六": 6,
"七": 7,
"八": 8,
"九": 9,
}
@setu_reg.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if isinstance(event, GroupMessageEvent):
impression = (
await SignGroupUser.ensure(event.user_id, event.group_id)
).impression
luox = get_luoxiang(impression)
if luox:
await setu.finish(luox, at_sender=True)
msg = get_message_text(event.json())
num = 1
msg = re.search(r"(.*)[份发张个次点](.*)[瑟涩色]图", msg)
# 解析 tags 以及 num
if msg:
num = msg.group(1)
tags = msg.group(2)
if tags:
tags = tags[:-1] if tags[-1] == "的" else tags
if num:
num = num[-1]
if num_key.get(num):
num = num_key[num]
elif is_number(num):
try:
num = int(num)
except ValueError:
num = 1
else:
num = 1
else:
return
await send_setu_handle(setu_reg, event, "色图", tags, num, 0)
@find_setu.args_parser
async def _(bot: Bot, event: MessageEvent, state: T_State):
if str(event.message) == "取消":
await find_setu.finish("取消了操作", at_sender=True)
imgs = get_message_imgs(event.json())
if not imgs:
await find_setu.reject("不搞错了,俺要图!")
state["img"] = imgs[0]
@find_setu.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if get_message_text(event.json()) in ["帮助"]:
await find_setu.finish("通过图片获取本地色图id\n\t示例:查色图(图片)")
imgs = get_message_imgs(event.json())
if imgs:
state["img"] = imgs[0]
@find_setu.got("img", prompt="速速来图!")
async def _(bot: Bot, event: MessageEvent, state: T_State):
img = state["img"]
await find_setu.send(await find_img_index(img, event.user_id), at_sender=True)
async def send_setu_handle(
matcher: Type[Matcher],
event: MessageEvent,
command: str,
msg: str,
num: int,
r18: int,
):
global setu_data_list
# 非 id,在线搜索
tags = msg.split()
# 真寻的色图?怎么可能
if f"{NICKNAME}" in tags:
await matcher.finish("咳咳咳,虽然我很可爱,但是我木有自己的色图~~~有的话记得发我一份呀")
# 本地先拿图,下载失败补上去
setu_list, code = None, 200
setu_count = await get_setu_count(r18)
if (not ONLY_USE_LOCAL_SETU and tags) or setu_count <= 0:
# 先尝试获取在线图片
urls, text_list, add_databases_list, code = await get_setu_urls(
tags, num, r18, command
)
for x in add_databases_list:
setu_data_list.append(x)
# 未找到符合的色图,想来本地应该也没有
if code == 401:
await setu.finish(urls[0], at_sender=True)
if code == 200:
for i in range(len(urls)):
try:
setu_img, index = await search_online_setu(urls[i])
# 下载成功的话
if index != -1:
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送色图 {index}.png"
)
msg_id = await matcher.send(
Message(f"{text_list[i]}\n{setu_img}")
)
else:
if setu_list is None:
setu_list, _ = await get_setu_list(tags=tags, r18=r18)
if setu_list:
setu_image = random.choice(setu_list)
setu_list.remove(setu_image)
msg_id = await matcher.send(
Message(
gen_message(setu_image)
+ (
await check_local_exists_or_download(setu_image)
)[0]
)
)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送本地色图 {setu_image.local_id}.png"
)
else:
msg_id = await matcher.send(text_list[i] + "\n" + setu_img)
if msg_id:
withdraw_message(event, msg_id["message_id"])
except ActionFailed:
await matcher.finish("坏了,这张图色过头了,我自己看看就行了!", at_sender=True)
return
if code != 200:
await matcher.finish("网络连接失败...", at_sender=True)
# 本地无图
if setu_list is None:
setu_list, code = await get_setu_list(tags=tags, r18=r18)
if code != 200:
await matcher.finish(setu_list[0], at_sender=True)
# 开始发图
for _ in range(num):
if not setu_list:
await setu.finish("坏了,已经没图了,被榨干了!")
setu_image = random.choice(setu_list)
setu_list.remove(setu_image)
try:
msg_id = await matcher.send(
Message(
gen_message(setu_image)
+ (await check_local_exists_or_download(setu_image))[0]
)
)
withdraw_message(event, msg_id["message_id"])
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送本地色图 {setu_image.local_id}.png"
)
except ActionFailed:
await matcher.finish("坏了,这张图色过头了,我自己看看就行了!", at_sender=True)
# 撤回图片
def withdraw_message(event: MessageEvent, id_: int):
if WITHDRAW_SETU_TIME[0]:
if (
(WITHDRAW_SETU_TIME[1] == 0 and isinstance(event, PrivateMessageEvent))
or (WITHDRAW_SETU_TIME[1] == 1 and isinstance(event, GroupMessageEvent))
or WITHDRAW_SETU_TIME[1] == 2
):
withdraw_message_manager.append((id_, WITHDRAW_SETU_TIME[0]))
import random
from nonebot import on_command, on_regex
from services.log import logger
from models.sign_group_user import SignGroupUser
from nonebot.message import run_postprocessor
from nonebot.matcher import Matcher
from typing import Optional, Type
from gino.exceptions import UninitializedError
from utils.utils import (
is_number,
get_message_text,
get_message_imgs,
)
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import (
Bot,
MessageEvent,
GroupMessageEvent,
PrivateMessageEvent,
Message,
Event,
)
from .data_source import (
get_setu_list,
get_luoxiang,
search_online_setu,
get_setu_urls,
find_img_index,
gen_message,
check_local_exists_or_download,
add_data_to_database,
get_setu_count,
)
from nonebot.adapters.cqhttp.exception import ActionFailed
from configs.config import Config, NICKNAME
from utils.manager import withdraw_message_manager
import re
try:
import ujson as json
except ModuleNotFoundError:
import json
__zx_plugin_name__ = "色图"
__plugin_usage__ = f"""
usage:
搜索 lolicon 图库,每日色图time...
指令:
色图: 随机本地色图
色图r: 随机在线十张r18涩图
色图 [id]: 本地指定id色图
色图 *[tags]: 在线搜索指定tag色图
色图r *[tags]: 同上
[1-9]张涩图: 本地随机色图连发
[1-9]张[tags]的涩图: 指定tag色图连发
示例:色图 萝莉|少女 白丝|黑丝
示例:色图 萝莉 猫娘
注:
tag至多取前20项,| 为或,萝莉|少女=萝莉或者少女
""".strip()
__plugin_des__ = "不要小看涩图啊混蛋!"
__plugin_cmd__ = ["色图 ?[id]", "色图 ?[tags]", "色图r ?[tags]", "[1-9]张?[tags]色图"]
__plugin_type__ = ("来点好康的",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 9,
"default_status": True,
"limit_superuser": False,
"cmd": ["色图", "涩图", "瑟图"],
}
__plugin_block_limit__ = {}
__plugin_cd_limit__ = {
"rst": "您冲的太快了,请稍后再冲.",
}
__plugin_configs__ = {
"WITHDRAW_SETU_MESSAGE": {
"value": (0, 1),
"help": "自动撤回,参1:延迟撤回色图时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
"default_value": (0, 1),
},
"ONLY_USE_LOCAL_SETU": {
"value": False,
"help": "仅仅使用本地色图,不在线搜索",
"default_value": False,
},
"INITIAL_SETU_PROBABILITY": {
"value": 0.7,
"help": "初始色图概率,总概率 = 初始色图概率 + 好感度",
"default_value": 0.7
},
"DOWNLOAD_SETU": {
"value": True,
"help": "是否存储下载的色图,使用本地色图可以加快图片发送速度",
"default_value": True
},
"TIMEOUT": {
"value": 10,
"help": "色图下载超时限制(秒)",
"default_value": 10
}
}
Config.add_plugin_config(
"pixiv",
"PIXIV_NGINX_URL",
"i.pixiv.re",
help_="Pixiv反向代理"
)
setu_data_list = []
@run_postprocessor
async def do_something(
matcher: Matcher,
exception: Optional[Exception],
bot: Bot,
event: Event,
state: T_State,
):
global setu_data_list
if isinstance(event, MessageEvent):
if matcher.module == "send_setu":
# 添加数据至数据库
try:
await add_data_to_database(setu_data_list)
logger.info("色图数据自动存储数据库成功...")
setu_data_list = []
except UninitializedError:
pass
setu = on_command(
"色图", aliases={"涩图", "不够色", "来一发", "再来点", "色图r"}, priority=5, block=True
)
setu_reg = on_regex("(.*)[份|发|张|个|次|点](.*)[瑟|色|涩]图$", priority=5, block=True)
find_setu = on_command("查色图", priority=5, block=True)
@setu.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
msg = get_message_text(event.json())
if isinstance(event, GroupMessageEvent):
impression = (
await SignGroupUser.ensure(event.user_id, event.group_id)
).impression
luox = get_luoxiang(impression)
if luox:
await setu.finish(luox)
r18 = 0
num = 1
# 是否看r18
if state["_prefix"]["raw_command"] == "色图r" and isinstance(
event, PrivateMessageEvent
):
r18 = 1
num = 10
elif state["_prefix"]["raw_command"] == "色图r" and isinstance(
event, GroupMessageEvent
):
await setu.finish(
random.choice(["这种不好意思的东西怎么可能给这么多人看啦", "羞羞脸!给我滚出克私聊!", "变态变态变态变态大变态!"])
)
# 有 数字 的话先尝试本地色图id
if msg and is_number(msg):
setu_list, code = await get_setu_list(int(msg), r18=r18)
if code != 200:
await setu.finish(setu_list[0], at_sender=True)
setu_img, code = await check_local_exists_or_download(setu_list[0])
msg_id = await setu.send(gen_message(setu_list[0]) + setu_img, at_sender=True)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送色图 {setu_list[0].local_id}.png"
)
if msg_id:
withdraw_message_manager.withdraw_message(
event,
msg_id["message_id"],
Config.get_config("send_setu", "WITHDRAW_SETU_MESSAGE"),
)
return
await send_setu_handle(setu, event, state["_prefix"]["raw_command"], msg, num, r18)
num_key = {
"一": 1,
"二": 2,
"两": 2,
"双": 2,
"三": 3,
"四": 4,
"五": 5,
"六": 6,
"七": 7,
"八": 8,
"九": 9,
}
@setu_reg.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if isinstance(event, GroupMessageEvent):
impression = (
await SignGroupUser.ensure(event.user_id, event.group_id)
).impression
luox = get_luoxiang(impression)
if luox:
await setu.finish(luox, at_sender=True)
msg = get_message_text(event.json())
num = 1
msg = re.search(r"(.*)[份发张个次点](.*)[瑟涩色]图", msg)
# 解析 tags 以及 num
if msg:
num = msg.group(1)
tags = msg.group(2)
if tags:
tags = tags[:-1] if tags[-1] == "的" else tags
if num:
num = num[-1]
if num_key.get(num):
num = num_key[num]
elif is_number(num):
try:
num = int(num)
except ValueError:
num = 1
else:
num = 1
else:
return
await send_setu_handle(setu_reg, event, "色图", tags, num, 0)
@find_setu.args_parser
async def _(bot: Bot, event: MessageEvent, state: T_State):
if str(event.message) == "取消":
await find_setu.finish("取消了操作", at_sender=True)
imgs = get_message_imgs(event.json())
if not imgs:
await find_setu.reject("不搞错了,俺要图!")
state["img"] = imgs[0]
@find_setu.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
if get_message_text(event.json()) in ["帮助"]:
await find_setu.finish("通过图片获取本地色图id\n\t示例:查色图(图片)")
imgs = get_message_imgs(event.json())
if imgs:
state["img"] = imgs[0]
@find_setu.got("img", prompt="速速来图!")
async def _(bot: Bot, event: MessageEvent, state: T_State):
img = state["img"]
await find_setu.send(await find_img_index(img, event.user_id), at_sender=True)
async def send_setu_handle(
matcher: Type[Matcher],
event: MessageEvent,
command: str,
msg: str,
num: int,
r18: int,
):
global setu_data_list
# 非 id,在线搜索
tags = msg.split()
# 真寻的色图?怎么可能
if f"{NICKNAME}" in tags:
await matcher.finish("咳咳咳,虽然我很可爱,但是我木有自己的色图~~~有的话记得发我一份呀")
# 本地先拿图,下载失败补上去
setu_list, code = None, 200
setu_count = await get_setu_count(r18)
if (
not Config.get_config("send_setu", "ONLY_USE_LOCAL_SETU") and tags
) or setu_count <= 0:
# 先尝试获取在线图片
urls, text_list, add_databases_list, code = await get_setu_urls(
tags, num, r18, command
)
for x in add_databases_list:
setu_data_list.append(x)
# 未找到符合的色图,想来本地应该也没有
if code == 401:
await setu.finish(urls[0], at_sender=True)
if code == 200:
for i in range(len(urls)):
try:
setu_img, index = await search_online_setu(urls[i])
# 下载成功的话
if index != -1:
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送色图 {index}.png"
)
msg_id = await matcher.send(
Message(f"{text_list[i]}\n{setu_img}")
)
else:
if setu_list is None:
setu_list, code = await get_setu_list(tags=tags, r18=r18)
if code != 200:
await setu.finish(setu_list[0], at_sender=True)
if setu_list:
setu_image = random.choice(setu_list)
setu_list.remove(setu_image)
msg_id = await matcher.send(
Message(
gen_message(setu_image)
+ (
await check_local_exists_or_download(setu_image)
)[0]
)
)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送本地色图 {setu_image.local_id}.png"
)
else:
msg_id = await matcher.send(text_list[i] + "\n" + setu_img)
if msg_id:
withdraw_message_manager.withdraw_message(
event,
msg_id["message_id"],
Config.get_config("send_setu", "WITHDRAW_SETU_MESSAGE"),
)
except ActionFailed:
await matcher.finish("坏了,这张图色过头了,我自己看看就行了!", at_sender=True)
return
if code != 200:
await matcher.finish("网络连接失败...", at_sender=True)
# 本地无图
if setu_list is None:
setu_list, code = await get_setu_list(tags=tags, r18=r18)
if code != 200:
await matcher.finish(setu_list[0], at_sender=True)
# 开始发图
for _ in range(num):
if not setu_list:
await setu.finish("坏了,已经没图了,被榨干了!")
setu_image = random.choice(setu_list)
setu_list.remove(setu_image)
try:
msg_id = await matcher.send(
Message(
gen_message(setu_image)
+ (await check_local_exists_or_download(setu_image))[0]
)
)
withdraw_message_manager.withdraw_message(
event,
msg_id["message_id"],
Config.get_config("send_setu", "WITHDRAW_SETU_MESSAGE"),
)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 发送本地色图 {setu_image.local_id}.png"
)
except ActionFailed:
await matcher.finish("坏了,这张图色过头了,我自己看看就行了!", at_sender=True)
@@ -1,273 +1,276 @@
from configs.path_config import IMAGE_PATH
from utils.message_builder import image
from services.log import logger
from aiohttp.client_exceptions import ClientConnectorError
from utils.image_utils import get_img_hash, compressed_image
from asyncpg.exceptions import UniqueViolationError
from utils.utils import get_local_proxy
from asyncio.exceptions import TimeoutError
from typing import List, Optional
from configs.config import INITIAL_SETU_PROBABILITY, NICKNAME, DOWNLOAD_SETU
from models.setu import Setu
import aiohttp
import aiofiles
import asyncio
import os
import random
try:
import ujson as json
except ModuleNotFoundError:
import json
url = "https://api.lolicon.app/setu/v2"
path = "_setu/"
r18_path = "_r18/"
# 获取url
async def get_setu_urls(
tags: List[str], num: int = 1, r18: int = 0, command: str = ""
) -> "List[str], List[str], List[tuple], int":
tags = tags[:3] if len(tags) > 3 else tags
params = {
"r18": r18, # 添加r18参数 0为否,1为是,2为混合
"tag": tags, # 若指定tag
"num": 100, # 一次返回的结果数量
"size": ["original"],
}
async with aiohttp.ClientSession() as session:
for count in range(3):
logger.info(f"get_setu_url: count --> {count}")
try:
async with session.get(
url, proxy=get_local_proxy(), timeout=2, params=params
) as response:
if response.status == 200:
data = await response.json()
if not data["error"]:
data = data["data"]
(
urls,
text_list,
add_databases_list,
) = await asyncio.get_event_loop().run_in_executor(
None, _setu_data_process, data, command
)
num = num if num < len(data) else len(data)
random_idx = random.sample(range(len(data)), num)
x_urls = []
x_text_lst = []
for x in random_idx:
x_urls.append(urls[x])
x_text_lst.append(text_list[x])
if not x_urls:
return ["没找到符合条件的色图..."], [], [], 401
return x_urls, x_text_lst, add_databases_list, 200
else:
return ["没找到符合条件的色图..."], [], [], 401
except (TimeoutError, ClientConnectorError):
pass
return ["我网线被人拔了..QAQ"], [], [], 999
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
async def search_online_setu(
url_: str, id_: Optional[int] = None, path_: Optional[str] = None
) -> "MessageSegment, int":
"""
下载色图
:param url_: 色图url
:param id_: 本地id
:param path_: 存储路径
"""
if "i.pixiv.cat" in url_:
url_ = url_.replace("i.pixiv.cat", "i.pximg.net")
async with aiohttp.ClientSession(headers=headers) as session:
for i in range(3):
logger.info(f"search_online_setu --> {i}")
try:
async with session.get(url_, proxy=get_local_proxy(), timeout=3) as res:
if res.status == 200:
index = random.randint(1, 100000) if id_ is None else id_
path_ = "temp" if not path_ else path_
file = f"{index}_temp_setu.jpg" if not path_ else f"{index}.jpg"
if not os.path.exists(f'{IMAGE_PATH}/{path_}'):
os.mkdir(f'{IMAGE_PATH}/{path_}')
async with aiofiles.open(
f"{IMAGE_PATH}/{path_}/{file}", "wb"
) as f:
try:
await f.write(await res.read())
except TimeoutError:
continue
if id_ is not None:
if (
os.path.getsize(f"{IMAGE_PATH}/{path_}/{index}.jpg")
> 1024 * 1024 * 1.5
):
compressed_image(
f"{IMAGE_PATH}/{path_}/{index}.jpg",
)
logger.info(f"下载 lolicon图片 {url_} 成功, id:{index}")
return image(file, path_), index
else:
logger.warning(f"访问 lolicon图片 {url_} 失败 status:{res.status}")
# return '\n这图好难下载啊!QAQ', -1, False
except (TimeoutError, ClientConnectorError):
pass
return "图片被小怪兽恰掉啦..!QAQ", -1
# 检测本地是否有id涩图,无的话则下载
async def check_local_exists_or_download(setu_image: Setu) -> "MessageSegment, int":
path_ = None
id_ = None
if DOWNLOAD_SETU:
id_ = setu_image.local_id
if setu_image.is_r18:
path_ = "_r18"
else:
path_ = path
if os.path.exists(f"{IMAGE_PATH}/{path_}/{setu_image.local_id}.jpg"):
return image(f"{setu_image.local_id}.jpg", path_), 200
return await search_online_setu(setu_image.img_url, id_, path_)
# 添加涩图数据到数据库
async def add_data_to_database(lst: List[tuple]):
tmp = []
for x in lst:
if x not in tmp:
tmp.append(x)
if tmp:
for x in tmp:
try:
r18 = 1 if "R-18" in x[5] else 0
idx = await Setu.get_image_count(r18)
await Setu.add_setu_data(
idx,
x[0],
x[1],
x[2],
x[3],
x[4],
x[5],
)
except UniqueViolationError:
pass
# 拿到本地色图列表
async def get_setu_list(
index: Optional[int] = None, tags: Optional[List[str]] = None, r18: int = 0
) -> "list, int":
if index:
image_count = await Setu.get_image_count(r18) - 1
if index < 0 or index > image_count:
return [f"超过当前上下限!({image_count})"], 999
image_list = [await Setu.query_image(index, r18=r18)]
elif tags:
image_list = await Setu.query_image(tags=tags, r18=r18)
else:
image_list = await Setu.query_image(r18=r18)
if not image_list:
return ["没找到符合条件的色图..."], 998
return image_list, 200
# 初始化消息
def gen_message(setu_image: Setu, img_msg: bool = False):
local_id = setu_image.local_id
title = setu_image.title
author = setu_image.author
pid = setu_image.pid
return (
f"id:{local_id}\n"
f"title:{title}\n"
f"author:{author}\n"
f"PID:{pid}\n"
f"{image(f'{local_id}', f'{r18_path if setu_image.is_r18 else path}') if img_msg else ''}"
)
# 罗翔老师!
def get_luoxiang(impression):
probability = impression + INITIAL_SETU_PROBABILITY * 100
if probability < random.randint(1, 101):
return (
"我为什么要给你发这个?"
+ image(random.choice(os.listdir(IMAGE_PATH + "luoxiang/")), "luoxiang")
+ f"\n(快向{NICKNAME}签到提升好感度吧!)"
)
return None
async def get_setu_count(r18: int) -> int:
"""
获取色图数量
:param r18: r18类型
"""
return await Setu.get_image_count(r18)
async def find_img_index(img_url, user_id):
async with aiohttp.ClientSession() as session:
async with session.get(img_url, proxy=get_local_proxy(), timeout=5) as res:
async with aiofiles.open(
IMAGE_PATH + f"temp/{user_id}_find_setu_index.jpg", "wb"
) as f:
await f.write(await res.read())
img_hash = str(get_img_hash(IMAGE_PATH + f"temp/{user_id}_find_setu_index.jpg"))
setu_img = await Setu.get_image_in_hash(img_hash)
if setu_img:
return (
f"id:{setu_img.local_id}\n"
f"title:{setu_img.title}\n"
f"author:{setu_img.author}\n"
f"PID:{setu_img.pid}"
)
return "该图不在色图库中或色图库未更新!"
# 处理色图数据
def _setu_data_process(data: dict, command: str) -> "list, list, list":
urls = []
text_list = []
add_databases_list = []
for i in range(len(data)):
img_url = data[i]["urls"]["original"]
img_url = (
img_url.replace("i.pixiv.cat", "i.pximg.net")
if "i.pixiv.cat" in img_url
else img_url
)
title = data[i]["title"]
author = data[i]["author"]
pid = data[i]["pid"]
urls.append(img_url)
text_list.append(f"title:{title}\nauthor:{author}\nPID:{pid}")
tags = []
for j in range(len(data[i]["tags"])):
tags.append(data[i]["tags"][j])
if command != "色图r":
if "R-18" in tags:
tags.remove("R-18")
add_databases_list.append(
(
title,
author,
pid,
"",
img_url,
",".join(tags),
)
)
return urls, text_list, add_databases_list
from configs.path_config import IMAGE_PATH
from utils.message_builder import image
from services.log import logger
from aiohttp.client_exceptions import ClientConnectorError
from utils.image_utils import get_img_hash, compressed_image
from asyncpg.exceptions import UniqueViolationError
from utils.utils import get_local_proxy
from asyncio.exceptions import TimeoutError
from typing import List, Optional
from configs.config import NICKNAME, Config
from ..model import Setu
import aiohttp
import aiofiles
import asyncio
import os
import random
try:
import ujson as json
except ModuleNotFoundError:
import json
url = "https://api.lolicon.app/setu/v2"
path = "_setu/"
r18_path = "_r18/"
# 获取url
async def get_setu_urls(
tags: List[str], num: int = 1, r18: int = 0, command: str = ""
) -> "List[str], List[str], List[tuple], int":
tags = tags[:3] if len(tags) > 3 else tags
params = {
"r18": r18, # 添加r18参数 0为否,1为是,2为混合
"tag": tags, # 若指定tag
"num": 100, # 一次返回的结果数量
"size": ["original"],
}
async with aiohttp.ClientSession() as session:
for count in range(3):
logger.info(f"get_setu_url: count --> {count}")
try:
async with session.get(
url, proxy=get_local_proxy(), timeout=Config.get_config("send_setu", "TIMEOUT"), params=params
) as response:
if response.status == 200:
data = await response.json()
if not data["error"]:
data = data["data"]
(
urls,
text_list,
add_databases_list,
) = await asyncio.get_event_loop().run_in_executor(
None, _setu_data_process, data, command
)
num = num if num < len(data) else len(data)
random_idx = random.sample(range(len(data)), num)
x_urls = []
x_text_lst = []
for x in random_idx:
x_urls.append(urls[x])
x_text_lst.append(text_list[x])
if not x_urls:
return ["没找到符合条件的色图..."], [], [], 401
return x_urls, x_text_lst, add_databases_list, 200
else:
return ["没找到符合条件的色图..."], [], [], 401
except (TimeoutError, ClientConnectorError):
pass
return ["我网线被人拔了..QAQ"], [], [], 999
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
async def search_online_setu(
url_: str, id_: Optional[int] = None, path_: Optional[str] = None
) -> "MessageSegment, int":
"""
下载色图
:param url_: 色图url
:param id_: 本地id
:param path_: 存储路径
"""
ws_url = Config.get_config("pixiv", "PIXIV_NGINX_URL")
if ws_url:
url_ = url_.replace("i.pixiv.cat", ws_url)
async with aiohttp.ClientSession(headers=headers) as session:
for i in range(3):
logger.info(f"search_online_setu --> {i}")
try:
async with session.get(url_, proxy=get_local_proxy(), timeout=Config.get_config("send_setu", "TIMEOUT")) as res:
if res.status == 200:
index = random.randint(1, 100000) if id_ is None else id_
path_ = "temp" if not path_ else path_
file = f"{index}_temp_setu.jpg" if not path_ else f"{index}.jpg"
if not os.path.exists(f"{IMAGE_PATH}/{path_}"):
os.mkdir(f"{IMAGE_PATH}/{path_}")
async with aiofiles.open(
f"{IMAGE_PATH}/{path_}/{file}", "wb"
) as f:
try:
await f.write(await res.read())
except TimeoutError:
continue
if id_ is not None:
if (
os.path.getsize(f"{IMAGE_PATH}/{path_}/{index}.jpg")
> 1024 * 1024 * 1.5
):
compressed_image(
f"{IMAGE_PATH}/{path_}/{index}.jpg",
)
logger.info(f"下载 lolicon图片 {url_} 成功, id:{index}")
return image(file, path_), index
else:
logger.warning(f"访问 lolicon图片 {url_} 失败 status:{res.status}")
# return '\n这图好难下载啊!QAQ', -1, False
except (TimeoutError, ClientConnectorError):
pass
return "图片被小怪兽恰掉啦..!QAQ", -1
# 检测本地是否有id涩图,无的话则下载
async def check_local_exists_or_download(setu_image: Setu) -> "MessageSegment, int":
path_ = None
id_ = None
if Config.get_config("send_setu", "DOWNLOAD_SETU"):
id_ = setu_image.local_id
if setu_image.is_r18:
path_ = "_r18"
else:
path_ = path
if os.path.exists(f"{IMAGE_PATH}/{path_}/{setu_image.local_id}.jpg"):
return image(f"{setu_image.local_id}.jpg", path_), 200
return await search_online_setu(setu_image.img_url, id_, path_)
# 添加涩图数据到数据库
async def add_data_to_database(lst: List[tuple]):
tmp = []
for x in lst:
if x not in tmp:
tmp.append(x)
if tmp:
for x in tmp:
try:
r18 = 1 if "R-18" in x[5] else 0
idx = await Setu.get_image_count(r18)
await Setu.add_setu_data(
idx,
x[0],
x[1],
x[2],
x[3],
x[4],
x[5],
)
except UniqueViolationError:
pass
# 拿到本地色图列表
async def get_setu_list(
index: Optional[int] = None, tags: Optional[List[str]] = None, r18: int = 0
) -> "list, int":
if index:
image_count = await Setu.get_image_count(r18) - 1
if index < 0 or index > image_count:
return [f"超过当前上下限!({image_count})"], 999
image_list = [await Setu.query_image(index, r18=r18)]
elif tags:
image_list = await Setu.query_image(tags=tags, r18=r18)
else:
image_list = await Setu.query_image(r18=r18)
if not image_list:
return ["没找到符合条件的色图..."], 998
return image_list, 200
# 初始化消息
def gen_message(setu_image: Setu, img_msg: bool = False) -> str:
local_id = setu_image.local_id
title = setu_image.title
author = setu_image.author
pid = setu_image.pid
return (
f"id:{local_id}\n"
f"title:{title}\n"
f"author:{author}\n"
f"PID:{pid}\n"
f"{image(f'{local_id}', f'{r18_path if setu_image.is_r18 else path}') if img_msg else ''}"
)
# 罗翔老师!
def get_luoxiang(impression):
probability = (
impression + Config.get_config("send_setu", "INITIAL_SETU_PROBABILITY") * 100
)
if probability < random.randint(1, 101):
return (
"我为什么要给你发这个?"
+ image(random.choice(os.listdir(IMAGE_PATH + "luoxiang/")), "luoxiang")
+ f"\n(快向{NICKNAME}签到提升好感度吧!)"
)
return None
async def get_setu_count(r18: int) -> int:
"""
获取色图数量
:param r18: r18类型
"""
return await Setu.get_image_count(r18)
async def find_img_index(img_url, user_id):
async with aiohttp.ClientSession() as session:
async with session.get(img_url, proxy=get_local_proxy(), timeout=Config.get_config("send_setu", "TIMEOUT")) as res:
async with aiofiles.open(
IMAGE_PATH + f"temp/{user_id}_find_setu_index.jpg", "wb"
) as f:
await f.write(await res.read())
img_hash = str(get_img_hash(IMAGE_PATH + f"temp/{user_id}_find_setu_index.jpg"))
setu_img = await Setu.get_image_in_hash(img_hash)
if setu_img:
return (
f"id:{setu_img.local_id}\n"
f"title:{setu_img.title}\n"
f"author:{setu_img.author}\n"
f"PID:{setu_img.pid}"
)
return "该图不在色图库中或色图库未更新!"
# 处理色图数据
def _setu_data_process(data: dict, command: str) -> "list, list, list":
urls = []
text_list = []
add_databases_list = []
for i in range(len(data)):
img_url = data[i]["urls"]["original"]
img_url = (
img_url.replace("i.pixiv.cat", "i.pximg.net")
if "i.pixiv.cat" in img_url
else img_url
)
title = data[i]["title"]
author = data[i]["author"]
pid = data[i]["pid"]
urls.append(img_url)
text_list.append(f"title:{title}\nauthor:{author}\nPID:{pid}")
tags = []
for j in range(len(data[i]["tags"])):
tags.append(data[i]["tags"][j])
if command != "色图r":
if "R-18" in tags:
tags.remove("R-18")
add_databases_list.append(
(
title,
author,
pid,
"",
img_url,
",".join(tags),
)
)
return urls, text_list, add_databases_list
@@ -1,48 +1,48 @@
from utils.utils import scheduler
from nonebot import on_command
from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
from nonebot.rule import to_me
from .data_source import update_setu_img
from configs.config import DOWNLOAD_SETU
__zx_plugin_name__ = "更新色图 [Superuser]"
__plugin_usage__ = """
usage:
更新数据库内存在的色图
指令:
更新色图
""".strip()
__plugin_cmd__ = ["更新色图"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_block_limit__ = {
"rst": "色图正在更新..."
}
update_setu = on_command(
"更新色图", rule=to_me(), permission=SUPERUSER, priority=1, block=True
)
@update_setu.handle()
async def _(bot: Bot, event: Event, state: T_State):
if DOWNLOAD_SETU:
await update_setu.send("开始更新色图...", at_sender=True)
await update_setu.send(await update_setu_img(), at_sender=True)
else:
await update_setu.finish("更新色图配置未开启")
# 更新色图
@scheduler.scheduled_job(
"cron",
hour=4,
minute=30,
)
async def _():
if DOWNLOAD_SETU:
await update_setu_img()
from utils.utils import scheduler
from nonebot import on_command
from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
from nonebot.rule import to_me
from .data_source import update_setu_img
from configs.config import Config
__zx_plugin_name__ = "更新色图 [Superuser]"
__plugin_usage__ = """
usage:
更新数据库内存在的色图
指令:
更新色图
""".strip()
__plugin_cmd__ = ["更新色图"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_block_limit__ = {
"rst": "色图正在更新..."
}
update_setu = on_command(
"更新色图", rule=to_me(), permission=SUPERUSER, priority=1, block=True
)
@update_setu.handle()
async def _(bot: Bot, event: Event, state: T_State):
if Config.get_config("send_setu", "DOWNLOAD_SETU"):
await update_setu.send("开始更新色图...", at_sender=True)
await update_setu.send(await update_setu_img(), at_sender=True)
else:
await update_setu.finish("更新色图配置未开启")
# 更新色图
@scheduler.scheduled_job(
"cron",
hour=4,
minute=30,
)
async def _():
if Config.get_config("send_setu", "DOWNLOAD_SETU"):
await update_setu_img()
@@ -1,164 +1,171 @@
from configs.path_config import IMAGE_PATH, TEXT_PATH
from services.log import logger
from datetime import datetime
from utils.image_utils import compressed_image, get_img_hash
from utils.utils import get_bot, get_local_proxy
from asyncio.exceptions import TimeoutError
from models.setu import Setu
from aiohttp.client_exceptions import ClientConnectorError
from asyncpg.exceptions import UniqueViolationError
from pathlib import Path
from nonebot import Driver
import nonebot
import aiofiles
import aiohttp
import os
import ujson as json
driver: Driver = nonebot.get_driver()
_path = Path(IMAGE_PATH)
# 替换旧色图数据,修复local_id一直是50的问题
@driver.on_startup
async def update_old_setu_data():
path = Path(TEXT_PATH)
setu_data_file = path / "setu_data.json"
r18_data_file = path / "r18_setu_data.json"
if setu_data_file.exists() or r18_data_file.exists():
index = 0
r18_index = 0
count = 0
fail_count = 0
for file in [setu_data_file, r18_data_file]:
if file.exists():
data = json.load(open(file, "r", encoding="utf8"))
for x in data:
if file == setu_data_file:
idx = index
if 'R-18' in data[x]["tags"]:
data[x]["tags"].remove('R-18')
else:
idx = r18_index
img_url = (
data[x]["img_url"].replace("i.pixiv.cat", "i.pximg.net")
if "i.pixiv.cat" in data[x]["img_url"]
else data[x]["img_url"]
)
# idx = r18_index if 'R-18' in data[x]["tags"] else index
try:
await Setu.add_setu_data(
idx,
data[x]["title"],
data[x]["author"],
data[x]["pid"],
data[x]["img_hash"],
img_url,
",".join(data[x]["tags"]),
)
count += 1
if 'R-18' in data[x]["tags"]:
r18_index += 1
else:
index += 1
logger.info(f'添加旧色图数据成功 PID:{data[x]["pid"]} index:{idx}....')
except UniqueViolationError:
fail_count += 1
logger.info(f'添加旧色图数据失败,色图重复 PID:{data[x]["pid"]} index:{idx}....')
file.unlink()
setu_url_path = path / "setu_url.json"
setu_r18_url_path = path / "setu_r18_url.json"
if setu_url_path.exists():
setu_url_path.unlink()
if setu_r18_url_path.exists():
setu_r18_url_path.unlink()
logger.info(f"更新旧色图数据完成,成功更新数据:{count} 条,累计失败:{fail_count} 条")
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
async def update_setu_img():
image_list = await Setu.get_all_setu()
image_list.reverse()
_success = 0
error_info = []
error_type = []
count = 0
async with aiohttp.ClientSession(headers=headers) as session:
for image in image_list:
count += 1
path = _path / "_r18" if image.is_r18 else _path / "_setu"
rar_path = _path / "r18_rar" if image.is_r18 else _path / "rar"
local_image = path / f"{image.local_id}.jpg"
path.mkdir(exist_ok=True, parents=True)
rar_path.mkdir(exist_ok=True, parents=True)
if not local_image.exists() or not image.img_hash:
for _ in range(3):
try:
async with session.get(
image.img_url, proxy=get_local_proxy(), timeout=30
) as response:
if response.status == 200:
async with aiofiles.open(
rar_path / f'{image.local_id}.jpg',
"wb",
) as f:
await f.write(await response.read())
_success += 1
try:
if (
os.path.getsize(
rar_path / f'{image.local_id}.jpg',
)
> 1024 * 1024 * 1.5
):
compressed_image(
rar_path / f"{image.local_id}.jpg",
path / f"{image.local_id}.jpg"
)
else:
logger.info(
f"不需要压缩,移动图片{rar_path}/{image.local_id}.jpg "
f"--> /{path}/{image.local_id}.jpg"
)
os.rename(
f"{rar_path}/{image.local_id}.jpg",
f"{path}/{image.local_id}.jpg",
)
except FileNotFoundError:
logger.warning(f"文件 {image.local_id}.jpg 不存在,跳过...")
continue
img_hash = str(
get_img_hash(
f"{path}/{image.local_id}.jpg"
)
)
await Setu.update_setu_data(
image.pid, img_hash=img_hash
)
break
except (TimeoutError, ClientConnectorError) as e:
logger.warning(f"{image.local_id}.jpg 更新失败 ..{type(e)}:{e}")
except Exception as e:
logger.error(f"更新色图 {image.local_id}.jpg 错误 {type(e)}: {e}")
if type(e) not in error_type:
error_type.append(type(e))
error_info.append(
f"更新色图 {image.local_id}.jpg 错误 {type(e)}: {e}"
)
else:
logger.info(f'更新色图 {image.local_id}.jpg 已存在')
error_info = ['无报错..'] if not error_info else error_info
await get_bot().send_private_msg(
user_id=int(list(get_bot().config.superusers)[0]),
message=f'{str(datetime.now()).split(".")[0]} 更新 色图 完成,本地存在 {count} 张,实际更新 {_success} 张,以下为更新时未知错误:\n'
+ "\n".join(error_info),
)
from configs.path_config import IMAGE_PATH, TEXT_PATH, TEMP_PATH
from services.log import logger
from datetime import datetime
from utils.image_utils import compressed_image, get_img_hash
from utils.utils import get_bot, get_local_proxy
from asyncio.exceptions import TimeoutError
from ..model import Setu
from aiohttp.client_exceptions import ClientConnectorError
from asyncpg.exceptions import UniqueViolationError
from pathlib import Path
from nonebot import Driver
import nonebot
import aiofiles
import aiohttp
import os
import ujson as json
import shutil
driver: Driver = nonebot.get_driver()
_path = Path(IMAGE_PATH)
# 替换旧色图数据,修复local_id一直是50的问题
@driver.on_startup
async def update_old_setu_data():
path = Path(TEXT_PATH)
setu_data_file = path / "setu_data.json"
r18_data_file = path / "r18_setu_data.json"
if setu_data_file.exists() or r18_data_file.exists():
index = 0
r18_index = 0
count = 0
fail_count = 0
for file in [setu_data_file, r18_data_file]:
if file.exists():
data = json.load(open(file, "r", encoding="utf8"))
for x in data:
if file == setu_data_file:
idx = index
if 'R-18' in data[x]["tags"]:
data[x]["tags"].remove('R-18')
else:
idx = r18_index
img_url = (
data[x]["img_url"].replace("i.pixiv.cat", "i.pximg.net")
if "i.pixiv.cat" in data[x]["img_url"]
else data[x]["img_url"]
)
# idx = r18_index if 'R-18' in data[x]["tags"] else index
try:
await Setu.add_setu_data(
idx,
data[x]["title"],
data[x]["author"],
data[x]["pid"],
data[x]["img_hash"],
img_url,
",".join(data[x]["tags"]),
)
count += 1
if 'R-18' in data[x]["tags"]:
r18_index += 1
else:
index += 1
logger.info(f'添加旧色图数据成功 PID:{data[x]["pid"]} index:{idx}....')
except UniqueViolationError:
fail_count += 1
logger.info(f'添加旧色图数据失败,色图重复 PID:{data[x]["pid"]} index:{idx}....')
file.unlink()
setu_url_path = path / "setu_url.json"
setu_r18_url_path = path / "setu_r18_url.json"
if setu_url_path.exists():
setu_url_path.unlink()
if setu_r18_url_path.exists():
setu_r18_url_path.unlink()
logger.info(f"更新旧色图数据完成,成功更新数据:{count} 条,累计失败:{fail_count} 条")
# 删除色图rar文件夹
shutil.rmtree(Path(IMAGE_PATH) / "setu_rar", ignore_errors=True)
shutil.rmtree(Path(IMAGE_PATH) / "r18_rar", ignore_errors=True)
shutil.rmtree(Path(IMAGE_PATH) / "rar", ignore_errors=True)
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
"Referer": "https://www.pixiv.net",
}
async def update_setu_img():
image_list = await Setu.get_all_setu()
image_list.reverse()
_success = 0
error_info = []
error_type = []
count = 0
async with aiohttp.ClientSession(headers=headers) as session:
for image in image_list:
count += 1
path = _path / "_r18" if image.is_r18 else _path / "_setu"
rar_path = Path(TEMP_PATH)
local_image = path / f"{image.local_id}.jpg"
path.mkdir(exist_ok=True, parents=True)
rar_path.mkdir(exist_ok=True, parents=True)
if not local_image.exists() or not image.img_hash:
for _ in range(3):
try:
async with session.get(
image.img_url, proxy=get_local_proxy(), timeout=30
) as response:
if response.status == 200:
async with aiofiles.open(
rar_path / f'{image.local_id}.jpg',
"wb",
) as f:
await f.write(await response.read())
_success += 1
try:
if (
os.path.getsize(
rar_path / f'{image.local_id}.jpg',
)
> 1024 * 1024 * 1.5
):
compressed_image(
rar_path / f"{image.local_id}.jpg",
path / f"{image.local_id}.jpg"
)
else:
logger.info(
f"不需要压缩,移动图片{rar_path}/{image.local_id}.jpg "
f"--> /{path}/{image.local_id}.jpg"
)
os.rename(
f"{rar_path}/{image.local_id}.jpg",
f"{path}/{image.local_id}.jpg",
)
except FileNotFoundError:
logger.warning(f"文件 {image.local_id}.jpg 不存在,跳过...")
continue
img_hash = str(
get_img_hash(
f"{path}/{image.local_id}.jpg"
)
)
await Setu.update_setu_data(
image.pid, img_hash=img_hash
)
break
except (TimeoutError, ClientConnectorError) as e:
logger.warning(f"{image.local_id}.jpg 更新失败 ..{type(e)}:{e}")
except Exception as e:
logger.error(f"更新色图 {image.local_id}.jpg 错误 {type(e)}: {e}")
if type(e) not in error_type:
error_type.append(type(e))
error_info.append(
f"更新色图 {image.local_id}.jpg 错误 {type(e)}: {e}"
)
else:
logger.info(f'更新色图 {image.local_id}.jpg 已存在')
error_info = ['无报错..'] if not error_info else error_info
if count or _success or (error_info and "无报错.." not in error_info):
await get_bot().send_private_msg(
user_id=int(list(get_bot().config.superusers)[0]),
message=f'{str(datetime.now()).split(".")[0]} 更新 色图 完成,本地存在 {count} 张,实际更新 {_success} 张,以下为更新时未知错误:\n'
+ "\n".join(error_info),
)
+11 -81
View File
@@ -1,84 +1,14 @@
from pathlib import Path
from configs.path_config import DATA_PATH
import nonebot
try:
import ujson as json
except ModuleNotFoundError:
import json
from configs.config import Config
Config.add_plugin_config(
"shop",
"IMPORT_DEFAULT_SHOP_GOODS",
True,
help_="导入商店自带的三个商品",
default_value=True
)
nonebot.load_plugins("plugins/shop")
# 修改旧数据
statistics_group_file = Path(DATA_PATH) / "statistics" / "_prefix_count.json"
statistics_user_file = Path(DATA_PATH) / "statistics" / "_prefix_user_count.json"
for file in [statistics_group_file, statistics_user_file]:
if file.exists():
with open(file, 'r', encoding='utf8') as f:
data = json.load(f)
if not (statistics_group_file.parent / f"{file}.bak").exists():
with open(f"{file}.bak", 'w', encoding='utf8') as wf:
json.dump(data, wf, ensure_ascii=False, indent=4)
for x in ['total_statistics', 'day_statistics']:
for key in data[x].keys():
num = 0
if data[x][key].get('我的道具') is not None:
num += data[x][key]['我的道具']
del data[x][key]['我的道具']
if data[x][key].get('使用道具') is not None:
num += data[x][key]['使用道具']
del data[x][key]['使用道具']
if data[x][key].get('我的金币') is not None:
num += data[x][key]['我的金币']
del data[x][key]['我的金币']
if data[x][key].get('购买') is not None:
num += data[x][key]['购买']
del data[x][key]['购买']
if data[x][key].get('商店') is not None:
data[x][key]['商店'] += num
else:
data[x][key]['商店'] = num
for x in ['week_statistics', 'month_statistics']:
for key in data[x].keys():
if key == 'total':
if data[x][key].get('我的道具') is not None:
num += data[x][key]['我的道具']
del data[x][key]['我的道具']
if data[x][key].get('使用道具') is not None:
num += data[x][key]['使用道具']
del data[x][key]['使用道具']
if data[x][key].get('我的金币') is not None:
num += data[x][key]['我的金币']
del data[x][key]['我的金币']
if data[x][key].get('购买') is not None:
num += data[x][key]['购买']
del data[x][key]['购买']
if data[x][key].get('商店') is not None:
data[x][key]['商店'] += num
else:
data[x][key]['商店'] = num
else:
for day in data[x][key].keys():
num = 0
if data[x][key][day].get('我的道具') is not None:
num += data[x][key][day]['我的道具']
del data[x][key][day]['我的道具']
if data[x][key][day].get('使用道具') is not None:
num += data[x][key][day]['使用道具']
del data[x][key][day]['使用道具']
if data[x][key][day].get('我的金币') is not None:
num += data[x][key][day]['我的金币']
del data[x][key][day]['我的金币']
if data[x][key][day].get('购买') is not None:
num += data[x][key][day]['购买']
del data[x][key][day]['购买']
if data[x][key][day].get('商店') is not None:
data[x][key][day]['商店'] += num
else:
data[x][key][day]['商店'] = num
with open(file, 'w', encoding='utf8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
+1 -1
View File
@@ -6,7 +6,7 @@ from utils.utils import get_message_text, is_number
from models.bag_user import BagUser
from services.db_context import db
from nonebot.adapters.cqhttp.permission import GROUP
from models.goods_info import GoodsInfo
from .models.goods_info import GoodsInfo
__zx_plugin_name__ = "商店 - 购买道具"
+11 -4
View File
@@ -4,6 +4,8 @@ from nonebot.typing import T_State
from nonebot.adapters.cqhttp.permission import GROUP
from utils.data_utils import init_rank
from models.bag_user import BagUser
from utils.message_builder import image
from utils.utils import get_message_text, is_number
__zx_plugin_name__ = "商店 - 我的金币"
__plugin_usage__ = """
@@ -14,7 +16,7 @@ usage:
""".strip()
__plugin_des__ = "商店 - 我的金币"
__plugin_cmd__ = ["我的金币"]
__plugin_type__ = ('商店',)
__plugin_type__ = ("商店",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
@@ -37,9 +39,14 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
@gold_rank.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
num = get_message_text(event.json())
if is_number(num) and 51 > int(num) > 10:
num = int(num)
else:
num = 10
all_users = await BagUser.get_all_users(event.group_id)
all_user_id = [user.user_qq for user in all_users]
all_user_data = [user.gold for user in all_users]
await gold_rank.finish(
"金币排行:\n" + await init_rank(all_user_id, all_user_data, event.group_id)
)
rank_image = await init_rank("金币排行", all_user_id, all_user_data, event.group_id, num)
if rank_image:
await gold_rank.finish(image(b64=rank_image.pic2bs4()))
+4
View File
@@ -19,6 +19,7 @@ from nonebot.matcher import Matcher
from utils.utils import get_message_text, is_number, scheduler
from utils.message_builder import image
from services.log import logger
from configs.path_config import IMAGE_PATH
from nonebot.permission import SUPERUSER
from nonebot.rule import to_me
from datetime import datetime, timedelta
@@ -49,6 +50,9 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["金币红包", "塞红包"],
}
__plugin_resources__ = {
"prts": IMAGE_PATH
}
gold_redbag = on_command(
"塞红包", aliases={"金币红包"}, priority=5, block=True, permission=GROUP
+1 -1
View File
@@ -3,7 +3,7 @@ from utils.utils import is_number, get_local_proxy
from utils.image_utils import CreateImg
from utils.user_agent import get_user_agent
from configs.path_config import IMAGE_PATH
from models.redbag_user import RedbagUser
from ..models.redbag_user import RedbagUser
import random
import os
import aiohttp
+1
View File
@@ -0,0 +1 @@
from .goods_info import *
+129
View File
@@ -0,0 +1,129 @@
from services.db_context import db
from typing import Optional, List
class GoodsInfo(db.Model):
__tablename__ = "goods_info"
id = db.Column(db.Integer(), primary_key=True)
goods_name = db.Column(db.TEXT(), nullable=False) # 名称
goods_price = db.Column(db.Integer(), nullable=False) # 价格
goods_description = db.Column(db.TEXT(), nullable=False) # 商品描述
goods_discount = db.Column(db.Numeric(scale=3, asdecimal=False), default=1) # 打折
goods_limit_time = db.Column(db.BigInteger(), default=0) # 限时
_idx1 = db.Index("goods_group_users_idx1", "goods_name", unique=True)
@classmethod
async def add_goods(
cls,
goods_name: str,
goods_price: int,
goods_description: str,
goods_discount: float = 1,
goods_limit_time: int = 0,
) -> bool:
"""
说明:
添加商品
参数:
:param goods_name: 商品名称
:param goods_price: 商品价格
:param goods_description: 商品简介
:param goods_discount: 商品折扣
:param goods_limit_time: 商品限时
"""
try:
await cls.create(
goods_name=goods_name,
goods_price=goods_price,
goods_description=goods_description,
goods_discount=goods_discount,
goods_limit_time=goods_limit_time,
)
return True
except Exception:
return False
@classmethod
async def delete_goods(cls, goods_name: str) -> bool:
"""
说明:
删除商品
参数:
:param goods_name: 商品名称
"""
query = (
await cls.query.where(cls.goods_name == goods_name)
.with_for_update()
.gino.first()
)
if not query:
return False
await query.delete()
return True
@classmethod
async def update_goods(
cls,
goods_name: str,
goods_price: Optional[int] = None,
goods_description: Optional[str] = None,
goods_discount: Optional[float] = None,
goods_limit_time: Optional[int] = None,
) -> bool:
"""
说明:
更新商品信息
参数:
:param goods_name: 商品名称
:param goods_price: 商品价格
:param goods_description: 商品简介
:param goods_discount: 商品折扣
:param goods_limit_time: 商品限时时间
"""
try:
query = (
await cls.query.where(cls.goods_name == goods_name)
.with_for_update()
.gino.first()
)
if not query:
return False
if goods_price:
await query.update(goods_price=goods_price).apply()
if goods_description:
await query.update(goods_description=goods_description).apply()
if goods_discount:
await query.update(goods_discount=goods_discount).apply()
if goods_limit_time:
await query.update(goods_limit_time=goods_limit_time).apply()
return True
except Exception:
return False
@classmethod
async def get_goods_info(cls, goods_name: str) -> "GoodsInfo":
"""
说明:
获取商品对象
参数:
:param goods_name: 商品名称
"""
query = await cls.query.where(cls.goods_name == goods_name).gino.first()
return query
@classmethod
async def get_all_goods(cls) -> List["GoodsInfo"]:
"""
说明:
获得全部有序商品对象
"""
query = await cls.query.gino.all()
id_lst = [x.id for x in query]
goods_lst = []
for _ in range(len(query)):
min_id = min(id_lst)
goods_lst.append([x for x in query if x.id == min_id][0])
id_lst.remove(min_id)
return goods_lst
+73
View File
@@ -0,0 +1,73 @@
from services.db_context import db
from typing import List
class RedbagUser(db.Model):
__tablename__ = "redbag_users"
id = db.Column(db.Integer(), primary_key=True)
user_qq = db.Column(db.BigInteger(), nullable=False)
group_id = db.Column(db.BigInteger(), nullable=False)
send_redbag_count = db.Column(db.Integer(), default=0)
get_redbag_count = db.Column(db.Integer(), default=0)
spend_gold = db.Column(db.Integer(), default=0)
get_gold = db.Column(db.Integer(), default=0)
_idx1 = db.Index("redbag_group_users_idx1", "user_qq", "group_id", unique=True)
@classmethod
async def add_redbag_data(cls, user_qq: int, group_id: int, itype: str, money: int):
"""
说明:
添加收发红包数据
参数:
:param user_qq: qq号
:param group_id: 群号
:param itype: 收或发
:param money: 金钱数量
"""
query = cls.query.where((cls.user_qq == user_qq) & (cls.group_id == group_id))
user = await query.with_for_update().gino.first() or await cls.create(
user_qq=user_qq,
group_id=group_id,
)
if itype == "get":
await user.update(
get_redbag_count=user.get_redbag_count + 1,
get_gold=user.get_gold + money,
).apply()
else:
await user.update(
send_redbag_count=user.send_redbag_count + 1,
spend_gold=user.spend_gold + money,
).apply()
@classmethod
async def ensure(cls, user_qq: int, group_id: int) -> bool:
"""
说明:
获取用户对象
参数:
:param user_qq: qq号
:param group_id: 群号
"""
query = cls.query.where((cls.user_qq == user_qq) & (cls.group_id == group_id))
user = await query.gino.first() or await cls.create(
user_qq=user_qq,
group_id=group_id,
)
return user
@classmethod
async def get_user_all(cls, group_id: int = None) -> List["RedbagUser"]:
"""
说明:
获取所有用户对象
参数:
:param group_id: 群号
"""
if not group_id:
query = await cls.query.gino.all()
else:
query = await cls.query.where((cls.group_id == group_id)).gino.all()
return query
+3 -3
View File
@@ -1,8 +1,8 @@
from models.goods_info import GoodsInfo
from ..models.goods_info import GoodsInfo
from utils.image_utils import CreateImg
from utils.utils import is_number
from configs.path_config import IMAGE_PATH
from configs.config import IMPORT_DEFAULT_SHOP_GOODS
from configs.config import Config
from nonebot import Driver
import nonebot
import time
@@ -17,7 +17,7 @@ driver: Driver = nonebot.get_driver()
async def init_default_shop_goods():
if os.path.exists(f"{IMAGE_PATH}/shop_help.png"):
os.remove(f"{IMAGE_PATH}/shop_help.png")
if IMPORT_DEFAULT_SHOP_GOODS:
if Config.get_config("shop", "IMPORT_DEFAULT_SHOP_GOODS"):
await add_goods(["好感度双倍加持卡Ⅰ", 30, "下次签到双倍好感度概率 + 10%(谁才是真命天子?)(同类商品将覆盖)"])
await add_goods(["好感度双倍加持卡Ⅱ", 150, "下次签到双倍好感度概率 + 20%(平平庸庸)(同类商品将覆盖)"])
await add_goods(["好感度双倍加持卡Ⅲ", 250, "下次签到双倍好感度概率 + 30%(金币才是真命天子!)(同类商品将覆盖)"])
+33 -5
View File
@@ -6,7 +6,6 @@ from .group_user_checkin import (
)
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
from utils.manager import plugins2cd_manager
from nonebot.adapters.cqhttp.permission import GROUP
from utils.message_builder import image
from nonebot import on_command
@@ -15,6 +14,7 @@ from pathlib import Path
from configs.path_config import DATA_PATH
from services.log import logger
from .utils import clear_sign_data_pic
from utils.utils import is_number
try:
import ujson as json
@@ -43,9 +43,30 @@ __plugin_settings__ = {
"limit_superuser": False,
"cmd": ["签到"],
}
plugins2cd_manager.add_cd_limit(
'sign_in',
)
__plugin_cd_limit__ = {}
__plugin_configs__ = {
"MAX_SIGN_GOLD": {
"value": 200,
"help": "签到好感度加成额外获得的最大金币数",
"default_value": 200
},
"SIGN_CARD1_PROB": {
"value": 0.2,
"help": "签到好感度双倍加持卡Ⅰ掉落概率",
"default_value": 0.2
},
"SIGN_CARD2_PROB": {
"value": 0.09,
"help": "签到好感度双倍加持卡Ⅱ掉落概率",
"default_value": 0.09
},
"SIGN_CARD3_PROB": {
"value": 0.05,
"help": "签到好感度双倍加持卡Ⅲ掉落概率",
"default_value": 0.05
}
}
_file = Path(f"{DATA_PATH}/not_show_sign_rank_user.json")
try:
@@ -90,7 +111,14 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
@sign_rank.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await sign_rank.send(await group_impression_rank(event.group_id))
num = get_message_text(event.json())
if is_number(num) and 51 > int(num) > 10:
num = int(num)
else:
num = 10
_image = await group_impression_rank(event.group_id, num)
if _image:
await sign_rank.send(image(b64=_image.pic2bs4()))
@total_sign_rank.handle()
-10
View File
@@ -10,16 +10,6 @@ SIGN_BACKGROUND_PATH = Path(SIGN_RESOURCE_PATH) / 'background'
SIGN_BORDER_PATH.mkdir(exist_ok=True, parents=True)
SIGN_BACKGROUND_PATH.mkdir(exist_ok=True, parents=True)
SIGN_CARD1_PROB = 0.2 # 好感度双倍加持卡Ⅰ
SIGN_CARD2_PROB = 0.09 # 好感度双倍加持卡Ⅱ
SIGN_CARD3_PROB = 0.05 # 好感度双倍加持卡Ⅲ
PROB_DATA = {
SIGN_CARD3_PROB: '好感度双倍加持卡Ⅲ',
SIGN_CARD2_PROB: '好感度双倍加持卡Ⅱ',
SIGN_CARD1_PROB: '好感度双倍加持卡Ⅰ'
}
lik2relation = {
'0': '路人',

Some files were not shown because too many files have changed in this diff Show More