mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
💩 适配超时空猫猫的奇怪图片
This commit is contained in:
parent
81d015f3d8
commit
d98b3e6be0
@ -1,11 +1,12 @@
|
|||||||
import io
|
|
||||||
import json
|
import json
|
||||||
import base64
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from pathlib import Path
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
from typing import Any, List, Tuple, Union, Literal
|
from typing import Any, List, Tuple, Union, Literal
|
||||||
|
|
||||||
import qrcode
|
import qrcode
|
||||||
|
import aiofiles
|
||||||
|
from qrcode.image.pil import PilImage
|
||||||
from qrcode.constants import ERROR_CORRECT_L
|
from qrcode.constants import ERROR_CORRECT_L
|
||||||
|
|
||||||
from gsuid_core.bot import Bot
|
from gsuid_core.bot import Bot
|
||||||
@ -25,7 +26,7 @@ disnote = '''免责声明:您将通过扫码完成获取米游社sk以及ck。
|
|||||||
get_sqla = DBSqla().get_sqla
|
get_sqla = DBSqla().get_sqla
|
||||||
|
|
||||||
|
|
||||||
def get_qrcode_base64(url):
|
async def get_qrcode_base64(url: str, path: Path) -> bytes:
|
||||||
qr = qrcode.QRCode(
|
qr = qrcode.QRCode(
|
||||||
version=1,
|
version=1,
|
||||||
error_correction=ERROR_CORRECT_L,
|
error_correction=ERROR_CORRECT_L,
|
||||||
@ -35,10 +36,21 @@ def get_qrcode_base64(url):
|
|||||||
qr.add_data(url)
|
qr.add_data(url)
|
||||||
qr.make(fit=True)
|
qr.make(fit=True)
|
||||||
img = qr.make_image(fill_color='black', back_color='white')
|
img = qr.make_image(fill_color='black', back_color='white')
|
||||||
img_byte = io.BytesIO()
|
assert isinstance(img, PilImage)
|
||||||
img.save(img_byte, format='PNG') # type: ignore
|
|
||||||
img_byte = img_byte.getvalue()
|
img = img.resize((700, 700)) # type: ignore
|
||||||
return base64.b64encode(img_byte).decode()
|
img.save( # type: ignore
|
||||||
|
path,
|
||||||
|
format='PNG',
|
||||||
|
save_all=True,
|
||||||
|
append_images=[img],
|
||||||
|
duration=100,
|
||||||
|
loop=0,
|
||||||
|
)
|
||||||
|
async with aiofiles.open(path, 'rb') as fp:
|
||||||
|
img = await fp.read()
|
||||||
|
|
||||||
|
return img
|
||||||
|
|
||||||
|
|
||||||
async def refresh(
|
async def refresh(
|
||||||
@ -74,13 +86,13 @@ async def qrcode_login(bot: Bot, ev: Event, user_id: str) -> str:
|
|||||||
code_data = await mys_api.create_qrcode_url()
|
code_data = await mys_api.create_qrcode_url()
|
||||||
if isinstance(code_data, int):
|
if isinstance(code_data, int):
|
||||||
return await send_msg('链接创建失败...')
|
return await send_msg('链接创建失败...')
|
||||||
try:
|
|
||||||
|
path = Path(__file__).parent / f'{user_id}.gif'
|
||||||
|
|
||||||
im = []
|
im = []
|
||||||
im.append(MessageSegment.text('请使用米游社扫描下方二维码登录:'))
|
im.append(MessageSegment.text('请使用米游社扫描下方二维码登录:'))
|
||||||
im.append(
|
im.append(
|
||||||
MessageSegment.image(
|
MessageSegment.image(await get_qrcode_base64(code_data['url'], path))
|
||||||
f'base64://{get_qrcode_base64(code_data["url"])}'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
im.append(
|
im.append(
|
||||||
MessageSegment.text(
|
MessageSegment.text(
|
||||||
@ -91,10 +103,11 @@ async def qrcode_login(bot: Bot, ev: Event, user_id: str) -> str:
|
|||||||
'害怕风险请勿扫码~'
|
'害怕风险请勿扫码~'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
await bot.send(MessageSegment.node(im))
|
await bot.send(im)
|
||||||
except Exception as e:
|
|
||||||
logger.error(e)
|
if path.exists():
|
||||||
logger.warning(f'[扫码登录] {user_id} 图片发送失败')
|
path.unlink()
|
||||||
|
|
||||||
status, game_token_data = await refresh(code_data)
|
status, game_token_data = await refresh(code_data)
|
||||||
if status:
|
if status:
|
||||||
assert game_token_data is not None # 骗过 pyright
|
assert game_token_data is not None # 骗过 pyright
|
||||||
|
Loading…
x
Reference in New Issue
Block a user