diff --git a/adapters/tg.py b/adapters/tg.py
index 3b2470f..bf4c6b4 100644
--- a/adapters/tg.py
+++ b/adapters/tg.py
@@ -12,6 +12,7 @@ from aiogram import F
from core.bitflip import handle_bitflip_command
from core.link import handle_links
+from core.promote import handle_promote_command
from core.repeater import MessageRepeater
from core.simple import handle_start_command, handle_baka, dummy_handler, handle_info_command
from core.actions import handle_actions, handle_reverse_actions
@@ -39,6 +40,8 @@ class TelegramAdapter:
router.message(Command('info'))(handle_info_command)
# bitflip 模块
router.message(Command('bitflip'))(handle_bitflip_command)
+ # promote 模块
+ router.message(Command('t'))(handle_promote_command)
# stats 模块
router.message(Command('stats'))(handle_stats_command)
# unpin 模块
diff --git a/config.example.yaml b/config.example.yaml
index 5e06e7b..e5630ae 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -1,4 +1,6 @@
-admin: 616760897
+# 管理员对应的 Telegram 用户 ID
+# 你可以通过 /info 命令获取你的用户 ID
+admin: 123456789
# global features settings
features:
@@ -11,6 +13,9 @@ features:
# 启用链接解析/清理
link:
enable: true
+ # 启用互送头衔
+ promote:
+ enable: true
# 启用复读
repeater:
enable: true
diff --git a/config.py b/config.py
index cf91b60..98d46a8 100644
--- a/config.py
+++ b/config.py
@@ -4,7 +4,7 @@ from pathlib import Path
class Config:
- def __init__(self, config_path: str = "config.example.yaml"):
+ def __init__(self, config_path: str = "config.yaml"):
self.config_path = Path(config_path)
self.config_data = self._load_config()
diff --git a/core/middleware/stats.py b/core/middleware/stats.py
index 5efd007..e543522 100644
--- a/core/middleware/stats.py
+++ b/core/middleware/stats.py
@@ -53,10 +53,19 @@ class MessageStatsMiddleware(BaseMiddleware):
if not self.stats[chat_id]['users'][user_id]['xm_count']:
self.stats[chat_id]['users'][user_id]['xm_count'] = 0
self.stats[chat_id]['users'][user_id]['xm_count'] += 1
+ if event.sticker and event.sticker.file_unique_id in ['AQADhhcAAs1rgFVy']:
+ if not self.stats[chat_id]['users'][user_id]['xm_count']:
+ self.stats[chat_id]['users'][user_id]['xm_count'] = 0
+ self.stats[chat_id]['users'][user_id]['xm_count'] += 1
+
if event.text and '我菜' in event.text:
if not self.stats[chat_id]['users'][user_id]['wocai_count']:
self.stats[chat_id]['users'][user_id]['xm_count'] = 0
self.stats[chat_id]['users'][user_id]['wocai_count'] += 1
+ if event.sticker and event.sticker.file_unique_id in ['AQAD6AUAAgGeUVZy']:
+ if not self.stats[chat_id]['users'][user_id]['wocai_count']:
+ self.stats[chat_id]['users'][user_id]['wocai_count'] = 0
+ self.stats[chat_id]['users'][user_id]['wocai_count'] += 1
# 保存统计数据
self.save_stats()
diff --git a/core/promote.py b/core/promote.py
new file mode 100644
index 0000000..c3a81f5
--- /dev/null
+++ b/core/promote.py
@@ -0,0 +1,48 @@
+from aiogram.exceptions import TelegramBadRequest
+from aiogram.types import Message
+
+from config import config
+
+
+async def handle_promote_command(message: Message) -> None:
+ title = message.text.replace('/t', '').strip()
+ if not config.is_feature_enabled('promote', message.chat.id):
+ return
+ if message.chat.type not in ['group', 'supergroup']:
+ return
+ try:
+ if not message.reply_to_message:
+ await message.reply('咱不知道给谁头衔呢')
+ return
+ if not title:
+ await message.reply('咱不知道给什么头衔呢')
+ return
+ else:
+ member = await message.chat.get_member(message.reply_to_message.from_user.id)
+ if len(title) > 16:
+ await message.reply('头衔太长了,咱设置不了')
+ return
+ if member.status == 'creator':
+ await message.reply('咱不能给群主设置头衔')
+ return
+ if not member.status in ['administrator','creator']:
+ await message.chat.promote(message.reply_to_message.from_user.id,can_manage_chat=True)
+ await message.chat.set_administrator_custom_title(message.reply_to_message.from_user.id,title)
+ await message.reply(
+ f'{message.from_user.mention_html()} 把 {message.reply_to_message.from_user.mention_html()} 变成了 {title}!',
+ parse_mode='HTML')
+ elif member.status == 'administrator' and member.can_be_edited:
+ await message.chat.set_administrator_custom_title(message.reply_to_message.from_user.id,title)
+ await message.reply(
+ f'{message.from_user.mention_html()} 把 {message.reply_to_message.from_user.mention_html()} 变成了 {title}!',
+ parse_mode='HTML')
+ else:
+ await message.reply('咱不能给这个人设置头衔,可能是因为ta已经被其它管理员设置了头衔')
+ return
+ except TelegramBadRequest as e:
+ await message.reply(f'因为咱没有添加新的管理员的权限,咱没办法设置头衔')
+ return
+ except Exception as e:
+ await message.reply(f'发生了错误: {str(e)}')
+ return
+
diff --git a/core/stats.py b/core/stats.py
index e1882ab..2de464b 100644
--- a/core/stats.py
+++ b/core/stats.py
@@ -30,12 +30,12 @@ async def handle_stats_command(message: Message):
)
sorted_most_xm_users = sorted(
stats['users'].items(),
- key=lambda x: x[1]['xm_count'],
+ key=lambda x: x[1].get('xm_count',0),
reverse=True
)
sorted_most_wocai_users = sorted(
stats['users'].items(),
- key=lambda x: x[1]['wocai_count'],
+ key=lambda x: x[1].get('wocai_count',0),
reverse=True
)
@@ -48,13 +48,13 @@ async def handle_stats_command(message: Message):
for i, (user_id, user_data) in enumerate(sorted_users[:10], 1):
name = user_data['name'] or user_data['username'] or str(user_id)
text += f"{i}. {name}: {user_data['message_count']} 条\n"
- if sorted_most_xm_users:
- text += "\n💬 羡慕统计:\n"
+ if sorted_most_xm_users and any(user_data['xm_count'] > 0 for _, user_data in sorted_most_xm_users):
+ text += "\n🍋 羡慕统计:\n"
for user_id, user_data in sorted_most_xm_users:
if user_data['xm_count'] > 0:
name = user_data['name'] or user_data['username'] or str(user_id)
text += f"{name}: {user_data['xm_count']} 次羡慕\n"
- if sorted_most_wocai_users:
+ if sorted_most_wocai_users and any(user_data['wocai_count'] > 0 for _, user_data in sorted_most_wocai_users):
text += "\n🥬 卖菜统计:\n"
for user_id, user_data in sorted_most_wocai_users:
if user_data['wocai_count'] > 0: