Commit f2ae1693 authored by nanahira's avatar nanahira

fix accident command click

parent cc711e8a
Pipeline #19432 canceled with stages
in 7 minutes and 59 seconds
......@@ -15,6 +15,7 @@ import PuppeteerPlugin from 'koishi-plugin-puppeteer';
import { HttpModule } from '@nestjs/axios';
import { Feedback } from './feedback/entities/feedback.entity';
import { OnSubscribeService } from './on-subscribe/on-subscribe.service';
import { BotService } from './bot/bot.service';
@Module({
imports: [
......@@ -153,6 +154,7 @@ import { OnSubscribeService } from './on-subscribe/on-subscribe.service';
CdbLoaderService,
FeedbackService,
OnSubscribeService,
BotService,
],
})
export class AppModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { BotService } from './bot.service';
describe('BotService', () => {
let service: BotService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [BotService],
}).compile();
service = module.get<BotService>(BotService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { WireContextService } from 'koishi-nestjs';
import WechatBot from 'koishi-plugin-adapter-wechat-official';
@Injectable()
export class BotService implements OnApplicationBootstrap {
@WireContextService()
private bots: WechatBot[];
getBot() {
return this.bots[0];
}
private builtinCommands = new Set<string>();
onApplicationBootstrap() {
this.getBot()
.config.menus.flatMap((menu) =>
menu.children.map((child) => child.command),
)
.filter((command) => command)
.forEach((command) => this.builtinCommands.add(command));
}
isBuiltinCommand(command: string) {
return this.builtinCommands.has(command);
}
}
......@@ -12,6 +12,7 @@ import { Random, Session } from 'koishi';
import { HttpService } from '@nestjs/axios';
import { lastValueFrom } from 'rxjs';
import { PutSession, UseCommand } from 'koishi-nestjs';
import { BotService } from '../bot/bot.service';
@Injectable()
export class FeedbackService extends CrudService(Feedback) {
......@@ -22,6 +23,7 @@ export class FeedbackService extends CrudService(Feedback) {
@InjectRepository(Feedback) repo: Repository<Feedback>,
private config: ConfigService,
private http: HttpService,
private botService: BotService,
) {
super(repo);
}
......@@ -88,6 +90,9 @@ export class FeedbackService extends CrudService(Feedback) {
let choice = 0;
while (true) {
const input = await session.prompt();
if (this.botService.isBuiltinCommand(input)) {
return session.execute(input);
}
choice = parseInt(input.trim());
if (choice >= 1 && choice <= 4) {
break;
......@@ -104,6 +109,9 @@ export class FeedbackService extends CrudService(Feedback) {
const category = ['游戏功能/改善', '游戏体验问题', '其他'][choice - 2];
await session.send('您启动了反馈系统!您的下一段文字会作为反馈发给我们!');
const content = await session.prompt();
if (this.botService.isBuiltinCommand(content)) {
return session.execute(content);
}
const count = await this.createFeedback(session, { category, content });
return `反馈成功!谢谢您的意见!
这是我们在决斗暗网服务号收到的第 ${count} 个反馈!`;
......@@ -118,6 +126,9 @@ export class FeedbackService extends CrudService(Feedback) {
'为此,希望您可以尽可能清晰表达您的意见,以便我们更好理解您的需求。',
);
const content = await session.prompt();
if (this.botService.isBuiltinCommand(content)) {
return session.execute(content);
}
const count = await this.createFeedback(session, {
category: '周边',
content,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment