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
fa2054d15c
commit
90ce1ee6d7
@ -128,9 +128,16 @@ class Bot:
|
|||||||
] = None,
|
] = None,
|
||||||
unsuported_platform: bool = False,
|
unsuported_platform: bool = False,
|
||||||
timeout: float = 60,
|
timeout: float = 60,
|
||||||
|
sep: str = ' / ',
|
||||||
):
|
):
|
||||||
return await self.receive_resp(
|
return await self.receive_resp(
|
||||||
reply, option_list, unsuported_platform, True, True, timeout
|
reply,
|
||||||
|
option_list,
|
||||||
|
unsuported_platform,
|
||||||
|
True,
|
||||||
|
True,
|
||||||
|
timeout,
|
||||||
|
sep=sep,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_option(
|
async def send_option(
|
||||||
@ -142,9 +149,10 @@ class Bot:
|
|||||||
Union[List[str], List[Button], List[List[str]], List[List[Button]]]
|
Union[List[str], List[Button], List[List[str]], List[List[Button]]]
|
||||||
] = None,
|
] = None,
|
||||||
unsuported_platform: bool = False,
|
unsuported_platform: bool = False,
|
||||||
|
sep: str = ' / ',
|
||||||
):
|
):
|
||||||
return await self.receive_resp(
|
return await self.receive_resp(
|
||||||
reply, option_list, unsuported_platform, False, False
|
reply, option_list, unsuported_platform, False, False, sep=sep
|
||||||
)
|
)
|
||||||
|
|
||||||
async def receive_resp(
|
async def receive_resp(
|
||||||
@ -159,6 +167,7 @@ class Bot:
|
|||||||
is_mutiply: bool = False,
|
is_mutiply: bool = False,
|
||||||
is_recive: bool = True,
|
is_recive: bool = True,
|
||||||
timeout: float = 60,
|
timeout: float = 60,
|
||||||
|
sep: str = ' / ',
|
||||||
) -> Optional[Event]:
|
) -> Optional[Event]:
|
||||||
if option_list:
|
if option_list:
|
||||||
if reply is None:
|
if reply is None:
|
||||||
@ -200,7 +209,7 @@ class Bot:
|
|||||||
|
|
||||||
_reply.append(
|
_reply.append(
|
||||||
MessageSegment.text(
|
MessageSegment.text(
|
||||||
'\n请输入以下命令之一:\n' + ' / '.join(_options)
|
'\n请输入以下命令之一:\n' + sep.join(_options)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
await self.send(_reply)
|
await self.send(_reply)
|
||||||
|
@ -4,6 +4,7 @@ from typing import Dict
|
|||||||
from gsuid_core.sv import SV
|
from gsuid_core.sv import SV
|
||||||
from gsuid_core.bot import Bot
|
from gsuid_core.bot import Bot
|
||||||
from gsuid_core.models import Event
|
from gsuid_core.models import Event
|
||||||
|
from gsuid_core.message_models import Button
|
||||||
from gsuid_core.utils.api.mys_api import mys_api
|
from gsuid_core.utils.api.mys_api import mys_api
|
||||||
from gsuid_core.utils.database.models import GsUser
|
from gsuid_core.utils.database.models import GsUser
|
||||||
from gsuid_core.utils.cookie_manager.qrlogin import qrcode_login
|
from gsuid_core.utils.cookie_manager.qrlogin import qrcode_login
|
||||||
@ -33,20 +34,46 @@ async def send_refresh_ck_msg(bot: Bot, ev: Event):
|
|||||||
await bot.send(im)
|
await bot.send(im)
|
||||||
|
|
||||||
|
|
||||||
|
async def _send_help(bot: Bot, im):
|
||||||
|
p = Button('🔍查询信息', '查询')
|
||||||
|
q = Button('💠查询探索度', '查询探索')
|
||||||
|
r = Button('💠查询收集度', '查询收集')
|
||||||
|
t = Button('🌌查询深渊', '查询深渊')
|
||||||
|
s = Button('✨查询体力', '每日')
|
||||||
|
u = Button('🆚查询七圣', '七圣召唤')
|
||||||
|
v = Button('✉原石札记', '原石札记')
|
||||||
|
x = Button('⏱注册时间', '原神注册时间')
|
||||||
|
y = Button('💗抽卡记录', '抽卡记录')
|
||||||
|
await bot.send_option(
|
||||||
|
im,
|
||||||
|
[
|
||||||
|
[p, q, r],
|
||||||
|
[t, s, u],
|
||||||
|
[v, x, y],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@sv_core_user_qrcode_login.on_fullmatch(('扫码登陆', '扫码登录'))
|
@sv_core_user_qrcode_login.on_fullmatch(('扫码登陆', '扫码登录'))
|
||||||
async def send_qrcode_login(bot: Bot, ev: Event):
|
async def send_qrcode_login(bot: Bot, ev: Event):
|
||||||
await bot.logger.info('开始执行[扫码登陆]')
|
await bot.logger.info('开始执行[扫码登陆]')
|
||||||
im = await qrcode_login(bot, ev, ev.user_id)
|
im = await qrcode_login(bot, ev, ev.user_id)
|
||||||
if not im:
|
if not im:
|
||||||
return
|
return
|
||||||
im = await deal_ck(ev.bot_id, im, ev.user_id)
|
im, status = await deal_ck(ev.bot_id, im, ev.user_id)
|
||||||
await bot.send(im)
|
if status:
|
||||||
|
await _send_help(bot, im)
|
||||||
|
else:
|
||||||
|
await bot.send(im)
|
||||||
|
|
||||||
|
|
||||||
@sv_core_user_addck.on_prefix(('添加'))
|
@sv_core_user_addck.on_prefix(('添加'))
|
||||||
async def send_add_ck_msg(bot: Bot, ev: Event):
|
async def send_add_ck_msg(bot: Bot, ev: Event):
|
||||||
im = await deal_ck(ev.bot_id, ev.text, ev.user_id)
|
im, status = await deal_ck(ev.bot_id, ev.text, ev.user_id)
|
||||||
await bot.send(im)
|
if status:
|
||||||
|
await _send_help(bot, im)
|
||||||
|
else:
|
||||||
|
await bot.send(im)
|
||||||
|
|
||||||
|
|
||||||
@sv_core_user_addck.on_prefix(('mys设备登录'))
|
@sv_core_user_addck.on_prefix(('mys设备登录'))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List
|
from typing import Dict, List, Tuple
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@ -89,21 +89,26 @@ async def refresh_ck_by_uid_list(bot_id: str, uid_dict: Dict):
|
|||||||
|
|
||||||
async def deal_ck(bot_id: str, mes: str, user_id: str, mode: str = 'PIC'):
|
async def deal_ck(bot_id: str, mes: str, user_id: str, mode: str = 'PIC'):
|
||||||
im = await _deal_ck(bot_id, mes, user_id)
|
im = await _deal_ck(bot_id, mes, user_id)
|
||||||
|
img, status = await _deal_ck_to_pic(im)
|
||||||
if mode == 'PIC':
|
if mode == 'PIC':
|
||||||
im = await _deal_ck_to_pic(im)
|
return img, status
|
||||||
return im
|
else:
|
||||||
|
return im, status
|
||||||
|
|
||||||
|
|
||||||
async def _deal_ck_to_pic(im: str) -> bytes:
|
async def _deal_ck_to_pic(im: str) -> Tuple[bytes, bool]:
|
||||||
ok_num = im.count('成功')
|
ok_num = im.count('成功')
|
||||||
if ok_num < 1:
|
if ok_num < 1:
|
||||||
status_pic = pic_path / 'ck_no.png'
|
status_pic = pic_path / 'ck_no.png'
|
||||||
|
status = False
|
||||||
elif ok_num < 2:
|
elif ok_num < 2:
|
||||||
status_pic = pic_path / 'ck_ok.png'
|
status_pic = pic_path / 'ck_ok.png'
|
||||||
|
status = False
|
||||||
else:
|
else:
|
||||||
status_pic = pic_path / 'all_ok.png'
|
status_pic = pic_path / 'all_ok.png'
|
||||||
|
status = True
|
||||||
img = Image.open(status_pic).convert('RGB')
|
img = Image.open(status_pic).convert('RGB')
|
||||||
return await convert_img(img)
|
return await convert_img(img), status
|
||||||
|
|
||||||
|
|
||||||
async def get_account_id(simp_dict: SimpleCookie) -> str:
|
async def get_account_id(simp_dict: SimpleCookie) -> str:
|
||||||
|
@ -66,9 +66,11 @@ def get_error_type(retcode: Union[int, str]) -> str:
|
|||||||
return 'Api错误'
|
return 'Api错误'
|
||||||
|
|
||||||
|
|
||||||
async def get_error_img(retcode: Union[int, str]) -> Union[bytes, str]:
|
async def get_error_img(
|
||||||
|
retcode: Union[int, str], force_image: bool = False
|
||||||
|
) -> Union[bytes, str]:
|
||||||
error_message = get_error(retcode)
|
error_message = get_error(retcode)
|
||||||
if is_pic_error:
|
if is_pic_error or force_image:
|
||||||
error_type = get_error_type(retcode)
|
error_type = get_error_type(retcode)
|
||||||
return await draw_error_img(retcode, error_message, error_type)
|
return await draw_error_img(retcode, error_message, error_type)
|
||||||
else:
|
else:
|
||||||
|
@ -14,6 +14,24 @@ TEXT_PATH = Path(__file__).parent / 'texture2d'
|
|||||||
BG_PATH = Path(__file__).parents[1] / 'default_bg'
|
BG_PATH = Path(__file__).parents[1] / 'default_bg'
|
||||||
|
|
||||||
|
|
||||||
|
async def shift_image_hue(img: Image.Image, angle: float = 30) -> Image.Image:
|
||||||
|
alpha = img.getchannel('A')
|
||||||
|
img = img.convert('HSV')
|
||||||
|
|
||||||
|
pixels = img.load()
|
||||||
|
hue_shift = angle
|
||||||
|
|
||||||
|
for y in range(img.height):
|
||||||
|
for x in range(img.width):
|
||||||
|
h, s, v = pixels[x, y]
|
||||||
|
h = (h + hue_shift) % 360
|
||||||
|
pixels[x, y] = (h, s, v)
|
||||||
|
|
||||||
|
img = img.convert('RGBA')
|
||||||
|
img.putalpha(alpha)
|
||||||
|
return img
|
||||||
|
|
||||||
|
|
||||||
async def get_pic(url, size: Optional[Tuple[int, int]] = None) -> Image.Image:
|
async def get_pic(url, size: Optional[Tuple[int, int]] = None) -> Image.Image:
|
||||||
"""
|
"""
|
||||||
从网络获取图片, 格式化为RGBA格式的指定尺寸
|
从网络获取图片, 格式化为RGBA格式的指定尺寸
|
||||||
|
Loading…
x
Reference in New Issue
Block a user