提交 a11f0f2a 编辑于 作者: yuudi's avatar yuudi
浏览文件

fix: separat miner module

上级 e1bed8d3
......@@ -11,7 +11,8 @@ head:
href: /logo/logo.ico
themeConfig:
logo: /logo/logo.png
search: false
search: true
searchMaxSuggestions: 10
smoothScroll: true
repo: https://github.com/yuudi/yobot
docsDir: documents
......@@ -58,6 +59,8 @@ themeConfig:
link: /project/open-source/
- text: 更新日志
link: /project/changelog/
- text: 项目贡献者
link: /project/contributors/
- text: 待办事项
link: https://github.com/yuudi/yobot/projects/1
plugins:
......
......@@ -12,6 +12,7 @@ QQ群:
1044314369(满)
1067699252(满)
774394459
<!-- 1087420601 -->
[项目贡献者](./project/contributors.md)
[更新日志](./project/changelog.md)
......
......@@ -58,6 +58,7 @@
| (自动:新闻推送) | 推送最新的新闻 |
| 日程(今日/明日/x月x日)(可自动) | 查看活动日程 |
| 日程表 | 查看一周日程 |
| 挖矿计算 +当前名次 | 计算剩余可获得的奖励钻石 |
## 娱乐类
......
# 更新日志
## 3.6.2
- 按日计算的统计图表([#99](https://github.com/yuudi/yobot/pull/99)
- 优化 Dockerfile([#97](https://github.com/yuudi/yobot/pull/97)
- 挖矿计算([#103](https://github.com/yuudi/yobot/pull/103)
## 3.6.1
- 竞技场查询支持pcrdfans
......@@ -9,11 +15,9 @@
## 3.6.0
- 公会战数据多存档
- 开放统计api与数据下载
- 开放统计
- 统计:出刀顺序表([#75](https://github.com/yuudi/yobot/pull/75)
- 统计:出刀统计图([#77](https://github.com/yuudi/yobot/pull/77)[#79](https://github.com/yuudi/yobot/pull/79)
- 自动更新时有反馈
- 允许删除公会
## 3.5
......
......@@ -17,6 +17,7 @@
[@winrey](https://github.com/winrey)
[@yyuueexxiinngg](https://github.com/yyuueexxiinngg)
[@AzurCrystal](https://github.com/AzurCrystal)
## Bug Report
......
......@@ -55,6 +55,7 @@
{#- <el-button type="primary" @click="new_data_slot" icon="el-icon-document-add" size="mini">新建档案</el-button> -#}
<el-button type="primary" @click="get_data_slot_record_count();switchVisible = true" icon="el-icon-receiving" size="mini">切换档案</el-button>
<el-dialog title="切换档案" :visible.sync="switchVisible">
<el-alert title="你可以切换存档编号,以记录不同期的公会战数据,这样能保留历史数据,也可以在统计里随时查看" type="info" close-text="知道了"></el-alert>
<ul>
<li v-for="item in data_slot_record_count">
[[ item.battle_id ]]号存档:[[ item.record_count ]]条记录
......
......@@ -185,6 +185,10 @@
<td>日程表</td>
<td>查看一周日程</td>
</tr>
<tr>
<td>挖矿计算 +当前名次</td>
<td>计算剩余可获得的奖励钻石</td>
</tr>
</tbody>
</table>
<h2>娱乐类</h2>
......
......@@ -17,7 +17,9 @@ from ..templating import render_template
from ..web_util import async_cached_func
from ..ybdata import (Clan_challenge, Clan_group, Clan_member, Clan_subscribe,
User)
from .exception import GroupError, InputError, UserError
from .exception import (
ClanBattleError, GroupError, GroupNotExist, InputError, UserError,
UserNotInGroup)
from .typing import BossStatus, ClanBattleReport, Groupid, Pcr_date, QQid
from .util import atqq, pcr_datetime, pcr_timestamp, timed_cached_func
......@@ -170,7 +172,7 @@ class ClanBattle:
except Exception as e:
_logger.exception('获取群成员列表错误'+str(type(e))+str(e))
asyncio.ensure_future(self.api.send_group_msg(
group_id=group_id, message='获取群成员错误,请查看日志'))
group_id=group_id, message='获取群成员错误,这可能是缓存问题,请稍后再试'))
return []
return group_member_list
......@@ -315,7 +317,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
boss_summary = (
f'现在{group.boss_cycle}周目,{group.boss_num}号boss\n'
f'生命值{group.boss_health:,}'
......@@ -352,7 +354,7 @@ class ClanBattle:
raise InputError('伤害不可以是负数')
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
if (not defeat) and (damage >= group.boss_health):
raise InputError('伤害超出剩余血量,如击败请使用尾刀')
behalf = None
......@@ -368,7 +370,7 @@ class ClanBattle:
is_member = Clan_member.get_or_none(
group_id=group_id, qqid=qqid)
if not is_member:
raise GroupError('未加入公会,请先发送“加入公会”')
raise UserNotInGroup
d, t = pcr_datetime(area=group.game_server)
if previous_day:
today_count = Clan_challenge.select().where(
......@@ -479,7 +481,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
user = User.get_or_create(
qqid=qqid,
defaults={
......@@ -530,7 +532,7 @@ class ClanBattle:
raise InputError('boss生命值不能为负')
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
if cycle is not None:
group.boss_cycle = cycle
if boss_num is not None:
......@@ -569,7 +571,7 @@ class ClanBattle:
raise InputError(f'不存在{game_server}游戏服务器')
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
group.game_server = game_server
group.save()
......@@ -585,7 +587,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
counts = []
for c in Clan_challenge.select(
Clan_challenge.bid,
......@@ -613,7 +615,7 @@ class ClanBattle:
# """
# group = Clan_group.get_or_none(group_id=group_id)
# if group is None:
# raise GroupError('本群未初始化,请发送“创建X服公会”')
# raise GroupNotExist
# group.boss_cycle = 1
# group.boss_num = 1
# group.boss_health = self.bossinfo[group.game_server][0][0]
......@@ -635,7 +637,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
group.boss_cycle = 1
group.boss_num = 1
group.boss_health = self.bossinfo[group.game_server][0][0]
......@@ -664,7 +666,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
group.battle_id = battle_id
last_challenge = self._get_group_previous_challenge(group)
if last_challenge is None:
......@@ -744,7 +746,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
user = User.get_or_none(qqid=qqid)
if user is None:
raise GroupError('请先加入公会')
......@@ -820,7 +822,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
if boss_num is None:
boss_num = group.boss_num
notice = []
......@@ -856,12 +858,12 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
user = User.get_or_none(qqid=qqid)
if user is None:
raise UserError('请先加入公会')
raise UserNotInGroup
if (appli_type != 1) and (extra_msg is None):
raise UserError('锁定boss时必须留言')
raise InputError('锁定boss时必须留言')
if group.challenging_member_qq_id is not None:
nik = self._get_nickname_by_qqid(
group.challenging_member_qq_id,
......@@ -902,7 +904,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
if group.challenging_member_qq_id is None:
raise GroupError('boss没有锁定')
user = User.get_or_create(
......@@ -948,11 +950,11 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
membership = Clan_member.get_or_none(
group_id=group_id, qqid=qqid)
if membership is None:
raise UserError('未加入公会,请先发送“加入公会”')
raise UserNotInGroup
today, _ = pcr_datetime(group.game_server)
if todaystatus:
if membership.last_save_slot == today:
......@@ -1001,7 +1003,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
report = []
expressions = [
Clan_challenge.gid == group_id,
......@@ -1062,7 +1064,7 @@ class ClanBattle:
"""
group = Clan_group.get_or_none(group_id=group_id)
if group is None:
raise GroupError('本群未初始化,请发送“创建X服公会”')
raise GroupNotExist
expressions = [
Clan_challenge.gid == group_id,
]
......@@ -1149,7 +1151,7 @@ class ClanBattle:
game_server = self.Server.get(match.group(1), 'cn')
try:
self.creat_group(group_id, game_server)
except GroupError as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1182,7 +1184,7 @@ class ClanBattle:
return
try:
boss_summary = self.boss_status_summary(group_id)
except GroupError as e:
except ClanBattleError as e:
return str(e)
return boss_summary
elif match_num == 4: # 报刀
......@@ -1215,7 +1217,7 @@ class ClanBattle:
behalf,
extra_msg=extra_msg,
previous_day=previous_day)
except (InputError, GroupError) as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1241,7 +1243,7 @@ class ClanBattle:
behalf,
extra_msg=extra_msg,
previous_day=previous_day)
except (InputError, GroupError) as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1251,7 +1253,7 @@ class ClanBattle:
return
try:
boss_status = self.undo(group_id, user_id)
except (GroupError, UserError) as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1301,7 +1303,7 @@ class ClanBattle:
extra_msg = None
try:
self.add_subscribe(group_id, user_id, boss_num, extra_msg)
except (GroupError, UserError) as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1317,7 +1319,7 @@ class ClanBattle:
extra_msg = None
try:
self.add_subscribe(group_id, user_id, 0, extra_msg)
except (GroupError, UserError) as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1342,7 +1344,7 @@ class ClanBattle:
try:
boss_status = self.apply_for_challenge(
group_id, user_id, extra_msg=extra_msg, appli_type=appli_type)
except GroupError as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1369,7 +1371,7 @@ class ClanBattle:
return
try:
boss_status = self.cancel_application(group_id, user_id)
except GroupError as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1390,7 +1392,7 @@ class ClanBattle:
return
try:
self.save_slot(group_id, user_id)
except (GroupError, UserError) as e:
except ClanBattleError as e:
_logger.info('群聊 失败 {} {} {}'.format(user_id, group_id, cmd))
return str(e)
_logger.info('群聊 成功 {} {} {}'.format(user_id, group_id, cmd))
......@@ -1577,7 +1579,7 @@ class ClanBattle:
extra_msg=payload.get(
'message'),
)
except InputError as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1607,7 +1609,7 @@ class ClanBattle:
extra_msg=payload.get(
'message'),
)
except InputError as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1631,7 +1633,7 @@ class ClanBattle:
try:
status = self.undo(
group_id, user_id)
except (UserError, GroupError) as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1658,7 +1660,7 @@ class ClanBattle:
extra_msg=payload['extra_msg'],
appli_type=payload['appli_type'],
)
except (GroupError, UserError) as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1682,7 +1684,7 @@ class ClanBattle:
try:
status = self.cancel_application(
group_id, user_id)
except GroupError as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1707,7 +1709,7 @@ class ClanBattle:
try:
self.save_slot(group_id, user_id,
todaystatus=todaystatus)
except (GroupError, UserError) as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1742,7 +1744,7 @@ class ClanBattle:
boss_num,
message,
)
except UserError as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(
......@@ -1822,7 +1824,7 @@ class ClanBattle:
boss_num=payload['boss_num'],
boss_health=payload['health'],
)
except InputError as e:
except ClanBattleError as e:
_logger.info('网页 失败 {} {} {}'.format(
user_id, group_id, action))
return jsonify(code=10, message=str(e))
......@@ -1870,8 +1872,8 @@ class ClanBattle:
except KeyError as e:
_logger.error(e)
return jsonify(code=31, message='missing key: '+str(e))
# except asyncio.CancelledError as e:
# raise e from e
except asyncio.CancelledError:
pass
except Exception as e:
_logger.exception(e)
return jsonify(code=40, message='server error')
......
class UserError(ValueError):...
class GroupError(ValueError):...
class InputError(ValueError):...
class ClanBattleError(ValueError):...
class UserError(ClanBattleError):...
class GroupError(ClanBattleError):...
class InputError(ClanBattleError):...
class UserNotInGroup(UserError):
def __init__(self, msg='未加入公会,请先发送“加入公会”', *args):
super().__init__(msg, *args)
class GroupNotExist(GroupError):
def __init__(self, msg='本群未初始化,请发送“创建X服公会”', *args):
super().__init__(msg, *args)
......@@ -85,7 +85,7 @@ class Consult:
result = await self.search_pcrdfans_async(def_lst, region)
else:
return f"错误的配置项:{search_source}"
except (RuntimeError,ValueError) as e:
except (RuntimeError, ValueError) as e:
return str(e)
if len(result) == 0:
......@@ -214,73 +214,6 @@ class Consult:
result = search['data']['result']
return list(map(self._parse_pcrdfans_team, result))
def get_this_season(self, rank):
"""
this_season[1:11] = 50
this_season[11:101] = 10
this_season[101:201] = 5
this_season[201:501] = 3
this_season[501:2001] = 2
this_season[2001:4000] = 1
this_season[4000:8000:100] = 50
this_season[8100:15001:100] = 15
"""
if rank <= 11:
return 50 *(rank-1)
elif rank <= 101:
return 10*(rank-11) + 50*10
elif rank <= 201:
return 5*(rank-101) + 10*90 + 50*10
elif rank <= 501:
return 3*(rank-201) + 5*100 +10*90 + 50*10
elif rank <= 2001:
return 2*(rank-501) + 3*300 + 5*100 +10*90 + 50*10
elif rank <= 4000:
return 1*(rank-2001) + 2*1500 + 3*300 + 5*100 +10*90 + 50*10
elif rank <= 8000:
return (rank-4000)//100*50 + 1*1999 + 2*1500 + 3*300 + 5*100 +10*90 + 50*10
else:
return (rank-8001)//100*15 + 40*50 + 1*1999 + 2*1500 + 3*300 + 5*100 +10*90 + 50*10
def get_all_season(self, rank):
"""
all_season[1:11] = 500
all_season[11:101] = 50
all_season[101:201] = 30
all_season[201:501] = 10
all_season[501:1001] = 5
all_season[1001:2001] = 3
all_season[2001:4001] = 2
all_season[4001:7999] = 1
all_season[8100:15001:100] = 30
"""
if rank <= 11:
return 500 *(rank-1)
elif rank <= 101:
return 50*(rank-11) + 500*10
elif rank <= 201:
return 30*(rank-101) + 50*90 + 500*10
elif rank <= 501:
return 10*(rank-201) + 30*100 +50*90 + 500*10
elif rank <= 1001:
return 5* (rank-501) + 10*300 + 30*100 +50*90 + 500*10
elif rank <= 2001:
return 3*(rank-1001) + 5*500 + 10*300 + 30*100 +50*90 + 500*10
elif rank <= 4001:
return 2*(rank-2001) + 3*1000 + 5*500 + 10*300 + 30*100 +50*90 + 500*10
elif rank <= 7999:
return (rank-4001) + 2*2000 + 3*1000 + 5*500 + 10*300 + 30*100 +50*90 + 500*10
else:
return (rank-8001)//100*30 + 3998 + 2*2000 + 3*1000 + 5*500 + 10*300 + 30*100 +50*90 + 500*10
def miner(self, cmd: str):
cmd = cmd.lstrip()
if cmd.isdigit() and 15001 >= int(cmd) >= 1:
rank = int(cmd)
reply = "当前排名为:{}\n最高排名奖励还剩 {} 钻\n历届最高排名还剩 {} 钻".format(rank, self.get_this_season(rank), self.get_all_season(rank))
return reply
else:
reply = "请输入1~15001之间的整数"
return reply
@staticmethod
def match(cmd: str) -> int:
if not cmd.startswith("jjc"):
......@@ -295,8 +228,6 @@ class Consult:
return 3
elif cmd.startswith("jjc日服"):
return 4
elif cmd.startswith("jjc钻石"):
return 6
else:
return 0
......@@ -308,8 +239,6 @@ class Consult:
return None
elif match_num == 5:
reply = "请接5个昵称,空格分隔"
elif match_num == 6:
reply = self.miner(msg["raw_message"][5:])
else:
try:
anlz = self.user_input(msg["raw_message"][5:])
......
class Miner:
def __init__(self, *args, **kwargs):
pass
def get_this_season(self, rank):
# this_season[1:11] = 50
# this_season[11:101] = 10
# this_season[101:201] = 5
# this_season[201:501] = 3
# this_season[501:2001] = 2
# this_season[2001:4000] = 1
# this_season[4000:8000:100] = 50
# this_season[8100:15001:100] = 15
if rank <= 11:
return 50*rank-50
elif rank <= 101:
return 10*rank+390
# return 10*(rank-11) + 50*10
elif rank <= 201:
return 5*rank+895
# return 5*(rank-101) + 10*90 + 50*10
elif rank <= 501:
return 3*rank+1297
# return 3*(rank-201) + 5*100 +10*90 + 50*10
elif rank <= 2001:
return 2*rank+1798
# return 2*(rank-501) + 3*300 + 5*100 +10*90 + 50*10
elif rank <= 4000:
return rank+3799
# return 1*(rank-2001) + 2*1500 + 3*300 + 5*100 +10*90 + 50*10
elif rank <= 8000:
return 50*(rank//100)+5799
# return (rank-4000)//100*50 + 1*1999 + 2*1500 + 3*300 + 5*100 +10*90 + 50*10
else:
return 15*(rank//100)+8599
# return (rank-8001)//100*15 + 40*50 + 1*1999 + 2*1500 + 3*300 + 5*100 +10*90 + 50*10
def get_all_season(self, rank):
# all_season[1:11] = 500
# all_season[11:101] = 50
# all_season[101:201] = 30