Skip to content

Commit

Permalink
fix: 修复myid指令在gocq平台上不可用的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Jan 9, 2024
1 parent 247015c commit 1ba6030
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cores/qqbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,16 @@ def run_qqchan_bot(cfg: dict, global_object: GlobalObject):
def run_gocq_bot(cfg: dict, _global_object: GlobalObject):
from model.platform.qq_gocq import QQGOCQ

gu.log("正在检查本地GO-CQHTTP连接...端口5700, 6700", tag="QQ")
gu.log("正在检查与 go-cqhttp 的连接...端口5700, 6700", tag="QQ")
noticed = False
while True:
if not gu.port_checker(5700, cc.get("gocq_host", "127.0.0.1")) or not gu.port_checker(6700, cc.get("gocq_host", "127.0.0.1")):
if not noticed:
noticed = True
gu.log("与GO-CQHTTP通信失败, 请检查GO-CQHTTP是否启动并正确配置。程序会每隔 5s 自动重试。", gu.LEVEL_CRITICAL, tag="QQ")
gu.log("与 go-cqhttp 通信失败, 请检查 go-cqhttp 是否启动并正确配置。程序会每隔 5s 自动重试。", gu.LEVEL_CRITICAL, tag="QQ")
time.sleep(5)
else:
gu.log("检查完毕,未发现问题。", tag="QQ")
gu.log("成功连接到 go-cqhttp。", tag="QQ")
break
try:
qq_gocq = QQGOCQ(cfg=cfg, message_handler=oper_msg)
Expand Down
12 changes: 9 additions & 3 deletions model/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def check_command(self,
if self.command_start_with(message, "plugin"):
return True, self.plugin_oper(message, role, cached_plugins, platform)
if self.command_start_with(message, "myid") or self.command_start_with(message, "!myid"):
return True, self.get_my_id(message_obj)
return True, self.get_my_id(message_obj, platform)
if self.command_start_with(message, "nconf") or self.command_start_with(message, "newconf"):
return True, self.get_new_conf(message, role)
if self.command_start_with(message, "web"): # 网页搜索
Expand All @@ -105,8 +105,14 @@ def web_search(self, message):
return True, "已关闭网页搜索", "web"
return True, f"网页搜索功能当前状态: {self.global_object.web_search}", "web"

def get_my_id(self, message_obj):
return True, f"你的ID:{str(message_obj.sender.tiny_id)}", "plugin"
def get_my_id(self, message_obj, platform):
user_id = "Unknown"
if platform == PLATFORM_QQCHAN:
user_id = str(message_obj.sender.tiny_id)
elif platform == PLATFORM_GOCQ:
user_id = str(message_obj.user_id)

return True, f"你的ID:{user_id}", "plugin"

def get_new_conf(self, message, role):
if role != "admin":
Expand Down

0 comments on commit 1ba6030

Please sign in to comment.