mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 更新群组信息
This commit is contained in:
parent
8d6417b8ff
commit
69f09b92d3
@ -279,6 +279,7 @@ body {
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
top: 350px;
|
top: 350px;
|
||||||
left: 260px;
|
left: 250px;
|
||||||
font-family: 'yshsFont';
|
font-family: 'yshsFont';
|
||||||
|
width: 210px;
|
||||||
}
|
}
|
||||||
45
zhenxun/builtin_plugins/admin/group_update.py
Normal file
45
zhenxun/builtin_plugins/admin/group_update.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from nonebot.adapters import Bot
|
||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||||
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.utils.message import MessageUtils
|
||||||
|
from zhenxun.utils.platform import PlatformUtils
|
||||||
|
from zhenxun.utils.rules import admin_check, ensure_group
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="更新群组列表",
|
||||||
|
description="更新群组列表",
|
||||||
|
usage="""
|
||||||
|
更新群组的基本信息
|
||||||
|
指令:
|
||||||
|
更新群组信息
|
||||||
|
""".strip(),
|
||||||
|
extra=PluginExtraData(
|
||||||
|
author="HibiKier",
|
||||||
|
version="0.1",
|
||||||
|
plugin_type=PluginType.SUPER_AND_ADMIN,
|
||||||
|
admin_level=1,
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_matcher = on_alconna(
|
||||||
|
Alconna("更新群组信息"),
|
||||||
|
rule=admin_check(1) & ensure_group,
|
||||||
|
priority=5,
|
||||||
|
block=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@_matcher.handle()
|
||||||
|
async def _(bot: Bot, session: EventSession, arparma: Arparma):
|
||||||
|
logger.info("更新群组信息", arparma.header_result, session=session)
|
||||||
|
try:
|
||||||
|
await PlatformUtils.update_group(bot)
|
||||||
|
await MessageUtils.build_message("已经成功更新了群组信息!").send(reply_to=True)
|
||||||
|
except Exception as e:
|
||||||
|
await MessageUtils.build_message("更新群组信息失败!").finish(reply_to=True)
|
||||||
@ -23,17 +23,15 @@ async def _(bot: Bot):
|
|||||||
if PlatformUtils.get_platform(bot) == "qq":
|
if PlatformUtils.get_platform(bot) == "qq":
|
||||||
logger.debug(f"更新Bot: {bot.self_id} 的群认证...")
|
logger.debug(f"更新Bot: {bot.self_id} 的群认证...")
|
||||||
group_list, _ = await PlatformUtils.get_group_list(bot)
|
group_list, _ = await PlatformUtils.get_group_list(bot)
|
||||||
gid_list = [(g.group_id, g.group_name) for g in group_list]
|
|
||||||
db_group_list = await GroupConsole.all().values_list("group_id", flat=True)
|
db_group_list = await GroupConsole.all().values_list("group_id", flat=True)
|
||||||
create_list = []
|
create_list = []
|
||||||
update_id = []
|
update_id = []
|
||||||
for gid, name in gid_list:
|
for group in group_list:
|
||||||
if gid not in db_group_list:
|
if group.group_id not in db_group_list:
|
||||||
create_list.append(
|
group.group_flag = 1
|
||||||
GroupConsole(group_id=gid, group_name=name, group_flag=1)
|
create_list.append(group)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
update_id.append(gid)
|
update_id.append(group.group_id)
|
||||||
if create_list:
|
if create_list:
|
||||||
await GroupConsole.bulk_create(create_list, 10)
|
await GroupConsole.bulk_create(create_list, 10)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -349,22 +349,37 @@ class PlatformUtils:
|
|||||||
int: 更新个数
|
int: 更新个数
|
||||||
"""
|
"""
|
||||||
create_list = []
|
create_list = []
|
||||||
|
update_list = []
|
||||||
group_list, platform = await cls.get_group_list(bot)
|
group_list, platform = await cls.get_group_list(bot)
|
||||||
if group_list:
|
if group_list:
|
||||||
exists_group_list = await GroupConsole.all().values_list(
|
db_group = await GroupConsole.all()
|
||||||
"group_id", "channel_id"
|
db_group_id = [(group.group_id, group.channel_id) for group in db_group]
|
||||||
)
|
|
||||||
for group in group_list:
|
for group in group_list:
|
||||||
group.platform = platform
|
group.platform = platform
|
||||||
if (group.group_id, group.channel_id) not in exists_group_list:
|
if (group.group_id, group.channel_id) not in db_group_id:
|
||||||
create_list.append(group)
|
create_list.append(group)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"群聊信息更新成功",
|
"群聊信息更新成功",
|
||||||
"更新群信息",
|
"更新群信息",
|
||||||
target=f"{group.group_id}:{group.channel_id}",
|
target=f"{group.group_id}:{group.channel_id}",
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
_group = [
|
||||||
|
g
|
||||||
|
for g in db_group
|
||||||
|
if g.group_id == group.group_id
|
||||||
|
and g.channel_id == group.channel_id
|
||||||
|
][0]
|
||||||
|
_group.group_name = group.group_name
|
||||||
|
_group.max_member_count = group.max_member_count
|
||||||
|
_group.member_count = group.member_count
|
||||||
|
update_list.append(_group)
|
||||||
if create_list:
|
if create_list:
|
||||||
await GroupConsole.bulk_create(create_list, 10)
|
await GroupConsole.bulk_create(create_list, 10)
|
||||||
|
if group_list:
|
||||||
|
await GroupConsole.bulk_update(
|
||||||
|
update_list, ["group_name", "max_member_count", "member_count"], 10
|
||||||
|
)
|
||||||
return len(create_list)
|
return len(create_list)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user