MCPcopy Create free account
hub / github.com/Loping151/RoverSign / get_current_plugin

Function get_current_plugin

RoverSign/utils/plugin_checker.py:18–63  ·  view source on GitHub ↗

获取当前执行的插件名称 Returns: Optional[str]: 插件名称,如果不在插件中则返回 None

()

Source from the content-addressed store, hash-verified

16
17
18def get_current_plugin() -> Optional[str]:
19 """获取当前执行的插件名称
20 Returns:
21 Optional[str]: 插件名称,如果不在插件中则返回 None
22 """
23 frame = inspect.currentframe()
24
25 # 需要跳过的工具文件
26 skip_files = ["plugin_checker.py", "bot_send_hook.py"]
27 all_plugins = [] # 记录所有遇到的插件
28
29 try:
30 frame = frame.f_back
31
32 while frame:
33 frame_info = inspect.getframeinfo(frame)
34 file_path = frame_info.filename
35
36 # 检查是否在 plugins 目录中
37 if "/plugins/" in file_path:
38 parts = file_path.split("/plugins/")
39 if len(parts) >= 2:
40 plugin_path = parts[1]
41 plugin_name = plugin_path.split("/")[0]
42 # 只记录非工具文件的插件
43 if not any(skip_file in file_path for skip_file in skip_files):
44 all_plugins.append(plugin_name)
45 elif "\\plugins\\" in file_path:
46 parts = file_path.split("\\plugins\\")
47 if len(parts) >= 2:
48 plugin_path = parts[1]
49 plugin_name = plugin_path.split("\\")[0]
50 if not any(skip_file in file_path for skip_file in skip_files):
51 all_plugins.append(plugin_name)
52
53 frame = frame.f_back
54
55 if all_plugins:
56 result = all_plugins[-1] # 最后一个就是离 hook 调用最近的
57 logger.debug(f"[库洛签到·插件检查] 找到的插件列表: {all_plugins}, 返回: {result}")
58 return result
59 finally:
60 del frame
61
62 logger.debug(f"[库洛签到·插件检查] 未找到插件来源")
63 return None
64
65
66def is_from_rover_plugin() -> bool:

Callers 1

is_from_pluginFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected