MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / QuestionFeature

Class QuestionFeature

ai/ai.ts:4362–4539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4360
4361class QuestionFeature extends BaseFeatureHandler {
4362 readonly name = "AI 提问";
4363 readonly command = "";
4364 readonly description = "向 AI 提问";
4365
4366 private aiService: AIService;
4367 private messageUtils: MessageUtils;
4368 private activeToken?: AbortToken;
4369
4370 constructor(
4371 aiService: AIService,
4372 configManagerPromise: Promise<ConfigManager>,
4373 httpClient: HttpClient,
4374 ) {
4375 super(configManagerPromise);
4376 this.aiService = aiService;
4377 this.messageUtils = new MessageUtils(configManagerPromise, httpClient);
4378 }
4379
4380 cancelCurrentOperation(): void {
4381 if (this.activeToken && !this.activeToken.aborted)
4382 this.activeToken.abort("操作被取消");
4383 this.activeToken = undefined;
4384 }
4385
4386 private async runQuestion(
4387 msg: Api.Message,
4388 question: string,
4389 trigger?: Api.Message,
4390 ): Promise<void> {
4391 this.cancelCurrentOperation();
4392
4393 const token = this.aiService.createAbortToken();
4394 this.activeToken = token;
4395
4396 try {
4397 await this.handleQuestion(msg, question, trigger, token);
4398 } finally {
4399 this.activeToken = undefined;
4400 this.aiService.releaseToken(token);
4401 }
4402 }
4403
4404 async execute(
4405 msg: Api.Message,
4406 args: string[],
4407 _prefixes: string[],
4408 ): Promise<void> {
4409 const question = args.join(" ").trim();
4410 await this.runQuestion(msg, question);
4411 }
4412
4413 async askFromReply(msg: Api.Message, trigger?: Api.Message): Promise<void> {
4414 const replyMsg = await safeGetReplyMessage(msg);
4415 requireUser(!!replyMsg, "至少需要一条提示");
4416 const question = getMessageText(replyMsg).trim();
4417 await this.runQuestion(msg, question, trigger);
4418 }
4419

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected