9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
export const sendCommand = cli({
|
|
site: 'discord-app',
|
|
name: 'send',
|
|
access: 'write',
|
|
description: 'Send a message in the active Discord channel',
|
|
domain: 'localhost',
|
|
strategy: Strategy.UI,
|
|
browser: true,
|
|
args: [{ name: 'text', required: true, positional: true, help: 'Message to send' }],
|
|
columns: ['Status'],
|
|
func: async (page, kwargs) => {
|
|
const text = kwargs.text;
|
|
await page.evaluate(`
|
|
(function(text) {
|
|
// Discord uses a Slate-based editor with [data-slate-editor="true"] or role="textbox"
|
|
const editor = document.querySelector('[role="textbox"][data-slate-editor="true"], [class*="slateTextArea"]');
|
|
if (!editor) throw new Error('Could not find Discord message input. Make sure a channel is open.');
|
|
|
|
editor.focus();
|
|
document.execCommand('insertText', false, text);
|
|
})(${JSON.stringify(text)})
|
|
`);
|
|
await page.wait(0.3);
|
|
await page.pressKey('Enter');
|
|
return [{ Status: 'Success' }];
|
|
},
|
|
});
|