@@ -25,32 +25,52 @@ limitations under the License.
2525 * are NOT distributed, contributed, committed, or licensed under the Apache License.
2626 */
2727
28- import { Mjolnir } from "../Mjolnir" ;
29- import { RichReply } from "matrix-bot-sdk" ;
30- import { Permalinks } from "./interface-manager/Permalinks" ;
31-
32- // !mjolnir watch <room alias or ID>
33- export async function execWatchCommand ( roomId : string , event : any , mjolnir : Mjolnir , parts : string [ ] ) {
34- const list = await mjolnir . policyListManager . watchList ( Permalinks . forRoom ( parts [ 2 ] ) ) ;
35- if ( ! list ) {
36- const replyText = "Cannot watch list due to error - is that a valid room alias?" ;
37- const reply = RichReply . createFor ( roomId , event , replyText , replyText ) ;
38- reply [ "msgtype" ] = "m.notice" ;
39- mjolnir . client . sendMessage ( roomId , reply ) ;
40- return ;
41- }
42- await mjolnir . client . unstableApis . addReactionToEvent ( roomId , event [ 'event_id' ] , '✅' ) ;
43- }
44-
45- // !mjolnir unwatch <room alias or ID>
46- export async function execUnwatchCommand ( roomId : string , event : any , mjolnir : Mjolnir , parts : string [ ] ) {
47- const list = await mjolnir . policyListManager . unwatchList ( Permalinks . forRoom ( parts [ 2 ] ) ) ;
48- if ( ! list ) {
49- const replyText = "Cannot unwatch list due to error - is that a valid room alias?" ;
50- const reply = RichReply . createFor ( roomId , event , replyText , replyText ) ;
51- reply [ "msgtype" ] = "m.notice" ;
52- mjolnir . client . sendMessage ( roomId , reply ) ;
53- return ;
54- }
55- await mjolnir . client . unstableApis . addReactionToEvent ( roomId , event [ 'event_id' ] , '✅' ) ;
56- }
28+ import { defineInterfaceCommand , findTableCommand } from "./interface-manager/InterfaceCommand" ;
29+ import { findPresentationType , parameters , ParsedKeywords } from "./interface-manager/ParameterParsing" ;
30+ import { MjolnirContext } from "./CommandHandler" ;
31+ import { MatrixRoomReference } from "./interface-manager/MatrixRoomReference" ;
32+ import { CommandError , CommandResult } from "./interface-manager/Validation" ;
33+ import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer" ;
34+ import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor" ;
35+
36+ defineInterfaceCommand ( {
37+ table : "mjolnir" ,
38+ designator : [ "watch" ] ,
39+ summary : "Watches a list and applies the list's assocated policies to draupnir's protected rooms." ,
40+ parameters : parameters ( [
41+ {
42+ name : 'list' ,
43+ acceptor : findPresentationType ( "MatrixRoomReference" ) ,
44+ }
45+ ] ) ,
46+ command : async function ( this : MjolnirContext , _keywords : ParsedKeywords , list : MatrixRoomReference ) : Promise < CommandResult < void , CommandError > > {
47+ await this . mjolnir . policyListManager . watchList ( list ) ;
48+ return CommandResult . Ok ( undefined ) ;
49+ } ,
50+ } )
51+
52+ defineMatrixInterfaceAdaptor ( {
53+ interfaceCommand : findTableCommand ( "mjolnir" , "watch" ) ,
54+ renderer : tickCrossRenderer ,
55+ } )
56+
57+ defineInterfaceCommand ( {
58+ table : "mjolnir" ,
59+ designator : [ "unwatch" ] ,
60+ summary : "Unwatches a list and stops applying the list's assocated policies to draupnir's protected rooms." ,
61+ parameters : parameters ( [
62+ {
63+ name : 'list' ,
64+ acceptor : findPresentationType ( "MatrixRoomReference" ) ,
65+ }
66+ ] ) ,
67+ command : async function ( this : MjolnirContext , _keywords : ParsedKeywords , list : MatrixRoomReference ) : Promise < CommandResult < void , CommandError > > {
68+ await this . mjolnir . policyListManager . unwatchList ( list ) ;
69+ return CommandResult . Ok ( undefined ) ;
70+ } ,
71+ } )
72+
73+ defineMatrixInterfaceAdaptor ( {
74+ interfaceCommand : findTableCommand ( "mjolnir" , "unwatch" ) ,
75+ renderer : tickCrossRenderer ,
76+ } )
0 commit comments