Compare commits

..
118 Commits
Author SHA1 Message Date
HibiKier ebf3df046a 🎨 修改版本号 2024-10-22 10:40:00 +08:00
HibiKier b6611d6d0e 🐛 修复admin_check 2024-10-22 10:38:40 +08:00
HibiKier 23ea21380a 🐛 导入修复 2024-10-22 09:29:11 +08:00
梦璃雨落 54a93a2f54 🎈 perf(image_utils): 在image_utils中禁用代理下载 (#1710)
* 🎈 perf(image_utils): 在image_utils中禁用代理下载

get_download_image_hash使用场景是访问腾讯服务器获取图片,无需走代理

* ✨ Add optional proxy support to image hash download function
2024-10-21 23:49:32 +08:00
HibiKier 05f954eb8b ✨ 指定bot的功能管理 (#1706) 2024-10-21 19:07:35 +08:00
HibiKier 27d4630874 ✨ 修改版本 2024-10-20 19:24:47 +08:00
HibiKier 7ac2ff92c4 ✨ 本地引入echart.js 2024-10-20 13:34:47 +08:00
HibiKier 92b0c6b4bf 🎨 http_utils代码优化 2024-10-19 23:02:05 +08:00
HibiKier 75e10fe38a 🎨 修改早安时间 2024-10-19 18:12:35 +08:00
HibiKier 6dfebaae96 🎨 帮助界面优化 2024-10-19 01:26:30 +08:00
HibiKier 3ffe213652 🐛 修复签到金币排行bug以及添加官bot监控 2024-10-19 00:36:19 +08:00
HibiKier c9aa568767 ✨ 可以通过Bot判断是否为官bot 2024-10-18 23:13:16 +08:00
HibiKier 3d3a2a5f7f ✨ 部分功能适配QQ BOT (#1701) 2024-10-18 18:57:55 +08:00
HibiKier 7567bfb732 🐛 修复插件限制加载 2024-10-16 17:29:21 +08:00
HibiKier f0f0e94a9c 🎨 引用uninfo 2024-10-16 17:18:30 +08:00
HibiKier 41b0dac223 🐛 修复群组权限刷新 (#1700) 2024-10-16 13:29:44 +08:00
HibiKier 792bcaa711 ✨ 添加获取nb配置api 2024-10-16 12:58:01 +08:00
HibiKier fe1634eb2d 🎨 代码优化 (#1698) 2024-10-15 03:44:30 +08:00
HibiKier 4a52c4825b 🐛 修复webui接口 2024-10-14 22:24:47 +08:00
HibiKier 6358ce5266 🐛 修复webui好友数量显示和登录次数 2024-10-14 22:17:05 +08:00
HibiKier e98af0ac21 Merge branch 'dev' of https://github.com/HibiKier/zhenxun_bot into dev 2024-10-14 22:11:39 +08:00
HibiKier 48a48204f3 🐛 包优化 2024-10-14 11:00:39 +08:00
HibiKier 6f313986df 🎨 生成lock 2024-10-14 10:06:38 +08:00
HibiKier 3856ba09bb 🐛 功能调用统计只统计已加载的插件 2024-10-13 01:07:19 +08:00
HibiKier f982d862ee 🎨 添加分支 2024-10-12 22:44:08 +08:00
HibiKier c76566c2df 🔥 移除旧资源文件夹 2024-10-12 14:06:12 +08:00
HibiKier e7fffa3ef4 🔥 移除dinggong语音文件夹 2024-10-12 14:02:45 +08:00
HibiKier f7b28127e9 🐛 修复功能调用统计空白 (#1694) 2024-10-12 11:03:24 +08:00
AkashiCoin 7ea11a884b 🐳 chore: 补全release draft文件 (#1693) 2024-10-11 21:47:06 +08:00
AkashiCoin faa0785fa1 🐳 chore(update_version): 支持选择性的更新版本 (#1691)
* 🐳 chore(update_version): 支持选择性的更新版本

* 🐳 chore: 替换邮箱格式
2024-10-11 16:18:42 +08:00
HibiKier 9e5266a491 ✨ 使用uninfo进行群组成员更新 (#1690) 2024-10-10 23:25:46 +08:00
HibiKierandHibiKier 2f459719e8 🐛 修改禁用module (#1688)
* 🐛 修改禁用module

* chore(version): Update version to v0.2.3-4cde662

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
2024-10-09 17:45:53 +08:00
HibiKierandHibiKier 5f92efa658 🐛 webui 添加bot详情参数 (#1686)
* 🐛 webui 添加bot详情参数

* chore(version): Update version to v0.2.3-ba3a9f1

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
2024-10-07 15:37:55 +08:00
HibiKier 856976526f 🎨 修改限制配置文件key (#1685) 2024-10-06 18:16:35 +08:00
HibiKier 6852363a03 🐛 修复导入问题 (#1684) 2024-10-06 01:19:24 +08:00
HibiKier 862427a872 🎨 webui群组代码优化 (#1683) 2024-10-06 01:05:37 +08:00
HibiKierandHibiKier fd90e1ab82 🎨 notice响应期添加rule (#1682)
* 🎨 notice响应期添加rule

* chore(version): Update version to v0.2.3-f3e5c9e

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
2024-10-05 22:37:30 +08:00
HibiKier 3117dc264f ✨ unban支持使用id (#1681) 2024-10-05 19:07:18 +08:00
HibiKierandHibiKier a28a60d9c8 🎨 功能开关代码优化 (#1680)
* 🎨 功能开关代码优化

* chore(version): Update version to v0.2.3-5f361ff

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
2024-10-05 18:02:53 +08:00
HibiKier f0063283e7 🐛 优化功能开关管理 (#1679) 2024-10-05 16:45:02 +08:00
AkashiCoin 84680aa88d 🐳 chore(release_drafter): 支持release-drafter (#1672)
* 🐳 chore(release_drafter): 支持release-drafter

* 🐛 fix: 修复依赖字段
2024-10-05 16:37:29 +08:00
HibiKier bd50e17c58 🐛 修复调用统计异常 (#1674) 2024-10-04 00:14:36 +08:00
HibiKier f08114f6c5 ✨ 提供新webui api (#1673) 2024-10-03 23:56:17 +08:00
42b6e94564 ✨ 更新插件商店功能,支持通过模块名操作插件(#1670)
* 更新插件商店功能,支持通过模块名操作插件

- 扩展插件添加、移除和更新功能,支持使用插件ID或模块名
- 增加更新全部插件的功能
- 优化插件商店的命令使用说明
- 修复了一些与插件模块名相关的逻辑问题

* 优化插件更新和加载机制,提供测试函数

- 修复了插件更新函数中的条件判断逻辑

* 优化插件更新通知的格式

调整了插件更新通知的文本格式,去掉了多余的换行符,使消息内容更加紧凑和清晰。

* 更新测试用例中的消息格式,将插件更新通知中的空格改为换行符

* 移除版本号更新

* 重构插件管理器的数据源解析逻辑

- 将插件ID和模块名的检查逻辑移至单独的私有方法 _resolve_plugin_key
- 简化了 get_info 和 update_plugin 方法中的逻辑
- 提高了代码的可读性和可维护性

* 优化插件商店数据源类的插件查询逻辑

简化了ShopManage类中查询插件信息的逻辑。通过新增的_resolve_plugin_key类方法来解析插件ID或模块名,如果解析失败则捕获ValueError异常并返回错误信息。这样可以更清晰地处理插件查询逻辑,并避免冗余代码。

* 移除更新全部插件日志中的f-string

更新全部插件功能中,移除了日志记录中的f-string,简化了日志消息的格式。这个更改可能是为了统一日志记录的风格或者减少不必要的字符串格式化操作。

* Revert "移除版本号更新"

This reverts commit 2bcaa6f12e.

---------

Co-authored-by: molanp <molanp@users.noreply.github.com>
Co-authored-by: HibiKier <45528451+HibiKier@users.noreply.github.com>
Co-authored-by: AkashiCoin <l1040186796@gmail.com>
2024-10-02 18:32:21 +08:00
AkashiCoinandAkashiCoin d3a4a5bbf7 🐛 fix(github_utils): 修复路径解析问题 (#1668)
* 🐛 fix(github_utils): 修复路径解析问题

* chore(version): Update version to v0.2.3-a39d7a3

---------

Co-authored-by: AkashiCoin <AkashiCoin@users.noreply.github.com>
2024-10-02 12:54:12 +08:00
HibiKier 482eb1a214 🎨 修改requirements (#1665) 2024-10-01 00:29:29 +08:00
HibiKier 94e05944fd 🎨 修改版本号 (#1664) 2024-10-01 00:24:45 +08:00
HibiKier 2c8c46d6b1 🎨 修改README (#1663) 2024-10-01 00:17:14 +08:00
HibiKier 717a973807 ✨ 将cd,block,count限制复原配置文件 (#1662) 2024-10-01 00:05:43 +08:00
HibiKierandHibiKier d68a4099ba ✨ 新增插件商店api (#1659)
* ✨ 新增插件商店api

* chore(version): Update version to v0.2.2-7e15f20

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
2024-09-29 20:47:58 +08:00
HibiKier e8425f371c ✨ 修改个人信息菜单名称 (#1658) 2024-09-29 17:06:17 +08:00
HibiKier a3311adebb ✨ 新增个人信息命令 (#1657) 2024-09-29 17:00:31 +08:00
HibiKier 28b61e57cd ✨ 新增超级用户与管理员帮助模板 (#1655) 2024-09-27 16:59:41 +08:00
HibiKier 7890cc577f ✨ 安装/移除插件提供插件安装/卸载方法用于插件初始化 (#1654) 2024-09-27 10:29:59 +08:00
HibiKier b14220e6e3 ✨ 移除默认图片文件夹:爬 (#1653) 2024-09-27 10:27:01 +08:00
HibiKierandHibiKier 7ec1bc9fac 🐛 修复webui下载后首次启动错误 (#1652)
* 🐛 修复webui下载后首次启动错误

* chore(version): Update version to v0.2.2-4a8ef85

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
2024-09-25 19:41:45 +08:00
HibiKier e89d1d4688 🐛 修复群欢迎消息设置 (#1651) 2024-09-25 19:04:36 +08:00
HibiKier 6be9e477b1 🐛 修复群组中帮助功能状态显示问题 (#1650) 2024-09-25 18:29:01 +08:00
AkashiCoin 207f947a1c 🐛 fix(http_utils): 流式下载Content-Length错误 (#1647) 2024-09-22 17:12:21 +08:00
HibiKier 32c11b9919 🎨 更新README (#1645) 2024-09-21 23:36:17 +08:00
HibiKier 3fc4eaa39a 🐛 签到名称自适应 (#1644) 2024-09-21 23:08:48 +08:00
HibiKier a04475abc1 ✨ 重构qq群事件处理 (#1643) 2024-09-21 23:07:00 +08:00
AkashiCoin 38976589ec 🐳 chore: 修改运行检查触发路径 (#1642)
* 🐳 chore: 修改运行检查触发路径

* 🐳 chore: 添加tests目录
2024-09-21 18:01:45 +08:00
AkashiCoinandAkashiCoin f2c20b84bf 🎈 perf: 使用commit号下载插件 (#1641)
* 🎈 perf: 使用commit号下载插件

* chore(version): Update version to v0.2.2-f9c7360

---------

Co-authored-by: AkashiCoin <AkashiCoin@users.noreply.github.com>
2024-09-21 17:38:37 +08:00
HibiKier 983248374d ✨ message_build支持AtAll (#1639) 2024-09-19 20:25:45 +08:00
HibiKier 6f635ed978 🐛 修复群权限与插件等级匹配 (#1635) 2024-09-16 21:18:42 +08:00
HibiKier fcfaf56021 🐛 修复商店商品为空时报错 (#1634) 2024-09-16 21:17:09 +08:00
AkashiCoin 60f4406ec1 🧪 test(auto_update): 修复测试用例 (#1633) 2024-09-16 20:29:46 +08:00
AkashiCoinandAkashiCoin 51c010daa8 🎈 perf(github_utils): 支持github url下载遍历 (#1632)
* 🎈 perf(github_utils): 支持github url下载遍历

* 🐞 fix(http_utils): 修复一些下载问题

* 🦄 refactor(http_utils): 部分重构

* chore(version): Update version to v0.2.2-e6f17c4

---------

Co-authored-by: AkashiCoin <AkashiCoin@users.noreply.github.com>
2024-09-16 20:08:42 +08:00
AkashiCoin cd88d805ce 🐳 chore: 支持自动修改版本号 (#1629) 2024-09-16 19:13:20 +08:00
HibiKier e41e16370e ✨ 群组发言时间检测提供开关配置 (#1630) 2024-09-14 19:17:40 +08:00
HibiKier f2e354edeb ✨ 当管理员尝试ban真寻时将被反杀 (#1628) 2024-09-14 16:29:27 +08:00
HibiKier f1354c6264 🐛 修复群权限与插件等级匹配 (#1627) 2024-09-14 14:23:19 +08:00
HibiKier 029a731fb9 ✨ 重构帮助,限制普通用户查询管理插件 (#1626) 2024-09-14 05:23:55 +08:00
AkashiCoin d97e437e80 🎈 优先使用github api (#1625) 2024-09-13 20:41:33 +08:00
HibiKier 8a688eb4f0 🐛 好感度排行提供默认值 (#1624) 2024-09-12 22:15:04 +08:00
HibiKier 94ef33264b 🐛 签到文本适应 (#1622) 2024-09-11 12:53:12 +08:00
HibiKier a8355fbab9 🐛 修复功能少时zhenxun帮助图片排序问题 (#1620) 2024-09-11 11:53:49 +08:00
HibiKier 95762bdddd 🐛 修复路径解压与挂载 (#1619) 2024-09-10 20:17:09 +08:00
HibiKier 4e42d1dda1 🐛 修复超级用户id获取问题 2024-09-09 23:01:15 +08:00
HibiKier e4a92ea34b ✨ 签到/金币排行限制最大数量 (#1616)
* ✨ 签到/金币排行限制最大数量
2024-09-09 22:47:23 +08:00
AkashiCoin f11e9c58e4 🔨 提取GitHub相关操作 (#1609)
* 🔨 提取GitHub相关操作

* 🔨 重构API策略
2024-09-08 12:38:30 +08:00
AkashiCoinandHibiKier 342e70cc38 📝 修改README
Co-Authored-By: HibiKier <45528451+HibiKier@users.noreply.github.com>
2024-09-08 11:34:26 +08:00
AkashiCoinandHibiKier 440e7b54a5 ✨ 添加金币排行
Co-Authored-By: HibiKier <45528451+HibiKier@users.noreply.github.com>
2024-09-08 11:33:19 +08:00
AkashiCoin fe11ff0772 🔧 VSCode配置修改 2024-09-07 17:51:03 +08:00
AkashiCoin 2b006b8f5e 🔧 VSCode配置修改 2024-09-07 17:11:01 +08:00
HibiKier 1790a0b09e ✨提供sqlite和mysql连接url示例 2024-09-07 17:10:08 +08:00
HibiKier 057001f0bd ✨ 支持mysql,psql,sqlite随机函数 2024-09-07 16:46:56 +08:00
AkashiCoin e618b19283 🐛 修复自检在ARM上的问题 (#1607)
* 🐛 修复自检在ARM上的问题

* ✅ 优化测试
2024-09-07 16:17:29 +08:00
HibiKier 62fd93c1ff 🐛 过滤父插件 2024-09-07 13:54:25 +08:00
HibiKier 807b2f6504 🐛 私聊时修改插件时删除私聊帮助 2024-09-07 13:16:41 +08:00
HibiKier 0a5ab83ffe 🎨 代码结构优化 2024-09-07 12:46:25 +08:00
ElagaandHibiKier 3f4787d4c6 修复签到逻辑bug,并使代码更灵活以适应签到好感度等级配置 (#1606)
* 修复签到功能已知问题

* 修复签到功能已知问题

* 修改参数名称

* 修改uid判断

---------

Co-authored-by: HibiKier <45528451+HibiKier@users.noreply.github.com>
2024-09-07 12:35:39 +08:00
HibiKier db9153f42c 🐛 自检html修正 2024-09-07 01:50:24 +08:00
HibiKier 3b4c206a24 ✨ 重构自检ui 2024-09-07 01:25:42 +08:00
HibiKier 51371ba954 🐛 修复插件开关有时出现错误 2024-09-05 17:41:33 +08:00
HibiKier c36bb9771c 🎨 优化代码 2024-09-04 21:10:54 +08:00
AkashiCoin ce97dedc5f 🐛 文件下载逻辑修改 2024-09-03 17:13:31 +08:00
AkashiCoin 682d19aa2b 🎨 采取Sourcery建议 2024-09-03 16:52:11 +08:00
AkashiCoin c3927c7f2e ✨ 添加API缓存 2024-09-03 16:52:11 +08:00
AkashiCoin 8911bbfa21 🐛 修复测试用例 2024-09-03 16:52:11 +08:00
AkashiCoin 7288d5bdba ✨ 添加仓库目录多获取渠道 2024-09-03 16:52:11 +08:00
AkashiCoin 8615eb20d4 ⚡ 添加github镜像 2024-09-03 16:52:11 +08:00
AkashiCoin a61934650e ➕ 添加依赖aiocache 2024-09-03 16:52:11 +08:00
HibiKier a2549a0ae9 🎨 更新requirements 2024-09-03 11:03:30 +08:00
fanyinrumeng 405e2d3a4c 🚀 更新Dockerfile (#1599) 2024-09-02 23:12:27 +08:00
HibiKier 02aba68269 🎨 代码优化 2024-09-02 21:45:37 +08:00
HibiKier 8d071f853b 🐛 修复更新群组成员信息 2024-09-02 17:32:12 +08:00
AkashiCoin 44e0f2d410 🐛 增加插件状态检查 (#1598)
* ✅ 优化测试用例

* 🐛 更改插件更新与安装逻辑
2024-09-02 15:00:37 +08:00
AkashiCoin 9eca6a97ca 🐛 修复插件商店检查插件更新问题 (#1597)
* 🐛 修复插件商店检查插件更新问题

* 🐛 恶意命令检测问题
2024-09-02 12:00:27 +08:00
HibiKier a56d1f2bd8 🐛 修复超级用户对群组功能开关 2024-09-02 11:43:01 +08:00
HibiKier 133d4e193a 🐛 修改bug与版本锁定 2024-09-02 11:25:47 +08:00
HibiKier db75c4a433 Update README.md 2024-09-02 09:53:58 +08:00
HibiKier 15ad90da88 🎨 修改readme 2024-09-02 09:51:36 +08:00
AkashiCoin 29c48765ae 🐛修复添加插件返回403的问题 (#1595)
* 完善测试方法
* vscode测试配置
* 重构插件安装过程
2024-09-02 01:50:39 +08:00
HibiKier 8fe061738a 🐛 bug修复 2024-09-01 23:30:26 +08:00
AkashiCoin 7e7436f433 ✅ 添加测试:更新与添加插件 (#1594)
* ✅ 测试更新与添加插件

* ✅ Sourcery建议

* 👷 添加pytest

* 🎨 优化代码
2024-09-01 14:53:41 +08:00
HibiKier a3681216bd ✨ 父级插件加载 2024-08-30 23:50:45 +08:00
14 changed files with 126 additions and 431 deletions
+8 -1
View File
@@ -8,12 +8,19 @@ NICKNAME=["真寻", "小真寻", "绪山真寻", "小寻子"]
SESSION_EXPIRE_TIMEOUT=30
ALCONNA_USE_COMMAND_START=True
# 全局图片统一使用bytes发送,当真寻与协议端不在同一服务器上时为True
IMAGE_TO_BYTES = False
IMAGE_TO_BYTES = True
# 回复消息时自称
SELF_NICKNAME="小真寻"
# 官bot appid:bot账号
QBOT_ID_DATA = '{
}'
# 数据库配置
# 示例: "postgres://user:password@127.0.0.1:5432/database"
# 示例: "mysql://user:password@127.0.0.1:3306/database"
-65
View File
@@ -1,65 +0,0 @@
name: Update Version
on:
pull_request_target:
paths:
- zhenxun/**
- resources/**
- bot.py
types:
- opened
- synchronize
branches:
- main
- dev
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Read current version
id: read_version
run: |
version_line=$(grep '__version__' __version__)
version=$(echo $version_line | sed -E 's/__version__:\s*v([0-9]+\.[0-9]+\.[0-9]+)(-.+)?/\1/')
echo "Current version: $version"
echo "current_version=$version" >> $GITHUB_OUTPUT
- name: Check for version file changes
id: check_diff
run: |
if git diff --name-only HEAD~1 HEAD | grep -q '__version__'; then
echo "Version file has changes"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version file has no changes"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
- name: Get commit hash
id: get_commit_hash
run: echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Update version file
if: steps.check_diff.outputs.version_changed == 'false'
run: |
current_version="${{ steps.read_version.outputs.current_version }}"
commit_hash="${{ steps.get_commit_hash.outputs.commit_hash }}"
new_version="v${current_version}-${commit_hash}"
echo "Updating version to: $new_version"
echo "__version__: $new_version" > __version__
git config --global user.name "${{ github.event.pull_request.user.login }}"
git config --global user.email "${{ github.event.pull_request.user.login }}@users.noreply.github.com"
git add __version__
git remote set-url origin https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git commit -m "chore(version): Update version to $new_version"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
- name: Check updated version
if: steps.check_diff.outputs.version_changed == 'false'
run: cat __version__
+3 -2
View File
@@ -13,18 +13,19 @@
"getbbox",
"hibiapi",
"httpx",
"jsdelivr",
"kaiheila",
"lolicon",
"nonebot",
"onebot",
"pixiv",
"qbot",
"Setu",
"tobytes",
"ujson",
"unban",
"userinfo",
"zhenxun",
"jsdelivr"
"zhenxun"
],
"python.analysis.autoImportCompletions": true,
"python.testing.pytestArgs": ["tests"],
+1 -1
View File
@@ -1 +1 @@
__version__: v0.2.4
__version__: v0.2.4-fix1
BIN
View File
Binary file not shown.
+6
View File
@@ -19,6 +19,8 @@ require("nonebot_plugin_htmlrender")
from zhenxun.services.log import logger
from zhenxun.models.sign_user import SignUser
from zhenxun.models.goods_info import GoodsInfo
from zhenxun.utils.platform import PlatformUtils
from zhenxun.models.bot_console import BotConsole
from zhenxun.models.user_console import UserConsole
from zhenxun.utils.decorator.shop import shop_register
from zhenxun.models.bot_connect_log import BotConnectLog
@@ -33,6 +35,10 @@ async def _(bot: Bot):
await BotConnectLog.create(
bot_id=bot.self_id, platform=bot.adapter, connect_time=datetime.now(), type=1
)
if not await BotConsole.exists(bot_id=bot.self_id):
await BotConsole.create(
bot_id=bot.self_id, platform=PlatformUtils.get_platform(bot)
)
@driver.on_bot_disconnect
@@ -11,6 +11,7 @@ from zhenxun.services.log import logger
from zhenxun.configs.config import Config
from zhenxun.utils.message import MessageUtils
from zhenxun.models.level_user import LevelUser
from zhenxun.models.bot_console import BotConsole
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.models.plugin_limit import PluginLimit
from zhenxun.models.user_console import UserConsole
@@ -244,6 +245,7 @@ class AuthChecker:
if not plugin.limit_superuser:
cost_gold = 0
raise IsSuperuserException()
await self.auth_bot(plugin, bot.self_id)
await self.auth_group(plugin, session, message)
await self.auth_admin(plugin, session)
await self.auth_plugin(plugin, session, event)
@@ -278,6 +280,16 @@ class AuthChecker:
if is_ignore:
raise IgnoredException("权限检测 ignore")
async def auth_bot(self, plugin: PluginInfo, bot_id: str):
"""机器人权限
参数:
plugin: PluginInfo
bot_id: bot_id
"""
if await BotConsole.is_block_plugin(plugin.module, bot_id):
raise IgnoredException("机器人权限检测 ignore")
async def auth_limit(self, plugin: PluginInfo, session: EventSession):
"""插件限制
@@ -1,321 +0,0 @@
import os
import re
import random
from datetime import datetime
import ujson as json
from nonebot.adapters import Bot
from nonebot_plugin_alconna import At
from nonebot import on_notice, on_request
from nonebot.plugin import PluginMetadata
from nonebot.adapters.onebot.v11 import (
GroupDecreaseNoticeEvent,
GroupIncreaseNoticeEvent,
)
from nonebot.adapters.onebot.v12 import (
GroupMemberDecreaseEvent,
GroupMemberIncreaseEvent,
)
from zhenxun.services.log import logger
from zhenxun.utils.utils import FreqLimiter
from zhenxun.utils.message import MessageUtils
from zhenxun.models.fg_request import FgRequest
from zhenxun.models.level_user import LevelUser
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.utils.common_utils import CommonUtils
from zhenxun.configs.config import Config, BotConfig
from zhenxun.models.group_console import GroupConsole
from zhenxun.models.group_member_info import GroupInfoUser
from zhenxun.utils.enum import PluginType, RequestHandleType
from zhenxun.configs.path_config import DATA_PATH, IMAGE_PATH
from zhenxun.configs.utils import Task, RegisterConfig, PluginExtraData
__plugin_meta__ = PluginMetadata(
name="QQ群事件处理",
description="群事件处理",
usage="",
extra=PluginExtraData(
author="HibiKier",
version="0.1",
plugin_type=PluginType.HIDDEN,
configs=[
RegisterConfig(
module="invite_manager",
key="message",
value=f"请不要未经同意就拉{BotConfig.self_nickname}入群!告辞!",
help="强制拉群后进群回复的内容",
),
RegisterConfig(
module="invite_manager",
key="flag",
value=True,
help="强制拉群后进群退出并回复内容",
default_value=True,
type=bool,
),
RegisterConfig(
module="invite_manager",
key="welcome_msg_cd",
value=5,
help="群欢迎消息cd",
default_value=5,
type=int,
),
RegisterConfig(
module="_task",
key="DEFAULT_GROUP_WELCOME",
value=True,
help="被动 进群欢迎 进群默认开关状态",
default_value=True,
type=bool,
),
RegisterConfig(
module="_task",
key="DEFAULT_REFUND_GROUP_REMIND",
value=True,
help="被动 退群提醒 进群默认开关状态",
default_value=True,
type=bool,
),
],
tasks=[
Task(module="group_welcome", name="进群欢迎"),
Task(module="refund_group_remind", name="退群提醒"),
],
).dict(),
)
base_config = Config.get("invite_manager")
limit_cd = base_config.get("welcome_msg_cd")
_flmt = FreqLimiter(limit_cd)
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 | GroupMemberIncreaseEvent):
superusers = BotConfig.get_superuser("qq")
user_id = str(event.user_id)
group_id = str(event.group_id)
if user_id == bot.self_id:
"""新成员为bot本身"""
group = await GroupConsole.get_or_none(
group_id=group_id, channel_id__isnull=True
)
if not group or group.group_flag == 0:
"""群聊不存在或被强制拉群"""
if base_config.get("flag"):
"""退出群组"""
try:
if result_msg := base_config.get("message"):
await bot.send_group_msg(
group_id=event.group_id, message=result_msg
)
await bot.set_group_leave(group_id=event.group_id)
if superusers:
await bot.send_private_msg(
user_id=int(superusers[0]),
message=f"触发强制入群保护,已成功退出群聊 {group_id}...",
)
logger.info(
"强制拉群或未有群信息,退出群聊成功",
"入群检测",
group_id=event.group_id,
)
if req := await FgRequest.get_or_none(
group_id=group_id, handle_type__isnull=True
):
req.handle_type = RequestHandleType.IGNORE
await req.save(update_fields=["handle_type"])
except Exception as e:
logger.error(
"强制拉群或未有群信息,退出群聊失败",
"入群检测",
group_id=event.group_id,
e=e,
)
if superusers:
await bot.send_private_msg(
user_id=int(superusers[0]),
message="触发强制入群保护,"
f"退出群聊 {event.group_id} 失败...",
)
await GroupConsole.filter(group_id=group_id).delete()
else:
"""允许群组并设置群认证,默认群功能开关"""
if group:
await GroupConsole.filter(
group_id=group_id, channel_id__isnull=True
).update(group_flag=1)
else:
block_plugin = ""
if plugin_list := await PluginInfo.filter(
default_status=False
).all():
for plugin in plugin_list:
block_plugin += f"{plugin.module},"
group_info = await bot.get_group_info(group_id=event.group_id)
await GroupConsole.create(
group_id=group_info["group_id"],
group_name=group_info["group_name"],
max_member_count=group_info["max_member_count"],
member_count=group_info["member_count"],
group_flag=1,
block_plugin=block_plugin,
platform="qq",
)
"""刷新群管理员权限"""
admin_default_auth = Config.get_config(
"admin_bot_manage", "ADMIN_DEFAULT_AUTH"
)
# 即刻刷新权限
for user_info in await bot.get_group_member_list(
group_id=event.group_id
):
"""即刻刷新权限"""
if (
user_info["role"]
in [
"owner",
"admin",
]
and not await LevelUser.is_group_flag(
user_info["user_id"], group_id
)
and admin_default_auth is not None
):
await LevelUser.set_level(
user_info["user_id"],
user_info["group_id"],
admin_default_auth,
)
logger.debug(
f"添加默认群管理员权限: {admin_default_auth}",
"入群检测",
session=user_info["user_id"],
group_id=user_info["group_id"],
)
if str(user_info["user_id"]) in bot.config.superusers:
await LevelUser.set_level(
user_info["user_id"], user_info["group_id"], 9
)
logger.debug(
"添加超级用户权限: 9",
"入群检测",
session=user_info["user_id"],
group_id=user_info["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
)
await GroupInfoUser.update_or_create(
user_id=str(user_info["user_id"]),
group_id=str(user_info["group_id"]),
defaults={"user_name": user_info["nickname"], "user_join_time": join_time},
)
logger.info(f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新成功")
if _flmt.check(group_id):
"""群欢迎消息"""
_flmt.start_cd(group_id)
path = DATA_PATH / "welcome_message" / "qq" / f"{group_id}"
file = path / "text.json"
msg_list = []
if file.exists():
data = json.load((path / "text.json").open(encoding="utf-8"))
message = data["message"]
msg_split = re.split(r"\[image:\d+\]", message)
if data["at"]:
msg_list.append(At(flag="user", target=user_id))
for i, text in enumerate(msg_split):
msg_list.append(text)
img_file = path / f"{i}.png"
if img_file.exists():
msg_list.append(img_file)
if not await CommonUtils.task_is_block("group_welcome", group_id):
logger.info("发送群欢迎消息...", "入群检测", group_id=group_id)
if msg_list:
await MessageUtils.build_message(msg_list).send()
else:
image = (
IMAGE_PATH
/ "qxz"
/ random.choice(os.listdir(IMAGE_PATH / "qxz"))
)
await MessageUtils.build_message(
[
"新人快跑啊!!本群现状↓(快使用自定义!)",
image,
]
).send()
@group_decrease_handle.handle()
async def _(bot: Bot, event: GroupDecreaseNoticeEvent | GroupMemberDecreaseEvent):
if event.sub_type == "kick_me":
"""踢出Bot"""
group_id = event.group_id
operator_id = event.operator_id
if user := await GroupInfoUser.get_or_none(
user_id=str(event.operator_id), group_id=str(event.group_id)
):
operator_name = user.user_name
else:
operator_name = "None"
group = await GroupConsole.filter(group_id=str(group_id)).first()
group_name = group.group_name if group else ""
if superusers := BotConfig.get_superuser("qq"):
coffee = int(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]}",
)
if group:
await group.delete()
return
if str(event.user_id) == bot.self_id:
"""踢出Bot"""
await GroupConsole.filter(group_id=str(event.group_id)).delete()
return
if user := await GroupInfoUser.get_or_none(
user_id=str(event.user_id), group_id=str(event.group_id)
):
user_name = user.user_name
else:
user_name = f"{event.user_id}"
await GroupInfoUser.filter(
user_id=str(event.user_id), group_id=str(event.group_id)
).delete()
logger.info(
f"名称: {user_name} 退出群聊",
"group_decrease_handle",
session=event.user_id,
group_id=event.group_id,
)
result = ""
if event.sub_type == "leave":
result = 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"] or operator["nickname"]
result = f"{user_name} 被 {operator_name} 送走了."
if not await CommonUtils.task_is_block("refund_group_remind", str(event.group_id)):
await group_decrease_handle.send(f"{result}")
@@ -0,0 +1,30 @@
import os
import time
from nonebot.rule import to_me
from nonebot.utils import run_sync
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot_plugin_session import EventSession
from nonebot_plugin_apscheduler import scheduler
from nonebot_plugin_alconna import Alconna, on_alconna
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
from zhenxun.utils.message import MessageUtils
from zhenxun.configs.path_config import TEMP_PATH
from zhenxun.configs.utils import PluginExtraData
from zhenxun.utils.utils import ResourceDirManager
__plugin_meta__ = PluginMetadata(
name="Bot管理",
description="指定bot对象的功能/被动开关和状态",
usage="""
清理临时数据
""".strip(),
extra=PluginExtraData(
author="",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
)
+60
View File
@@ -0,0 +1,60 @@
from tortoise import fields
from zhenxun.services.db_context import Model
class BotConsole(Model):
id = fields.IntField(pk=True, generated=True, auto_increment=True)
"""自增id"""
bot_id = fields.CharField(255, unique=True, description="bot_id")
"""bot_id"""
status = fields.BooleanField(default=True, description="Bot状态")
"""Bot状态"""
block_plugin = fields.TextField(default="", description="禁用插件")
"""禁用插件"""
block_task = fields.TextField(default="", description="禁用被动技能")
"""禁用被动技能"""
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
"""创建时间"""
platform = fields.CharField(255, null=True, description="平台")
"""平台"""
class Meta: # type: ignore
table = "bot_console"
table_description = "Bot数据表"
@classmethod
async def get_bot_status(cls, bot_id: str) -> bool:
result = await cls.get_or_none(bot_id=bot_id)
return result.status if result else False
@classmethod
async def set_block_plugin(cls, bot_id: str, module: str):
bot_data, _ = await cls.get_or_create(bot_id=bot_id)
if f"<{module}," not in bot_data.block_plugin:
bot_data.block_plugin += f"<{module},"
await bot_data.save(update_fields=["block_plugin"])
@classmethod
async def set_unblock_plugin(cls, bot_id: str, module: str):
bot_data, _ = await cls.get_or_create(bot_id=bot_id)
if f"<{module}," in bot_data.block_plugin:
bot_data.block_plugin = bot_data.block_plugin.replace(f"<{module},", "")
await bot_data.save(update_fields=["block_plugin"])
@classmethod
async def set_block_task(cls, bot_id: str, task: str):
bot_data, _ = await cls.get_or_create(bot_id=bot_id)
if f"<{task}," not in bot_data.block_task:
bot_data.block_plugin += f"<{task},"
await bot_data.save(update_fields=["block_task"])
@classmethod
async def is_block_plugin(cls, bot_id: str, task: str) -> bool:
bot_data, _ = await cls.get_or_create(bot_id=bot_id)
return f"<{task}," in bot_data.block_plugin
@classmethod
async def is_block_task(cls, bot_id: str, task: str) -> bool:
bot_data, _ = await cls.get_or_create(bot_id=bot_id)
return f"<{task}," in bot_data.block_task
+2 -2
View File
@@ -37,8 +37,8 @@ class GroupConsole(Model):
default="", description="超级用户禁用插件"
)
"""超级用户禁用插件"""
block_task = fields.TextField(default="", description="禁用插件")
"""禁用插件"""
block_task = fields.TextField(default="", description="禁用被动技能")
"""禁用被动技能"""
superuser_block_task = fields.TextField(default="", description="超级用户禁用被动")
"""超级用户禁用被动"""
platform = fields.CharField(255, default="qq", description="所属平台")
-35
View File
@@ -1,35 +0,0 @@
import re
GITHUB_REPO_URL_PATTERN = re.compile(
r"^https://github.com/(?P<owner>[^/]+)/(?P<repo>[^/]+)(/tree/(?P<branch>[^/]+))?$"
)
"""github仓库地址正则"""
JSD_PACKAGE_API_FORMAT = (
"https://data.jsdelivr.com/v1/packages/gh/{owner}/{repo}@{branch}"
)
"""jsdelivr包地址格式"""
GIT_API_TREES_FORMAT = (
"https://api.github.com/repos/{owner}/{repo}/git/trees/{branch}?recursive=1"
)
"""git api trees地址格式"""
CACHED_API_TTL = 300
"""缓存api ttl"""
RAW_CONTENT_FORMAT = "https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}"
"""raw content格式"""
ARCHIVE_URL_FORMAT = "https://github.com/{owner}/{repo}/archive/refs/heads/{branch}.zip"
"""archive url格式"""
RELEASE_ASSETS_FORMAT = (
"https://github.com/{owner}/{repo}/releases/download/{version}/{filename}"
)
"""release assets格式"""
RELEASE_SOURCE_FORMAT = (
"https://codeload.github.com/{owner}/{repo}/legacy.{compress}/refs/tags/{version}"
)
"""release 源码格式"""
+2 -2
View File
@@ -390,7 +390,7 @@ def get_img_hash(image_file: str | Path) -> str:
return str(hash_value)
async def get_download_image_hash(url: str, mark: str) -> str:
async def get_download_image_hash(url: str, mark: str, use_proxy: bool = False) -> str:
"""下载图片获取哈希值
参数:
@@ -402,7 +402,7 @@ async def get_download_image_hash(url: str, mark: str) -> str:
"""
try:
if await AsyncHttpx.download_file(
url, TEMP_PATH / f"compare_download_{mark}_img.jpg"
url, TEMP_PATH / f"compare_download_{mark}_img.jpg", use_proxy=use_proxy
):
img_hash = get_img_hash(TEMP_PATH / f"compare_download_{mark}_img.jpg")
return str(img_hash)
+2 -2
View File
@@ -27,14 +27,14 @@ def admin_check(a: int | str, key: str | None = None) -> Rule:
if PlatformUtils.is_qbot(session):
"""官bot接口,放弃所有权限检查"""
return False
if session.id and session.group:
if session.group:
level = a
if isinstance(a, str) and key:
level = Config.get_config(a, key)
if level is not None:
return bool(
await LevelUser.check_level(
session.id, session.group.id, int(level)
session.user.id, session.group.id, int(level)
)
)
return False