mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 04:46:42 +02:00
♻️ refactor: migrate 5 bots to KeywordCommandDetector
Migrated to KeywordCommandDetector from @manacore/matrix-bot-common: - matrix-calendar-bot (termine, kalender keywords) - matrix-clock-bot (timer, zeit keywords) - matrix-picture-bot (modelle, verlauf keywords) - matrix-todo-bot (aufgaben, projekte keywords) - matrix-zitare-bot (zitat, kategorien keywords) Removed duplicate KEYWORD_COMMANDS arrays and detectKeywordCommand() methods from all 5 bots. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
462ef006f0
commit
867a1a7fb6
9 changed files with 291 additions and 168 deletions
|
|
@ -1,24 +1,30 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { BaseMatrixService, MatrixBotConfig, MatrixRoomEvent } from '@manacore/matrix-bot-common';
|
||||
import {
|
||||
BaseMatrixService,
|
||||
MatrixBotConfig,
|
||||
MatrixRoomEvent,
|
||||
KeywordCommandDetector,
|
||||
COMMON_KEYWORDS,
|
||||
} from '@manacore/matrix-bot-common';
|
||||
import { ClockService } from '../clock/clock.service';
|
||||
import { TranscriptionService } from '@manacore/bot-services';
|
||||
import { HELP_TEXT, WELCOME_TEXT } from '../config/configuration';
|
||||
|
||||
// Natural language keywords
|
||||
const KEYWORD_COMMANDS: { keywords: string[]; command: string }[] = [
|
||||
{ keywords: ['hilfe', 'help', 'befehle', 'commands'], command: 'help' },
|
||||
{ keywords: ['status', 'timer status', 'laufend'], command: 'status' },
|
||||
{ keywords: ['stop', 'stopp', 'pause', 'anhalten'], command: 'stop' },
|
||||
{ keywords: ['weiter', 'resume', 'fortsetzen'], command: 'resume' },
|
||||
{ keywords: ['zeit', 'time', 'uhrzeit', 'wie spat'], command: 'time' },
|
||||
];
|
||||
|
||||
@Injectable()
|
||||
export class MatrixService extends BaseMatrixService {
|
||||
// Demo token for development (TODO: implement proper auth)
|
||||
private readonly demoToken = process.env.CLOCK_API_TOKEN || '';
|
||||
|
||||
// Note: We override COMMON_KEYWORDS' cancel->cancel with stop->stop for this bot
|
||||
private readonly keywordDetector = new KeywordCommandDetector([
|
||||
{ keywords: ['hilfe', 'help', 'befehle', 'commands'], command: 'help' },
|
||||
{ keywords: ['status', 'timer status', 'laufend'], command: 'status' },
|
||||
{ keywords: ['stop', 'stopp', 'pause', 'anhalten'], command: 'stop' },
|
||||
{ keywords: ['weiter', 'resume', 'fortsetzen'], command: 'resume' },
|
||||
{ keywords: ['zeit', 'time', 'uhrzeit', 'wie spat'], command: 'time' },
|
||||
]);
|
||||
|
||||
constructor(
|
||||
configService: ConfigService,
|
||||
private clockService: ClockService,
|
||||
|
|
@ -47,7 +53,7 @@ export class MatrixService extends BaseMatrixService {
|
|||
sender: string
|
||||
): Promise<void> {
|
||||
// Check keywords first
|
||||
const keywordCommand = this.detectKeywordCommand(message);
|
||||
const keywordCommand = this.keywordDetector.detect(message);
|
||||
if (keywordCommand) {
|
||||
await this.executeCommand(roomId, event, sender, keywordCommand, '');
|
||||
return;
|
||||
|
|
@ -137,20 +143,6 @@ export class MatrixService extends BaseMatrixService {
|
|||
}
|
||||
}
|
||||
|
||||
private detectKeywordCommand(message: string): string | null {
|
||||
const lowerMessage = message.toLowerCase().trim();
|
||||
if (lowerMessage.length > 50) return null;
|
||||
|
||||
for (const { keywords, command } of KEYWORD_COMMANDS) {
|
||||
for (const keyword of keywords) {
|
||||
if (lowerMessage === keyword || lowerMessage.startsWith(keyword + ' ')) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async executeCommand(
|
||||
roomId: string,
|
||||
event: MatrixRoomEvent,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue