@@ -20,6 +20,7 @@ limitations under the License.
2020
2121import * as React from 'react' ;
2222
23+ import { ContentHelpers } from 'matrix-js-sdk' ;
2324import { MatrixClientPeg } from './MatrixClientPeg' ;
2425import dis from './dispatcher/dispatcher' ;
2526import * as sdk from './index' ;
@@ -126,10 +127,10 @@ export class Command {
126127 return this . getCommand ( ) + " " + this . args ;
127128 }
128129
129- run ( roomId : string , args : string , cmd : string ) {
130+ run ( roomId : string , args : string ) {
130131 // if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
131132 if ( ! this . runFn ) return reject ( _t ( "Command error" ) ) ;
132- return this . runFn . bind ( this ) ( roomId , args , cmd ) ;
133+ return this . runFn . bind ( this ) ( roomId , args ) ;
133134 }
134135
135136 getUsage ( ) {
@@ -163,7 +164,7 @@ export const Commands = [
163164 if ( args ) {
164165 message = message + ' ' + args ;
165166 }
166- return success ( MatrixClientPeg . get ( ) . sendTextMessage ( roomId , message ) ) ;
167+ return success ( ContentHelpers . makeTextMessage ( message ) ) ;
167168 } ,
168169 category : CommandCategories . messages ,
169170 } ) ,
@@ -176,7 +177,7 @@ export const Commands = [
176177 if ( args ) {
177178 message = message + ' ' + args ;
178179 }
179- return success ( MatrixClientPeg . get ( ) . sendTextMessage ( roomId , message ) ) ;
180+ return success ( ContentHelpers . makeTextMessage ( message ) ) ;
180181 } ,
181182 category : CommandCategories . messages ,
182183 } ) ,
@@ -189,7 +190,7 @@ export const Commands = [
189190 if ( args ) {
190191 message = message + ' ' + args ;
191192 }
192- return success ( MatrixClientPeg . get ( ) . sendTextMessage ( roomId , message ) ) ;
193+ return success ( ContentHelpers . makeTextMessage ( message ) ) ;
193194 } ,
194195 category : CommandCategories . messages ,
195196 } ) ,
@@ -202,7 +203,7 @@ export const Commands = [
202203 if ( args ) {
203204 message = message + ' ' + args ;
204205 }
205- return success ( MatrixClientPeg . get ( ) . sendTextMessage ( roomId , message ) ) ;
206+ return success ( ContentHelpers . makeTextMessage ( message ) ) ;
206207 } ,
207208 category : CommandCategories . messages ,
208209 } ) ,
@@ -211,7 +212,7 @@ export const Commands = [
211212 args : '<message>' ,
212213 description : _td ( 'Sends a message as plain text, without interpreting it as markdown' ) ,
213214 runFn : function ( roomId , messages ) {
214- return success ( MatrixClientPeg . get ( ) . sendTextMessage ( roomId , messages ) ) ;
215+ return success ( ContentHelpers . makeTextMessage ( messages ) ) ;
215216 } ,
216217 category : CommandCategories . messages ,
217218 } ) ,
@@ -220,7 +221,7 @@ export const Commands = [
220221 args : '<message>' ,
221222 description : _td ( 'Sends a message as html, without interpreting it as markdown' ) ,
222223 runFn : function ( roomId , messages ) {
223- return success ( MatrixClientPeg . get ( ) . sendHtmlMessage ( roomId , messages , messages ) ) ;
224+ return success ( ContentHelpers . makeHtmlMessage ( messages , messages ) ) ;
224225 } ,
225226 category : CommandCategories . messages ,
226227 } ) ,
@@ -965,7 +966,7 @@ export const Commands = [
965966 args : '<message>' ,
966967 runFn : function ( roomId , args ) {
967968 if ( ! args ) return reject ( this . getUserId ( ) ) ;
968- return success ( MatrixClientPeg . get ( ) . sendHtmlMessage ( roomId , args , textToHtmlRainbow ( args ) ) ) ;
969+ return success ( ContentHelpers . makeHtmlMessage ( args , textToHtmlRainbow ( args ) ) ) ;
969970 } ,
970971 category : CommandCategories . messages ,
971972 } ) ,
@@ -975,7 +976,7 @@ export const Commands = [
975976 args : '<message>' ,
976977 runFn : function ( roomId , args ) {
977978 if ( ! args ) return reject ( this . getUserId ( ) ) ;
978- return success ( MatrixClientPeg . get ( ) . sendHtmlEmote ( roomId , args , textToHtmlRainbow ( args ) ) ) ;
979+ return success ( ContentHelpers . makeHtmlEmote ( args , textToHtmlRainbow ( args ) ) ) ;
979980 } ,
980981 category : CommandCategories . messages ,
981982 } ) ,
@@ -1200,10 +1201,13 @@ export function parseCommandString(input: string) {
12001201 * processing the command, or 'promise' if a request was sent out.
12011202 * Returns null if the input didn't match a command.
12021203 */
1203- export function getCommand ( roomId : string , input : string ) {
1204+ export function getCommand ( input : string ) {
12041205 const { cmd, args} = parseCommandString ( input ) ;
12051206
12061207 if ( CommandMap . has ( cmd ) && CommandMap . get ( cmd ) . isEnabled ( ) ) {
1207- return ( ) => CommandMap . get ( cmd ) . run ( roomId , args , cmd ) ;
1208+ return {
1209+ cmd : CommandMap . get ( cmd ) ,
1210+ args,
1211+ } ;
12081212 }
12091213}
0 commit comments