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'; ...@@ -15,6 +15,7 @@ import PuppeteerPlugin from 'koishi-plugin-puppeteer';
import { HttpModule } from '@nestjs/axios'; import { HttpModule } from '@nestjs/axios';
import { Feedback } from './feedback/entities/feedback.entity'; import { Feedback } from './feedback/entities/feedback.entity';
import { OnSubscribeService } from './on-subscribe/on-subscribe.service'; import { OnSubscribeService } from './on-subscribe/on-subscribe.service';
import { BotService } from './bot/bot.service';
@Module({ @Module({
imports: [ imports: [
...@@ -153,6 +154,7 @@ import { OnSubscribeService } from './on-subscribe/on-subscribe.service'; ...@@ -153,6 +154,7 @@ import { OnSubscribeService } from './on-subscribe/on-subscribe.service';
CdbLoaderService, CdbLoaderService,
FeedbackService, FeedbackService,
OnSubscribeService, OnSubscribeService,
BotService,
], ],
}) })
export class AppModule {} 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'; ...@@ -12,6 +12,7 @@ import { Random, Session } from 'koishi';
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
import { PutSession, UseCommand } from 'koishi-nestjs'; import { PutSession, UseCommand } from 'koishi-nestjs';
import { BotService } from '../bot/bot.service';
@Injectable() @Injectable()
export class FeedbackService extends CrudService(Feedback) { export class FeedbackService extends CrudService(Feedback) {
...@@ -22,6 +23,7 @@ export class FeedbackService extends CrudService(Feedback) { ...@@ -22,6 +23,7 @@ export class FeedbackService extends CrudService(Feedback) {
@InjectRepository(Feedback) repo: Repository<Feedback>, @InjectRepository(Feedback) repo: Repository<Feedback>,
private config: ConfigService, private config: ConfigService,
private http: HttpService, private http: HttpService,
private botService: BotService,
) { ) {
super(repo); super(repo);
} }
...@@ -88,6 +90,9 @@ export class FeedbackService extends CrudService(Feedback) { ...@@ -88,6 +90,9 @@ export class FeedbackService extends CrudService(Feedback) {
let choice = 0; let choice = 0;
while (true) { while (true) {
const input = await session.prompt(); const input = await session.prompt();
if (this.botService.isBuiltinCommand(input)) {
return session.execute(input);
}
choice = parseInt(input.trim()); choice = parseInt(input.trim());
if (choice >= 1 && choice <= 4) { if (choice >= 1 && choice <= 4) {
break; break;
...@@ -104,6 +109,9 @@ export class FeedbackService extends CrudService(Feedback) { ...@@ -104,6 +109,9 @@ export class FeedbackService extends CrudService(Feedback) {
const category = ['游戏功能/改善', '游戏体验问题', '其他'][choice - 2]; const category = ['游戏功能/改善', '游戏体验问题', '其他'][choice - 2];
await session.send('您启动了反馈系统!您的下一段文字会作为反馈发给我们!'); await session.send('您启动了反馈系统!您的下一段文字会作为反馈发给我们!');
const content = await session.prompt(); const content = await session.prompt();
if (this.botService.isBuiltinCommand(content)) {
return session.execute(content);
}
const count = await this.createFeedback(session, { category, content }); const count = await this.createFeedback(session, { category, content });
return `反馈成功!谢谢您的意见! return `反馈成功!谢谢您的意见!
这是我们在决斗暗网服务号收到的第 ${count} 个反馈!`; 这是我们在决斗暗网服务号收到的第 ${count} 个反馈!`;
...@@ -118,6 +126,9 @@ export class FeedbackService extends CrudService(Feedback) { ...@@ -118,6 +126,9 @@ export class FeedbackService extends CrudService(Feedback) {
'为此,希望您可以尽可能清晰表达您的意见,以便我们更好理解您的需求。', '为此,希望您可以尽可能清晰表达您的意见,以便我们更好理解您的需求。',
); );
const content = await session.prompt(); const content = await session.prompt();
if (this.botService.isBuiltinCommand(content)) {
return session.execute(content);
}
const count = await this.createFeedback(session, { const count = await this.createFeedback(session, {
category: '周边', category: '周边',
content, 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