Skip to content

Commit

Permalink
feat(config): add options for webhook connection
Browse files Browse the repository at this point in the history
  • Loading branch information
musnows committed May 6, 2023
1 parent eb0b76e commit 2e739c6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
35 changes: 21 additions & 14 deletions code/config/config.exp.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
{
"token":{
"bot": "机器人websocket token",
"token": {
"bot": {
"token": "bot webhook/websocket token",
"verify_token": "webhook verify token",
"encrypt": "webhook encrypt token",
"webhook_port": 50000,
"ws": true,
"info":"如果要使用webhook,将ws字段修改为false"
},
"api_bot_token": "api用来上传图片的机器人websocket token",
"img_upload_token": "用来进行vip商店图片测试的机器人websocket token(发图片让kook的内容识别来判断有么有问题)"
},
"master_id": "机器人开发者userid",
"caiyun": "彩云小译的token,可为空,但不能删除本键值",
"channel":{
"channel": {
"debug_ch": "发送错误日志的频道",
"img_upload_ch": "用来测试vip商店图片的频道"
},
"lsky":{
"url":"lsky图床的url(该功能未启用)",
"token":"lsky图床的token(该功能未启用)"
"lsky": {
"url": "lsky图床的url(该功能未启用,可留空",
"token": "lsky图床的token(该功能未启用,可留空"
},
"leancloud":{
"appid":"leancloud数据库的appid(可联系作者,共用皮肤评价数据库)",
"appkey":"leancloud数据库的appkey",
"master_key":"leancloud数据库的masterkey(可为空,目前没有使用)",
"user_name":"数据库内置用户id",
"user_pwd":"数据库内置用户密码"
"leancloud": {
"appid": "leancloud数据库的appid(可联系作者,共用皮肤评价数据库)",
"appkey": "leancloud数据库的appkey",
"master_key": "leancloud数据库的masterkey(可为空,目前没有使用)",
"user_name": "数据库内置用户id",
"user_pwd": "数据库内置用户密码"
},
"no":1000,
"platform":"kook"
"no": 1000,
"platform": "kook"
}
5 changes: 4 additions & 1 deletion code/pkg/Admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ async def kill_bot_cmd(msg: Message, at_text = '', *arg):
cm = CardMessage(Card(Module.Section(
Element.Text(f"[KILL] 保存全局变量成功,bot下线\n当前时间:{Gtime.get_time()}", Types.Text.KMD))))
await msg.reply(cm)
res = await KookApi.bot_offline() # 调用接口下线bot
res = "webhook"
if config['token']['bot']['ws']: # 用的是ws才需要调用
res = await KookApi.bot_offline() # 调用接口下线bot
# 打印日志
_log.info(f"KILL | bot-off: {res}\n")
os._exit(0) # 退出程序
else:
Expand Down
2 changes: 1 addition & 1 deletion code/pkg/utils/KookApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .file.Files import config,bot,_log
# kook的base_url和headers
kook_base_url = "https://www.kookapp.cn"
kook_headers = {f'Authorization': f"Bot {config['token']['bot']}"}
kook_headers = {f'Authorization': f"Bot {config['token']['bot']['token']}"}


#################################机器人在玩状态####################################
Expand Down
11 changes: 9 additions & 2 deletions code/pkg/utils/file/Files.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,16 @@
"""

# 实例化一个khl的bot,方便其他模组调用
from khl import Bot
bot = Bot(token=config['token']['bot'])
from khl import Bot,Cert
bot = Bot(token=config['token']['bot']['token']) # websocket
"""main bot"""
if not config['token']['bot']['ws']: # webhook
_log.info(f"[BOT] using webhook at port {config['token']['bot']['webhook_port']}")
bot = Bot(cert=Cert(token=config['token']['bot']['token'],
verify_token=config['token']['bot']['verify_token'],
encrypt_key=config['token']['bot']['encrypt']),
port=config['token']['bot']['webhook_port'])
# 上传图片测试的机器人
bot_upd_img = Bot(token=config['token']['img_upload_token'])
"""用来上传图片的bot"""
_log.info(f"Loading all files") # 走到这里代表所有文件都打开了

0 comments on commit 2e739c6

Please sign in to comment.