diff --git a/.lintstagedrc.mjs b/.lintstagedrc.mjs index 909a1050c..f5686b79e 100644 --- a/.lintstagedrc.mjs +++ b/.lintstagedrc.mjs @@ -1,4 +1,4 @@ export default { - "*.{j,t}s": ["eslint --concurrency 4" /* sweet spot it seems */, "prettier --write"], + "*.{j,t}s": [() => "npm run build:src:tsgo", "eslint --concurrency 4" /* sweet spot it seems */, "prettier --write"], "src/schemas/{*,**/*}.ts": [() => "tsc -b -v", () => "node scripts/schema.js", () => "node scripts/openapi.js", () => "git add assets/schemas.json assets/openapi.json"], }; diff --git a/assets/openapi.json b/assets/openapi.json index 178e208af..095d60d33 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 65b6edba7..7de877419 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/src/api/routes/interactions/index.ts b/src/api/routes/interactions/index.ts index 599a364e5..fd42050c7 100644 --- a/src/api/routes/interactions/index.ts +++ b/src/api/routes/interactions/index.ts @@ -17,10 +17,10 @@ */ import { randomBytes } from "node:crypto"; -import { InteractionFailureReason, InteractionSchema } from "@spacebar/schemas"; +import { InteractionFailureReason, InteractionSchema, InteractionType } from "@spacebar/schemas"; import { route } from "@spacebar/api"; import { Request, Response, Router } from "express"; -import { Config, emitEvent, getPermission, Guild, InteractionCreateEvent, InteractionFailureEvent, InteractionType, Member, Message, Snowflake } from "@spacebar/util"; +import { Config, emitEvent, getPermission, Guild, InteractionCreateEvent, InteractionFailureEvent, Member, Message, Snowflake } from "@spacebar/util"; import { pendingInteractions } from "@spacebar/util/imports/Interactions"; import { InteractionCreateSchema } from "@spacebar/schemas/api/bots/InteractionCreateSchema"; diff --git a/src/schemas/api/bots/InteractionCallbackSchema.ts b/src/schemas/api/bots/InteractionCallbackSchema.ts index dd09fb90a..ab0d7ca41 100644 --- a/src/schemas/api/bots/InteractionCallbackSchema.ts +++ b/src/schemas/api/bots/InteractionCallbackSchema.ts @@ -16,9 +16,8 @@ along with this program. If not, see . */ -import { Message } from "@spacebar/util"; import { InteractionCallbackType } from "./InteractionCallbackType"; -import { AllowedMentions, BaseMessageComponents, Embed, MessageComponentType } from "../messages"; +import { AllowedMentions, BaseMessageComponents, Embed } from "../messages"; import { MessageCreateAttachment, MessageCreateCloudAttachment, PollCreationSchema } from "#schemas/uncategorised"; export interface InteractionCallbackSchema { diff --git a/src/schemas/api/bots/InteractionCreateSchema.ts b/src/schemas/api/bots/InteractionCreateSchema.ts index 44e7e651d..5a6d1c3f4 100644 --- a/src/schemas/api/bots/InteractionCreateSchema.ts +++ b/src/schemas/api/bots/InteractionCreateSchema.ts @@ -16,8 +16,9 @@ along with this program. If not, see . */ -import { PublicMember, PublicUser, Snowflake } from "@spacebar/schemas"; -import { Channel, InteractionType, Message } from "@spacebar/util"; +import { PublicMember, PublicUser, Snowflake, InteractionType } from "@spacebar/schemas"; +// TODO: remove entity imports +import { Channel, Message } from "@spacebar/util"; export interface InteractionCreateSchema { version: number; // TODO: types? diff --git a/src/schemas/api/bots/InteractionSchema.ts b/src/schemas/api/bots/InteractionSchema.ts index 9e79df526..47c0f1140 100644 --- a/src/schemas/api/bots/InteractionSchema.ts +++ b/src/schemas/api/bots/InteractionSchema.ts @@ -16,8 +16,7 @@ along with this program. If not, see . */ -import { ApplicationCommandOption, Snowflake, UploadAttachmentRequestSchema } from "@spacebar/schemas"; -import { InteractionType } from "@spacebar/util"; +import { AllowedMentions, ApplicationCommandOption, Embed, Snowflake, UploadAttachmentRequestSchema } from "@spacebar/schemas"; export interface InteractionSchema { type: InteractionType; @@ -44,3 +43,38 @@ interface InteractionData { type: number; version: string; } + +export interface Interaction { + id: string; + type: InteractionType; + data?: object; // TODO typing + guild_id: string; + channel_id: string; + member_id: string; + token: string; + version: number; +} + +export enum InteractionType { + Ping = 1, + ApplicationCommand = 2, + MessageComponent = 3, + ApplicationCommandAutocomplete = 4, + ModalSubmit = 5, +} + +export enum InteractionResponseType { + SelfCommandResponse = 0, + Pong = 1, + Acknowledge = 2, + ChannelMessage = 3, + ChannelMessageWithSource = 4, + AcknowledgeWithSource = 5, +} + +export interface InteractionApplicationCommandCallbackData { + tts?: boolean; + content: string; + embeds?: Embed[]; + allowed_mentions?: AllowedMentions; +} diff --git a/src/schemas/api/bots/SendableApplicationCommandDataSchema.ts b/src/schemas/api/bots/SendableApplicationCommandDataSchema.ts index e559abe02..31a1abdd8 100644 --- a/src/schemas/api/bots/SendableApplicationCommandDataSchema.ts +++ b/src/schemas/api/bots/SendableApplicationCommandDataSchema.ts @@ -16,7 +16,7 @@ along with this program. If not, see . */ -import { Snowflake } from "@spacebar/util"; +import { Snowflake } from "../../Identifiers"; import { ApplicationCommandOption } from "../developers"; import { ApplicationCommandType } from "./ApplicationCommandSchema"; diff --git a/src/schemas/api/bots/SendableMessageComponentDataSchema.ts b/src/schemas/api/bots/SendableMessageComponentDataSchema.ts index 0ad37cc6e..7237af42b 100644 --- a/src/schemas/api/bots/SendableMessageComponentDataSchema.ts +++ b/src/schemas/api/bots/SendableMessageComponentDataSchema.ts @@ -16,7 +16,7 @@ along with this program. If not, see . */ -import { Snowflake } from "@spacebar/util"; +import { Snowflake } from "../../Identifiers"; import { MessageComponentType } from "../messages"; import { ApplicationCommandType } from "./ApplicationCommandSchema"; diff --git a/src/schemas/api/bots/SendableModalSubmitDataSchema.ts b/src/schemas/api/bots/SendableModalSubmitDataSchema.ts index f898c0cae..7c3056323 100644 --- a/src/schemas/api/bots/SendableModalSubmitDataSchema.ts +++ b/src/schemas/api/bots/SendableModalSubmitDataSchema.ts @@ -17,7 +17,7 @@ */ import { UploadAttachmentRequestSchema } from "@spacebar/schemas"; -import { Snowflake } from "@spacebar/util"; +import { Snowflake } from "../../Identifiers"; export interface SendableModalSubmitDataSchema { id: Snowflake; diff --git a/src/schemas/api/bots/index.ts b/src/schemas/api/bots/index.ts index fba2677a9..4c1a78043 100644 --- a/src/schemas/api/bots/index.ts +++ b/src/schemas/api/bots/index.ts @@ -15,6 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ + export * from "./ApplicationCommandCreateSchema"; export * from "./ApplicationCommandSchema"; export * from "./InteractionSchema"; diff --git a/src/schemas/api/channels/Channel.ts b/src/schemas/api/channels/Channel.ts index b9fb8c37b..efa0f5f53 100644 --- a/src/schemas/api/channels/Channel.ts +++ b/src/schemas/api/channels/Channel.ts @@ -1,6 +1,24 @@ -import { Channel, Guild, Invite, Message, ReadState, Recipient, Tag, ThreadMember, User, VoiceState, Webhook } from "@spacebar/util"; +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2026 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +// TODO: remove entity imports +import { Channel, Recipient, Tag, ThreadMember } from "@spacebar/util"; import { HTTPError } from "lambert-server"; -import { Column, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm"; import { Snowflake } from "../../Identifiers"; import { PartialUser, PublicMember } from "../users"; diff --git a/src/schemas/uncategorised/MessageCreateSchema.ts b/src/schemas/uncategorised/MessageCreateSchema.ts index 5afbfe2ad..ad1efc683 100644 --- a/src/schemas/uncategorised/MessageCreateSchema.ts +++ b/src/schemas/uncategorised/MessageCreateSchema.ts @@ -16,8 +16,8 @@ along with this program. If not, see . */ -import { InteractionType, Snowflake } from "@spacebar/util"; -import { AllowedMentions, MessageReference, ApplicationCommandType, BaseMessageComponents, Embed, PollAnswer, PollMedia, PublicUser } from "@spacebar/schemas"; +import { Snowflake } from "@spacebar/util"; +import { InteractionType, AllowedMentions, MessageReference, ApplicationCommandType, BaseMessageComponents, Embed, PollAnswer, PollMedia, PublicUser } from "@spacebar/schemas"; export type MessageCreateAttachment = { id: string; diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index c35b3f60c..153e086d4 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -20,7 +20,6 @@ import { User } from "./User"; import { Member } from "./Member"; import { Role } from "./Role"; import { Channel } from "./Channel"; -import { InteractionType } from "../interfaces"; import { Application } from "./Application"; import { Column, CreateDateColumn, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, RelationId, FindOneOptions, Raw, Not, BaseEntity, In } from "typeorm"; import { BaseClass } from "./BaseClass"; @@ -42,6 +41,7 @@ import { Reaction, UnfurledMediaItem, PartialUser, + InteractionType, } from "@spacebar/schemas"; import { MessageFlags } from "@spacebar/util"; import { JsonRemoveEmpty } from "../util/Decorators"; diff --git a/src/util/imports/Interactions.ts b/src/util/imports/Interactions.ts index 304241cdd..7c3bbd3db 100644 --- a/src/util/imports/Interactions.ts +++ b/src/util/imports/Interactions.ts @@ -16,8 +16,8 @@ along with this program. If not, see . */ -import { ApplicationCommandType } from "@spacebar/schemas"; -import { InteractionType, Snowflake } from "@spacebar/util"; +import { ApplicationCommandType, InteractionType } from "@spacebar/schemas"; +import { Snowflake } from "@spacebar/util"; interface PendingInteraction { timeout: NodeJS.Timeout; diff --git a/src/util/interfaces/Event.ts b/src/util/interfaces/Event.ts index 63e206f37..96d04a556 100644 --- a/src/util/interfaces/Event.ts +++ b/src/util/interfaces/Event.ts @@ -18,8 +18,6 @@ import { ConnectedAccount, - Interaction, - Message, Invite, Role, Emoji, @@ -42,6 +40,7 @@ import { JsonValue } from "@protobuf-ts/runtime"; import { ApplicationCommand, GuildCreateResponse, + Interaction, InteractionFailureReason, PartialEmoji, PublicChannel, diff --git a/src/util/interfaces/Interaction.ts b/src/util/interfaces/Interaction.ts deleted file mode 100644 index 8c9c752db..000000000 --- a/src/util/interfaces/Interaction.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* - Spacebar: A FOSS re-implementation and extension of the Discord.com backend. - Copyright (C) 2023 Spacebar and Spacebar Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import { Embed, AllowedMentions } from "@spacebar/schemas"; - -export interface Interaction { - id: string; - type: InteractionType; - data?: object; // TODO typing - guild_id: string; - channel_id: string; - member_id: string; - token: string; - version: number; -} - -export enum InteractionType { - Ping = 1, - ApplicationCommand = 2, - MessageComponent = 3, - ApplicationCommandAutocomplete = 4, - ModalSubmit = 5, -} - -export enum InteractionResponseType { - SelfCommandResponse = 0, - Pong = 1, - Acknowledge = 2, - ChannelMessage = 3, - ChannelMessageWithSource = 4, - AcknowledgeWithSource = 5, -} - -export interface InteractionApplicationCommandCallbackData { - tts?: boolean; - content: string; - embeds?: Embed[]; - allowed_mentions?: AllowedMentions; -} diff --git a/src/util/interfaces/index.ts b/src/util/interfaces/index.ts index 6620ba32d..63a3dc6ca 100644 --- a/src/util/interfaces/index.ts +++ b/src/util/interfaces/index.ts @@ -20,6 +20,5 @@ export * from "./Activity"; export * from "./ConnectedAccount"; export * from "./Event"; export * from "./GuildWelcomeScreen"; -export * from "./Interaction"; export * from "./Presence"; export * from "./Status";