@@ -24,7 +24,7 @@ const MODULE = 'src/openai/platform/base.ts'
24
24
25
25
export const defaultCtx = {
26
26
apiKey : '' , // 用户的 OpenAI apiKey
27
- role : CONST . ROLE . GUEST as Role ,
27
+ role : new Set ( CONST . ROLE . GUEST ) as Set < Role > ,
28
28
chatType : '单聊' as ChatType ,
29
29
conversationId : '' ,
30
30
isRequestOpenAi : false , // 收到的消息是命令还是请求 OpenAI
@@ -467,17 +467,16 @@ export abstract class Base<T extends Platform> {
467
467
if ( subcommand ) {
468
468
const obj = this . commands [ subcommand ]
469
469
const roles = obj . roles as Role [ ]
470
- if ( ! obj || ! roles . includes ( role ) ) {
470
+ if ( ! obj || roles . every ( i => ! role . has ( i ) ) ) {
471
471
return genFail ( `命令 ${ subcommand } 不存在` )
472
472
}
473
473
cmdList . push ( { name : subcommand , description : obj . description } )
474
474
} else {
475
475
Object . entries ( this . commands ) . forEach ( ( [ name , obj ] ) => {
476
476
const roles = obj . roles as Role [ ]
477
- if ( ! roles . includes ( role ) ) {
478
- return
477
+ if ( roles . some ( i => role . has ( i ) ) ) {
478
+ cmdList . push ( { name , description : obj . description } )
479
479
}
480
- cmdList . push ( { name, description : obj . description } )
481
480
} )
482
481
}
483
482
@@ -620,7 +619,7 @@ export abstract class Base<T extends Platform> {
620
619
protected async handleCommandMessage ( message : string ) {
621
620
for ( const [ command , commandObj ] of Object . entries ( this . commands ) ) {
622
621
const roles = commandObj . roles as Role [ ]
623
- if ( ! roles . includes ( this . ctx . role ) ) continue
622
+ if ( roles . every ( i => ! this . ctx . role . has ( i ) ) ) continue
624
623
if ( message === command || message . startsWith ( `${ command } ` ) ) {
625
624
const params = message . slice ( command . length ) . trim ( )
626
625
this . logger . info ( `${ MODULE } 执行命令 ${ command } 参数 ${ params } ` )
@@ -647,7 +646,7 @@ export abstract class Base<T extends Platform> {
647
646
id : this . platform . id ,
648
647
reqId : this . request . reqId ,
649
648
userId : this . platform . ctx . userId ,
650
- role : this . ctx . role ,
649
+ role : Array . from ( this . ctx . role ) . join ( ',' ) ,
651
650
chatType : this . ctx . chatType ,
652
651
} )
653
652
this . platform . logger = logger
0 commit comments