mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-21 22:58:05 +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):
|
def get_pool_by_id(pool_type):
|
||||||
if pool_type == 200:
|
if pool_type == 200:
|
||||||
return POOL_200
|
return POOL_200
|
||||||
if pool_type == 301:
|
if pool_type in [301, 400]:
|
||||||
return POOL_301
|
return POOL_301
|
||||||
if pool_type == 302:
|
if pool_type == 302:
|
||||||
return POOL_302
|
return POOL_302
|
||||||
|
@ -26,7 +26,6 @@ class SetCommandPlugin(Plugin):
|
|||||||
BotCommand("wish_log_import", "导入抽卡记录"),
|
BotCommand("wish_log_import", "导入抽卡记录"),
|
||||||
BotCommand("wish_log_export", "导出抽卡记录"),
|
BotCommand("wish_log_export", "导出抽卡记录"),
|
||||||
BotCommand("wish_log_delete", "删除抽卡记录"),
|
BotCommand("wish_log_delete", "删除抽卡记录"),
|
||||||
BotCommand("wish_count", "查看抽卡统计(按卡池)"),
|
|
||||||
BotCommand("pay_log", "查看充值记录"),
|
BotCommand("pay_log", "查看充值记录"),
|
||||||
BotCommand("pay_log_import", "导入充值记录"),
|
BotCommand("pay_log_import", "导入充值记录"),
|
||||||
BotCommand("pay_log_export", "导出充值记录"),
|
BotCommand("pay_log_export", "导出充值记录"),
|
||||||
|
@ -392,13 +392,15 @@ class WishLogPlugin(Plugin.Conversation):
|
|||||||
for i in range(0, len(pools), 2):
|
for i in range(0, len(pools), 2):
|
||||||
row = []
|
row = []
|
||||||
for pool in pools[i : i + 2]:
|
for pool in pools[i : i + 2]:
|
||||||
|
for k, v in {"log": "", "count": "(按卡池)"}.items():
|
||||||
row.append(
|
row.append(
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
pool,
|
f"{pool.replace('祈愿', '')}{v}",
|
||||||
callback_data=f"get_wish_log|{user_id}|{uid}|{pool}",
|
callback_data=f"get_wish_log|{user_id}|{uid}|{k}|{pool}",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
buttons.append(row)
|
buttons.append(row)
|
||||||
|
buttons.append([InlineKeyboardButton("五星抽卡统计", callback_data=f"get_wish_log|{user_id}|{uid}|count|five")])
|
||||||
return buttons
|
return buttons
|
||||||
|
|
||||||
async def wish_log_pool_choose(self, user_id: int, message: "Message"):
|
async def wish_log_pool_choose(self, user_id: int, message: "Message"):
|
||||||
@ -421,7 +423,7 @@ class WishLogPlugin(Plugin.Conversation):
|
|||||||
if reply_message.photo:
|
if reply_message.photo:
|
||||||
self.wish_photo = reply_message.photo[-1].file_id
|
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)
|
await message.reply_chat_action(ChatAction.TYPING)
|
||||||
uid = await self.get_player_id(user_id)
|
uid = await self.get_player_id(user_id)
|
||||||
png_data = await self.rander_wish_log_analysis(user_id, uid, pool_type)
|
png_data = await self.rander_wish_log_analysis(user_id, uid, pool_type)
|
||||||
@ -429,6 +431,9 @@ class WishLogPlugin(Plugin.Conversation):
|
|||||||
reply = await message.reply_text(png_data)
|
reply = await message.reply_text(png_data)
|
||||||
else:
|
else:
|
||||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||||
|
if png_data.file_type == FileType.DOCUMENT:
|
||||||
|
reply = await png_data.reply_document(message, filename="抽卡统计.png")
|
||||||
|
else:
|
||||||
reply = await png_data.reply_photo(message)
|
reply = await png_data.reply_photo(message)
|
||||||
if filters.ChatType.GROUPS.filter(message):
|
if filters.ChatType.GROUPS.filter(message):
|
||||||
self.add_delete_message_job(reply)
|
self.add_delete_message_job(reply)
|
||||||
@ -455,7 +460,7 @@ class WishLogPlugin(Plugin.Conversation):
|
|||||||
if pool_type is None:
|
if pool_type is None:
|
||||||
await self.wish_log_pool_choose(user_id, message)
|
await self.wish_log_pool_choose(user_id, message)
|
||||||
else:
|
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:
|
except PlayerNotFoundError:
|
||||||
await message.reply_text("该用户暂未绑定账号")
|
await message.reply_text("该用户暂未绑定账号")
|
||||||
except GachaLogNotFound:
|
except GachaLogNotFound:
|
||||||
@ -473,23 +478,39 @@ class WishLogPlugin(Plugin.Conversation):
|
|||||||
|
|
||||||
async def get_wish_log_callback(
|
async def get_wish_log_callback(
|
||||||
callback_query_data: str,
|
callback_query_data: str,
|
||||||
) -> Tuple[str, int, int]:
|
) -> Tuple[str, str, int, int]:
|
||||||
_data = callback_query_data.split("|")
|
_data = callback_query_data.split("|")
|
||||||
_user_id = int(_data[1])
|
_user_id = int(_data[1])
|
||||||
_uid = int(_data[2])
|
_uid = int(_data[2])
|
||||||
_result = _data[3]
|
_t = _data[3]
|
||||||
|
_result = _data[4]
|
||||||
logger.debug(
|
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,
|
_result,
|
||||||
_user_id,
|
_user_id,
|
||||||
_uid,
|
_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:
|
if user.id != user_id:
|
||||||
await callback_query.answer(text="这不是你的按钮!\n" + config.notice.user_mismatch, show_alert=True)
|
await callback_query.answer(text="这不是你的按钮!\n" + config.notice.user_mismatch, show_alert=True)
|
||||||
return
|
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)
|
pool_type = GACHA_TYPE_LIST_REVERSE.get(pool)
|
||||||
await message.reply_chat_action(ChatAction.TYPING)
|
await message.reply_chat_action(ChatAction.TYPING)
|
||||||
try:
|
try:
|
||||||
@ -502,64 +523,52 @@ class WishLogPlugin(Plugin.Conversation):
|
|||||||
else:
|
else:
|
||||||
await callback_query.answer(text="正在渲染图片中 请稍等 请不要重复点击按钮", show_alert=False)
|
await callback_query.answer(text="正在渲染图片中 请稍等 请不要重复点击按钮", show_alert=False)
|
||||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||||
|
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)
|
await png_data.edit_media(message)
|
||||||
|
|
||||||
@handler.command(command="wish_count", block=False)
|
async def get_wish_log_count(self, update: "Update", user_id: int, uid: int, pool: str):
|
||||||
@handler.command(command="gacha_count", block=False)
|
callback_query = update.callback_query
|
||||||
@handler.message(filters=filters.Regex("^抽卡统计?(武器|角色|常驻|仅五星|)$"), block=False)
|
message = callback_query.message
|
||||||
async def command_start_count(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> None:
|
|
||||||
user_id = await self.get_real_user_id(update)
|
all_five = pool == "five"
|
||||||
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)
|
|
||||||
try:
|
|
||||||
player_id = await self.get_player_id(user_id)
|
|
||||||
group = filters.ChatType.GROUPS.filter(message)
|
group = filters.ChatType.GROUPS.filter(message)
|
||||||
|
pool_type = GACHA_TYPE_LIST_REVERSE.get(pool)
|
||||||
await message.reply_chat_action(ChatAction.TYPING)
|
await message.reply_chat_action(ChatAction.TYPING)
|
||||||
|
try:
|
||||||
if all_five:
|
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:
|
else:
|
||||||
data = await self.gacha_log.get_pool_analysis(user_id, player_id, pool_type, self.assets_service, group)
|
png_data = await self.gacha_log.get_pool_analysis(user_id, uid, pool_type, self.assets_service, group)
|
||||||
if isinstance(data, str):
|
except GachaLogNotFound:
|
||||||
reply_message = await message.reply_text(data)
|
png_data = "未找到抽卡记录"
|
||||||
if filters.ChatType.GROUPS.filter(message):
|
if isinstance(png_data, str):
|
||||||
self.add_delete_message_job(reply_message)
|
await callback_query.answer(png_data, show_alert=True)
|
||||||
self.add_delete_message_job(message)
|
self.add_delete_message_job(message, delay=1)
|
||||||
else:
|
else:
|
||||||
name_card = await self.player_info.get_name_card(player_id, user_id)
|
await callback_query.answer(text="正在渲染图片中 请稍等 请不要重复点击按钮", show_alert=False)
|
||||||
|
name_card = await self.player_info.get_name_card(uid, user_id)
|
||||||
document = False
|
document = False
|
||||||
if data["hasMore"] and not group:
|
if png_data["hasMore"] and not group:
|
||||||
document = True
|
document = True
|
||||||
data["hasMore"] = False
|
png_data["hasMore"] = False
|
||||||
data["name_card"] = name_card
|
png_data["name_card"] = name_card
|
||||||
await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT if document else ChatAction.UPLOAD_PHOTO)
|
await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT if document else ChatAction.UPLOAD_PHOTO)
|
||||||
png_data = await self.template_service.render(
|
png = await self.template_service.render(
|
||||||
"genshin/wish_count/wish_count.jinja2",
|
"genshin/wish_count/wish_count.jinja2",
|
||||||
data,
|
png_data,
|
||||||
full_page=True,
|
full_page=True,
|
||||||
query_selector=".body_box",
|
query_selector=".body_box",
|
||||||
file_type=FileType.DOCUMENT if document else FileType.PHOTO,
|
file_type=FileType.DOCUMENT if document else FileType.PHOTO,
|
||||||
)
|
)
|
||||||
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||||
if document:
|
if document:
|
||||||
await png_data.reply_document(message, filename="抽卡统计.png")
|
await png.reply_document(message, filename="抽卡统计.png")
|
||||||
|
self.add_delete_message_job(message, delay=1)
|
||||||
else:
|
else:
|
||||||
await png_data.reply_photo(message)
|
await png.edit_media(message)
|
||||||
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))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_migrate_data(
|
async def get_migrate_data(
|
||||||
|
@ -150,13 +150,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="command-description">抽卡记录</div>
|
<div class="command-description">抽卡记录</div>
|
||||||
</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">
|
||||||
<div class="command-name">
|
<div class="command-name">
|
||||||
/pay_log
|
/pay_log
|
||||||
|
@ -21,14 +21,14 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
width: 530px;
|
width: 1286px;
|
||||||
color: #1E1F20;
|
color: #1E1F20;
|
||||||
transform: scale(1.5);
|
transform: scale(1.5);
|
||||||
transform-origin: 0 0;
|
transform-origin: 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 530px;
|
width: 1286px;
|
||||||
padding: 20px 15px 10px 15px;
|
padding: 20px 15px 10px 15px;
|
||||||
background-color: #F5F6FB;
|
background-color: #F5F6FB;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user