MCPcopy
hub / github.com/zhayujie/CowAgent / on_handle_context

Method on_handle_context

plugins/godcmd/godcmd.py:214–443  ·  view source on GitHub ↗
(self, e_context: EventContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

authenticateMethod · 0.95
is_admin_in_groupMethod · 0.95
model_mappingMethod · 0.95
ReplyClass · 0.90
BridgeClass · 0.90
confFunction · 0.90
load_configFunction · 0.90
get_help_textFunction · 0.85
PluginManagerClass · 0.85
get_bot_typeMethod · 0.80
get_botMethod · 0.80
list_pluginsMethod · 0.80

Tested by

no test coverage detected