支持nonebot.adapter.villa的回调按钮支持

This commit is contained in:
KimigaiiWuyi 2023-12-02 06:02:58 +08:00
parent 37ce5e3b0c
commit d0a1dce142
2 changed files with 92 additions and 63 deletions

View File

@ -130,6 +130,18 @@ async def get_notice_message(bot: Bot, ev: Event):
) )
else: else:
return return
elif bot.adapter.get_name() == 'Villa':
from nonebot.adapters.villa.event import ClickMsgComponentEvent
if isinstance(ev, ClickMsgComponentEvent):
user_id = str(ev.uid)
group_id = f'{ev.villa_id}-{ev.room_id}'
msg_id = ev.msg_uid
bot_id = 'villa'
message = [Message('text', ev.extra)]
user_type = 'group'
else:
return
else: else:
return return

View File

@ -342,14 +342,85 @@ def del_file(path: Path):
os.remove(path) os.remove(path)
def _villa_kb(index: int, button: Dict): def _bt(button: Dict):
from nonebot.adapters.villa.models import InputButton from nonebot.adapters.qq.models import (
Action,
Button,
Permission,
RenderData,
)
action = button['action']
if action == -1:
action = 2
return Button(
render_data=RenderData(
label=button['text'],
visited_label=button['pressed_text'],
style=button['style'],
),
action=Action(
type=button['action'],
permission=Permission(
type=button['permisson'],
specify_role_ids=button['specify_role_ids'],
specify_user_ids=button['specify_user_ids'],
),
unsupport_tips=button['unsupport_tips'],
data=button['data'],
),
)
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:
_rows.append(InlineKeyboardRow(buttons=_buttons))
_buttons = []
else:
_buttons_rows.append([_bt(b) for b in button])
if _buttons:
_rows.append(InlineKeyboardRow(buttons=_buttons))
if _buttons_rows:
_rows.extend([InlineKeyboardRow(buttons=b) for b in _buttons_rows])
return MessageKeyboard(content=InlineKeyboard(rows=_rows))
def _villa_kb(index: int, button: Dict):
from nonebot.adapters.villa.models import InputButton, CallbackButton
if button['action'] == 1:
return CallbackButton(
id=str(index),
text=button['text'],
extra=button['data'],
)
elif button['action'] == 2:
return InputButton( return InputButton(
id=str(index), id=str(index),
text=button['text'], text=button['text'],
input=button['data'], input=button['data'],
) )
else:
return CallbackButton(
id=str(index),
text=button['text'],
extra=button['data'],
)
def _dodo_kb(button: Dict): def _dodo_kb(button: Dict):
@ -362,11 +433,12 @@ def _dodo_kb(button: Dict):
def _kaiheila_kb(button: Dict): def _kaiheila_kb(button: Dict):
action = "return-val"
return { return {
"type": "button", "type": "button",
"theme": "info", "theme": "info",
"value": button['data'], "value": button['data'],
"click": "return-val", "click": action,
"text": {"type": "plain-text", "content": button['text']}, "text": {"type": "plain-text", "content": button['text']},
} }
@ -884,60 +956,6 @@ async def dodo_send(
await _send(content, image) await _send(content, image)
def _bt(button: Dict):
from nonebot.adapters.qq.models import (
Action,
Button,
Permission,
RenderData,
)
return Button(
render_data=RenderData(
label=button['text'],
visited_label=button['pressed_text'],
style=button['style'],
),
action=Action(
type=button['action'],
permission=Permission(
type=button['permisson'],
specify_role_ids=button['specify_role_ids'],
specify_user_ids=button['specify_user_ids'],
),
unsupport_tips=button['unsupport_tips'],
data=button['data'],
),
)
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:
_rows.append(InlineKeyboardRow(buttons=_buttons))
_buttons = []
else:
_buttons_rows.append([_bt(b) for b in button])
if _buttons:
_rows.append(InlineKeyboardRow(buttons=_buttons))
if _buttons_rows:
_rows.extend([InlineKeyboardRow(buttons=b) for b in _buttons_rows])
return MessageKeyboard(content=InlineKeyboard(rows=_rows))
async def group_send( async def group_send(
bot: Bot, bot: Bot,
content: Optional[str], content: Optional[str],
@ -1148,7 +1166,6 @@ async def kaiheila_send(
} }
] ]
message.append(MessageSegment.Card(cards)) message.append(MessageSegment.Card(cards))
print(message)
if target_type == 'group': if target_type == 'group':
await bot.send_channel_msg(channel_id=target_id, message=message) await bot.send_channel_msg(channel_id=target_id, message=message)
else: else: