Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 适配QQ 官方 频道 API #602

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions config-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# 目前支持以下适配器:
# - "yirimirai": mirai的通信框架,YiriMirai框架适配器, 请同时填写下方mirai_http_api_config
# - "nakuru": go-cqhttp通信框架,请同时填写下方nakuru_config
# - "qq-botpy": QQ官方机器人框架,请同时填写下方qq_botpy_config
msg_source_adapter = "yirimirai"

# [必需(与nakuru二选一,取决于msg_source_adapter)] Mirai的配置
# [必需(与nakuru、qq-botpy三选一,取决于msg_source_adapter)] Mirai的配置
# 请到配置mirai的步骤中的教程查看每个字段的信息
# adapter: 选择适配器,目前支持HTTPAdapter和WebSocketAdapter
# host: 运行mirai的主机地址
Expand All @@ -24,7 +25,7 @@
"qq": 1234567890
}

# [必需(与mirai二选一,取决于msg_source_adapter)]
# [必需(与mirai、qq-botpy三选一,取决于msg_source_adapter)]
# 使用nakuru-project框架连接go-cqhttp的配置
nakuru_config = {
"host": "localhost", # go-cqhttp的地址
Expand All @@ -33,6 +34,13 @@
"token": "" # 若在go-cqhttp的config.yml设置了access_token, 则填写此处
}

# [必需(与mirai、nakuru三选一,取决于msg_source_adapter)]
# 使用qq-botpy框架连接QQ官方机器人的配置
qq_botpy_config = {
"appid": "1234567890", # QQ机器人的appid
"token": "jwnxxxxxxxxxx", # QQ机器人的token
}

# [必需] OpenAI的配置
# api_key: OpenAI的API Key
# http_proxy: 请求OpenAI时使用的代理,None为不使用,https和socks5暂不能使用
Expand Down
4 changes: 4 additions & 0 deletions override-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"http_port": 5700,
"token": ""
},
"qq_botpy_config": {
"appid": "1234567890",
"token": "jwnxxxxxxxxxx"
},
"openai_config": {
"api_key": {
"default": "openai_api_key"
Expand Down
8 changes: 8 additions & 0 deletions pkg/qqbot/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def __init__(self, first_time_init=True):
from pkg.qqbot.sources.nakuru import NakuruProjectAdapter
self.adapter = NakuruProjectAdapter(config.nakuru_config)
self.bot_account_id = self.adapter.bot_account_id
elif config.msg_source_adapter == 'qq-botpy':
# 创建eventloop
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
from pkg.qqbot.sources.official import OfficialAdapter
self.adapter = OfficialAdapter(config.qq_botpy_config)
self.bot_account_id = self.adapter.bot_account_id
else:
self.adapter = context.get_qqbot_manager().adapter
self.bot_account_id = context.get_qqbot_manager().bot_account_id
Expand Down
4 changes: 2 additions & 2 deletions pkg/qqbot/sources/nakuru.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def yiri2target(event: typing.Type[mirai.Event]):
elif event is mirai.FriendMessage:
return nakuru.FriendMessage
else:
raise Exception("未支持转换的事件类型: " + str(event))
raise Exception("未支持转换的事件类型(YiriMirai -> Nakuru): " + str(event))

@staticmethod
def target2yiri(event: typing.Any) -> mirai.Event:
Expand Down Expand Up @@ -153,7 +153,7 @@ def target2yiri(event: typing.Any) -> mirai.Event:
time=event.time
)
else:
raise Exception("未支持转换的事件类型: " + str(event))
raise Exception("未支持转换的事件类型(Nakuru -> YiriMirai): " + str(event))


class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
Expand Down
Loading