17 Commits

Author SHA1 Message Date
itsMapleLeaf
96affac979 release v0.4.0 2022-07-21 16:23:15 -05:00
Crawron
93b321dc36 clean imports 2022-07-21 16:20:14 -05:00
Crawron
e313399a5a fix type guards 2022-07-21 16:20:14 -05:00
Crawron
90744ebe47 tweak and infer return type 2022-07-21 16:20:14 -05:00
Crawron
33bb2ee196 use enums instead of strings for component type 2022-07-21 16:20:14 -05:00
Crawron
eb97b2d23d Add helper to convert button style to enum 2022-07-21 16:20:14 -05:00
Crawron
5aaaffbda9 Update playground for djs v14 2022-07-21 16:20:14 -05:00
Crawron
43029019f4 gitignore pnpm debug log 2022-07-21 16:20:14 -05:00
Crawron
8c481f18c6 Update Discord.js version 2022-07-21 16:20:14 -05:00
itsMapleLeaf
87ecb20f7a fix pnpm scripts & lock pnpm version 2022-07-09 15:13:44 -05:00
itsMapleLeaf
2324f3c89f release v0.3.7 2022-07-09 14:55:00 -05:00
itsMapleLeaf
c35c32bddd fix cjs require 2022-07-09 14:54:27 -05:00
itsMapleLeaf
6eb36b44f3 move scripts to root for deployment 2022-07-07 12:20:00 -05:00
itsMapleLeaf
a1fc0287fc remove engines config 2022-07-07 12:02:13 -05:00
itsMapleLeaf
02dd763e63 install node 16 for website 2022-07-07 12:01:06 -05:00
itsMapleLeaf
a4024394e3 remove dockerfile 2022-07-07 11:56:13 -05:00
itsMapleLeaf
c72096058a fix umami script 2022-07-07 11:49:14 -05:00
12 changed files with 615 additions and 266 deletions

View File

@@ -19,15 +19,15 @@ jobs:
# if these run in the same process, it dies, # if these run in the same process, it dies,
# so we test them separate # so we test them separate
- name: test reacord - name: test reacord
run: pnpm test -C packages/reacord run: pnpm -C packages/reacord test
- name: test website - name: test website
run: pnpm test -C packages/website run: pnpm -C packages/website test
- name: build - name: build
run: pnpm build --recursive run: pnpm --recursive run build
- name: lint - name: lint
run: pnpm lint run: pnpm run lint
- name: typecheck - name: typecheck
run: pnpm typecheck --parallel run: pnpm --recursive run typecheck
name: ${{ matrix.command.name }} name: ${{ matrix.command.name }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -36,6 +36,6 @@ jobs:
with: with:
# https://github.com/actions/setup-node#supported-version-syntax # https://github.com/actions/setup-node#supported-version-syntax
node-version: "16" node-version: "16"
- run: npm i -g pnpm - run: npm i -g pnpm@7.5.0
- run: pnpm install --frozen-lockfile - run: pnpm install --frozen-lockfile
- run: ${{ matrix.command.run }} - run: ${{ matrix.command.run }}

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@ node_modules
coverage coverage
.env .env
*.code-workspace *.code-workspace
.pnpm-debug.log
build build
.cache .cache

View File

@@ -1,15 +0,0 @@
FROM node:lts-slim
ENV CYPRESS_INSTALL_BINARY=0
WORKDIR /app
COPY / ./
RUN ls -R
RUN npm install -g pnpm
RUN pnpm install --unsafe-perm --frozen-lockfile
RUN pnpm run build -C packages/website
ENV NODE_ENV=production
CMD [ "pnpm", "-C", "packages/website", "start" ]

View File

@@ -4,7 +4,9 @@
"lint": "eslint --ext js,ts,tsx .", "lint": "eslint --ext js,ts,tsx .",
"lint-fix": "pnpm lint -- --fix", "lint-fix": "pnpm lint -- --fix",
"format": "prettier --write .", "format": "prettier --write .",
"release": "pnpm release -C packages/reacord" "release": "pnpm -C packages/reacord run release",
"build": "pnpm -C packages/website run build",
"start": "pnpm -C packages/website run start"
}, },
"devDependencies": { "devDependencies": {
"@itsmapleleaf/configs": "^1.1.3", "@itsmapleleaf/configs": "^1.1.3",
@@ -12,7 +14,8 @@
"@types/eslint": "^8.4.1", "@types/eslint": "^8.4.1",
"eslint": "^8.14.0", "eslint": "^8.14.0",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"typescript": "^4.6.3" "typescript": "^4.6.3",
"node": "^16"
}, },
"resolutions": { "resolutions": {
"esbuild": "latest" "esbuild": "latest"

View File

@@ -5,9 +5,12 @@ import type { Except } from "type-fest"
import { pick } from "../../helpers/pick" import { pick } from "../../helpers/pick"
import { pruneNullishValues } from "../../helpers/prune-nullish-values" import { pruneNullishValues } from "../../helpers/prune-nullish-values"
import { raise } from "../../helpers/raise" import { raise } from "../../helpers/raise"
import { toUpper } from "../../helpers/to-upper"
import type { ComponentInteraction } from "../internal/interaction" import type { ComponentInteraction } from "../internal/interaction"
import type { Message, MessageOptions } from "../internal/message" import type {
Message,
MessageButtonOptions,
MessageOptions,
} from "../internal/message"
import { ChannelMessageRenderer } from "../internal/renderers/channel-message-renderer" import { ChannelMessageRenderer } from "../internal/renderers/channel-message-renderer"
import { InteractionReplyRenderer } from "../internal/renderers/interaction-reply-renderer" import { InteractionReplyRenderer } from "../internal/renderers/interaction-reply-renderer"
import type { import type {
@@ -30,7 +33,7 @@ export class ReacordDiscordJs extends Reacord {
super(config) super(config)
client.on("interactionCreate", (interaction) => { client.on("interactionCreate", (interaction) => {
if (interaction.isMessageComponent()) { if (interaction.isButton() || interaction.isSelectMenu()) {
this.handleComponentInteraction( this.handleComponentInteraction(
this.createReacordComponentInteraction(interaction), this.createReacordComponentInteraction(interaction),
) )
@@ -88,7 +91,7 @@ export class ReacordDiscordJs extends Reacord {
(await this.client.channels.fetch(channelId)) ?? (await this.client.channels.fetch(channelId)) ??
raise(`Channel ${channelId} not found`) raise(`Channel ${channelId} not found`)
if (!channel.isText()) { if (!channel.isTextBased()) {
raise(`Channel ${channelId} is not a text channel`) raise(`Channel ${channelId} is not a text channel`)
} }
@@ -317,25 +320,34 @@ function createEphemeralReacordMessage(): Message {
} }
} }
function convertButtonStyleToEnum(style: MessageButtonOptions["style"]) {
const styleMap = {
primary: Discord.ButtonStyle.Primary,
secondary: Discord.ButtonStyle.Secondary,
success: Discord.ButtonStyle.Success,
danger: Discord.ButtonStyle.Danger,
} as const
return styleMap[style ?? "secondary"]
}
// TODO: this could be a part of the core library, // TODO: this could be a part of the core library,
// and also handle some edge cases, e.g. empty messages // and also handle some edge cases, e.g. empty messages
function getDiscordMessageOptions( function getDiscordMessageOptions(reacordOptions: MessageOptions) {
reacordOptions: MessageOptions, const options = {
): Discord.MessageOptions {
const options: Discord.MessageOptions = {
// eslint-disable-next-line unicorn/no-null // eslint-disable-next-line unicorn/no-null
content: reacordOptions.content || null, content: reacordOptions.content || null,
embeds: reacordOptions.embeds, embeds: reacordOptions.embeds,
components: reacordOptions.actionRows.map((row) => ({ components: reacordOptions.actionRows.map((row) => ({
type: "ACTION_ROW", type: Discord.ComponentType.ActionRow,
components: row.map( components: row.map(
(component): Discord.MessageActionRowComponentOptions => { (component): Discord.MessageActionRowComponentData => {
if (component.type === "button") { if (component.type === "button") {
return { return {
type: "BUTTON", type: Discord.ComponentType.Button,
customId: component.customId, customId: component.customId,
label: component.label ?? "", label: component.label ?? "",
style: toUpper(component.style ?? "secondary"), style: convertButtonStyleToEnum(component.style),
disabled: component.disabled, disabled: component.disabled,
emoji: component.emoji, emoji: component.emoji,
} }
@@ -344,7 +356,7 @@ function getDiscordMessageOptions(
if (component.type === "select") { if (component.type === "select") {
return { return {
...component, ...component,
type: "SELECT_MENU", type: Discord.ComponentType.SelectMenu,
options: component.options.map((option) => ({ options: component.options.map((option) => ({
...option, ...option,
default: component.values?.includes(option.value), default: component.values?.includes(option.value),

View File

@@ -2,7 +2,7 @@
"name": "reacord", "name": "reacord",
"type": "module", "type": "module",
"description": "Create interactive Discord messages using React.", "description": "Create interactive Discord messages using React.",
"version": "0.3.6", "version": "0.4.0",
"types": "./dist/main.d.ts", "types": "./dist/main.d.ts",
"homepage": "https://reacord.mapleleaf.dev", "homepage": "https://reacord.mapleleaf.dev",
"repository": "https://github.com/itsMapleLeaf/reacord.git", "repository": "https://github.com/itsMapleLeaf/reacord.git",
@@ -35,7 +35,7 @@
} }
}, },
"scripts": { "scripts": {
"build": "tsup-node library/main.ts --target node16 --format cjs,esm --dts --sourcemap", "build": "tsup library/main.ts --target node16 --format cjs,esm --dts --sourcemap",
"build-watch": "pnpm build -- --watch", "build-watch": "pnpm build -- --watch",
"test": "vitest --coverage --no-watch", "test": "vitest --coverage --no-watch",
"test-dev": "vitest", "test-dev": "vitest",
@@ -52,7 +52,7 @@
"rxjs": "^7.5.5" "rxjs": "^7.5.5"
}, },
"peerDependencies": { "peerDependencies": {
"discord.js": "^13.3", "discord.js": "^14",
"react": ">=17" "react": ">=17"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
@@ -63,7 +63,7 @@
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.6", "@types/lodash-es": "^4.17.6",
"c8": "^7.11.2", "c8": "^7.11.2",
"discord.js": "^13.6.0", "discord.js": "^14.0.3",
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"esbuild": "latest", "esbuild": "latest",
"esbuild-jest": "^0.5.0", "esbuild-jest": "^0.5.0",

View File

@@ -22,7 +22,7 @@ export function createCommandHandler(client: Client, commands: Command[]) {
}) })
client.on("interactionCreate", async (interaction) => { client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return if (!interaction.isChatInputCommand()) return
const command = commands.find( const command = commands.find(
(command) => command.name === interaction.commandName, (command) => command.name === interaction.commandName,

View File

@@ -1,4 +1,4 @@
import { Client } from "discord.js" import { Client, IntentsBitField } from "discord.js"
import "dotenv/config" import "dotenv/config"
import React from "react" import React from "react"
import { Button, ReacordDiscordJs, useInstance } from "../library/main" import { Button, ReacordDiscordJs, useInstance } from "../library/main"
@@ -7,7 +7,7 @@ import { Counter } from "./counter"
import { FruitSelect } from "./fruit-select" import { FruitSelect } from "./fruit-select"
const client = new Client({ const client = new Client({
intents: ["GUILDS"], intents: IntentsBitField.Flags.Guilds,
}) })
const reacord = new ReacordDiscordJs(client) const reacord = new ReacordDiscordJs(client)

View File

@@ -0,0 +1,12 @@
import { spawnSync } from "node:child_process"
import { createRequire } from "node:module"
import { beforeAll, expect, test } from "vitest"
beforeAll(() => {
spawnSync("pnpm", ["run", "build"])
})
test("can require commonjs", () => {
const require = createRequire(import.meta.url)
expect(() => require("../dist/main.cjs")).not.toThrow()
})

View File

@@ -85,9 +85,10 @@ export default function App() {
{process.env.NODE_ENV === "production" && ( {process.env.NODE_ENV === "production" && (
<script <script
async async
data-website-id="49c69ade-5593-4853-9686-c9ca9d519a18" defer
src="https://umami-production-265f.up.railway.app/umami.js" data-website-id="e3ce3a50-720e-4489-be37-cc091c1b7029"
/> src="https://umami-production-72bc.up.railway.app/umami.js"
></script>
)} )}
</head> </head>
<body> <body>

View File

@@ -48,8 +48,5 @@
"typescript": "^4.6.3", "typescript": "^4.6.3",
"wait-on": "^6.0.1" "wait-on": "^6.0.1"
}, },
"engines": {
"node": ">=14"
},
"sideEffects": false "sideEffects": false
} }

772
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff