feat: welcome the new users (disabled by default)
This commit is contained in:
parent
d06bc1f2c9
commit
2cd679f5ff
3 changed files with 37 additions and 1 deletions
29
core/welcome.py
Normal file
29
core/welcome.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import logging
|
||||
|
||||
from aiogram.enums import ChatMemberStatus
|
||||
from aiogram.types import ChatMemberUpdated
|
||||
|
||||
from config import config
|
||||
|
||||
|
||||
async def get_welcome_message(chat_id: int) -> str | None:
|
||||
if chat_id is None:
|
||||
return None
|
||||
elif not config.is_feature_enabled('welcome', chat_id):
|
||||
logging.debug(f"收到了欢迎事件,但是 welcome 功能未启用,跳过处理")
|
||||
return None
|
||||
# 根据 chat_id 获取不同的欢迎消息
|
||||
return config.get_feature_config('welcome', chat_id)['message']
|
||||
|
||||
|
||||
async def handle_tg_welcome(event: ChatMemberUpdated):
|
||||
"""
|
||||
处理用户加入群组的事件,发送欢迎消息
|
||||
"""
|
||||
try:
|
||||
if event.new_chat_member.status == ChatMemberStatus.MEMBER:
|
||||
welcome_message = await get_welcome_message(event.chat.id)
|
||||
if welcome_message:
|
||||
await event.answer(welcome_message)
|
||||
except Exception as e:
|
||||
logging.error(f"Error in handle_tg_welcome: {e}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue