From e3d1615169eee14ff6c832c328fb78f204d34c54 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Oct 2021 11:40:33 +0100 Subject: [PATCH] Make /msg param optional for more flexibility (#7028) --- src/SlashCommands.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 4ffab08780..c8884cead4 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -1014,14 +1014,14 @@ export const Commands = [ new Command({ command: "msg", description: _td("Sends a message to the given user"), - args: " ", + args: " []", runFn: function(roomId, args) { if (args) { // matches the first whitespace delimited group and then the rest of the string const matches = args.match(/^(\S+?)(?: +(.*))?$/s); if (matches) { const [userId, msg] = matches.slice(1); - if (msg && userId && userId.startsWith("@") && userId.includes(":")) { + if (userId && userId.startsWith("@") && userId.includes(":")) { return success((async () => { const cli = MatrixClientPeg.get(); const roomId = await ensureDMExists(cli, userId); @@ -1029,7 +1029,9 @@ export const Commands = [ action: 'view_room', room_id: roomId, }); - cli.sendTextMessage(roomId, msg); + if (msg) { + cli.sendTextMessage(roomId, msg); + } })()); } }