1010import {
1111 MatrixInterfaceCommandDispatcher ,
1212 StandardMatrixInterfaceCommandDispatcher ,
13- CommandPrefixExtractor ,
1413 JSInterfaceCommandDispatcher ,
1514 BasicInvocationInformation ,
1615 StandardJSInterfaceCommandDispatcher ,
16+ CommandNormaliser ,
17+ makeCommandNormaliser ,
1718} from "@the-draupnir-project/interface-manager" ;
1819import { Draupnir } from "../Draupnir" ;
1920import {
@@ -22,33 +23,29 @@ import {
2223 invocationInformationFromMatrixEventcontext ,
2324} from "./interface-manager/MPSMatrixInterfaceAdaptor" ;
2425import { DraupnirHelpCommand } from "./Help" ;
25- import { userLocalpart } from "@the-draupnir-project/matrix-basic-types" ;
26+ import { StringUserID } from "@the-draupnir-project/matrix-basic-types" ;
2627import { DraupnirTopLevelCommands } from "./DraupnirCommandTable" ;
2728import {
2829 DraupnirContextToCommandContextTranslator ,
2930 DraupnirInterfaceAdaptor ,
3031} from "./DraupnirCommandPrerequisites" ;
3132import "./DraupnirCommands" ;
33+ import { IConfig } from "../config" ;
3234
33- function makePrefixExtractor ( draupnir : Draupnir ) : CommandPrefixExtractor {
34- const plainPrefixes = [
35- "!draupnir" ,
36- userLocalpart ( draupnir . clientUserID ) ,
37- draupnir . clientUserID ,
38- ...draupnir . config . commands . additionalPrefixes ,
39- ] ;
40- const allPossiblePrefixes = [
41- ...plainPrefixes . map ( ( p ) => `!${ p } ` ) ,
42- ...plainPrefixes . map ( ( p ) => `${ p } :` ) ,
43- ...plainPrefixes ,
44- ...( draupnir . config . commands . allowNoPrefix ? [ "!" ] : [ ] ) ,
45- ] ;
46- return ( body ) => {
47- const isPrefixUsed = allPossiblePrefixes . find ( ( p ) =>
48- body . toLowerCase ( ) . startsWith ( p . toLowerCase ( ) )
49- ) ;
50- return isPrefixUsed ? "draupnir" : undefined ;
51- } ;
35+ export function makeDraupnirCommandNormaliser (
36+ clientUserID : StringUserID ,
37+ displayNameIssuer : { clientDisplayName : string } ,
38+ config : IConfig
39+ ) : CommandNormaliser {
40+ return makeCommandNormaliser ( clientUserID , {
41+ symbolPrefixes : [ "!" ] ,
42+ isAllowedOnlySymbolPrefixes : config . commands . allowNoPrefix ,
43+ additionalPrefixes : [ "draupnir" , ...config . commands . additionalPrefixes ] ,
44+ getDisplayName : function ( ) : string {
45+ return displayNameIssuer . clientDisplayName ;
46+ } ,
47+ normalisedPrefix : "draupnir" ,
48+ } ) ;
5249}
5350
5451export function makeDraupnirCommandDispatcher (
@@ -62,7 +59,11 @@ export function makeDraupnirCommandDispatcher(
6259 invocationInformationFromMatrixEventcontext ,
6360 {
6461 ...MPSCommandDispatcherCallbacks ,
65- prefixExtractor : makePrefixExtractor ( draupnir ) ,
62+ commandNormaliser : makeDraupnirCommandNormaliser (
63+ draupnir . clientUserID ,
64+ draupnir ,
65+ draupnir . config
66+ ) ,
6667 }
6768 ) ;
6869}
@@ -76,7 +77,11 @@ export function makeDraupnirJSCommandDispatcher(
7677 draupnir ,
7778 {
7879 ...MPSCommandDispatcherCallbacks ,
79- prefixExtractor : makePrefixExtractor ( draupnir ) ,
80+ commandNormaliser : makeDraupnirCommandNormaliser (
81+ draupnir . clientUserID ,
82+ draupnir ,
83+ draupnir . config
84+ ) ,
8085 } ,
8186 DraupnirContextToCommandContextTranslator
8287 ) ;
0 commit comments