mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 09:37:30 +00:00
🔥 Remove qlogin
This commit is contained in:
parent
44a01bffd1
commit
e146ca5c16
@ -1,16 +1,11 @@
|
|||||||
import asyncio
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from io import BytesIO
|
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
import qrcode
|
|
||||||
from arkowrapper import ArkoWrapper
|
from arkowrapper import ArkoWrapper
|
||||||
from qrcode.image.pure import PyPNGImage
|
|
||||||
from simnet import GenshinClient, Region
|
from simnet import GenshinClient, Region
|
||||||
from simnet.errors import DataNotPublic, InvalidCookies, BadRequest as SimnetBadRequest
|
from simnet.errors import DataNotPublic, InvalidCookies, BadRequest as SimnetBadRequest
|
||||||
from simnet.models.lab.record import Account
|
from simnet.models.lab.record import Account
|
||||||
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, TelegramObject, Update
|
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, TelegramObject, Update
|
||||||
from telegram.constants import ParseMode
|
|
||||||
from telegram.ext import CallbackContext, ConversationHandler, filters
|
from telegram.ext import CallbackContext, ConversationHandler, filters
|
||||||
from telegram.helpers import escape_markdown
|
from telegram.helpers import escape_markdown
|
||||||
|
|
||||||
@ -134,59 +129,6 @@ class AccountCookiesPlugin(Plugin.Conversation):
|
|||||||
await message.reply_markdown_v2(text, reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
await message.reply_markdown_v2(text, reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
|
||||||
return CHECK_SERVER
|
return CHECK_SERVER
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def generate_qrcode(url: str) -> bytes:
|
|
||||||
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
|
|
||||||
qr.add_data(url)
|
|
||||||
qr.make(fit=True)
|
|
||||||
img = qr.make_image(image_factory=PyPNGImage, fill_color="black", back_color="white")
|
|
||||||
bio = BytesIO()
|
|
||||||
img.save(bio)
|
|
||||||
return bio.getvalue()
|
|
||||||
|
|
||||||
@conversation.entry_point
|
|
||||||
@handler.command("qlogin", filters=filters.ChatType.PRIVATE, block=False)
|
|
||||||
async def qrcode_login(self, update: Update, context: CallbackContext):
|
|
||||||
user = update.effective_user
|
|
||||||
message = update.effective_message
|
|
||||||
logger.info("用户 %s[%s] 绑定账号命令请求", user.full_name, user.id)
|
|
||||||
account_cookies_plugin_data: AccountCookiesPluginData = context.chat_data.get("account_cookies_plugin_data")
|
|
||||||
if account_cookies_plugin_data is None:
|
|
||||||
account_cookies_plugin_data = AccountCookiesPluginData()
|
|
||||||
context.chat_data["account_cookies_plugin_data"] = account_cookies_plugin_data
|
|
||||||
else:
|
|
||||||
account_cookies_plugin_data.reset()
|
|
||||||
account_cookies_plugin_data.region = RegionEnum.HYPERION
|
|
||||||
async with GenshinClient(region=Region.CHINESE) as client:
|
|
||||||
url, ticket = await client.gen_login_qrcode()
|
|
||||||
data = self.generate_qrcode(url)
|
|
||||||
text = f"你好 {user.mention_html()} !该绑定方法仅支持国服,请在3分钟内使用米游社扫码并确认进行绑定。"
|
|
||||||
await message.reply_photo(data, caption=text, parse_mode=ParseMode.HTML)
|
|
||||||
for _ in range(20):
|
|
||||||
await asyncio.sleep(10)
|
|
||||||
try:
|
|
||||||
if game_token := await client.check_login_qrcode(ticket):
|
|
||||||
stoken_v2, mid = await client.get_stoken_v2_and_mid_by_game_token(game_token)
|
|
||||||
cookie_token = await client.get_cookie_token_by_stoken()
|
|
||||||
ltoken = await client.get_ltoken_by_stoken()
|
|
||||||
cookies = {
|
|
||||||
"stuid": str(client.account_id),
|
|
||||||
"ltuid": str(client.account_id),
|
|
||||||
"account_id": str(client.account_id),
|
|
||||||
"stoken": stoken_v2,
|
|
||||||
"mid": mid,
|
|
||||||
"cookie_token": cookie_token,
|
|
||||||
"ltoken": ltoken,
|
|
||||||
}
|
|
||||||
account_cookies_plugin_data.cookies = cookies
|
|
||||||
return await self.check_cookies(update, context)
|
|
||||||
except SimnetBadRequest as e:
|
|
||||||
if e.ret_code == -106:
|
|
||||||
break
|
|
||||||
raise e
|
|
||||||
await message.reply_text("可能是验证码已过期或者你没有同意授权,请重新发送命令进行绑定。")
|
|
||||||
return ConversationHandler.END
|
|
||||||
|
|
||||||
@conversation.state(state=CHECK_SERVER)
|
@conversation.state(state=CHECK_SERVER)
|
||||||
@handler.message(filters=filters.TEXT & ~filters.COMMAND, block=False)
|
@handler.message(filters=filters.TEXT & ~filters.COMMAND, block=False)
|
||||||
async def check_server(self, update: Update, context: CallbackContext) -> int:
|
async def check_server(self, update: Update, context: CallbackContext) -> int:
|
||||||
|
Loading…
Reference in New Issue
Block a user