feat: Add slashcommand api

This commit is contained in:
2026-06-05 17:12:26 +02:00
parent 4070ef6caf
commit 8ecfc9a1fe
101 changed files with 3526 additions and 147 deletions

View File

@@ -1,3 +1,5 @@
# E2E All API Plugin
Fixture plugin for Playwright coverage. It calls every public Toju plugin API surface, registers UI contributions, writes storage, publishes events, creates plugin user data, and logs completion.
Fixture plugin for Playwright coverage. It calls every public Toju plugin API surface, registers UI contributions, writes storage, publishes events, creates plugin user data, imports attachments/messages, exercises typing APIs, and logs completion.
It also registers two `/` slash commands: `/e2e-echo <message>` (server scope, echoes text back into the channel) and `/e2e-ping` (global scope, logs a pong), exercising `api.commands.register` / `api.commands.list`.

View File

@@ -48,6 +48,29 @@ export async function activate(context) {
embedType: 'e2e.coverage',
render: (payload) => `E2E custom embed: ${payload?.title ?? 'missing title'}`
}));
context.subscriptions.push(api.commands.register('e2e-echo', {
description: 'Echo the provided text back into the channel',
icon: '📣',
name: 'e2e-echo',
options: [{ name: 'message', required: true, type: 'rest' }],
run: (slashContext) => {
api.messages.send(`E2E echo: ${slashContext.args.message || '(empty)'}`);
},
scope: 'server'
}));
context.subscriptions.push(api.commands.register('e2e-ping', {
description: 'Log a pong from the plugin runtime',
icon: '🏓',
name: 'e2e-ping',
run: (slashContext) => {
api.logger.info(`E2E ping handled in ${slashContext.server?.name ?? 'no server'}`);
},
scope: 'global'
}));
api.commands.list();
api.context.getCurrent();
api.logger.debug('coverage debug');
api.logger.error('coverage error');
const injectedBadge = document.createElement('div');
@@ -99,12 +122,15 @@ export async function activate(context) {
api.roles.setAssignments([]);
api.channels.list();
api.channels.addTextChannel({ id: 'e2e-text', name: 'E2E Text', position: 89 });
api.channels.addAudioChannel({ id: 'e2e-audio', name: 'E2E Audio', position: 90 });
api.channels.addVideoChannel({ id: 'e2e-video', name: 'E2E Video', position: 91 });
api.channels.select('general');
api.channels.rename('e2e-audio', 'E2E Audio Renamed');
api.channels.remove('e2e-text');
api.server.getCurrent();
await api.server.updateIcon('e2e-plugin-icon').catch((error) => api.logger.warn('server icon rejected', String(error)));
api.server.updatePermissions({ allowVoice: true });
api.server.updateSettings({
name: api.server.getCurrent()?.name,
@@ -129,6 +155,10 @@ export async function activate(context) {
});
api.messages.moderateDelete('missing-message-id');
api.messages.sync(api.messages.readCurrent());
await api.messages.import(api.messages.readCurrent()).catch((error) => api.logger.warn('message import rejected', String(error)));
api.messages.setTyping(true);
api.messages.setTyping(false);
context.subscriptions.push(api.messages.subscribeTyping(() => {}));
context.subscriptions.push(api.messageBus.subscribe({
handler: () => {},
latestMessageLimit: 5,
@@ -147,6 +177,19 @@ export async function activate(context) {
topic: 'e2e:latest'
});
if (shouldMutateChat) {
const sentMessage = api.messages.readCurrent().find((message) => message.content === editedMessage);
if (sentMessage) {
const attachmentFile = new File(['plugin attachment'], 'e2e-plugin.txt', { type: 'text/plain' });
await api.attachments.import({
files: [attachmentFile],
messageId: sentMessage.id
}).catch((error) => api.logger.warn('attachment import rejected', String(error)));
}
}
api.p2p.connectedPeers();
api.p2p.broadcastData('e2e:p2p', { ok: true });
api.p2p.sendData('missing-peer', 'e2e:p2p', { ok: true });

View File

@@ -50,6 +50,7 @@
"ui.channelsSection",
"ui.embeds",
"ui.dom",
"ui.commands",
"storage.local",
"storage.serverData.read",
"storage.serverData.write",
@@ -91,7 +92,8 @@
"ui": {
"settingsPages": ["coverage"],
"sidePanels": ["coverage"],
"channelSections": ["coverage"]
"channelSections": ["coverage"],
"slashCommands": ["e2e-echo", "e2e-ping"]
},
"pluginUser": {
"displayName": "E2E Plugin Bot",