mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 07:47:39 +00:00
groupindex 获取群组当日活跃数据
This commit is contained in:
parent
485c2d6444
commit
8000ba3173
82
groupindex.py
Normal file
82
groupindex.py
Normal file
@ -0,0 +1,82 @@
|
||||
import datetime
|
||||
from pytz import timezone
|
||||
from telethon.tl.functions.users import GetFullUserRequest
|
||||
from pagermaid.utils import alias_command
|
||||
from pagermaid.listener import listener
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, command=alias_command("groupindex"),
|
||||
description="获取群组当日活跃数据")
|
||||
async def group_index(context):
|
||||
if not context.is_group:
|
||||
await context.edit('请在群组中运行。')
|
||||
return
|
||||
# 获取群组信息
|
||||
title = context.chat.title
|
||||
end_id = context.id
|
||||
text = f'以下是群组 {title} 今日的活跃数据:\n'
|
||||
|
||||
await context.edit('正在分析群组数据中...(1/3)')
|
||||
|
||||
# 格式化日期
|
||||
now = datetime.date.today()
|
||||
yesterday = now - datetime.timedelta(days=1)
|
||||
search = datetime.datetime(yesterday.year, yesterday.month, yesterday.day, 16, 0, 0)
|
||||
|
||||
# 初始化变量
|
||||
all_members = []
|
||||
member_count = {}
|
||||
start_id = None
|
||||
utc_tz = timezone('UTC')
|
||||
cst_tz = timezone('Asia/Shanghai')
|
||||
join_count = 0
|
||||
leave_count = 0
|
||||
# 读取管理员操作日志
|
||||
try:
|
||||
async for i in context.client.iter_admin_log(context.chat_id, join=True):
|
||||
utc_time = i.date.replace(tzinfo=utc_tz)
|
||||
cst_time = utc_time.astimezone(cst_tz)
|
||||
date = datetime.date(cst_time.year, cst_time.month, cst_time.day)
|
||||
if not date == now:
|
||||
break
|
||||
join_count += 1
|
||||
async for i in context.client.iter_admin_log(context.chat_id, leave=True):
|
||||
utc_time = i.date.replace(tzinfo=utc_tz)
|
||||
cst_time = utc_time.astimezone(cst_tz)
|
||||
date = datetime.date(cst_time.year, cst_time.month, cst_time.day)
|
||||
if not date == now:
|
||||
break
|
||||
leave_count += 1
|
||||
except:
|
||||
pass
|
||||
await context.edit('正在分析群组数据中...(2/3)')
|
||||
async for i in context.client.iter_messages(context.chat_id, offset_date=search, reverse=True):
|
||||
uid = i.sender_id
|
||||
if not start_id:
|
||||
start_id = i.id
|
||||
if uid:
|
||||
if uid > 0:
|
||||
if uid not in all_members:
|
||||
all_members.append(uid)
|
||||
try:
|
||||
count = member_count[uid]
|
||||
except KeyError:
|
||||
count = 0
|
||||
count += 1
|
||||
member_count[uid] = count
|
||||
|
||||
msg_counts = end_id - start_id
|
||||
member_counts = len(all_members)
|
||||
text += f'活跃人数:{member_counts} 人\n' \
|
||||
f'总消息数:{msg_counts}\n 条' \
|
||||
f'加群 {join_count} 人,退群 {leave_count} 人\n' \
|
||||
f'最活跃的小可爱们:\n'
|
||||
# 字典倒序排序
|
||||
member_count = sorted(member_count.items(), key=lambda x: x[1], reverse=True)
|
||||
# 遍历列表
|
||||
for i in range(min(len(member_count), 5)):
|
||||
# 获取用户信息
|
||||
target_user = await context.client(GetFullUserRequest(member_count[i][0]))
|
||||
first_name = target_user.user.first_name.replace("\u2060", "")
|
||||
text += f'{first_name} `{member_count[i][1]}`\n'
|
||||
await context.edit(text)
|
10
list.json
10
list.json
@ -689,6 +689,16 @@
|
||||
"supported": true,
|
||||
"des-short": "生成文本矩形",
|
||||
"des": "指令:-square"
|
||||
},
|
||||
{
|
||||
"name": "groupindex",
|
||||
"version": "1.0",
|
||||
"section": "daily",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "3.1 kb",
|
||||
"supported": true,
|
||||
"des-short": "获取群组当日活跃数据",
|
||||
"des": "获取群组当日活跃数据。\n指令:-groupindex"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user