2025-02-22 23:00:37 -06:00
|
|
|
'use client';
|
|
|
|
|
|
2025-02-22 23:06:37 -06:00
|
|
|
import Editor from "@monaco-editor/react";
|
2025-02-22 23:00:37 -06:00
|
|
|
import styles from './CodeExample.module.css';
|
|
|
|
|
|
2025-02-22 23:32:23 -06:00
|
|
|
type CodeExampleProps = {
|
|
|
|
|
code: string;
|
|
|
|
|
height?: string | number;
|
2025-02-22 23:56:47 -06:00
|
|
|
noScroll?: boolean;
|
2025-02-22 23:32:23 -06:00
|
|
|
}
|
|
|
|
|
|
2025-02-22 23:56:47 -06:00
|
|
|
export default function CodeExample({ code, height = "100%", noScroll = false }: CodeExampleProps) {
|
2025-02-22 23:32:23 -06:00
|
|
|
return (
|
2025-02-22 23:53:20 -06:00
|
|
|
<div className={styles.editorWrapper}>
|
2025-02-22 23:56:47 -06:00
|
|
|
<div className={styles.editorContainer} style={{ pointerEvents: noScroll ? 'none' : 'auto' }}>
|
2025-02-22 23:53:20 -06:00
|
|
|
<Editor
|
|
|
|
|
height={height}
|
|
|
|
|
defaultLanguage="typescript"
|
|
|
|
|
defaultValue={code}
|
|
|
|
|
theme="vs-dark"
|
|
|
|
|
options={{
|
|
|
|
|
readOnly: true,
|
|
|
|
|
minimap: { enabled: false },
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
lineNumbers: 'on',
|
|
|
|
|
scrollBeyondLastLine: false,
|
|
|
|
|
roundedSelection: false,
|
|
|
|
|
padding: { top: 16, bottom: 16 },
|
|
|
|
|
automaticLayout: true,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-02-22 23:32:23 -06:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Export the example code snippets for reuse
|
|
|
|
|
export const simpleExample = `\
|
2025-02-22 23:00:37 -06:00
|
|
|
import { Client, type Context } from 'unicord';
|
|
|
|
|
|
|
|
|
|
// Initialize and configure
|
|
|
|
|
const client = new Client({
|
|
|
|
|
token: '<token>',
|
|
|
|
|
application_id: '<application_id>',
|
|
|
|
|
intents: [
|
|
|
|
|
Intent.GUILDS,
|
|
|
|
|
Intent.GUILD_MESSAGES,
|
|
|
|
|
Intent.GUILD_MESSAGE_REACTIONS,
|
|
|
|
|
Intent.MESSAGE_CONTENT
|
|
|
|
|
],
|
|
|
|
|
prefix: '??'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Register a command
|
|
|
|
|
client.chatCommands.register('ping', (context: Context, args) => {
|
|
|
|
|
context.reply('Pong!', true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Connect
|
|
|
|
|
client.connect();`;
|
|
|
|
|
|
2025-02-22 23:32:23 -06:00
|
|
|
export const hydrationExample = `\
|
|
|
|
|
client.chatCommands.register('ping', async (context: Context, args: any[]) => {
|
|
|
|
|
// Hydrate the message id from the context
|
|
|
|
|
const { message } = await context.hydrate(context, [Expectation.Message]);
|
|
|
|
|
// Send a message to the channel
|
|
|
|
|
const response = await context.reply(\`Pong!: got \${args.join(', ')}\`, true);
|
|
|
|
|
// Calculate the time it took to send the message
|
|
|
|
|
const time = message.timestamp.getTime() - message.timestamp.getTime();
|
|
|
|
|
// Edit the message to include the time
|
|
|
|
|
await context.editMessage(response, \`Pong! Latency: \${time}ms\`);
|
|
|
|
|
});`;
|