AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Plugin] 插件名group_welcome_with_time

Open mjy1113451 opened this issue 10 months ago • 1 comments

插件信息

{
repo:main.py
name:欢迎新人
Author  : mjy1113457,爱玩电脑的张翰博
Version : 1.0.0
Desc    : 群聊新成员入群欢迎插件,自动发送包含入群时间的欢迎消息
"""
from datetime import datetime
from nonebot import on_notice
from nonebot.plugin import PluginMetadata
from nonebot.adapters.onebot.v11 import Bot, GroupIncreaseNoticeEvent, MessageSegment

# 插件元信息(必填,用于插件市场展示/识别)
__plugin_meta__ = PluginMetadata(
    name="入群欢迎插件",
    description="新成员入群时自动发送欢迎消息,附带精确入群时间",
    usage="无需手动触发,新成员入群自动生效",
    type="application",
    author="新时代少年",
    version="1.0.0",
    supported_adapters={"~onebot.v11"}
)

# 监听群成员增加通知事件
welcome_handler = on_notice(priority=10, block=False)

@welcome_handler.handle()
async def _(bot: Bot, event: GroupIncreaseNoticeEvent):
    """处理新成员入群事件"""
    # 排除机器人自身入群
    if event.user_id == event.self_id:
        await welcome_handler.finish()

    # 获取入群时间(格式化:年-月-日 时:分:秒)
    join_time = datetime.fromtimestamp(event.time).strftime("%Y-%m-%d %H:%M:%S")
    
    # 获取群名和新成员昵称
    group_info = await bot.get_group_info(group_id=event.group_id)
    user_info = await bot.get_stranger_info(user_id=event.user_id)
    group_name = group_info["group_name"]
    user_name = user_info["nickname"]

    # 构造欢迎消息(支持自定义)
    welcome_msg = (
        f"{MessageSegment.at(event.user_id)}\n"
        f"🎉 欢迎 {user_name} 加入【{group_name}】!\n"
        f"⏰ 入群时间:{join_time}\n"
        f"✨ 请遵守群规,和大家一起愉快交流吧~"
    )

    # 发送欢迎消息到群聊
    await welcome_handler.send(welcome_msg)
}

插件检查清单

  • [x] 我的插件经过完整的测试
  • [x] 我的插件不包含恶意代码
  • [x] 我已阅读并同意遵守该项目的 行为准则。

审核选项

  • [ ] 重新提交审核

mjy1113451 avatar Jan 23 '26 07:01 mjy1113451

⚠️ 插件提交格式错误

您好!您的插件提交格式存在问题,无法进行自动审核。请根据以下指南修正:

  • JSON格式错误: Expected property name or '}' in JSON at position 2 (line 2 column 1)。请检查语法,如逗号、引号是否正确。

请根据上述问题进行修改。修改完成后,请在 Issue 正文 中勾选"重新提交审核"复选框以再次触发审核。

此消息由系统自动生成

astrpluginreviewer avatar Jan 23 '26 07:01 astrpluginreviewer