mirror of https://github.com/vector-im/riot-web
Add slash commands /query and /msg to match IRC
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
159547e6f8
commit
6ea9aebda3
|
@ -40,6 +40,7 @@ import { Jitsi } from "./widgets/Jitsi";
|
|||
import { parseFragment as parseHtml } from "parse5";
|
||||
import sendBugReport from "./rageshake/submit-rageshake";
|
||||
import SdkConfig from "./SdkConfig";
|
||||
import { ensureDMExists } from "./createRoom";
|
||||
|
||||
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
|
||||
interface HTMLInputEvent extends Event {
|
||||
|
@ -970,6 +971,51 @@ export const Commands = [
|
|||
},
|
||||
category: CommandCategories.advanced,
|
||||
}),
|
||||
new Command({
|
||||
command: "query",
|
||||
description: _td("Opens chat with the given user"),
|
||||
args: "<user-id>",
|
||||
runFn: function(roomId, userId) {
|
||||
if (!userId || !userId.startsWith("@") || !userId.includes(":")) {
|
||||
return reject(this.getUsage());
|
||||
}
|
||||
|
||||
return success((async () => {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: await ensureDMExists(MatrixClientPeg.get(), userId),
|
||||
});
|
||||
})());
|
||||
},
|
||||
category: CommandCategories.actions,
|
||||
}),
|
||||
new Command({
|
||||
command: "msg",
|
||||
description: _td("Sends a message to the given user"),
|
||||
args: "<user-id> <message>",
|
||||
runFn: function(roomId, args) {
|
||||
if (args) {
|
||||
const matches = args.match(/^(\S+?)(?: +(.*))?$/s);
|
||||
if (matches) {
|
||||
const [userId, msg] = matches.slice(1);
|
||||
if (msg && userId && userId.startsWith("@") && userId.includes(":")) {
|
||||
return success((async () => {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const roomId = await ensureDMExists(cli, userId);
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: roomId,
|
||||
});
|
||||
cli.sendTextMessage(roomId, msg);
|
||||
})());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reject(this.getUsage());
|
||||
},
|
||||
category: CommandCategories.actions,
|
||||
}),
|
||||
|
||||
// Command definitions for autocompletion ONLY:
|
||||
// /me is special because its not handled by SlashCommands.js and is instead done inside the Composer classes
|
||||
|
|
|
@ -221,6 +221,8 @@
|
|||
"Send a bug report with logs": "Send a bug report with logs",
|
||||
"Logs sent": "Logs sent",
|
||||
"Thank you!": "Thank you!",
|
||||
"Opens chat with the given user": "Opens chat with the given user",
|
||||
"Sends a message to the given user": "Sends a message to the given user",
|
||||
"Displays action": "Displays action",
|
||||
"Reason": "Reason",
|
||||
"%(targetName)s accepted the invitation for %(displayName)s.": "%(targetName)s accepted the invitation for %(displayName)s.",
|
||||
|
|
Loading…
Reference in New Issue