diff --git a/code/config/config.exp.json b/code/config/config.exp.json index 5d335c7..55176a7 100644 --- a/code/config/config.exp.json +++ b/code/config/config.exp.json @@ -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" } \ No newline at end of file diff --git a/code/pkg/Admin.py b/code/pkg/Admin.py index da1ded2..3d4418f 100644 --- a/code/pkg/Admin.py +++ b/code/pkg/Admin.py @@ -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: diff --git a/code/pkg/utils/KookApi.py b/code/pkg/utils/KookApi.py index 70e292f..1a14bdb 100644 --- a/code/pkg/utils/KookApi.py +++ b/code/pkg/utils/KookApi.py @@ -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']}"} #################################机器人在玩状态#################################### diff --git a/code/pkg/utils/file/Files.py b/code/pkg/utils/file/Files.py index eafa8ab..7e3b837 100644 --- a/code/pkg/utils/file/Files.py +++ b/code/pkg/utils/file/Files.py @@ -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") # 走到这里代表所有文件都打开了 \ No newline at end of file