Add room-scoped Matrix plugins and bilingual configuration commands

This commit is contained in:
Matrix Bot Project committed 2026-11-20 23:29:33 +08:00
1 parent 061bfbd12a
commit f4f30c3b5c
75 files changed
+2559 -1975

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import { Command, CommandRouter } from './command-router';
import { message } from '../../test/fakes';
const command: Command = { id: 'checkin', paths: [['checkin'], ['签到']], bare: ['签到'],
description: { 'zh-CN': '签到', en: 'check in' }, usage: { 'zh-CN': '!签到', en: '!checkin' }, run: async () => undefined };
describe('shared command aliases', () => {
it.each(['签到', '!签到', '!签到', '/签到', '/checkin', '!CHECKIN', '!checkin'])('%s resolves to the same command', (text) => {
expect(new CommandRouter([command]).match(message(text))?.command.id).toBe('checkin');
});
it('does not parse normal conversation as commands', () => {
expect(new CommandRouter([command]).match(message('今天已经签到了吗'))).toBeUndefined();
expect(new CommandRouter([command]).match(message('checkin'))).toBeUndefined();
});
it('matches longest registered paths and preserves quoted arguments', () => {
const nested = { ...command, id: 'query', paths: [['签到', '查询']], bare: [] };
const result = new CommandRouter([command, nested]).match(message('!签到 查询 "value with spaces" --原始'))!;
expect(result.command.id).toBe('query');
expect(result.invocation).toMatchObject({ args: ['value with spaces'], raw: true });
});
it('rejects alias collisions instead of dispatching multiple handlers', () => {
expect(() => new CommandRouter([command, { ...command, id: 'other' }])).toThrow('Duplicate');
});
});