mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-12 06:55:58 +08:00
✨ 支持nonebot-adapter-qq
This commit is contained in:
parent
a74634f4d2
commit
332e2eeea8
@ -131,12 +131,13 @@ async def get_all_message(bot: Bot, ev: Event):
|
||||
msg_id = ''
|
||||
|
||||
# qqguild
|
||||
if bot.adapter.get_name() == 'QQ Guild':
|
||||
from nonebot.adapters.qqguild.event import (
|
||||
MessageEvent,
|
||||
C2CMessageCreate,
|
||||
GroupAtMessageCreate,
|
||||
if bot.adapter.get_name() == 'QQ':
|
||||
sp_bot_id = 'qqguild'
|
||||
from nonebot.adapters.qq.event import (
|
||||
GuildMessageEvent,
|
||||
C2CMessageCreateEvent,
|
||||
DirectMessageCreateEvent,
|
||||
GroupAtMessageCreateEvent,
|
||||
)
|
||||
|
||||
# 私聊
|
||||
@ -144,18 +145,18 @@ async def get_all_message(bot: Bot, ev: Event):
|
||||
user_type = 'direct'
|
||||
group_id = str(ev.guild_id)
|
||||
msg_id = ev.id
|
||||
elif isinstance(ev, GroupAtMessageCreate):
|
||||
elif isinstance(ev, GroupAtMessageCreateEvent):
|
||||
sp_bot_id = 'qqgroup'
|
||||
user_type = 'group'
|
||||
group_id = str(ev.group_id)
|
||||
msg_id = ev.id
|
||||
elif isinstance(ev, C2CMessageCreate):
|
||||
elif isinstance(ev, C2CMessageCreateEvent):
|
||||
sp_bot_id = 'qqgroup'
|
||||
user_type = 'direct'
|
||||
group_id = None
|
||||
msg_id = ev.id
|
||||
# 群聊
|
||||
elif isinstance(ev, MessageEvent):
|
||||
elif isinstance(ev, GuildMessageEvent):
|
||||
user_type = 'group'
|
||||
group_id = str(ev.channel_id)
|
||||
if ev.member and ev.member.roles:
|
||||
@ -170,8 +171,11 @@ async def get_all_message(bot: Bot, ev: Event):
|
||||
logger.debug('[gsuid] 不支持该 QQ Guild 事件...')
|
||||
return
|
||||
|
||||
if ev.message_reference:
|
||||
reply_msg_id = ev.message_reference.message_id
|
||||
if (
|
||||
hasattr(ev, 'message_reference')
|
||||
and ev.message_reference # type: ignore
|
||||
):
|
||||
reply_msg_id = ev.message_reference.message_id # type: ignore
|
||||
message.append(Message('reply', reply_msg_id))
|
||||
# telegram
|
||||
elif bot.adapter.get_name() == 'Telegram':
|
||||
|
@ -124,6 +124,9 @@ class GsClient:
|
||||
file = ''
|
||||
at_list = []
|
||||
group_id = ''
|
||||
markdown = ''
|
||||
buttons = []
|
||||
|
||||
if msg.content:
|
||||
for _c in msg.content:
|
||||
if _c.data:
|
||||
@ -139,6 +142,10 @@ class GsClient:
|
||||
at_list.append(_c.data)
|
||||
elif _c.type == 'group':
|
||||
group_id = _c.data
|
||||
elif _c.type == 'markdown':
|
||||
markdown = _c.data
|
||||
elif _c.type == 'buttons':
|
||||
buttons = _c.data
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -231,7 +238,8 @@ class GsClient:
|
||||
content,
|
||||
image,
|
||||
node,
|
||||
at_list,
|
||||
markdown,
|
||||
buttons,
|
||||
msg.target_id,
|
||||
msg.target_type,
|
||||
msg.msg_id,
|
||||
@ -496,30 +504,80 @@ async def group_send(
|
||||
content: Optional[str],
|
||||
image: Optional[str],
|
||||
node: Optional[List[Dict]],
|
||||
at_list: Optional[List[str]],
|
||||
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 (
|
||||
Action,
|
||||
Button,
|
||||
Permission,
|
||||
RenderData,
|
||||
InlineKeyboard,
|
||||
MessageKeyboard,
|
||||
InlineKeyboardRow,
|
||||
)
|
||||
|
||||
assert isinstance(bot, qqbot)
|
||||
assert isinstance(target_id, str)
|
||||
|
||||
async def _send(content: Optional[str], image: Optional[str]):
|
||||
result: Dict[str, Any] = {}
|
||||
message = Message()
|
||||
if content:
|
||||
result['content'] = content
|
||||
message.append(MessageSegment.text(content))
|
||||
if image:
|
||||
result['image'] = 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(
|
||||
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'],
|
||||
),
|
||||
)
|
||||
_buttons.append(bt)
|
||||
if len(_buttons) >= 2:
|
||||
_rows.append(InlineKeyboardRow(buttons=_buttons))
|
||||
_buttons = []
|
||||
if _buttons:
|
||||
_rows.append(InlineKeyboardRow(buttons=_buttons))
|
||||
|
||||
kb = MessageKeyboard(content=InlineKeyboard(rows=_rows))
|
||||
|
||||
message.append(MessageSegment.keyboard(kb))
|
||||
|
||||
if target_type == 'group':
|
||||
await bot.post_group_message(
|
||||
await bot.send_to_group(
|
||||
group_id=target_id,
|
||||
msg_id=msg_id,
|
||||
event_id=msg_id,
|
||||
**result,
|
||||
message=message,
|
||||
)
|
||||
else:
|
||||
await bot.post_c2c_message(
|
||||
await bot.send_to_c2c(
|
||||
user_id=target_id,
|
||||
msg_id=msg_id,
|
||||
event_id=msg_id,
|
||||
**result,
|
||||
message=message,
|
||||
)
|
||||
|
||||
if node:
|
||||
|
@ -23,7 +23,7 @@ build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry]
|
||||
name = "nonebot-plugin-genshinuid"
|
||||
version = "4.2.0"
|
||||
version = "4.3.0"
|
||||
description = "支持OneBot(QQ)、OneBotV12、QQ频道、微信、KOOK(开黑啦)、Telegram(电报)、FeiShu(飞书)的全功能NoneBot2原神插件"
|
||||
authors = ["KimigaiiWuyi <444835641@qq.com>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
|
Loading…
x
Reference in New Issue
Block a user