提交 7717d958 编辑于 作者: AzurCrystal's avatar AzurCrystal
浏览文件

Merge remote-tracking branch 'upstream/master'

......@@ -185,6 +185,10 @@
<td>日程表</td>
<td>查看一周日程</td>
</tr>
<tr>
<td>挖矿计算 +当前名次</td>
<td>计算剩余可获得的奖励钻石</td>
</tr>
</tbody>
</table>
<h2>娱乐类</h2>
......
......@@ -93,7 +93,11 @@
{% endfor -%}
</tbody>
</table>
<div>数据来源<a href="{{ 'https://nomae.net/arenadb/' if search_source=='nomae.net' else 'https://www.pcrdfans.com/battle' }}/">{{ search_source }}</a></div>
{% if search_source=="nomae.net" -%}
<div>数据来源<a href="https://nomae.net/arenadb/">nomae.net</a></div>
{% elif search_source=="pcrdfans.com" -%}
<div>数据来源<a href="https://www.pcrdfans.com/battle">公主连结Re: Dive Fan Club</a></div>
{% endif -%}
</body>
</html>
\ No newline at end of file
......@@ -15,7 +15,7 @@
<p>欢迎{{ user.nickname }}</p>
<div>上次登录:[[ from_ts({{ session.get('last_login_time') }}) ]] at {{ session.get('last_login_ipaddr') }}([[ addr.join('') ]])
</div>
{% if user.authority_group < 100 -%}
{% if user.authority_group < 10 -%}
<el-row>
<a href="{{ url_for('yobot_setting') }}">
<el-button type="primary">设置</el-button>
......
import asyncio
import datetime
import json
import re
......@@ -51,9 +50,6 @@ class Event:
self.timeline = None
loop = asyncio.get_event_loop()
asyncio.ensure_future(self.load_timeline_async(), loop=loop)
def load_timeline(self, rg):
raise RuntimeError("no more sync calling")
......@@ -248,7 +244,8 @@ class Event:
reply = "未设置区服,请发送“{}设置”".format(
self.setting.get("preffix_string", ""))
else:
reply = "日程表未初始化"
reply = "日程表未初始化\n\n更多日程:{}".format(
_calender_url.get(self.setting["calender_region"]))
return {"reply": reply, "block": True}
if match_num == 1:
return {"reply": "", "block": True}
......@@ -304,4 +301,9 @@ class Event:
hour, minute = time.split(":")
trigger = CronTrigger(hour=hour, minute=minute)
job = (trigger, self.send_daily_async)
return (job,)
init_trigger = DateTrigger(
datetime.datetime.now() +
datetime.timedelta(seconds=5)
) # 启动5秒后初始化
init_job = (init_trigger, self.load_timeline_async)
return (job, init_job)
......@@ -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
......@@ -133,14 +135,17 @@ class ClanBattle:
return user.nickname or str(qqid)
def _get_group_previous_challenge(self, group: Clan_group):
try:
lc = Clan_challenge.select(
peewee.fn.MAX(Clan_challenge.cid)
Clan_challenge_alias = Clan_challenge.alias()
query = Clan_challenge.select().where(
Clan_challenge.cid == Clan_challenge_alias.select(
peewee.fn.MAX(Clan_challenge_alias.cid)
).where(
Clan_challenge.gid == group.group_id,
Clan_challenge.bid == group.battle_id,
).scalar()
return Clan_challenge.get_by_id(lc)
Clan_challenge_alias.gid == group.group_id,
Clan_challenge_alias.bid == group.battle_id,
)
)
try:
return query.get()
except peewee.DoesNotExist:
return None
......@@ -167,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
......@@ -312,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:,}'
......@@ -349,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
......@@ -365,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(
......@@ -476,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={
......@@ -527,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:
......@@ -566,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()
......@@ -582,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,
......@@ -610,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]
......@@ -632,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]
......@@ -661,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:
......@@ -741,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('请先加入公会')
......@@ -817,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 = []
......@@ -853,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,
......@@ -899,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(
......@@ -945,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:
......@@ -998,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,
......@@ -1046,9 +1051,9 @@ class ClanBattle:
@timed_cached_func(max_len=64, max_age_seconds=10, ignore_self=True)
def get_battle_member_list(self,
group_id: Groupid,
battle_id: Union[str, int, None],
):
group_id: Groupid,
battle_id: Union[str, int, None],
):
"""
get the member lists for clan-battle report
......@@ -1059,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,
]
......@@ -1146,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))
......@@ -1179,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: # 报刀
......@@ -1212,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))
......@@ -1238,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))
......@@ -1248,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))
......@@ -1298,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))
......@@ -1314,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))
......@@ -1339,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))
......@@ -1366,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))
......@@ -1387,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))
......@@ -1401,9 +1406,9 @@ class ClanBattle:
return '没有人'+beh
reply = beh+'的成员:\n'
for m in subscribers:
reply+=self._get_nickname_by_qqid(m['qqid'])
if m.get('message', ''):
reply += ':'+ m.get['message']
reply += '\n'+self._get_nickname_by_qqid(m['qqid'])
if m.get('message'):
reply += ':' + m['message']
return reply
def register_routes(self, app: Quart):
......@@ -1574,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(
......@@ -1604,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(
......@@ -1628,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(
......@@ -1655,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(
......@@ -1679,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(
......@@ -1704,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(
......@@ -1739,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(
......@@ -1819,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))
......@@ -1867,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)
......@@ -169,8 +169,6 @@ class Gacha:
if today != last_day:
last_day = today
day_times = 0
if day_limit != 0 and day_times+30 >= day_limit:
return "{}今天剩余抽卡次数不足30次,不能抽一井".format(nickname, day_times)
reply = ""
result = ""
flag = False
......
......@@ -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:
......
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
# 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-500
elif rank <= 101:
return 50*rank+4450
# return 50*(rank-11) + 500*10
elif rank <= 201:
return 30*rank+6470
# return 30*(rank-101) + 50*90 + 500*10
elif rank <= 501:
return 10*rank+10490
# return 10*(rank-201) + 30*100 +50*90 + 500*10
elif rank <= 1001:
return 5*rank+12995
# return 5* (rank-501) + 10*300 + 30*100 +50*90 + 500*10
elif rank <= 2001:
return 3*rank+14997
# return 3*(rank-1001) + 5*500 + 10*300 + 30*100 +50*90 + 500*10
elif rank <= 4001:
return 2*rank+16998
# return 2*(rank-2001) + 3*1000 + 5*500 + 10*300 + 30*100 +50*90 + 500*10
elif rank <= 7999:
return rank+20999
# return (rank-4001) + 2*2000 + 3*1000 + 5*500 + 10*300 + 30*100 +50*90 + 500*10
else:
return 30*(rank//100)+26598
# 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
async def execute_async(self, ctx):
if ctx['raw_message'].startswith('挖矿计算'):
return self.miner(ctx['raw_message'][4:])
......@@ -95,7 +95,7 @@ class Setting:
if user.authority_group >= 10:
return await render_template(
'unauthorized.html',
limit='机器人管理员',
limit='主人',
uath=user.authority_group,
)
return await render_template('admin/pool-setting.html')
......@@ -156,7 +156,7 @@ class Setting:
if user.authority_group >= 10:
return await render_template(
'unauthorized.html',