move stuff around

This commit is contained in:
MapleLeaf
2021-12-26 22:57:17 -06:00
parent 5ed8ea059f
commit 349fff1bcb
29 changed files with 180 additions and 171 deletions

View File

@@ -1,15 +0,0 @@
import type { CommandInteraction, ComponentInteraction } from "../interaction"
export type Adapter<InteractionInit> = {
/**
* @internal
*/
addComponentInteractionListener(
listener: (interaction: ComponentInteraction) => void,
): void
/**
* @internal
*/
createCommandInteraction(interactionInfo: InteractionInit): CommandInteraction
}

View File

@@ -1,107 +0,0 @@
import { nanoid } from "nanoid"
import { raise } from "../../helpers/raise"
import type {
ButtonInteraction,
CommandInteraction,
ComponentInteraction,
} from "../interaction"
import type { Message, MessageButtonOptions, MessageOptions } from "../message"
import type { Adapter } from "./adapter"
export class TestAdapter implements Adapter<{}> {
readonly messages: TestMessage[] = []
// eslint-disable-next-line class-methods-use-this
private componentInteractionListener: (
interaction: ComponentInteraction,
) => void = () => {}
addComponentInteractionListener(
listener: (interaction: ComponentInteraction) => void,
): void {
this.componentInteractionListener = listener
}
// eslint-disable-next-line class-methods-use-this
createCommandInteraction(
interaction: CommandInteraction,
): CommandInteraction {
return interaction
}
findButtonByLabel(label: string) {
for (const message of this.messages) {
for (const component of message.options.actionRows.flat()) {
if (component.type === "button" && component.label === label) {
return this.createButtonActions(component, message)
}
}
}
raise(`Couldn't find button with label "${label}"`)
}
private createButtonActions(
button: MessageButtonOptions,
message: TestMessage,
) {
return {
click: () => {
this.componentInteractionListener(
new TestButtonInteraction(button.customId, message),
)
},
}
}
}
export class TestMessage implements Message {
constructor(public options: MessageOptions) {}
async edit(options: MessageOptions): Promise<void> {
this.options = options
}
async disableComponents(): Promise<void> {
for (const row of this.options.actionRows) {
for (const action of row) {
if (action.type === "button") {
action.disabled = true
}
}
}
}
}
export class TestCommandInteraction implements CommandInteraction {
readonly type = "command"
readonly id = "test-command-interaction"
readonly channelId = "test-channel-id"
constructor(private adapter: TestAdapter) {}
private createMesssage(messageOptions: MessageOptions): Message {
const message = new TestMessage(messageOptions)
this.adapter.messages.push(message)
return message
}
reply(messageOptions: MessageOptions): Promise<Message> {
return Promise.resolve(this.createMesssage(messageOptions))
}
followUp(messageOptions: MessageOptions): Promise<Message> {
return Promise.resolve(this.createMesssage(messageOptions))
}
}
export class TestButtonInteraction implements ButtonInteraction {
readonly type = "button"
readonly id = nanoid()
readonly channelId = "test-channel-id"
constructor(readonly customId: string, readonly message: TestMessage) {}
async update(options: MessageOptions): Promise<void> {
this.message.options = options
}
}

View File

@@ -0,0 +1,18 @@
import type {
CommandInteraction,
ComponentInteraction,
} from "../../internal/interaction"
export type Adapter<CommandReplyInit> = {
/**
* @internal
*/
addComponentInteractionListener(
listener: (interaction: ComponentInteraction) => void,
): void
/**
* @internal
*/
createCommandInteraction(init: CommandReplyInit): CommandInteraction
}

View File

@@ -1,8 +1,11 @@
import type * as Discord from "discord.js"
import { raise } from "../../helpers/raise"
import { toUpper } from "../../helpers/to-upper"
import type { CommandInteraction, ComponentInteraction } from "../interaction"
import type { Message, MessageOptions } from "../message"
import { raise } from "../../../helpers/raise"
import { toUpper } from "../../../helpers/to-upper"
import type {
CommandInteraction,
ComponentInteraction,
} from "../../internal/interaction"
import type { Message, MessageOptions } from "../../internal/message"
import type { Adapter } from "./adapter"
export class DiscordJsAdapter implements Adapter<Discord.CommandInteraction> {

View File

@@ -1,10 +1,10 @@
import { nanoid } from "nanoid"
import React from "react"
import { last } from "../helpers/last.js"
import { ReacordElement } from "./element.js"
import type { ComponentInteraction } from "./interaction"
import type { MessageOptions } from "./message"
import { Node } from "./node.js"
import { last } from "../../../helpers/last.js"
import { ReacordElement } from "../../internal/element.js"
import type { ComponentInteraction } from "../../internal/interaction"
import type { MessageOptions } from "../../internal/message"
import { Node } from "../../internal/node.js"
export type ButtonProps = {
label?: string

View File

@@ -1,5 +1,5 @@
import React from "react"
import { ReacordElement } from "../element.js"
import { ReacordElement } from "../../internal/element.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,4 +1,4 @@
import { Node } from "../node.js"
import { Node } from "../../internal/node.js"
import type { EmbedOptions } from "./embed-options"
export abstract class EmbedChildNode<Props> extends Node<Props> {

View File

@@ -1,5 +1,5 @@
import React from "react"
import { ReacordElement } from "../element.js"
import { ReacordElement } from "../../internal/element.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,5 +1,5 @@
import React from "react"
import { ReacordElement } from "../element.js"
import { ReacordElement } from "../../internal/element.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,5 +1,5 @@
import React from "react"
import { ReacordElement } from "../element.js"
import { ReacordElement } from "../../internal/element.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,5 +1,5 @@
import React from "react"
import { ReacordElement } from "../element.js"
import { ReacordElement } from "../../internal/element.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,5 +1,5 @@
import React from "react"
import { ReacordElement } from "../element.js"
import { ReacordElement } from "../../internal/element.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,9 +1,9 @@
import React from "react"
import { snakeCaseDeep } from "../../helpers/convert-object-property-case"
import { omit } from "../../helpers/omit"
import { ReacordElement } from "../element.js"
import type { MessageOptions } from "../message"
import { Node } from "../node.js"
import { snakeCaseDeep } from "../../../helpers/convert-object-property-case"
import { omit } from "../../../helpers/omit"
import { ReacordElement } from "../../internal/element.js"
import type { MessageOptions } from "../../internal/message"
import { Node } from "../../internal/node.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"

View File

@@ -1,8 +1,8 @@
import React from "react"
import { last } from "../helpers/last.js"
import { ReacordElement } from "./element.js"
import type { MessageOptions } from "./message"
import { Node } from "./node.js"
import { last } from "../../../helpers/last.js"
import { ReacordElement } from "../../internal/element.js"
import type { MessageOptions } from "../../internal/message"
import { Node } from "../../internal/node.js"
export type LinkProps = {
label?: string

View File

@@ -1,7 +1,7 @@
import type { ReactNode } from "react"
import type { Adapter } from "./adapter/adapter"
import { reconciler } from "./reconciler.js"
import { Renderer } from "./renderer.js"
import { reconciler } from "../internal/reconciler.js"
import { Renderer } from "../internal/renderer.js"
import type { Adapter } from "./adapters/adapter"
export type ReacordConfig<InteractionInit> = {
adapter: Adapter<InteractionInit>

View File

@@ -1,6 +1,6 @@
import type { ReactNode } from "react"
import React from "react"
import type { Node } from "./node.js"
import type { Node } from "./node"
export function ReacordElement<Props>(props: {
props: Props

View File

@@ -1,4 +1,4 @@
import type { EmbedOptions } from "./embed/embed-options"
import type { EmbedOptions } from "../core/components/embed-options"
export type MessageOptions = {
content: string

View File

@@ -1,9 +1,9 @@
import type { HostConfig } from "react-reconciler"
import ReactReconciler from "react-reconciler"
import { raise } from "../helpers/raise.js"
import { raise } from "../../helpers/raise.js"
import { Node } from "./node.js"
import type { Renderer } from "./renderer.js"
import { TextNode } from "./text.js"
import { TextNode } from "./text-node.js"
const config: HostConfig<
string, // Type,

View File

@@ -1,12 +1,12 @@
export * from "./adapter/adapter"
export * from "./adapter/discord-js-adapter"
export * from "./button"
export * from "./embed/embed"
export * from "./embed/embed-author"
export * from "./embed/embed-field"
export * from "./embed/embed-footer"
export * from "./embed/embed-image"
export * from "./embed/embed-thumbnail"
export * from "./embed/embed-title"
export * from "./link"
export * from "./reacord"
export * from "./core/adapters/adapter"
export * from "./core/adapters/discord-js-adapter"
export * from "./core/components/button"
export * from "./core/components/embed"
export * from "./core/components/embed-author"
export * from "./core/components/embed-field"
export * from "./core/components/embed-footer"
export * from "./core/components/embed-image"
export * from "./core/components/embed-thumbnail"
export * from "./core/components/embed-title"
export * from "./core/components/link"
export * from "./core/reacord"

View File

@@ -1 +1,111 @@
export * from "./adapter/test-adapter"
/* eslint-disable class-methods-use-this */
/* eslint-disable require-await */
import { nanoid } from "nanoid"
import { raise } from "../helpers/raise"
import type { Adapter } from "./core/adapters/adapter"
import type {
ButtonInteraction,
CommandInteraction,
ComponentInteraction,
} from "./internal/interaction"
import type {
Message,
MessageButtonOptions,
MessageOptions,
} from "./internal/message"
export class TestAdapter implements Adapter<TestCommandInteraction> {
readonly messages: TestMessage[] = []
private componentInteractionListener: (
interaction: ComponentInteraction,
) => void = () => {}
addComponentInteractionListener(
listener: (interaction: ComponentInteraction) => void,
): void {
this.componentInteractionListener = listener
}
createCommandInteraction(
interaction: CommandInteraction,
): CommandInteraction {
return interaction
}
findButtonByLabel(label: string) {
for (const message of this.messages) {
for (const component of message.options.actionRows.flat()) {
if (component.type === "button" && component.label === label) {
return this.createButtonActions(component, message)
}
}
}
raise(`Couldn't find button with label "${label}"`)
}
private createButtonActions(
button: MessageButtonOptions,
message: TestMessage,
) {
return {
click: () => {
this.componentInteractionListener(
new TestButtonInteraction(button.customId, message),
)
},
}
}
}
export class TestMessage implements Message {
constructor(public options: MessageOptions) {}
async edit(options: MessageOptions): Promise<void> {
this.options = options
}
async disableComponents(): Promise<void> {
for (const row of this.options.actionRows) {
for (const action of row) {
if (action.type === "button") {
action.disabled = true
}
}
}
}
}
export class TestCommandInteraction implements CommandInteraction {
readonly type = "command"
readonly id = "test-command-interaction"
readonly channelId = "test-channel-id"
constructor(private adapter: TestAdapter) {}
private createMesssage(messageOptions: MessageOptions): Message {
const message = new TestMessage(messageOptions)
this.adapter.messages.push(message)
return message
}
reply(messageOptions: MessageOptions): Promise<Message> {
return Promise.resolve(this.createMesssage(messageOptions))
}
followUp(messageOptions: MessageOptions): Promise<Message> {
return Promise.resolve(this.createMesssage(messageOptions))
}
}
export class TestButtonInteraction implements ButtonInteraction {
readonly type = "button"
readonly id = nanoid()
readonly channelId = "test-channel-id"
constructor(readonly customId: string, readonly message: TestMessage) {}
async update(options: MessageOptions): Promise<void> {
this.message.options = options
}
}