feat: more logs into the terminal

This commit is contained in:
草师傅 2025-08-04 14:35:40 +08:00
parent f591d546a5
commit ac67cdef7d
4 changed files with 27 additions and 7 deletions

View file

@ -1,3 +1,5 @@
import logging
from aiogram.types import Message
from config import config
@ -6,6 +8,7 @@ from config import config
async def handle_unpin_channel_message(message: Message):
"""Handle unpinning messages from linked channels without a specific hashtag"""
if not config.is_feature_enabled('unpin', message.chat.id):
logging.debug('发现了频道试图置顶消息,但未启用 unpin 功能,跳过处理')
return
try:
regex_pattern = config.get_feature_config('unpin', message.chat.id)['regex']
@ -13,10 +16,11 @@ async def handle_unpin_channel_message(message: Message):
if regex_pattern:
import re
if re.search(regex_pattern, message.text or message.caption or ""):
logging.debug(f"发现了频道试图置顶消息,但消息匹配了正则表达式{regex_pattern},跳过取消置顶")
# Message matches regex, don't unpin
return
# Either no regex pattern or message doesn't match, proceed to unpin
print("trying to unpin the message")
logging.debug('正在尝试取消频道消息的置顶')
await message.unpin()
except Exception as e:
print('Error unpinning message:', e)
logging.error('Error unpinning message:', e)