mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
✨ bot已有群组添加群认证
This commit is contained in:
parent
59b32f8b25
commit
5a5c0be51a
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -20,6 +20,7 @@
|
||||
"pixiv",
|
||||
"Setu",
|
||||
"tobytes",
|
||||
"ujson",
|
||||
"unban",
|
||||
"userinfo",
|
||||
"zhenxun"
|
||||
|
||||
@ -1,5 +1,41 @@
|
||||
from pathlib import Path
|
||||
|
||||
import nonebot
|
||||
from nonebot.adapters import Bot
|
||||
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
nonebot.load_plugins(str(Path(__file__).parent.resolve()))
|
||||
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
|
||||
|
||||
@driver.on_bot_connect
|
||||
async def _(bot: Bot):
|
||||
"""将bot已存在的群组添加群认证
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
"""
|
||||
if PlatformUtils.get_platform(bot) == "qq":
|
||||
logger.debug(f"更新Bot: {bot.self_id} 的群认证...")
|
||||
group_list, _ = await PlatformUtils.get_group_list(bot)
|
||||
gid_list = [g.group_id for g in group_list]
|
||||
db_group_list = await GroupConsole.all().values_list("group_id", flat=True)
|
||||
create_list = []
|
||||
update_id = []
|
||||
for gid in gid_list:
|
||||
if gid not in db_group_list:
|
||||
create_list.append(GroupConsole(group_id=gid, group_flag=1))
|
||||
else:
|
||||
update_id.append(gid)
|
||||
if create_list:
|
||||
await GroupConsole.bulk_create(create_list, 10)
|
||||
else:
|
||||
await GroupConsole.filter(group_id__in=update_id).update(group_flag=1)
|
||||
logger.debug(
|
||||
f"更新Bot: {bot.self_id} 的群认证完成,共创建 {len(create_list)} 条数据,共修改 {len(update_id)} 条数据..."
|
||||
)
|
||||
|
||||
@ -63,6 +63,7 @@ for file in [statistics_group_file, statistics_user_file]:
|
||||
data[x][key]["商店"] = num
|
||||
for x in ["week_statistics", "month_statistics"]:
|
||||
for key in data[x].keys():
|
||||
num = 0
|
||||
if key == "total":
|
||||
if data[x][key].get("ai") is not None:
|
||||
if data[x][key].get("Ai") is not None:
|
||||
|
||||
@ -111,7 +111,7 @@ async def init():
|
||||
await Tortoise.generate_schemas()
|
||||
logger.info(f"Database loaded successfully!")
|
||||
except Exception as e:
|
||||
raise Exception(f"数据库连接错误...")
|
||||
raise Exception(f"数据库连接错误... e:{e}")
|
||||
|
||||
|
||||
async def disconnect():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user