update readme & remove useless comments

This commit is contained in:
Domin-MND
2023-10-31 20:07:21 +03:00
parent a41c825cdd
commit 5674e3c1b6
3 changed files with 94 additions and 19 deletions

View File

@@ -22,21 +22,49 @@ pnpm add reacord react discord.js
## Example ## Example
<!-- prettier-ignore -->
```tsx ```tsx
import * as React from "react" import { useState } from "react"
import { Embed, Button } from "reacord" import { Embed, EmbedField, Button } from "reacord"
interface EmbedCounterProps {
count: number
visible: boolean
}
function EmbedCounter({ count, visible }: EmbedCounterProps) {
if (!visible) return <></>
return (
<Embed title="the counter">
<EmbedField name="is it even?">{count % 2 ? "no" : "yes"}</EmbedField>
</Embed>
)
}
function Counter() { function Counter() {
const [count, setCount] = React.useState(0) const [showEmbed, setShowEmbed] = useState<boolean>(false)
const [count, setCount] = useState<number>(0)
const instance = useInstance()
return ( return (
<> <>
<Embed title="Counter"> this button was clicked {count} times
This button has been clicked {count} times. <EmbedCounter count={count} visible={showEmbed} />
</Embed> <Button
<Button onClick={() => setCount(count + 1)}> style="primary"
+1 label="clicc"
</Button> onClick={() => setCount(count + 1)}
/>
<Button
style="secondary"
label={showEmbed ? "hide embed" : "show embed"}
onClick={() => setShowEmbed(!showEmbed)}
/>
<Button
style="danger"
label="deactivate"
onClick={() => instance.destroy()}
/>
</> </>
) )
} }

View File

@@ -1,6 +1,8 @@
import { raise } from "@reacord/helpers/raise.js" import { raise } from "@reacord/helpers/raise.js"
import { import {
Button, Button,
Embed,
EmbedField,
Link, Link,
Option, Option,
ReacordDiscordJs, ReacordDiscordJs,
@@ -11,7 +13,6 @@ import type { TextChannel } from "discord.js"
import { ChannelType, Client, IntentsBitField } from "discord.js" import { ChannelType, Client, IntentsBitField } from "discord.js"
import "dotenv/config" import "dotenv/config"
import { kebabCase } from "lodash-es" import { kebabCase } from "lodash-es"
import * as React from "react"
import { useState } from "react" import { useState } from "react"
const client = new Client({ intents: IntentsBitField.Flags.Guilds }) const client = new Client({ intents: IntentsBitField.Flags.Guilds })
@@ -53,9 +54,57 @@ await createTest("basic", (channel) => {
reacord.createChannelMessage(channel).render("Hello, world!") reacord.createChannelMessage(channel).render("Hello, world!")
}) })
await createTest("readme counter", (channel) => {
interface EmbedCounterProps {
count: number
visible: boolean
}
function EmbedCounter({ count, visible }: EmbedCounterProps) {
if (!visible) return <></>
return (
<Embed title="the counter">
<EmbedField name="is it even?">{count % 2 ? "no" : "yes"}</EmbedField>
</Embed>
)
}
function Counter() {
const [showEmbed, setShowEmbed] = useState(false)
const [count, setCount] = useState(0)
const instance = useInstance()
return (
<>
this button was clicked {count} times
<EmbedCounter count={count} visible={showEmbed} />
<Button
style="primary"
label="clicc"
onClick={() => setCount(count + 1)}
/>
<Button
style="secondary"
label={showEmbed ? "hide embed" : "show embed"}
onClick={() => setShowEmbed(!showEmbed)}
/>
<Button
style="danger"
label="deactivate"
onClick={() => instance.destroy()}
/>
</>
)
}
reacord.createChannelMessage(channel).render(<Counter />)
})
await createTest("counter", (channel) => { await createTest("counter", (channel) => {
const Counter = () => { function Counter() {
const [count, setCount] = React.useState(0) const [count, setCount] = useState(0)
return ( return (
<> <>
count: {count} count: {count}

View File

@@ -141,14 +141,12 @@ interface Command {
} }
function handleCommands(client: Client, commands: Command[]) { function handleCommands(client: Client, commands: Command[]) {
// Registering commands when client is ready
client.once(Events.ClientReady, () => { client.once(Events.ClientReady, () => {
for (const { name, description } of commands) { for (const { name, description } of commands) {
client.application?.commands.create({ name, description }) client.application?.commands.create({ name, description })
} }
}) })
// Subscribing to interactionCreate event
client.on(Events.InteractionCreate, (interaction) => { client.on(Events.InteractionCreate, (interaction) => {
if (interaction.isCommand()) { if (interaction.isCommand()) {
for (const command of commands) { for (const command of commands) {