Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/app/hooks/useCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
} from '$utils/matrix';
import { getStateEvent } from '$utils/room';
import { splitWithSpace } from '$utils/common';
import { useSetting } from '$state/hooks/settings';
import { settingsAtom } from '$state/settings';
import { createRoomEncryptionState } from '$components/create-room';
import { useRoomNavigate } from './useRoomNavigate';
import { enrichWidgetUrl } from './useRoomWidgets';
Expand Down Expand Up @@ -229,6 +231,7 @@ export enum Command {
Pronoun = 'pronoun',
GPronoun = 'gpronoun',
Rainbow = 'rainbow',
Raw = 'raw',
}

export type CommandContent = {
Expand All @@ -241,6 +244,7 @@ export type CommandRecord = Record<Command, CommandContent>;

export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
const { navigateRoom } = useRoomNavigate();
const [developerTools] = useSetting(settingsAtom, 'developerTools');

const commands: CommandRecord = useMemo(
() => ({
Expand Down Expand Up @@ -1001,8 +1005,36 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
});
},
},
[Command.Raw]: {
name: Command.Raw,
description:
'Send raw JSON event (Dev Mode only). Example: /raw {"msgtype":"m.text", "body":"hello"}',
exe: async (payload) => {
const userId = mx.getSafeUserId();
const sendFeedback = (msg: string) => {
const localNotice = new (window as any).matrixcs.MatrixEvent({
type: 'm.room.message',
content: { msgtype: 'm.notice', body: msg },
event_id: `~raw-${Date.now()}`,
room_id: room.roomId,
sender: userId,
});
(room as any).addLiveEvents([localNotice], { duplicateStrategy: 'ignore' } as any);
};
if (!developerTools) {
sendFeedback('Command available in Developer Mode only.');
return;
}
try {
const content = JSON.parse(payload);
await mx.sendMessage(room.roomId, content);
} catch (e: any) {
sendFeedback(`Invalid JSON: ${e.message}`);
}
},
},
}),
[mx, room, navigateRoom]
[mx, room, navigateRoom, developerTools]
);

return commands;
Expand Down
Loading