mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
✨ 增加深渊统计
指令
This commit is contained in:
parent
a995aca8fd
commit
757503b89f
@ -154,6 +154,7 @@ class AbyssInfo(Model):
|
||||
|
||||
@classmethod
|
||||
async def update_info(cls, user_id: str, uid: str, data: dict):
|
||||
await cls.filter(user_id=user_id, uid=uid).delete()
|
||||
info, _ = await cls.get_or_create(user_id=user_id, uid=uid)
|
||||
if player_info := await PlayerInfo.get_or_none(user_id=user_id, uid=uid):
|
||||
info.nickname = player_info.nickname
|
||||
|
@ -1,5 +1,5 @@
|
||||
from nonebot import on_command, on_regex
|
||||
from nonebot.adapters.onebot.v11 import Message, MessageEvent, MessageSegment
|
||||
from nonebot.adapters.onebot.v11 import Message, MessageEvent, MessageSegment, GroupMessageEvent
|
||||
from nonebot.params import Arg, RegexDict, CommandArg
|
||||
from nonebot.plugin import PluginMetadata
|
||||
|
||||
@ -16,6 +16,7 @@ from .draw_character_bag import draw_chara_bag
|
||||
from .draw_character_detail import draw_chara_detail
|
||||
from .draw_character_card import draw_chara_card
|
||||
from .draw_abyss import draw_abyss_card
|
||||
from .abyss_statistics import get_statistics
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name='原神信息查询',
|
||||
@ -84,7 +85,12 @@ show_alias = on_command('查看别名', priority=10, block=True, state={
|
||||
'pm_usage': '查看别名',
|
||||
'pm_priority': 9
|
||||
})
|
||||
|
||||
show_abyss = on_command('深渊统计', priority=10, block=True, state={
|
||||
'pm_name': '深渊统计',
|
||||
'pm_description': '查看本群深渊统计,仅群可用',
|
||||
'pm_usage': '深渊统计',
|
||||
'pm_priority': 10
|
||||
})
|
||||
|
||||
@ys.handle()
|
||||
async def _(event: MessageEvent, players=CommandPlayer()):
|
||||
@ -283,3 +289,9 @@ async def _(event: MessageEvent):
|
||||
await show_alias.finish('你已设以下别名:' + '\n'.join(f'{alias.alias}->{alias.character}' for alias in aliases), at_sender=True)
|
||||
else:
|
||||
await show_alias.finish('你还没有设置过角色别名哦', at_sender=True)
|
||||
|
||||
|
||||
@show_abyss.handle()
|
||||
async def _(event: GroupMessageEvent):
|
||||
result = await get_statistics(event.group_id)
|
||||
await show_abyss.finish(result)
|
80
LittlePaimon/plugins/Paimon_Info/abyss_statistics.py
Normal file
80
LittlePaimon/plugins/Paimon_Info/abyss_statistics.py
Normal file
@ -0,0 +1,80 @@
|
||||
import datetime
|
||||
from collections import defaultdict
|
||||
from nonebot import get_bot
|
||||
from LittlePaimon.database.models import AbyssInfo
|
||||
from LittlePaimon.utils.image import PMImage, font_manager as fm
|
||||
from LittlePaimon.utils.message import MessageBuild
|
||||
|
||||
|
||||
async def get_statistics(group_id: int):
|
||||
if not (info_list := await AbyssInfo.all()):
|
||||
return '本群还没有深渊战斗数据哦!'
|
||||
member_list = await get_bot().get_group_member_list(group_id=group_id)
|
||||
member_id_list = [str(member['user_id']) for member in member_list]
|
||||
info_list = [info for info in info_list if info.user_id in member_id_list and info.total_battle]
|
||||
now = datetime.datetime.now()
|
||||
if 1 <= now.day < 15:
|
||||
left_day = 1
|
||||
right_day = 15
|
||||
else:
|
||||
left_day = 16
|
||||
right_day = 31
|
||||
info_list = [info for info in info_list if left_day <= info.update_time.day <= right_day]
|
||||
if not info_list:
|
||||
return '本群还没有深渊战斗数据哦!'
|
||||
# 数据数
|
||||
info_num = len(info_list)
|
||||
# 满星人数
|
||||
full_star_num = len([info for info in info_list if info.total_star >= 36])
|
||||
# 平均星数
|
||||
average_star = round(sum(info.total_star for info in info_list) / info_num, 1)
|
||||
# 平均战斗次数
|
||||
average_battle_num = round(sum(info.total_battle for info in info_list) / info_num, 1)
|
||||
# 最高伤害角色
|
||||
max_damage = max(info_list, key=lambda x: x.max_damage.value)
|
||||
# print(max_damage)
|
||||
# return '123'
|
||||
max_damage_user = [m for m in member_list if str(m['user_id']) == max_damage.user_id][0]
|
||||
max_damage_user = max_damage_user['card'] or max_damage_user['nickname']
|
||||
# 最多承伤角色
|
||||
max_take_damage = max(info_list, key=lambda x: x.max_take_damage.value)
|
||||
max_take_damage_user = [m for m in member_list if str(m['user_id']) == max_take_damage.user_id][0]
|
||||
max_take_damage_user = max_take_damage_user['card'] or max_take_damage_user['nickname']
|
||||
# 11、12层阵容
|
||||
battle_characters_up11 = defaultdict(lambda: 0)
|
||||
battle_characters_down11 = defaultdict(lambda: 0)
|
||||
battle_characters_up12 = defaultdict(lambda: 0)
|
||||
battle_characters_down12 = defaultdict(lambda: 0)
|
||||
for info in info_list:
|
||||
if floor11 := info.floors.get(11):
|
||||
for battles in floor11.battles_up:
|
||||
for character in battles.characters:
|
||||
battle_characters_up11[character.name] += 1
|
||||
for battles in floor11.battles_down:
|
||||
for character in battles.characters:
|
||||
battle_characters_down11[character.name] += 1
|
||||
if floor12 := info.floors.get(12):
|
||||
for battles in floor12.battles_up:
|
||||
for character in battles.characters:
|
||||
battle_characters_up12[character.name] += 1
|
||||
for battles in floor12.battles_down:
|
||||
for character in battles.characters:
|
||||
battle_characters_down12[character.name] += 1
|
||||
up_sort11 = [character[0] for character in
|
||||
sorted(battle_characters_up11.items(), key=lambda x: x[1], reverse=True)[:4]]
|
||||
down_sort11 = [character[0] for character in
|
||||
sorted(battle_characters_down11.items(), key=lambda x: x[1], reverse=True)[:4]]
|
||||
up_sort12 = [character[0] for character in
|
||||
sorted(battle_characters_up12.items(), key=lambda x: x[1], reverse=True)[:4]]
|
||||
down_sort12 = [character[0] for character in
|
||||
sorted(battle_characters_down12.items(), key=lambda x: x[1], reverse=True)[:4]]
|
||||
|
||||
text = f'本群群友{now.strftime("%m月%d日")}深渊统计情况:\n满星人数/总人数: {full_star_num}/{info_num}\n平均星数: {average_star}\n平均战斗次数: {average_battle_num}\n最高伤害角色: {max_damage_user}的{max_damage.max_damage.name}({max_damage.max_damage.value})\n' \
|
||||
f'最高承伤角色: {max_take_damage_user}的{max_take_damage.max_take_damage.name}({max_take_damage.max_take_damage.value})\n' \
|
||||
f'11层出场率最高角色:\n 上半:{" ".join(up_sort11)}\n 下半:{" ".join(down_sort11)}\n' \
|
||||
f'12层出场率最高角色:\n 上半:{" ".join(up_sort12)}\n 下半:{" ".join(down_sort12)}\n' \
|
||||
f'Created by LittlePaimon'
|
||||
|
||||
img = PMImage(size=(500, 33 * 13), color=(255, 255, 255, 255))
|
||||
await img.text_box(text.replace('\n', '^'), (5, 495), (5, 33 * 13 - 5), fm.get('hywh', 25), 'black')
|
||||
return MessageBuild.Image(img, mode='RGB')
|
Loading…
Reference in New Issue
Block a user