(self, e_context: EventContext)
| 212 | logger.debug("[Godcmd] inited") |
| 213 | |
| 214 | def on_handle_context(self, e_context: EventContext): |
| 215 | context_type = e_context["context"].type |
| 216 | if context_type != ContextType.TEXT: |
| 217 | if not self.isrunning: |
| 218 | e_context.action = EventAction.BREAK_PASS |
| 219 | return |
| 220 | |
| 221 | content = e_context["context"].content |
| 222 | logger.debug("[Godcmd] on_handle_context. content: %s" % content) |
| 223 | if content.startswith("#"): |
| 224 | if len(content) == 1: |
| 225 | reply = Reply() |
| 226 | reply.type = ReplyType.ERROR |
| 227 | reply.content = f"空指令,输入#help查看指令列表\n" |
| 228 | e_context["reply"] = reply |
| 229 | e_context.action = EventAction.BREAK_PASS |
| 230 | return |
| 231 | # msg = e_context['context']['msg'] |
| 232 | channel = e_context["channel"] |
| 233 | user = e_context["context"]["receiver"] |
| 234 | session_id = e_context["context"]["session_id"] |
| 235 | isgroup = e_context["context"].get("isgroup", False) |
| 236 | bottype = Bridge().get_bot_type("chat") |
| 237 | bot = Bridge().get_bot("chat") |
| 238 | # 将命令和参数分割 |
| 239 | command_parts = content[1:].strip().split() |
| 240 | cmd = command_parts[0] |
| 241 | args = command_parts[1:] |
| 242 | isadmin = False |
| 243 | if user in self.admin_users: |
| 244 | isadmin = True |
| 245 | ok = False |
| 246 | result = "string" |
| 247 | if any(cmd in info["alias"] for info in COMMANDS.values()): |
| 248 | cmd = next(c for c, info in COMMANDS.items() if cmd in info["alias"]) |
| 249 | if cmd == "auth": |
| 250 | ok, result = self.authenticate(user, args, isadmin, isgroup) |
| 251 | elif cmd == "help" or cmd == "helpp": |
| 252 | if len(args) == 0: |
| 253 | ok, result = True, get_help_text(isadmin, isgroup) |
| 254 | else: |
| 255 | # This can replace the helpp command |
| 256 | plugins = PluginManager().list_plugins() |
| 257 | query_name = args[0].upper() |
| 258 | # search name and namecn |
| 259 | for name, plugincls in plugins.items(): |
| 260 | if not plugincls.enabled: |
| 261 | continue |
| 262 | if query_name == name or query_name == plugincls.namecn: |
| 263 | ok, result = True, PluginManager().instances[name].get_help_text(isgroup=isgroup, isadmin=isadmin, verbose=True) |
| 264 | break |
| 265 | if not ok: |
| 266 | result = "插件不存在或未启用" |
| 267 | elif cmd == "model": |
| 268 | if not isadmin and not self.is_admin_in_group(e_context["context"]): |
| 269 | ok, result = False, "需要管理员权限执行" |
| 270 | elif len(args) == 0: |
| 271 | model = conf().get("model") or const.GPT35 |
nothing calls this directly
no test coverage detected