mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-21 14:48:20 +00:00
⚡ Refactor warp log
merge log and count
This commit is contained in:
parent
5a3989efb1
commit
c1ada7cffd
@ -7,7 +7,7 @@ from metadata.pool.pool_500 import POOL_500
|
||||
def get_pool_by_id(pool_type):
|
||||
if pool_type == 200:
|
||||
return POOL_200
|
||||
if pool_type == 301:
|
||||
if pool_type in [301, 400]:
|
||||
return POOL_301
|
||||
if pool_type == 302:
|
||||
return POOL_302
|
||||
|
@ -26,7 +26,6 @@ class SetCommandPlugin(Plugin):
|
||||
BotCommand("wish_log_import", "导入抽卡记录"),
|
||||
BotCommand("wish_log_export", "导出抽卡记录"),
|
||||
BotCommand("wish_log_delete", "删除抽卡记录"),
|
||||
BotCommand("wish_count", "查看抽卡统计(按卡池)"),
|
||||
BotCommand("pay_log", "查看充值记录"),
|
||||
BotCommand("pay_log_import", "导入充值记录"),
|
||||
BotCommand("pay_log_export", "导出充值记录"),
|
||||
|
@ -392,13 +392,15 @@ class WishLogPlugin(Plugin.Conversation):
|
||||
for i in range(0, len(pools), 2):
|
||||
row = []
|
||||
for pool in pools[i : i + 2]:
|
||||
row.append(
|
||||
InlineKeyboardButton(
|
||||
pool,
|
||||
callback_data=f"get_wish_log|{user_id}|{uid}|{pool}",
|
||||
for k, v in {"log": "", "count": "(按卡池)"}.items():
|
||||
row.append(
|
||||
InlineKeyboardButton(
|
||||
f"{pool.replace('祈愿', '')}{v}",
|
||||
callback_data=f"get_wish_log|{user_id}|{uid}|{k}|{pool}",
|
||||
)
|
||||
)
|
||||
)
|
||||
buttons.append(row)
|
||||
buttons.append([InlineKeyboardButton("五星抽卡统计", callback_data=f"get_wish_log|{user_id}|{uid}|count|five")])
|
||||
return buttons
|
||||
|
||||
async def wish_log_pool_choose(self, user_id: int, message: "Message"):
|
||||
@ -421,7 +423,7 @@ class WishLogPlugin(Plugin.Conversation):
|
||||
if reply_message.photo:
|
||||
self.wish_photo = reply_message.photo[-1].file_id
|
||||
|
||||
async def wish_log_pool_send(self, user_id: int, uid: int, pool_type: "BannerType", message: "Message"):
|
||||
async def wish_log_pool_send(self, user_id: int, pool_type: "BannerType", message: "Message"):
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
uid = await self.get_player_id(user_id)
|
||||
png_data = await self.rander_wish_log_analysis(user_id, uid, pool_type)
|
||||
@ -429,7 +431,10 @@ class WishLogPlugin(Plugin.Conversation):
|
||||
reply = await message.reply_text(png_data)
|
||||
else:
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
reply = await png_data.reply_photo(message)
|
||||
if png_data.file_type == FileType.DOCUMENT:
|
||||
reply = await png_data.reply_document(message, filename="抽卡统计.png")
|
||||
else:
|
||||
reply = await png_data.reply_photo(message)
|
||||
if filters.ChatType.GROUPS.filter(message):
|
||||
self.add_delete_message_job(reply)
|
||||
self.add_delete_message_job(message)
|
||||
@ -455,7 +460,7 @@ class WishLogPlugin(Plugin.Conversation):
|
||||
if pool_type is None:
|
||||
await self.wish_log_pool_choose(user_id, message)
|
||||
else:
|
||||
await self.wish_log_pool_send(user_id, user_id, pool_type, message)
|
||||
await self.wish_log_pool_send(user_id, pool_type, message)
|
||||
except PlayerNotFoundError:
|
||||
await message.reply_text("该用户暂未绑定账号")
|
||||
except GachaLogNotFound:
|
||||
@ -473,23 +478,39 @@ class WishLogPlugin(Plugin.Conversation):
|
||||
|
||||
async def get_wish_log_callback(
|
||||
callback_query_data: str,
|
||||
) -> Tuple[str, int, int]:
|
||||
) -> Tuple[str, str, int, int]:
|
||||
_data = callback_query_data.split("|")
|
||||
_user_id = int(_data[1])
|
||||
_uid = int(_data[2])
|
||||
_result = _data[3]
|
||||
_t = _data[3]
|
||||
_result = _data[4]
|
||||
logger.debug(
|
||||
"callback_query_data函数返回 result[%s] user_id[%s] uid[%s]",
|
||||
"callback_query_data函数返回 result[%s] user_id[%s] uid[%s] show_type[%s]",
|
||||
_result,
|
||||
_user_id,
|
||||
_uid,
|
||||
_t,
|
||||
)
|
||||
return _result, _user_id, _uid
|
||||
return _result, _t, _user_id, _uid
|
||||
|
||||
pool, user_id, uid = await get_wish_log_callback(callback_query.data)
|
||||
try:
|
||||
pool, show_type, user_id, uid = await get_wish_log_callback(callback_query.data)
|
||||
except IndexError:
|
||||
await callback_query.answer("按钮数据已过期,请重新获取。", show_alert=True)
|
||||
self.add_delete_message_job(message, delay=1)
|
||||
return
|
||||
if user.id != user_id:
|
||||
await callback_query.answer(text="这不是你的按钮!\n" + config.notice.user_mismatch, show_alert=True)
|
||||
return
|
||||
if show_type == "count":
|
||||
await self.get_wish_log_count(update, user_id, uid, pool)
|
||||
else:
|
||||
await self.get_wish_log_log(update, user_id, uid, pool)
|
||||
|
||||
async def get_wish_log_log(self, update: "Update", user_id: int, uid: int, pool: str):
|
||||
callback_query = update.callback_query
|
||||
message = callback_query.message
|
||||
|
||||
pool_type = GACHA_TYPE_LIST_REVERSE.get(pool)
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
try:
|
||||
@ -502,64 +523,52 @@ class WishLogPlugin(Plugin.Conversation):
|
||||
else:
|
||||
await callback_query.answer(text="正在渲染图片中 请稍等 请不要重复点击按钮", show_alert=False)
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
await png_data.edit_media(message)
|
||||
if png_data.file_type == FileType.DOCUMENT:
|
||||
await png_data.reply_document(message, filename="抽卡统计.png")
|
||||
self.add_delete_message_job(message, delay=1)
|
||||
else:
|
||||
await png_data.edit_media(message)
|
||||
|
||||
@handler.command(command="wish_count", block=False)
|
||||
@handler.command(command="gacha_count", block=False)
|
||||
@handler.message(filters=filters.Regex("^抽卡统计?(武器|角色|常驻|仅五星|)$"), block=False)
|
||||
async def command_start_count(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> None:
|
||||
user_id = await self.get_real_user_id(update)
|
||||
message = update.effective_message
|
||||
pool_type = BannerType.CHARACTER1
|
||||
all_five = False
|
||||
if args := self.get_args(context):
|
||||
if "武器" in args:
|
||||
pool_type = BannerType.WEAPON
|
||||
elif "常驻" in args:
|
||||
pool_type = BannerType.STANDARD
|
||||
elif "集录" in args:
|
||||
pool_type = BannerType.CHRONICLED
|
||||
elif "仅五星" in args:
|
||||
all_five = True
|
||||
self.log_user(update, logger.info, "抽卡统计命令请求 || 参数 %s || 仅五星 %s", pool_type.name, all_five)
|
||||
async def get_wish_log_count(self, update: "Update", user_id: int, uid: int, pool: str):
|
||||
callback_query = update.callback_query
|
||||
message = callback_query.message
|
||||
|
||||
all_five = pool == "five"
|
||||
group = filters.ChatType.GROUPS.filter(message)
|
||||
pool_type = GACHA_TYPE_LIST_REVERSE.get(pool)
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
try:
|
||||
player_id = await self.get_player_id(user_id)
|
||||
group = filters.ChatType.GROUPS.filter(message)
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
if all_five:
|
||||
data = await self.gacha_log.get_all_five_analysis(user_id, player_id, self.assets_service)
|
||||
png_data = await self.gacha_log.get_all_five_analysis(user_id, uid, self.assets_service)
|
||||
else:
|
||||
data = await self.gacha_log.get_pool_analysis(user_id, player_id, pool_type, self.assets_service, group)
|
||||
if isinstance(data, str):
|
||||
reply_message = await message.reply_text(data)
|
||||
if filters.ChatType.GROUPS.filter(message):
|
||||
self.add_delete_message_job(reply_message)
|
||||
self.add_delete_message_job(message)
|
||||
else:
|
||||
name_card = await self.player_info.get_name_card(player_id, user_id)
|
||||
document = False
|
||||
if data["hasMore"] and not group:
|
||||
document = True
|
||||
data["hasMore"] = False
|
||||
data["name_card"] = name_card
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT if document else ChatAction.UPLOAD_PHOTO)
|
||||
png_data = await self.template_service.render(
|
||||
"genshin/wish_count/wish_count.jinja2",
|
||||
data,
|
||||
full_page=True,
|
||||
query_selector=".body_box",
|
||||
file_type=FileType.DOCUMENT if document else FileType.PHOTO,
|
||||
)
|
||||
if document:
|
||||
await png_data.reply_document(message, filename="抽卡统计.png")
|
||||
else:
|
||||
await png_data.reply_photo(message)
|
||||
png_data = await self.gacha_log.get_pool_analysis(user_id, uid, pool_type, self.assets_service, group)
|
||||
except GachaLogNotFound:
|
||||
self.log_user(update, logger.info, "未找到抽卡记录")
|
||||
buttons = [
|
||||
[InlineKeyboardButton("点我导入", url=create_deep_linked_url(context.bot.username, "gacha_log_import"))]
|
||||
]
|
||||
await message.reply_text("派蒙没有找到你的抽卡记录,快来私聊派蒙导入吧~", reply_markup=InlineKeyboardMarkup(buttons))
|
||||
png_data = "未找到抽卡记录"
|
||||
if isinstance(png_data, str):
|
||||
await callback_query.answer(png_data, show_alert=True)
|
||||
self.add_delete_message_job(message, delay=1)
|
||||
else:
|
||||
await callback_query.answer(text="正在渲染图片中 请稍等 请不要重复点击按钮", show_alert=False)
|
||||
name_card = await self.player_info.get_name_card(uid, user_id)
|
||||
document = False
|
||||
if png_data["hasMore"] and not group:
|
||||
document = True
|
||||
png_data["hasMore"] = False
|
||||
png_data["name_card"] = name_card
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT if document else ChatAction.UPLOAD_PHOTO)
|
||||
png = await self.template_service.render(
|
||||
"genshin/wish_count/wish_count.jinja2",
|
||||
png_data,
|
||||
full_page=True,
|
||||
query_selector=".body_box",
|
||||
file_type=FileType.DOCUMENT if document else FileType.PHOTO,
|
||||
)
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
if document:
|
||||
await png.reply_document(message, filename="抽卡统计.png")
|
||||
self.add_delete_message_job(message, delay=1)
|
||||
else:
|
||||
await png.edit_media(message)
|
||||
|
||||
@staticmethod
|
||||
async def get_migrate_data(
|
||||
|
@ -150,13 +150,6 @@
|
||||
</div>
|
||||
<div class="command-description">抽卡记录</div>
|
||||
</div>
|
||||
<div class="command">
|
||||
<div class="command-name">
|
||||
/wish_count
|
||||
<i class="fa fa-user-circle-o ml-2"></i>
|
||||
</div>
|
||||
<div class="command-description">抽卡统计</div>
|
||||
</div>
|
||||
<div class="command">
|
||||
<div class="command-name">
|
||||
/pay_log
|
||||
|
@ -21,14 +21,14 @@
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
width: 530px;
|
||||
width: 1286px;
|
||||
color: #1E1F20;
|
||||
transform: scale(1.5);
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 530px;
|
||||
width: 1286px;
|
||||
padding: 20px 15px 10px 15px;
|
||||
background-color: #F5F6FB;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user