Compare commits
5 commits
7a4d998261
...
102d52cd5b
Author | SHA1 | Date | |
---|---|---|---|
102d52cd5b | |||
1ae5293fcb | |||
5694426193 | |||
09bb6acf71 | |||
0a9c25d108 |
6 changed files with 72 additions and 7 deletions
|
@ -12,6 +12,7 @@ from aiogram import F
|
||||||
|
|
||||||
from core.bitflip import handle_bitflip_command
|
from core.bitflip import handle_bitflip_command
|
||||||
from core.link import handle_links
|
from core.link import handle_links
|
||||||
|
from core.promote import handle_promote_command
|
||||||
from core.repeater import MessageRepeater
|
from core.repeater import MessageRepeater
|
||||||
from core.simple import handle_start_command, handle_baka, dummy_handler, handle_info_command
|
from core.simple import handle_start_command, handle_baka, dummy_handler, handle_info_command
|
||||||
from core.actions import handle_actions, handle_reverse_actions
|
from core.actions import handle_actions, handle_reverse_actions
|
||||||
|
@ -39,6 +40,8 @@ class TelegramAdapter:
|
||||||
router.message(Command('info'))(handle_info_command)
|
router.message(Command('info'))(handle_info_command)
|
||||||
# bitflip 模块
|
# bitflip 模块
|
||||||
router.message(Command('bitflip'))(handle_bitflip_command)
|
router.message(Command('bitflip'))(handle_bitflip_command)
|
||||||
|
# promote 模块
|
||||||
|
router.message(Command('t'))(handle_promote_command)
|
||||||
# stats 模块
|
# stats 模块
|
||||||
router.message(Command('stats'))(handle_stats_command)
|
router.message(Command('stats'))(handle_stats_command)
|
||||||
# unpin 模块
|
# unpin 模块
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
admin: 616760897
|
# 管理员对应的 Telegram 用户 ID
|
||||||
|
# 你可以通过 /info 命令获取你的用户 ID
|
||||||
|
admin: 123456789
|
||||||
|
|
||||||
# global features settings
|
# global features settings
|
||||||
features:
|
features:
|
||||||
|
@ -11,6 +13,9 @@ features:
|
||||||
# 启用链接解析/清理
|
# 启用链接解析/清理
|
||||||
link:
|
link:
|
||||||
enable: true
|
enable: true
|
||||||
|
# 启用互送头衔
|
||||||
|
promote:
|
||||||
|
enable: true
|
||||||
# 启用复读
|
# 启用复读
|
||||||
repeater:
|
repeater:
|
||||||
enable: true
|
enable: true
|
||||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
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_path = Path(config_path)
|
||||||
self.config_data = self._load_config()
|
self.config_data = self._load_config()
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,19 @@ class MessageStatsMiddleware(BaseMiddleware):
|
||||||
if not self.stats[chat_id]['users'][user_id]['xm_count']:
|
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'] = 0
|
||||||
self.stats[chat_id]['users'][user_id]['xm_count'] += 1
|
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 event.text and '我菜' in event.text:
|
||||||
if not self.stats[chat_id]['users'][user_id]['wocai_count']:
|
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]['xm_count'] = 0
|
||||||
self.stats[chat_id]['users'][user_id]['wocai_count'] += 1
|
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()
|
self.save_stats()
|
||||||
|
|
||||||
|
|
48
core/promote.py
Normal file
48
core/promote.py
Normal file
|
@ -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()} 变成了 <b>{title}</b>!',
|
||||||
|
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()} 变成了 <b>{title}</b>!',
|
||||||
|
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
|
||||||
|
|
|
@ -30,12 +30,12 @@ async def handle_stats_command(message: Message):
|
||||||
)
|
)
|
||||||
sorted_most_xm_users = sorted(
|
sorted_most_xm_users = sorted(
|
||||||
stats['users'].items(),
|
stats['users'].items(),
|
||||||
key=lambda x: x[1]['xm_count'],
|
key=lambda x: x[1].get('xm_count',0),
|
||||||
reverse=True
|
reverse=True
|
||||||
)
|
)
|
||||||
sorted_most_wocai_users = sorted(
|
sorted_most_wocai_users = sorted(
|
||||||
stats['users'].items(),
|
stats['users'].items(),
|
||||||
key=lambda x: x[1]['wocai_count'],
|
key=lambda x: x[1].get('wocai_count',0),
|
||||||
reverse=True
|
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):
|
for i, (user_id, user_data) in enumerate(sorted_users[:10], 1):
|
||||||
name = user_data['name'] or user_data['username'] or str(user_id)
|
name = user_data['name'] or user_data['username'] or str(user_id)
|
||||||
text += f"{i}. {name}: {user_data['message_count']} 条\n"
|
text += f"{i}. {name}: {user_data['message_count']} 条\n"
|
||||||
if sorted_most_xm_users:
|
if sorted_most_xm_users and any(user_data['xm_count'] > 0 for _, user_data in sorted_most_xm_users):
|
||||||
text += "\n💬 羡慕统计:\n"
|
text += "\n🍋 羡慕统计:\n"
|
||||||
for user_id, user_data in sorted_most_xm_users:
|
for user_id, user_data in sorted_most_xm_users:
|
||||||
if user_data['xm_count'] > 0:
|
if user_data['xm_count'] > 0:
|
||||||
name = user_data['name'] or user_data['username'] or str(user_id)
|
name = user_data['name'] or user_data['username'] or str(user_id)
|
||||||
text += f"{name}: {user_data['xm_count']} 次羡慕\n"
|
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"
|
text += "\n🥬 卖菜统计:\n"
|
||||||
for user_id, user_data in sorted_most_wocai_users:
|
for user_id, user_data in sorted_most_wocai_users:
|
||||||
if user_data['wocai_count'] > 0:
|
if user_data['wocai_count'] > 0:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue