forked from zyujs/clanbattle_info
-
Notifications
You must be signed in to change notification settings - Fork 2
/
info.py
190 lines (178 loc) · 6.31 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import os
import aiohttp
import asyncio
import datetime
import json
import traceback
from .base import *
def format_number(number: int) -> str:
if number == 0:
return '0'
num_str = ''
if number > 100000000: #亿
yi = number // 100000000
number %= 100000000
if yi != 0:
num_str += f'{yi}亿'
if number > 10000:
wan = number // 10000
number %= 10000
if wan != 0:
num_str += f'{wan}万'
if number != 0:
num_str += f'{number}'
return num_str
#格式化出刀记录
def format_challenge_report(challenge_list: list):
msg = "新增出刀记录:"
for item in challenge_list:
dt = datetime.datetime.fromtimestamp(item['datetime'])
msg += f"\n{dt.strftime('%Y/%m/%d %H:%M:%S')} "
msg += f"{item['lap_num']}周目 "
msg += f"{item['boss']+1}王\n"
msg += f"{item['name']} "
msg += f"伤害:{format_number(item['damage'])} "
msg += f"得分:{format_number(item['score'])} "
if item['kill'] == 1:
msg += "尾刀"
if item['reimburse'] == 1:
msg += "补偿刀"
return msg
#总表
async def get_collect_report(group_id: str) -> (int, str):
group_id = str(group_id)
msg = ""
data = await query_data(group_id, '/webview/android', {
'target': 'gzlj-clan-collect-report/a'
})
if 'code' not in data: #网络错误
return '网络异常'
if data['code'] != 0: #cookie错误
return 'cookie无效'
if 'data' not in data: #数据异常
return '数据异常'
data = data['data']
msg = f"公会:{data['clan']['name']}\n"
msg += f"排名:{data['clan']['last_ranking']}\n"
msg += "出刀情况:"
for member in data['data']:
msg += f"\n昵称:{member['username']} "
msg += f"出刀:{member['number']} "
msg += f"伤害:{format_number(member['damage'])} "
msg += f"占比:{member['rate']} "
msg += f"得分:{format_number(member['score'])}"
return msg
#日表
async def get_day_report(group_id: str, day: int = 0) -> (int, str):
msg = ''
day_str = get_daystr_from_daylist(group_id, day)
if not day_str:
return '无数据'
data = await query_data(group_id, '/webview/android', {
'target': 'gzlj-clan-day-report/a',
'date': day_str,
'page': 1,
'size': 30
})
if 'code' not in data: #网络错误
return '网络异常'
if data['code'] != 0: #cookie错误
return 'cookie无效'
if 'data' not in data: #数据异常
return '数据异常'
data = data['data']
msg += f"{day_str}的出刀情况:"
for member in data:
msg += f"\n{member['name']} "
msg += f"出刀:{member['number']} "
msg += f"伤害:{format_number(member['damage'])} "
msg += f"得分:{format_number(member['score'])}"
return msg
#boss表
async def get_boss_report(group_id: str, boss: int = 0) -> (int, str):
group_id = str(group_id)
if boss >= len(boss_challenge_list[group_id]):
return '序号超出范围'
challenges = boss_challenge_list[group_id][boss]
if len(challenges) == 0:
return '无记录'
msg = ''
boss_name = ''
try:
boss_name = clanbattle_info[group_id]['boss_list'][boss]['boss_name']
except:
boss_name = f'{boss + 1}王'
msg += f"{boss_name}的出刀记录:"
for item in challenges:
dt = datetime.datetime.fromtimestamp(item['datetime'])
msg += f"\n时间:{dt.strftime('%Y/%m/%d %H:%M:%S')} "
msg += f"昵称:{item['name']} "
msg += f"伤害:"
damage = item['damage']
if damage > 10000:
msg += f"{damage // 10000}万"
msg += f"{damage % 10000} "
msg += f"得分:{format_number(item['score'])} "
if item['kill'] == 1:
msg += "尾刀"
if item['reimburse'] == 1:
msg += "补偿刀"
return msg
#日出刀
async def get_day_challenge_report(group_id: str, day: int = 0) -> (int, str):
day_str = get_daystr_from_daylist(group_id, day)
if not day_str:
return '无数据'
today = datetime.datetime(*map(int, day_str.split('-')))
today = today.replace(hour=5, minute=0, second=0, microsecond=0) #当天5点
tomorrow = today + datetime.timedelta(days=1)
msg = f"{today.strftime('%Y/%m/%d')}的出刀记录:"
for item in all_challenge_list[group_id]:
dt = datetime.datetime.fromtimestamp(item['datetime'])
if dt >= today and dt < tomorrow:
msg += f"\n时间:{dt.strftime('%Y/%m/%d %H:%M:%S')} "
msg += f"昵称:{item['name']} "
msg += f"伤害:"
damage = item['damage']
if damage > 10000:
msg += f"{damage // 10000}万"
msg += f"{damage % 10000} "
msg += f"得分:{format_number(item['score'])} "
if item['kill'] == 1:
msg += "尾刀"
if item['reimburse'] == 1:
msg += "补偿刀"
return msg
#个人出刀
async def get_member_challenge_report(group_id: str, name: str) -> (int, str):
msg = f"{name}的出刀记录:"
for item in all_challenge_list[group_id]:
if item['name'] == name:
dt = datetime.datetime.fromtimestamp(item['datetime'])
msg += f"\n时间:{dt.strftime('%Y/%m/%d %H:%M:%S')} "
msg += f"昵称:{item['name']} "
msg += f"伤害:"
damage = item['damage']
if damage > 10000:
msg += f"{damage // 10000}万"
msg += f"{damage % 10000} "
msg += f"得分:{format_number(item['score'])} "
if item['kill'] == 1:
msg += "尾刀"
if item['reimburse'] == 1:
msg += "补偿刀"
return msg
#boss状态
def get_boss_state_report(group_id: str) -> (int, str):
group_id = str(group_id)
msg = ""
boss_info = {}
try:
boss_info = clanbattle_info[group_id]['boss_info']
msg = "boss状态:"
msg += f"\n{boss_info['lap_num']}周目 {boss_info['name']}"
msg += f"\n{format_number(boss_info['current_life'])} / {format_number(boss_info['total_life'])} "
msg += f"({boss_info['current_life']/boss_info['total_life']*100:.2f}%)"
except:
msg = "无数据"
return msg