Gacha Log Online View

This commit is contained in:
omg-xtao 2024-09-08 22:45:03 +08:00 committed by GitHub
parent 051c3e5e38
commit 9c26cd8649
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 213 additions and 68 deletions

View File

@ -35,3 +35,15 @@ class PaimonMoeGachaLogFileError(GachaLogFileError):
super().__init__("Paimon.Moe version not supported") super().__init__("Paimon.Moe version not supported")
self.support_version = support_version self.support_version = support_version
self.file_version = file_version self.file_version = file_version
class GachaLogWebError(GachaLogException):
pass
class GachaLogWebNotConfigError(GachaLogWebError):
pass
class GachaLogWebUploadError(GachaLogWebError):
pass

View File

@ -40,6 +40,7 @@ from modules.gacha_log.models import (
UIGFItem, UIGFItem,
UIGFModel, UIGFModel,
) )
from modules.gacha_log.online_view import GachaLogOnlineView
from utils.const import PROJECT_ROOT from utils.const import PROJECT_ROOT
from utils.uid import mask_number from utils.uid import mask_number
@ -51,7 +52,7 @@ GACHA_LOG_PATH = PROJECT_ROOT.joinpath("data", "apihelper", "gacha_log")
GACHA_LOG_PATH.mkdir(parents=True, exist_ok=True) GACHA_LOG_PATH.mkdir(parents=True, exist_ok=True)
class GachaLog: class GachaLog(GachaLogOnlineView):
def __init__(self, gacha_log_path: Path = GACHA_LOG_PATH): def __init__(self, gacha_log_path: Path = GACHA_LOG_PATH):
self.gacha_log_path = gacha_log_path self.gacha_log_path = gacha_log_path

View File

@ -0,0 +1,82 @@
from pathlib import Path
from typing import Optional
import httpx
from httpx import URL
from httpx import HTTPError
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from telegram.helpers import create_deep_linked_url
from gram_core.basemodel import Settings
from modules.gacha_log.error import GachaLogWebNotConfigError, GachaLogWebUploadError, GachaLogNotFound
class GachaLogWebConfig(Settings):
"""抽卡记录在线查询配置"""
url: Optional[str] = ""
token: Optional[str] = ""
class Config(Settings.Config):
env_prefix = "gacha_log_web_"
gacha_log_web_config = GachaLogWebConfig()
DEFAULT_POOL = "角色祈愿"
class GachaLogOnlineView:
"""抽卡记录在线查询"""
gacha_log_path: Path
@staticmethod
def get_web_upload_button(bot_username: str):
if not gacha_log_web_config.url:
return None
return InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
">> 查询详细信息 <<", url=create_deep_linked_url(bot_username, "gacha_log_online_view")
)
]
]
)
async def web_upload(self, user_id: str, uid: str) -> str:
if not gacha_log_web_config.url:
raise GachaLogWebNotConfigError
file_path = self.gacha_log_path / f"{user_id}-{uid}.json"
if not file_path.exists():
raise GachaLogNotFound
async with httpx.AsyncClient() as client:
with open(file_path, "rb") as file:
try:
req = await client.post(
URL(gacha_log_web_config.url).join("upload"),
files={"file": file},
data={
"token": gacha_log_web_config.token,
"uid": uid,
"game": "genshin",
},
)
req.raise_for_status()
except HTTPError as e:
raise GachaLogWebUploadError from e
account_id = req.json()["account_id"]
url = (
URL(gacha_log_web_config.url)
.join("gacha_log")
.copy_merge_params(
{
"account_id": account_id,
"banner_type": DEFAULT_POOL,
"rarities": "3,4,5",
"size": 100,
"page": 1,
}
)
)
return str(url)

View File

@ -5,7 +5,7 @@
groups = ["default", "genshin-artifact", "pyro", "test"] groups = ["default", "genshin-artifact", "pyro", "test"]
strategy = ["inherit_metadata"] strategy = ["inherit_metadata"]
lock_version = "4.5.0" lock_version = "4.5.0"
content_hash = "sha256:c0907b6fd6045504c749e63c157e63691cac53dc5a9578aaac095d8cfd47b971" content_hash = "sha256:d28f2bc077e14daefc70a324633075cf5a1c02d3d6f96c728873d0cebee08093"
[[metadata.targets]] [[metadata.targets]]
requires_python = "~=3.8" requires_python = "~=3.8"
@ -662,7 +662,7 @@ files = [
[[package]] [[package]]
name = "cryptography" name = "cryptography"
version = "43.0.0" version = "43.0.1"
requires_python = ">=3.7" requires_python = ">=3.7"
summary = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." summary = "cryptography is a package which provides cryptographic recipes and primitives to Python developers."
groups = ["default"] groups = ["default"]
@ -670,33 +670,33 @@ dependencies = [
"cffi>=1.12; platform_python_implementation != \"PyPy\"", "cffi>=1.12; platform_python_implementation != \"PyPy\"",
] ]
files = [ files = [
{file = "cryptography-43.0.0-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:64c3f16e2a4fc51c0d06af28441881f98c5d91009b8caaff40cf3548089e9c74"}, {file = "cryptography-43.0.1-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:8385d98f6a3bf8bb2d65a73e17ed87a3ba84f6991c155691c51112075f9ffc5d"},
{file = "cryptography-43.0.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3dcdedae5c7710b9f97ac6bba7e1052b95c7083c9d0e9df96e02a1932e777895"}, {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:27e613d7077ac613e399270253259d9d53872aaf657471473ebfc9a52935c062"},
{file = "cryptography-43.0.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3d9a1eca329405219b605fac09ecfc09ac09e595d6def650a437523fcd08dd22"}, {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:68aaecc4178e90719e95298515979814bda0cbada1256a4485414860bd7ab962"},
{file = "cryptography-43.0.0-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:ea9e57f8ea880eeea38ab5abf9fbe39f923544d7884228ec67d666abd60f5a47"}, {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:de41fd81a41e53267cb020bb3a7212861da53a7d39f863585d13ea11049cf277"},
{file = "cryptography-43.0.0-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:9a8d6802e0825767476f62aafed40532bd435e8a5f7d23bd8b4f5fd04cc80ecf"}, {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f98bf604c82c416bc829e490c700ca1553eafdf2912a91e23a79d97d9801372a"},
{file = "cryptography-43.0.0-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:cc70b4b581f28d0a254d006f26949245e3657d40d8857066c2ae22a61222ef55"}, {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:61ec41068b7b74268fa86e3e9e12b9f0c21fcf65434571dbb13d954bceb08042"},
{file = "cryptography-43.0.0-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:4a997df8c1c2aae1e1e5ac49c2e4f610ad037fc5a3aadc7b64e39dea42249431"}, {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:014f58110f53237ace6a408b5beb6c427b64e084eb451ef25a28308270086494"},
{file = "cryptography-43.0.0-cp37-abi3-win32.whl", hash = "sha256:6e2b11c55d260d03a8cf29ac9b5e0608d35f08077d8c087be96287f43af3ccdc"}, {file = "cryptography-43.0.1-cp37-abi3-win32.whl", hash = "sha256:2bd51274dcd59f09dd952afb696bf9c61a7a49dfc764c04dd33ef7a6b502a1e2"},
{file = "cryptography-43.0.0-cp37-abi3-win_amd64.whl", hash = "sha256:31e44a986ceccec3d0498e16f3d27b2ee5fdf69ce2ab89b52eaad1d2f33d8778"}, {file = "cryptography-43.0.1-cp37-abi3-win_amd64.whl", hash = "sha256:666ae11966643886c2987b3b721899d250855718d6d9ce41b521252a17985f4d"},
{file = "cryptography-43.0.0-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:7b3f5fe74a5ca32d4d0f302ffe6680fcc5c28f8ef0dc0ae8f40c0f3a1b4fca66"}, {file = "cryptography-43.0.1-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:ac119bb76b9faa00f48128b7f5679e1d8d437365c5d26f1c2c3f0da4ce1b553d"},
{file = "cryptography-43.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ac1955ce000cb29ab40def14fd1bbfa7af2017cca696ee696925615cafd0dce5"}, {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1bbcce1a551e262dfbafb6e6252f1ae36a248e615ca44ba302df077a846a8806"},
{file = "cryptography-43.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:299d3da8e00b7e2b54bb02ef58d73cd5f55fb31f33ebbf33bd00d9aa6807df7e"}, {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:58d4e9129985185a06d849aa6df265bdd5a74ca6e1b736a77959b498e0505b85"},
{file = "cryptography-43.0.0-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:ee0c405832ade84d4de74b9029bedb7b31200600fa524d218fc29bfa371e97f5"}, {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:d03a475165f3134f773d1388aeb19c2d25ba88b6a9733c5c590b9ff7bbfa2e0c"},
{file = "cryptography-43.0.0-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:cb013933d4c127349b3948aa8aaf2f12c0353ad0eccd715ca789c8a0f671646f"}, {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:511f4273808ab590912a93ddb4e3914dfd8a388fed883361b02dea3791f292e1"},
{file = "cryptography-43.0.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:fdcb265de28585de5b859ae13e3846a8e805268a823a12a4da2597f1f5afc9f0"}, {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:80eda8b3e173f0f247f711eef62be51b599b5d425c429b5d4ca6a05e9e856baa"},
{file = "cryptography-43.0.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:2905ccf93a8a2a416f3ec01b1a7911c3fe4073ef35640e7ee5296754e30b762b"}, {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:38926c50cff6f533f8a2dae3d7f19541432610d114a70808f0926d5aaa7121e4"},
{file = "cryptography-43.0.0-cp39-abi3-win32.whl", hash = "sha256:47ca71115e545954e6c1d207dd13461ab81f4eccfcb1345eac874828b5e3eaaf"}, {file = "cryptography-43.0.1-cp39-abi3-win32.whl", hash = "sha256:a575913fb06e05e6b4b814d7f7468c2c660e8bb16d8d5a1faf9b33ccc569dd47"},
{file = "cryptography-43.0.0-cp39-abi3-win_amd64.whl", hash = "sha256:0663585d02f76929792470451a5ba64424acc3cd5227b03921dab0e2f27b1709"}, {file = "cryptography-43.0.1-cp39-abi3-win_amd64.whl", hash = "sha256:d75601ad10b059ec832e78823b348bfa1a59f6b8d545db3a24fd44362a1564cb"},
{file = "cryptography-43.0.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:2c6d112bf61c5ef44042c253e4859b3cbbb50df2f78fa8fae6747a7814484a70"}, {file = "cryptography-43.0.1-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ea25acb556320250756e53f9e20a4177515f012c9eaea17eb7587a8c4d8ae034"},
{file = "cryptography-43.0.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:844b6d608374e7d08f4f6e6f9f7b951f9256db41421917dfb2d003dde4cd6b66"}, {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c1332724be35d23a854994ff0b66530119500b6053d0bd3363265f7e5e77288d"},
{file = "cryptography-43.0.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:51956cf8730665e2bdf8ddb8da0056f699c1a5715648c1b0144670c1ba00b48f"}, {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:fba1007b3ef89946dbbb515aeeb41e30203b004f0b4b00e5e16078b518563289"},
{file = "cryptography-43.0.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:aae4d918f6b180a8ab8bf6511a419473d107df4dbb4225c7b48c5c9602c38c7f"}, {file = "cryptography-43.0.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:5b43d1ea6b378b54a1dc99dd8a2b5be47658fe9a7ce0a58ff0b55f4b43ef2b84"},
{file = "cryptography-43.0.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:232ce02943a579095a339ac4b390fbbe97f5b5d5d107f8a08260ea2768be8cc2"}, {file = "cryptography-43.0.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:88cce104c36870d70c49c7c8fd22885875d950d9ee6ab54df2745f83ba0dc365"},
{file = "cryptography-43.0.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:5bcb8a5620008a8034d39bce21dc3e23735dfdb6a33a06974739bfa04f853947"}, {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:9d3cdb25fa98afdd3d0892d132b8d7139e2c087da1712041f6b762e4f807cc96"},
{file = "cryptography-43.0.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:08a24a7070b2b6804c1940ff0f910ff728932a9d0e80e7814234269f9d46d069"}, {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e710bf40870f4db63c3d7d929aa9e09e4e7ee219e703f949ec4073b4294f6172"},
{file = "cryptography-43.0.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:e9c5266c432a1e23738d178e51c2c7a5e2ddf790f248be939448c0ba2021f9d1"}, {file = "cryptography-43.0.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7c05650fe8023c5ed0d46793d4b7d7e6cd9c04e68eabe5b0aeea836e37bdcec2"},
{file = "cryptography-43.0.0.tar.gz", hash = "sha256:b88075ada2d51aa9f18283532c9f60e72170041bba88d7f37e49cbb10275299e"}, {file = "cryptography-43.0.1.tar.gz", hash = "sha256:203e92a75716d8cfb491dc47c79e17d0d9207ccffcbcb35f598fbe463ae3444d"},
] ]
[[package]] [[package]]
@ -754,7 +754,7 @@ files = [
[[package]] [[package]]
name = "fastapi" name = "fastapi"
version = "0.112.2" version = "0.114.0"
requires_python = ">=3.8" requires_python = ">=3.8"
summary = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" summary = "FastAPI framework, high performance, easy to learn, fast to code, ready for production"
groups = ["default"] groups = ["default"]
@ -764,8 +764,8 @@ dependencies = [
"typing-extensions>=4.8.0", "typing-extensions>=4.8.0",
] ]
files = [ files = [
{file = "fastapi-0.112.2-py3-none-any.whl", hash = "sha256:db84b470bd0e2b1075942231e90e3577e12a903c4dc8696f0d206a7904a7af1c"}, {file = "fastapi-0.114.0-py3-none-any.whl", hash = "sha256:fee75aa1b1d3d73f79851c432497e4394e413e1dece6234f68d3ce250d12760a"},
{file = "fastapi-0.112.2.tar.gz", hash = "sha256:3d4729c038414d5193840706907a41839d839523da6ed0c2811f1168cac1798c"}, {file = "fastapi-0.114.0.tar.gz", hash = "sha256:9908f2a5cc733004de6ca5e1412698f35085cefcbfd41d539245b9edf87b73c1"},
] ]
[[package]] [[package]]
@ -1871,7 +1871,7 @@ files = [
[[package]] [[package]]
name = "python-telegram-bot" name = "python-telegram-bot"
version = "21.4" version = "21.5"
requires_python = ">=3.8" requires_python = ">=3.8"
summary = "We have made you a wrapper you can't refuse" summary = "We have made you a wrapper you can't refuse"
groups = ["default"] groups = ["default"]
@ -1879,13 +1879,13 @@ dependencies = [
"httpx~=0.27", "httpx~=0.27",
] ]
files = [ files = [
{file = "python_telegram_bot-21.4-py3-none-any.whl", hash = "sha256:71ce864130af43b48be70ff0593ef4db31d99d92aa64a2933289b8d544e6e9df"}, {file = "python_telegram_bot-21.5-py3-none-any.whl", hash = "sha256:1bbba653477ba164411622b717a0cfe1eb7843da016348e41df97f96c93f578e"},
{file = "python_telegram_bot-21.4.tar.gz", hash = "sha256:d4d41f29f2e2c02920a4be75d9c1ecf85ec381bf47bbeb51af5b097e340b8377"}, {file = "python_telegram_bot-21.5.tar.gz", hash = "sha256:2d679173072cce8d6b49aac2e438d49dbfc01c1a4ef5658828c2a65951ee830b"},
] ]
[[package]] [[package]]
name = "python-telegram-bot" name = "python-telegram-bot"
version = "21.4" version = "21.5"
extras = ["ext", "rate-limiter"] extras = ["ext", "rate-limiter"]
requires_python = ">=3.8" requires_python = ">=3.8"
summary = "We have made you a wrapper you can't refuse" summary = "We have made you a wrapper you can't refuse"
@ -1894,14 +1894,14 @@ dependencies = [
"aiolimiter~=1.1.0", "aiolimiter~=1.1.0",
"aiolimiter~=1.1.0", "aiolimiter~=1.1.0",
"apscheduler~=3.10.4", "apscheduler~=3.10.4",
"cachetools~=5.3.3", "cachetools<5.6.0,>=5.3.3",
"python-telegram-bot==21.4", "python-telegram-bot==21.5",
"pytz>=2018.6", "pytz>=2018.6",
"tornado~=6.4", "tornado~=6.4",
] ]
files = [ files = [
{file = "python_telegram_bot-21.4-py3-none-any.whl", hash = "sha256:71ce864130af43b48be70ff0593ef4db31d99d92aa64a2933289b8d544e6e9df"}, {file = "python_telegram_bot-21.5-py3-none-any.whl", hash = "sha256:1bbba653477ba164411622b717a0cfe1eb7843da016348e41df97f96c93f578e"},
{file = "python_telegram_bot-21.4.tar.gz", hash = "sha256:d4d41f29f2e2c02920a4be75d9c1ecf85ec381bf47bbeb51af5b097e340b8377"}, {file = "python_telegram_bot-21.5.tar.gz", hash = "sha256:2d679173072cce8d6b49aac2e438d49dbfc01c1a4ef5658828c2a65951ee830b"},
] ]
[[package]] [[package]]
@ -2170,7 +2170,7 @@ name = "simnet"
version = "0.1.23" version = "0.1.23"
requires_python = "<4.0,>=3.8" requires_python = "<4.0,>=3.8"
git = "https://github.com/PaiGramTeam/SIMNet" git = "https://github.com/PaiGramTeam/SIMNet"
revision = "10aa45ddbbadec40769c01206a1266a3e8b9addc" revision = "1ba4729700d9455014f0fae75c30ccd418190399"
summary = "Modern API wrapper for Genshin Impact & Honkai: Star Rail built on asyncio and pydantic." summary = "Modern API wrapper for Genshin Impact & Honkai: Star Rail built on asyncio and pydantic."
groups = ["default"] groups = ["default"]
dependencies = [ dependencies = [
@ -2290,7 +2290,7 @@ files = [
[[package]] [[package]]
name = "sqlmodel" name = "sqlmodel"
version = "0.0.21" version = "0.0.22"
requires_python = ">=3.7" requires_python = ">=3.7"
summary = "SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness." summary = "SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness."
groups = ["default"] groups = ["default"]
@ -2299,8 +2299,8 @@ dependencies = [
"pydantic<3.0.0,>=1.10.13", "pydantic<3.0.0,>=1.10.13",
] ]
files = [ files = [
{file = "sqlmodel-0.0.21-py3-none-any.whl", hash = "sha256:eca104afe8a643f0764076b29f02e51d19d6b35c458f4c119942960362a4b52a"}, {file = "sqlmodel-0.0.22-py3-none-any.whl", hash = "sha256:a1ed13e28a1f4057cbf4ff6cdb4fc09e85702621d3259ba17b3c230bfb2f941b"},
{file = "sqlmodel-0.0.21.tar.gz", hash = "sha256:b2034c23d930f66d2091b17a4280a9c23a7ea540a71e7fcf9c746d262f06f74a"}, {file = "sqlmodel-0.0.22.tar.gz", hash = "sha256:7d37c882a30c43464d143e35e9ecaf945d88035e20117bf5ec2834a23cbe505e"},
] ]
[[package]] [[package]]

View File

@ -26,6 +26,7 @@ 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_log_online_view", "抽卡记录在线浏览"),
BotCommand("pay_log", "查看充值记录"), BotCommand("pay_log", "查看充值记录"),
BotCommand("pay_log_import", "导入充值记录"), BotCommand("pay_log_import", "导入充值记录"),
BotCommand("pay_log_export", "导出充值记录"), BotCommand("pay_log_export", "导出充值记录"),

View File

@ -8,7 +8,6 @@ from simnet import GenshinClient, Region
from simnet.models.genshin.wish import BannerType from simnet.models.genshin.wish import BannerType
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove
from telegram.constants import ChatAction from telegram.constants import ChatAction
from telegram.error import BadRequest
from telegram.ext import ConversationHandler, filters from telegram.ext import ConversationHandler, filters
from telegram.helpers import create_deep_linked_url from telegram.helpers import create_deep_linked_url
@ -31,6 +30,7 @@ from modules.gacha_log.error import (
GachaLogMixedProvider, GachaLogMixedProvider,
GachaLogNotFound, GachaLogNotFound,
PaimonMoeGachaLogFileError, PaimonMoeGachaLogFileError,
GachaLogWebError,
) )
from modules.gacha_log.helpers import from_url_get_authkey from modules.gacha_log.helpers import from_url_get_authkey
from modules.gacha_log.log import GachaLog from modules.gacha_log.log import GachaLog
@ -56,6 +56,11 @@ if TYPE_CHECKING:
INPUT_URL, INPUT_FILE, CONFIRM_DELETE = range(10100, 10103) INPUT_URL, INPUT_FILE, CONFIRM_DELETE = range(10100, 10103)
WAITING = f"{config.notice.bot_name}正在从服务器获取数据,请稍后" WAITING = f"{config.notice.bot_name}正在从服务器获取数据,请稍后"
WISHLOG_NOT_FOUND = f"{config.notice.bot_name}没有找到你的抽卡记录,快来私聊{config.notice.bot_name}导入吧~" WISHLOG_NOT_FOUND = f"{config.notice.bot_name}没有找到你的抽卡记录,快来私聊{config.notice.bot_name}导入吧~"
WISHLOG_WEB = """<b>抽卡记录详细信息查询</b>
已为您创建一枚令牌点击下方按钮可直接进行查询
有效期为 1 小时过期需重新申请如怀疑泄漏请立即重新申请"""
class WishLogPlugin(Plugin.Conversation): class WishLogPlugin(Plugin.Conversation):
@ -439,7 +444,9 @@ 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, uid: int, pool_type: "BannerType", message: "Message", bot_username: str
):
await message.reply_chat_action(ChatAction.TYPING) await message.reply_chat_action(ChatAction.TYPING)
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)
if isinstance(png_data, str): if isinstance(png_data, str):
@ -450,9 +457,11 @@ class WishLogPlugin(Plugin.Conversation):
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: if png_data.file_type == FileType.DOCUMENT:
await png_data.reply_document(message, filename="抽卡统计.png") await png_data.reply_document(
message, filename="抽卡统计.png", reply_markup=self.gacha_log.get_web_upload_button(bot_username)
)
else: else:
await png_data.reply_photo(message) await png_data.reply_photo(message, reply_markup=self.gacha_log.get_web_upload_button(bot_username))
@handler.command(command="wish_log", block=False) @handler.command(command="wish_log", block=False)
@handler.command(command="gacha_log", block=False) @handler.command(command="gacha_log", block=False)
@ -477,7 +486,7 @@ class WishLogPlugin(Plugin.Conversation):
if pool_type is None: if pool_type is None:
await self.wish_log_pool_choose(user_id, player_id, message) await self.wish_log_pool_choose(user_id, player_id, message)
else: else:
await self.wish_log_pool_send(user_id, player_id, pool_type, message) await self.wish_log_pool_send(user_id, player_id, pool_type, message, context.bot.username)
except GachaLogNotFound: except GachaLogNotFound:
self.log_user(update, logger.info, "未找到抽卡记录") self.log_user(update, logger.info, "未找到抽卡记录")
buttons = [ buttons = [
@ -486,7 +495,7 @@ class WishLogPlugin(Plugin.Conversation):
await message.reply_text(WISHLOG_NOT_FOUND, reply_markup=InlineKeyboardMarkup(buttons)) await message.reply_text(WISHLOG_NOT_FOUND, reply_markup=InlineKeyboardMarkup(buttons))
@handler.callback_query(pattern=r"^get_wish_log\|", block=False) @handler.callback_query(pattern=r"^get_wish_log\|", block=False)
async def get_wish_log(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> None: async def get_wish_log(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> None:
callback_query = update.callback_query callback_query = update.callback_query
user = callback_query.from_user user = callback_query.from_user
message = callback_query.message message = callback_query.message
@ -518,11 +527,13 @@ class WishLogPlugin(Plugin.Conversation):
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": if show_type == "count":
await self.get_wish_log_count(update, user_id, uid, pool) await self.get_wish_log_count(update, context, user_id, uid, pool)
else: else:
await self.get_wish_log_log(update, user_id, uid, pool) await self.get_wish_log_log(update, context, user_id, uid, pool)
async def get_wish_log_log(self, update: "Update", user_id: int, uid: int, pool: str): async def get_wish_log_log(
self, update: "Update", context: "ContextTypes.DEFAULT_TYPE", user_id: int, uid: int, pool: str
):
callback_query = update.callback_query callback_query = update.callback_query
message = callback_query.message message = callback_query.message
@ -539,12 +550,20 @@ class WishLogPlugin(Plugin.Conversation):
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: if png_data.file_type == FileType.DOCUMENT:
await png_data.reply_document(message, filename="抽卡统计.png") await png_data.reply_document(
message,
filename="抽卡统计.png",
reply_markup=self.gacha_log.get_web_upload_button(context.bot.username),
)
self.add_delete_message_job(message, delay=1) self.add_delete_message_job(message, delay=1)
else: else:
await png_data.edit_media(message) await png_data.edit_media(
message, reply_markup=self.gacha_log.get_web_upload_button(context.bot.username)
)
async def get_wish_log_count(self, update: "Update", user_id: int, uid: int, pool: str): async def get_wish_log_count(
self, update: "Update", context: "ContextTypes.DEFAULT_TYPE", user_id: int, uid: int, pool: str
):
callback_query = update.callback_query callback_query = update.callback_query
message = callback_query.message message = callback_query.message
@ -580,10 +599,40 @@ class WishLogPlugin(Plugin.Conversation):
) )
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
if document: if document:
await png.reply_document(message, filename="抽卡统计.png") await png.reply_document(
message,
filename="抽卡统计.png",
reply_markup=self.gacha_log.get_web_upload_button(context.bot.username),
)
self.add_delete_message_job(message, delay=1) self.add_delete_message_job(message, delay=1)
else: else:
await png.edit_media(message) await png.edit_media(message, reply_markup=self.gacha_log.get_web_upload_button(context.bot.username))
@handler.command(command="wish_log_online_view", block=False)
@handler.command(command="gacha_log_online_view", block=False)
@handler.command(command="start", filters=filters.Regex(r"gacha_log_online_view$"), block=False)
async def command_start_upload_web(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> None:
user_id = await self.get_real_user_id(update)
uid, offset = self.get_real_uid_or_offset(update)
message = update.effective_message
self.log_user(update, logger.info, "抽卡记录在线浏览命令请求")
try:
player_id = await self.get_player_id(user_id, uid, offset)
url = await self.gacha_log.web_upload(user_id, str(player_id))
await message.reply_text(
WISHLOG_WEB,
parse_mode="html",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("点我查看", url=url)]]),
)
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(WISHLOG_NOT_FOUND, reply_markup=InlineKeyboardMarkup(buttons))
except GachaLogWebError as e:
logger.error("申请在线查看抽卡记录失败", exc_info=e)
await message.reply_text("申请在线查看抽卡记录失败,请联系管理员")
@staticmethod @staticmethod
async def get_migrate_data( async def get_migrate_data(

View File

@ -17,7 +17,7 @@ dependencies = [
"ujson<6.0.0,>=5.9.0", "ujson<6.0.0,>=5.9.0",
"Jinja2<4.0.0,>=3.1.2", "Jinja2<4.0.0,>=3.1.2",
"python-telegram-bot[ext,rate-limiter]<22.0,>=21.3", "python-telegram-bot[ext,rate-limiter]<22.0,>=21.3",
"sqlmodel<1.0.0,>=0.0.21", "sqlmodel<1.0.0,>=0.0.22",
"colorlog<7.0.0,>=6.8.0", "colorlog<7.0.0,>=6.8.0",
"fakeredis<3.0.0,>=2.19.0", "fakeredis<3.0.0,>=2.19.0",
"redis<6.0.0,>=5.0.1", "redis<6.0.0,>=5.0.1",
@ -31,14 +31,14 @@ dependencies = [
"enkanetwork-py @ git+https://github.com/PaiGramTeam/EnkaNetwork.py", "enkanetwork-py @ git+https://github.com/PaiGramTeam/EnkaNetwork.py",
"lxml<6.0.0,>=5.0.0", "lxml<6.0.0,>=5.0.0",
"arko-wrapper<1.0.0,>=0.3.0", "arko-wrapper<1.0.0,>=0.3.0",
"fastapi<1.0.0,>=0.112.0", "fastapi<1.0.0,>=0.113.0",
"uvicorn[standard]<1.0.0,>=0.30.1", "uvicorn[standard]<1.0.0,>=0.30.1",
"sentry-sdk<3.0.0,>=2.7.0", "sentry-sdk<3.0.0,>=2.7.0",
"GitPython<4.0.0,>=3.1.30", "GitPython<4.0.0,>=3.1.30",
"openpyxl<4.0.0,>=3.1.1", "openpyxl<4.0.0,>=3.1.1",
"async-lru<3.0.0,>=2.0.4", "async-lru<3.0.0,>=2.0.4",
"thefuzz<1.0.0,>=0.22.1", "thefuzz<1.0.0,>=0.22.1",
"cryptography<44.0.0,>=43.0.0", "cryptography<44.0.0,>=43.0.1",
"pillow<11.0.0,>=10.0.1", "pillow<11.0.0,>=10.0.1",
"playwright==1.46.0", "playwright==1.46.0",
"aiosqlite[sqlite]<1.0.0,>=0.20.0", "aiosqlite[sqlite]<1.0.0,>=0.20.0",

View File

@ -27,12 +27,12 @@ ciso8601==2.3.1
click==8.1.7 click==8.1.7
colorama==0.4.6; sys_platform == "win32" or platform_system == "Windows" colorama==0.4.6; sys_platform == "win32" or platform_system == "Windows"
colorlog==6.8.2 colorlog==6.8.2
cryptography==43.0.0 cryptography==43.0.1
enkanetwork-py @ git+https://github.com/PaiGramTeam/EnkaNetwork.py@0924cbce3b8b61cee1db33d7bc7a89f34572a048 enkanetwork-py @ git+https://github.com/PaiGramTeam/EnkaNetwork.py@0924cbce3b8b61cee1db33d7bc7a89f34572a048
et-xmlfile==1.1.0 et-xmlfile==1.1.0
exceptiongroup==1.2.2; python_version < "3.11" exceptiongroup==1.2.2; python_version < "3.11"
fakeredis==2.24.1 fakeredis==2.24.1
fastapi==0.112.2 fastapi==0.114.0
flaky==3.8.1 flaky==3.8.1
frozenlist==1.4.1 frozenlist==1.4.1
gcsim-pypi==2.25.5 gcsim-pypi==2.25.5
@ -77,8 +77,8 @@ pytest-asyncio==0.24.0
python-dateutil==2.9.0.post0 python-dateutil==2.9.0.post0
python-dotenv==1.0.1 python-dotenv==1.0.1
python-genshin-artifact==1.0.9 python-genshin-artifact==1.0.9
python-telegram-bot==21.4 python-telegram-bot==21.5
python-telegram-bot[ext,rate-limiter]==21.4 python-telegram-bot[ext,rate-limiter]==21.5
pytz==2024.1 pytz==2024.1
pyyaml==6.0.2 pyyaml==6.0.2
rapidfuzz==3.9.6 rapidfuzz==3.9.6
@ -87,14 +87,14 @@ redis==5.0.8
rich==13.8.0 rich==13.8.0
sentry-sdk==2.13.0 sentry-sdk==2.13.0
setuptools==73.0.1 setuptools==73.0.1
simnet @ git+https://github.com/PaiGramTeam/SIMNet@10aa45ddbbadec40769c01206a1266a3e8b9addc simnet @ git+https://github.com/PaiGramTeam/SIMNet@1ba4729700d9455014f0fae75c30ccd418190399
six==1.16.0 six==1.16.0
smmap==5.0.1 smmap==5.0.1
sniffio==1.3.1 sniffio==1.3.1
sortedcontainers==2.4.0 sortedcontainers==2.4.0
soupsieve==2.6 soupsieve==2.6
sqlalchemy==2.0.32 sqlalchemy==2.0.32
sqlmodel==0.0.21 sqlmodel==0.0.22
starlette==0.38.2 starlette==0.38.2
tgcrypto==1.2.5 tgcrypto==1.2.5
thefuzz==0.22.1 thefuzz==0.22.1