Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

版本更新 #1666

Merged
merged 73 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a368121
✨ 父级插件加载
HibiKier Aug 30, 2024
7e7436f
:white_check_mark: 添加测试:更新与添加插件 (#1594)
AkashiCoin Sep 1, 2024
8fe0617
🐛 bug修复
HibiKier Sep 1, 2024
29c4876
🐛修复添加插件返回403的问题 (#1595)
AkashiCoin Sep 1, 2024
15ad90d
🎨 修改readme
HibiKier Sep 2, 2024
db75c4a
Update README.md
HibiKier Sep 2, 2024
133d4e1
🐛 修改bug与版本锁定
HibiKier Sep 2, 2024
a56d1f2
🐛 修复超级用户对群组功能开关
HibiKier Sep 2, 2024
9eca6a9
🐛 修复插件商店检查插件更新问题 (#1597)
AkashiCoin Sep 2, 2024
44e0f2d
🐛 增加插件状态检查 (#1598)
AkashiCoin Sep 2, 2024
8d071f8
🐛 修复更新群组成员信息
HibiKier Sep 2, 2024
02aba68
🎨 代码优化
HibiKier Sep 2, 2024
405e2d3
:rocket: 更新Dockerfile (#1599)
fanyinrumeng Sep 2, 2024
a2549a0
🎨 更新requirements
HibiKier Sep 3, 2024
a619346
:heavy_plus_sign: 添加依赖aiocache
AkashiCoin Sep 3, 2024
8615eb2
:zap: 添加github镜像
AkashiCoin Sep 3, 2024
7288d5b
✨ 添加仓库目录多获取渠道
AkashiCoin Sep 3, 2024
8911bbf
🐛 修复测试用例
AkashiCoin Sep 3, 2024
c3927c7
✨ 添加API缓存
AkashiCoin Sep 3, 2024
682d19a
🎨 采取Sourcery建议
AkashiCoin Sep 3, 2024
ce97ded
🐛 文件下载逻辑修改
AkashiCoin Sep 3, 2024
c36bb97
🎨 优化代码
HibiKier Sep 4, 2024
51371ba
🐛 修复插件开关有时出现错误
HibiKier Sep 5, 2024
3b4c206
✨ 重构自检ui
HibiKier Sep 6, 2024
db9153f
🐛 自检html修正
HibiKier Sep 6, 2024
3f4787d
修复签到逻辑bug,并使代码更灵活以适应签到好感度等级配置 (#1606)
McElaga Sep 7, 2024
0a5ab83
🎨 代码结构优化
HibiKier Sep 7, 2024
807b2f6
🐛 私聊时修改插件时删除私聊帮助
HibiKier Sep 7, 2024
62fd93c
🐛 过滤父插件
HibiKier Sep 7, 2024
e618b19
🐛 修复自检在ARM上的问题 (#1607)
AkashiCoin Sep 7, 2024
057001f
✨ 支持mysql,psql,sqlite随机函数
HibiKier Sep 7, 2024
1790a0b
✨提供sqlite和mysql连接url示例
HibiKier Sep 7, 2024
2b006b8
:wrench: VSCode配置修改
AkashiCoin Sep 7, 2024
fe11ff0
:wrench: VSCode配置修改
AkashiCoin Sep 7, 2024
440e7b5
✨ 添加金币排行
AkashiCoin Sep 8, 2024
342e70c
:memo: 修改README
AkashiCoin Sep 8, 2024
f11e9c5
:hammer: 提取GitHub相关操作 (#1609)
AkashiCoin Sep 8, 2024
e4a92ea
✨ 签到/金币排行限制最大数量 (#1616)
HibiKier Sep 9, 2024
4e42d1d
🐛 修复超级用户id获取问题
HibiKier Sep 9, 2024
95762bd
🐛 修复路径解压与挂载 (#1619)
HibiKier Sep 10, 2024
a8355fb
🐛 修复功能少时zhenxun帮助图片排序问题 (#1620)
HibiKier Sep 11, 2024
94ef332
🐛 签到文本适应 (#1622)
HibiKier Sep 11, 2024
8a688eb
🐛 好感度排行提供默认值 (#1624)
HibiKier Sep 12, 2024
d97e437
🎈 优先使用github api (#1625)
AkashiCoin Sep 13, 2024
029a731
✨ 重构帮助,限制普通用户查询管理插件 (#1626)
HibiKier Sep 13, 2024
f1354c6
🐛 修复群权限与插件等级匹配 (#1627)
HibiKier Sep 14, 2024
f2e354e
✨ 当管理员尝试ban真寻时将被反杀 (#1628)
HibiKier Sep 14, 2024
e41e163
✨ 群组发言时间检测提供开关配置 (#1630)
HibiKier Sep 14, 2024
cd88d80
🐳 chore: 支持自动修改版本号 (#1629)
AkashiCoin Sep 16, 2024
51c010d
🎈 perf(github_utils): 支持github url下载遍历 (#1632)
AkashiCoin Sep 16, 2024
60f4406
🧪 test(auto_update): 修复测试用例 (#1633)
AkashiCoin Sep 16, 2024
fcfaf56
🐛 修复商店商品为空时报错 (#1634)
HibiKier Sep 16, 2024
6f635ed
🐛 修复群权限与插件等级匹配 (#1635)
HibiKier Sep 16, 2024
9832483
✨ message_build支持AtAll (#1639)
HibiKier Sep 19, 2024
f2c20b8
🎈 perf: 使用commit号下载插件 (#1641)
AkashiCoin Sep 21, 2024
3897658
🐳 chore: 修改运行检查触发路径 (#1642)
AkashiCoin Sep 21, 2024
a04475a
✨ 重构qq群事件处理 (#1643)
HibiKier Sep 21, 2024
3fc4eaa
🐛 签到名称自适应 (#1644)
HibiKier Sep 21, 2024
32c11b9
🎨 更新README (#1645)
HibiKier Sep 21, 2024
207f947
:bug: fix(http_utils): 流式下载Content-Length错误 (#1647)
AkashiCoin Sep 22, 2024
6be9e47
🐛 修复群组中帮助功能状态显示问题 (#1650)
HibiKier Sep 25, 2024
e89d1d4
🐛 修复群欢迎消息设置 (#1651)
HibiKier Sep 25, 2024
7ec1bc9
🐛 修复webui下载后首次启动错误 (#1652)
HibiKier Sep 25, 2024
b14220e
✨ 移除默认图片文件夹:爬 (#1653)
HibiKier Sep 27, 2024
7890cc5
✨ 安装/移除插件提供插件安装/卸载方法用于插件初始化 (#1654)
HibiKier Sep 27, 2024
28b61e5
✨ 新增超级用户与管理员帮助模板 (#1655)
HibiKier Sep 27, 2024
a3311ad
✨ 新增个人信息命令 (#1657)
HibiKier Sep 29, 2024
e8425f3
✨ 修改个人信息菜单名称 (#1658)
HibiKier Sep 29, 2024
d68a409
✨ 新增插件商店api (#1659)
HibiKier Sep 29, 2024
717a973
✨ 将cd,block,count限制复原配置文件 (#1662)
HibiKier Sep 30, 2024
2c8c46d
🎨 修改README (#1663)
HibiKier Sep 30, 2024
94e0594
🎨 修改版本号 (#1664)
HibiKier Sep 30, 2024
482eb1a
🎨 修改requirements (#1665)
HibiKier Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ 重构自检ui
HibiKier committed Sep 6, 2024
commit 3b4c206a24803ed25ce0ae6aeae5acdb3c8f534a
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ python-multipart = "^0.0.9"
nonebot-plugin-alconna = "0.51.1"
arclet-alconna = "1.8.23"
aiocache = "^0.12.2"
py-cpuinfo = "^9.0.0"

[tool.poetry.dev-dependencies]
nonebug = "^0.3.2"
179 changes: 179 additions & 0 deletions resources/template/check/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@


@font-face {
font-family: fzrzFont;
/* 导入的字体文件 */
src: url("./res/font/fzrzExtraBold.ttf");
}




body {
position: absolute;
left: -8px;
top: -8px;
}

.wrapper{
height: 750px;
width: 395px;
background-color: antiquewhite;
position: relative;
}

.top-image {
height: 215px;
width: 395px;
}

.abs-image {
height: 426px;
width: 93px;
position: absolute;
right: 39px;
top: 240px;
}

.bot-text {
height: 55px;
width: 335px;
position: relative;
padding: 0 30px;
margin-top: 10px;
}

.main {
height: 448px;
width: 335px;
padding: 0 30px;
position: relative;
}

.title {
background-color: #EB869D;
height: 32px;
font-family: 'fzrzFont';
color: white;
width: max-content;
border-radius: 20px;
padding: 0 10px;
float: left;
margin-top: 10px;
}

.title-n {
height: 23px;
width: 23px;
border-radius: 50%;
background-color: white;
position: absolute;
left: 36px;
top: 15px;
display: flex;
justify-content: center;
align-items: center;
}

.title-a {
background-color: #ED859E;
height: 19px;
width: 19px;
border-radius: 50%;
}

.network {
display: flex;
margin-left: 10px;
}

.network-item {
font-family: 'fzrzFont';
color: #EC859F;
display: flex;
justify-items: center;
align-items: center;
margin-left: 20px;
}

.network-status {
height: 10px;
width: 10px;
border-radius: 50%;
margin-left: 5px;
}

.network-text {
margin-left: 5px;
}

.network-item {
margin-top: 10px;
}

.data-status-item {
margin-top: 10px;
}

.data-status {
width: 100%;
height: 240px;
/* background-color:blueviolet; */
margin-top: 22px;
}

.data-status-item {
display: flex;
font-family: 'fzrzFont';
font-size: 15px;
line-height: 18.5px;
height: 50px;
}

.process {
height: 28px;
width: 105px;
border: #ED859E 4px solid;
border-radius: 30px;
overflow: hidden;
}

.process-bar {
height: 28px;
width: 30px;
background-color: #EB869D;
border-top-right-radius: 30px;
border-bottom-right-radius: 30px;
}

.data-status-item-text {
margin-left: 10px;
color: #EC839D;
}

.line {
background-color: #EC859F;
height: 2px;
width: 100%;
border-radius: 20px;
}

.status-text {
font-family: 'fzrzFont';
color: #EC859F;
height: 90px;
display: flex;
}

.status-text-title {
height: 25%;
}

.tip {
font-family: 'fzrzFont';
color: #ecbac7;
font-size: 10px;
position: absolute;
right: 5px;
bottom: 1px;
}
90 changes: 90 additions & 0 deletions resources/template/check/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

</html>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
<!-- <link rel="stylesheet" href="./res/font-awesome/css/font-awesome.min.css"> -->
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="wrapper">
<img class="top-image" src="res/img/top.jpg"></img>
<img class="abs-image" src="res/img/bk.png"></img>
<div class="bot-text">
<div class="title">
<div class="title-n">
<div class="title-a"></div>
</div>
<span style="margin-left: 22px;">{{data.nickname}}自检</span>
</div>
<div class="network">
<div class="network-item">BaiDu<span class="network-status" style="background-color: {{data.baidu}}; border: 1px solid {{data.baidu}}"></span></div>
<div class="network-item">Google<span class="network-status" style="background-color: {{data.google}}; border: 1px solid {{data.google}}"></span></div>
</div>
</div>
<div class="main">
<div class="data-status">
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.cpu_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>CPU</div>
<!-- <div style="font-size: 13px;">0.8% - 3.5Ghz [14core]</div> -->
<div style="font-size: 13px;">{{data.cpu_info}}</div>
</div>
</div>
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.ram_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>RAM</div>
<div>{{data.ram_info}}</div>
</div>
</div>
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.swap_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>SWAP</div>
<div>{{data.swap_info}}</div>
</div>
</div>
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.disk_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>DISK</div>
<div>{{data.disk_info}}</div>
</div>
</div>
</div>
<div class="line"></div>
<div class="status-text">
<div>
<p class="status-text-title">CPU</p>
<p class="status-text-title">SYSTEM</p>
<p class="status-text-title">VERSION</p>
<p class="status-text-title">PLUGINS</p>
</div>
<div style="margin-left: 37px;">
<p class="status-text-title" style="font-size: 14px;line-height: 18.5px;">{{data.brand_raw}}</p>
<p class="status-text-title">{{data.system}}</p>
<p class="status-text-title">{{data.version}}</p>
<p class="status-text-title">{{data.plugin_count}} loaded</p>
</div>
</div>
</div>
<div class="tip">Create By Zhenxun</div>
</div>
</body>
<script type="text/javascript" src="main.js">
</script>
</html>
Empty file.
Binary file not shown.
Binary file added resources/template/check/res/img/bk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/template/check/res/img/top.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions zhenxun/builtin_plugins/check/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from nonebot.rule import to_me
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot_plugin_session import EventSession
from nonebot_plugin_htmlrender import template_to_pic
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna

from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
from zhenxun.utils.message import MessageUtils
from zhenxun.configs.utils import PluginExtraData
from zhenxun.configs.path_config import TEMPLATE_PATH

from .data_source import get_status_info

__plugin_meta__ = PluginMetadata(
name="服务器自我检查",
description="查看服务器当前状态",
usage="""
查看服务器当前状态
指令:
自检
""".strip(),
extra=PluginExtraData(
author="HibiKier", version="0.1", plugin_type=PluginType.SUPERUSER
).dict(),
)


_matcher = on_alconna(
Alconna("自检"), rule=to_me(), permission=SUPERUSER, block=True, priority=1
)


@_matcher.handle()
async def _(session: EventSession, arparma: Arparma):
try:
data = await get_status_info()
image = await template_to_pic(
template_path=str((TEMPLATE_PATH / "check").absolute()),
template_name="main.html",
templates={"data": data},
pages={
"viewport": {"width": 195, "height": 750},
"base_url": f"file://{TEMPLATE_PATH}",
},
wait=2,
)
await MessageUtils.build_message(image).send()
logger.info("自检", arparma.header_result, session=session)
except Exception as e:
await MessageUtils.build_message(f"自检失败: {e}").send()
logger.error("自检失败", arparma.header_result, session=session, e=e)
163 changes: 163 additions & 0 deletions zhenxun/builtin_plugins/check/data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import platform
from pathlib import Path
from dataclasses import dataclass

import psutil
import cpuinfo
import nonebot
from pydantic import BaseModel
from nonebot.utils import run_sync
from httpx import NetworkError, ConnectTimeout

from zhenxun.services.log import logger
from zhenxun.configs.config import BotConfig
from zhenxun.utils.http_utils import AsyncHttpx

BAIDU_URL = "https://www.baidu.com/"
GOOGLE_URL = "https://www.google.com/"

VERSION_FILE = Path() / "__version__"


@dataclass
class CPUInfo:
core: int
"""CPU 物理核心数"""
usage: float
"""CPU 占用百分比,取值范围(0,100]"""
freq: float
"""CPU 的时钟速度(单位:GHz)"""

@classmethod
def get_cpu_info(cls):
cpu_core = psutil.cpu_count(logical=False)
cpu_usage = psutil.cpu_percent(interval=1)
cpu_freq = round(psutil.cpu_freq().current / 1000, 2)

return CPUInfo(core=cpu_core, usage=cpu_usage, freq=cpu_freq)


@dataclass
class RAMInfo:
"""RAM 信息(单位:GB)"""

total: float
"""RAM 总量"""
usage: float
"""当前 RAM 占用量/GB"""

@classmethod
def get_ram_info(cls):
ram_total = round(psutil.virtual_memory().total / (1024**3), 2)
ram_usage = round(psutil.virtual_memory().used / (1024**3), 2)

return RAMInfo(total=ram_total, usage=ram_usage)


@dataclass
class SwapMemory:
"""Swap 信息(单位:GB)"""

total: float
"""Swap 总量"""
usage: float
"""当前 Swap 占用量/GB"""

@classmethod
def get_swap_info(cls):
swap_total = round(psutil.swap_memory().total / (1024**3), 2)
swap_usage = round(psutil.swap_memory().used / (1024**3), 2)

return SwapMemory(total=swap_total, usage=swap_usage)


@dataclass
class DiskInfo:
"""硬盘信息"""

total: float
"""硬盘总量"""
usage: float
"""当前硬盘占用量/GB"""

@classmethod
def get_disk_info(cls):
disk_total = round(psutil.disk_usage("/").total / (1024**3), 2)
disk_usage = round(psutil.disk_usage("/").used / (1024**3), 2)

return DiskInfo(total=disk_total, usage=disk_usage)


class SystemInfo(BaseModel):
"""系统信息"""

cpu: CPUInfo
"""CPU信息"""
ram: RAMInfo
"""RAM信息"""
swap: SwapMemory
"""SWAP信息"""
disk: DiskInfo
"""DISK信息"""

def get_system_info(self):
return {
"cpu_info": f"{self.cpu.usage}% - {self.cpu.freq}Ghz [{self.cpu.core} core]",
"cpu_process": psutil.cpu_percent(),
"ram_info": f"{self.ram.usage} / {self.ram.total} GB",
"ram_process": self.ram.usage / self.ram.total * 100,
"swap_info": f"{self.swap.usage} / {self.swap.total} GB",
"swap_process": self.swap.usage / self.swap.total * 100,
"disk_info": f"{self.disk.usage} / {self.disk.total} GB",
"disk_process": self.disk.usage / self.disk.total * 100,
}


@run_sync
def __build_status() -> dict:
"""获取 `CPU` `RAM` `SWAP` `DISK` 信息"""
cpu = CPUInfo.get_cpu_info()
ram = RAMInfo.get_ram_info()
swap = SwapMemory.get_swap_info()
disk = DiskInfo.get_disk_info()

return SystemInfo(cpu=cpu, ram=ram, swap=swap, disk=disk).get_system_info()


async def __get_network_info():
"""网络请求"""
baidu, google = True, True
try:
await AsyncHttpx.get(BAIDU_URL, timeout=5)
except Exception as e:
logger.warning("自检:百度无法访问...", e=e)
baidu = False
try:
await AsyncHttpx.get(GOOGLE_URL, timeout=5)
except Exception as e:
logger.warning("自检:谷歌无法访问...", e=e)
google = False
return baidu, google


def __get_version() -> str | None:
"""获取版本信息"""
with open(VERSION_FILE, encoding="utf-8") as f:
if text := f.read():
text.split(":")[-1]
return None


async def get_status_info() -> dict:
"""获取信息"""
data = await __build_status()
baidu, google = await __get_network_info()
data["baidu"] = "#8CC265" if baidu else "red"
data["google"] = "#8CC265" if google else "red"
system = platform.uname()
data["system"] = f"{system.system} {system.release}"
data["version"] = __get_version()
data["brand_raw"] = cpuinfo.get_cpu_info()["brand_raw"]
data["plugin_count"] = len(nonebot.get_loaded_plugins())
data["nickname"] = BotConfig.self_nickname
return data
176 changes: 88 additions & 88 deletions zhenxun/builtin_plugins/record_request.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import time
from datetime import datetime

from nonebot.plugin import PluginMetadata
from nonebot import on_message, on_request
from nonebot_plugin_session import EventSession
from nonebot_plugin_apscheduler import scheduler
from nonebot.adapters.onebot.v11 import Bot as v11Bot
from nonebot.adapters.onebot.v12 import Bot as v12Bot
from nonebot.adapters.onebot.v11 import (
ActionFailed,
FriendRequestEvent,
GroupRequestEvent,
FriendRequestEvent,
)
from nonebot.adapters.onebot.v11 import Bot as v11Bot
from nonebot.adapters.onebot.v12 import Bot as v12Bot
from nonebot.plugin import PluginMetadata
from nonebot_plugin_apscheduler import scheduler
from nonebot_plugin_session import EventSession

from zhenxun.configs.config import BotConfig, Config
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
from zhenxun.services.log import logger
from zhenxun.models.fg_request import FgRequest
from zhenxun.utils.platform import PlatformUtils
from zhenxun.models.friend_user import FriendUser
from zhenxun.configs.config import Config, BotConfig
from zhenxun.models.group_console import GroupConsole
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType, RequestHandleType, RequestType
from zhenxun.utils.message import MessageUtils
from zhenxun.utils.platform import PlatformUtils
from zhenxun.configs.utils import RegisterConfig, PluginExtraData
from zhenxun.utils.enum import PluginType, RequestType, RequestHandleType

base_config = Config.get("invite_manager")

@@ -119,91 +118,92 @@ async def _(bot: v12Bot | v11Bot, event: FriendRequestEvent, session: EventSessi

@group_req.handle()
async def _(bot: v12Bot | v11Bot, event: GroupRequestEvent, session: EventSession):
if event.sub_type == "invite":
if str(event.user_id) in bot.config.superusers:
try:
logger.debug(
"超级用户自动同意加入群聊",
"群聊请求",
session=event.user_id,
target=event.group_id,
)
group, _ = await GroupConsole.update_or_create(
group_id=str(event.group_id),
defaults={
"group_name": "",
"max_member_count": 0,
"member_count": 0,
"group_flag": 1,
},
)
await bot.set_group_add_request(
flag=event.flag, sub_type="invite", approve=True
)
if isinstance(bot, v11Bot):
group_info = await bot.get_group_info(group_id=event.group_id)
max_member_count = group_info["max_member_count"]
member_count = group_info["member_count"]
else:
group_info = await bot.get_group_info(group_id=str(event.group_id))
max_member_count = 0
member_count = 0
group.max_member_count = max_member_count
group.member_count = member_count
group.group_name = group_info["group_name"]
await group.save(
update_fields=["group_name", "max_member_count", "member_count"]
)
except ActionFailed as e:
logger.error(
"超级用户自动同意加入群聊发生错误",
"群聊请求",
session=event.user_id,
target=event.group_id,
e=e,
)
elif Timer.check(f"{event.user_id}:{event.group_id}"):
if event.sub_type != "invite":
return
if str(event.user_id) in bot.config.superusers:
try:
logger.debug(
f"收录 用户[{event.user_id}] 群聊[{event.group_id}] 群聊请求",
"超级用户自动同意加入群聊",
"群聊请求",
session=event.user_id,
target=event.group_id,
)
nickname = await FriendUser.get_user_name(str(event.user_id))
await bot.send_private_msg(
user_id=event.user_id,
message=f"想要邀请我偷偷入群嘛~已经提醒{BotConfig.self_nickname}的管理员大人了\n"
"请确保已经群主或群管理沟通过!\n"
"等待管理员处理吧!",
)
# 旧请求全部设置为过期
await FgRequest.filter(
request_type=RequestType.GROUP,
user_id=str(event.user_id),
group_id=str(event.group_id),
handle_type__isnull=True,
).update(handle_type=RequestHandleType.EXPIRE)
f = await FgRequest.create(
request_type=RequestType.GROUP,
platform=session.platform,
bot_id=bot.self_id,
flag=event.flag,
user_id=str(event.user_id),
nickname=nickname,
group, _ = await GroupConsole.update_or_create(
group_id=str(event.group_id),
defaults={
"group_name": "",
"max_member_count": 0,
"member_count": 0,
"group_flag": 1,
},
)
await PlatformUtils.send_superuser(
bot,
f"*****一份入群申请*****\n"
"ID:{f.id}\n"
"申请人:{nickname}({event.user_id})\n群聊:"
f"{event.group_id}\n邀请日期:{datetime.now().replace(microsecond=0)}",
await bot.set_group_add_request(
flag=event.flag, sub_type="invite", approve=True
)
else:
logger.debug(
"群聊请求五分钟内重复, 已忽略",
if isinstance(bot, v11Bot):
group_info = await bot.get_group_info(group_id=event.group_id)
max_member_count = group_info["max_member_count"]
member_count = group_info["member_count"]
else:
group_info = await bot.get_group_info(group_id=str(event.group_id))
max_member_count = 0
member_count = 0
group.max_member_count = max_member_count
group.member_count = member_count
group.group_name = group_info["group_name"]
await group.save(
update_fields=["group_name", "max_member_count", "member_count"]
)
except ActionFailed as e:
logger.error(
"超级用户自动同意加入群聊发生错误",
"群聊请求",
target=f"{event.user_id}:{event.group_id}",
session=event.user_id,
target=event.group_id,
e=e,
)
elif Timer.check(f"{event.user_id}:{event.group_id}"):
logger.debug(
f"收录 用户[{event.user_id}] 群聊[{event.group_id}] 群聊请求",
"群聊请求",
target=event.group_id,
)
nickname = await FriendUser.get_user_name(str(event.user_id))
await bot.send_private_msg(
user_id=event.user_id,
message=f"想要邀请我偷偷入群嘛~已经提醒{BotConfig.self_nickname}的管理员大人了\n"
"请确保已经群主或群管理沟通过!\n"
"等待管理员处理吧!",
)
# 旧请求全部设置为过期
await FgRequest.filter(
request_type=RequestType.GROUP,
user_id=str(event.user_id),
group_id=str(event.group_id),
handle_type__isnull=True,
).update(handle_type=RequestHandleType.EXPIRE)
f = await FgRequest.create(
request_type=RequestType.GROUP,
platform=session.platform,
bot_id=bot.self_id,
flag=event.flag,
user_id=str(event.user_id),
nickname=nickname,
group_id=str(event.group_id),
)
await PlatformUtils.send_superuser(
bot,
f"*****一份入群申请*****\n"
f"ID:{f.id}\n"
f"申请人:{nickname}({event.user_id})\n群聊:"
f"{event.group_id}\n邀请日期:{datetime.now().replace(microsecond=0)}",
)
else:
logger.debug(
"群聊请求五分钟内重复, 已忽略",
"群聊请求",
target=f"{event.user_id}:{event.group_id}",
)


@scheduler.scheduled_job(
3 changes: 2 additions & 1 deletion zhenxun/utils/http_utils.py
Original file line number Diff line number Diff line change
@@ -173,6 +173,7 @@ async def download_file(
cookies: dict[str, str] | None = None,
timeout: int = 30,
stream: bool = False,
follow_redirects: bool = True,
**kwargs,
) -> bool:
"""下载文件
@@ -204,7 +205,7 @@ async def download_file(
use_proxy=use_proxy,
proxy=proxy,
timeout=timeout,
follow_redirects=True,
follow_redirects=follow_redirects,
**kwargs,
)
response.raise_for_status()