mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-12 06:55:58 +08:00
🎨 支持发送多列按钮
This commit is contained in:
parent
bd0aa78bdb
commit
44bd8b63b6
@ -208,6 +208,8 @@ class GsClient:
|
|||||||
image,
|
image,
|
||||||
node,
|
node,
|
||||||
at_list,
|
at_list,
|
||||||
|
markdown,
|
||||||
|
buttons,
|
||||||
msg.target_id,
|
msg.target_id,
|
||||||
msg.target_type,
|
msg.target_type,
|
||||||
msg.msg_id,
|
msg.msg_id,
|
||||||
@ -429,7 +431,11 @@ async def onebot_red_send(
|
|||||||
result_msg += MessageSegment.file(path)
|
result_msg += MessageSegment.file(path)
|
||||||
|
|
||||||
if target_id:
|
if target_id:
|
||||||
await bot.send_message(chat_type, target_id, result_msg)
|
await bot.send_message(
|
||||||
|
chat_type, # type: ignore
|
||||||
|
target_id,
|
||||||
|
result_msg,
|
||||||
|
)
|
||||||
|
|
||||||
if file:
|
if file:
|
||||||
del_file(path) # type: ignore
|
del_file(path) # type: ignore
|
||||||
@ -453,6 +459,8 @@ async def guild_send(
|
|||||||
image: Optional[str],
|
image: Optional[str],
|
||||||
node: Optional[List[Dict]],
|
node: Optional[List[Dict]],
|
||||||
at_list: Optional[List[str]],
|
at_list: Optional[List[str]],
|
||||||
|
markdown: Optional[str],
|
||||||
|
buttons: Optional[Union[List[Dict], List[List[Dict]]]],
|
||||||
target_id: Optional[str],
|
target_id: Optional[str],
|
||||||
target_type: Optional[str],
|
target_type: Optional[str],
|
||||||
msg_id: Optional[str],
|
msg_id: Optional[str],
|
||||||
@ -468,6 +476,11 @@ async def guild_send(
|
|||||||
if at_list and target_type == 'group':
|
if at_list and target_type == 'group':
|
||||||
for at in at_list:
|
for at in at_list:
|
||||||
result['content'] += f'<@{at}>'
|
result['content'] += f'<@{at}>'
|
||||||
|
if markdown:
|
||||||
|
logger.warning('[gscore] qqguild暂不支持发送markdown消息')
|
||||||
|
if buttons:
|
||||||
|
logger.warning('[gscore] qqguild暂不支持发送buttons消息')
|
||||||
|
|
||||||
if target_type == 'group':
|
if target_type == 'group':
|
||||||
await bot.call_api(
|
await bot.call_api(
|
||||||
'post_messages',
|
'post_messages',
|
||||||
@ -499,45 +512,15 @@ async def guild_send(
|
|||||||
await _send(content, image)
|
await _send(content, image)
|
||||||
|
|
||||||
|
|
||||||
async def group_send(
|
def _bt(button: Dict):
|
||||||
bot: Bot,
|
|
||||||
content: Optional[str],
|
|
||||||
image: Optional[str],
|
|
||||||
node: Optional[List[Dict]],
|
|
||||||
markdown: Optional[str],
|
|
||||||
buttons: Optional[List[Dict]],
|
|
||||||
target_id: Optional[str],
|
|
||||||
target_type: Optional[str],
|
|
||||||
msg_id: Optional[str],
|
|
||||||
):
|
|
||||||
from nonebot.adapters.qq.bot import Bot as qqbot
|
|
||||||
from nonebot.adapters.qq.message import Message, MessageSegment
|
|
||||||
from nonebot.adapters.qq.models import (
|
from nonebot.adapters.qq.models import (
|
||||||
Action,
|
Action,
|
||||||
Button,
|
Button,
|
||||||
Permission,
|
Permission,
|
||||||
RenderData,
|
RenderData,
|
||||||
InlineKeyboard,
|
|
||||||
MessageKeyboard,
|
|
||||||
InlineKeyboardRow,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert isinstance(bot, qqbot)
|
return Button(
|
||||||
assert isinstance(target_id, str)
|
|
||||||
|
|
||||||
async def _send(content: Optional[str], image: Optional[str]):
|
|
||||||
message = Message()
|
|
||||||
if content:
|
|
||||||
message.append(MessageSegment.text(content))
|
|
||||||
if image:
|
|
||||||
message.append(MessageSegment.image(image))
|
|
||||||
if markdown:
|
|
||||||
message.append(MessageSegment.markdown(markdown))
|
|
||||||
if buttons:
|
|
||||||
_rows = []
|
|
||||||
_buttons = []
|
|
||||||
for button in buttons:
|
|
||||||
bt = Button(
|
|
||||||
render_data=RenderData(
|
render_data=RenderData(
|
||||||
label=button['text'],
|
label=button['text'],
|
||||||
visited_label=button['pressed_text'],
|
visited_label=button['pressed_text'],
|
||||||
@ -554,16 +537,62 @@ async def group_send(
|
|||||||
data=button['data'],
|
data=button['data'],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
_buttons.append(bt)
|
|
||||||
|
|
||||||
|
def _kb(buttons: Union[List[Dict], List[List[Dict]]]):
|
||||||
|
from nonebot.adapters.qq.models import (
|
||||||
|
InlineKeyboard,
|
||||||
|
MessageKeyboard,
|
||||||
|
InlineKeyboardRow,
|
||||||
|
)
|
||||||
|
|
||||||
|
_rows = []
|
||||||
|
_buttons = []
|
||||||
|
_buttons_rows = []
|
||||||
|
for button in buttons:
|
||||||
|
if isinstance(button, Dict):
|
||||||
|
_buttons.append(_bt(button))
|
||||||
if len(_buttons) >= 2:
|
if len(_buttons) >= 2:
|
||||||
_rows.append(InlineKeyboardRow(buttons=_buttons))
|
_rows.append(InlineKeyboardRow(buttons=_buttons))
|
||||||
_buttons = []
|
_buttons = []
|
||||||
|
else:
|
||||||
|
_buttons_rows.append([_bt(b) for b in button])
|
||||||
|
|
||||||
if _buttons:
|
if _buttons:
|
||||||
_rows.append(InlineKeyboardRow(buttons=_buttons))
|
_rows.append(InlineKeyboardRow(buttons=_buttons))
|
||||||
|
if _buttons_rows:
|
||||||
|
_rows.extend([InlineKeyboardRow(buttons=b) for b in _buttons_rows])
|
||||||
|
|
||||||
kb = MessageKeyboard(content=InlineKeyboard(rows=_rows))
|
return MessageKeyboard(content=InlineKeyboard(rows=_rows))
|
||||||
|
|
||||||
message.append(MessageSegment.keyboard(kb))
|
|
||||||
|
async def group_send(
|
||||||
|
bot: Bot,
|
||||||
|
content: Optional[str],
|
||||||
|
image: Optional[str],
|
||||||
|
node: Optional[List[Dict]],
|
||||||
|
markdown: Optional[str],
|
||||||
|
buttons: Optional[Union[List[Dict], List[List[Dict]]]],
|
||||||
|
target_id: Optional[str],
|
||||||
|
target_type: Optional[str],
|
||||||
|
msg_id: Optional[str],
|
||||||
|
):
|
||||||
|
from nonebot.adapters.qq.bot import Bot as qqbot
|
||||||
|
from nonebot.adapters.qq.message import Message, MessageSegment
|
||||||
|
|
||||||
|
assert isinstance(bot, qqbot)
|
||||||
|
assert isinstance(target_id, str)
|
||||||
|
|
||||||
|
async def _send(content: Optional[str], image: Optional[str]):
|
||||||
|
message = Message()
|
||||||
|
if content:
|
||||||
|
message.append(MessageSegment.text(content))
|
||||||
|
if image:
|
||||||
|
message.append(MessageSegment.image(image))
|
||||||
|
if markdown:
|
||||||
|
message.append(MessageSegment.markdown(markdown))
|
||||||
|
if buttons:
|
||||||
|
message.append(MessageSegment.keyboard(_kb(buttons)))
|
||||||
|
|
||||||
if target_type == 'group':
|
if target_type == 'group':
|
||||||
await bot.send_to_group(
|
await bot.send_to_group(
|
||||||
|
@ -23,7 +23,7 @@ build-backend = "poetry.core.masonry.api"
|
|||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "nonebot-plugin-genshinuid"
|
name = "nonebot-plugin-genshinuid"
|
||||||
version = "4.3.0"
|
version = "4.3.1"
|
||||||
description = "支持OneBot(QQ)、OneBotV12、QQ频道、微信、KOOK(开黑啦)、Telegram(电报)、FeiShu(飞书)的全功能NoneBot2原神插件"
|
description = "支持OneBot(QQ)、OneBotV12、QQ频道、微信、KOOK(开黑啦)、Telegram(电报)、FeiShu(飞书)的全功能NoneBot2原神插件"
|
||||||
authors = ["KimigaiiWuyi <444835641@qq.com>"]
|
authors = ["KimigaiiWuyi <444835641@qq.com>"]
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user