summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2024-07-28 20:51:16 +1000
committerGitHub <noreply@github.com>2024-07-28 20:51:16 +1000
commita8acb554ad4e52eb9f85968eb4f590a2adac01a5 (patch)
tree173ae43b2022bb4d1733ed1e556c9a88e3e65a82 /src
parentUpdated the openapi schema (diff)
parentprettier .-. (diff)
downloadserver-ts-a8acb554ad4e52eb9f85968eb4f590a2adac01a5.tar.xz
Merge branch 'master' into master
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts14
-rw-r--r--src/api/routes/users/@me/index.ts11
-rw-r--r--src/util/entities/Message.ts87
-rw-r--r--src/util/schemas/MessageCreateSchema.ts9
-rw-r--r--src/util/schemas/responses/GuildMessagesSearchResponse.ts4
5 files changed, 112 insertions, 13 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts

index 645c6db23..d4635b1d7 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -130,19 +130,25 @@ router.get( query.take = Math.floor(limit / 2); if (query.take != 0) { const [right, left] = await Promise.all([ - Message.find({ ...query, where: { id: LessThan(around) } }), Message.find({ ...query, - where: { id: MoreThanOrEqual(around) }, + where: { channel_id, id: LessThan(around) }, + }), + Message.find({ + ...query, + where: { channel_id, id: MoreThanOrEqual(around) }, + order: { timestamp: "ASC" }, }), ]); left.push(...right); - messages = left; + messages = left.sort( + (a, b) => a.timestamp.getTime() - b.timestamp.getTime(), + ); } else { query.take = 1; const message = await Message.findOne({ ...query, - where: { id: around }, + where: { channel_id, id: around }, }); messages = message ? [message] : []; } diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts
index ad11a4281..cddc3a087 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts
@@ -120,7 +120,7 @@ router.patch( if (!body.password) throw FieldErrors({ password: { - message: req.t("auth:register.INVALID_PASSWORD"), + message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD", }, }); @@ -160,6 +160,15 @@ router.patch( }, }); } + + if (!body.password) { + throw FieldErrors({ + password: { + message: req.t("auth:login.INVALID_PASSWORD"), + code: "INVALID_PASSWORD", + }, + }); + } } if (body.discriminator) { diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts
index d28c8c29a..9ba6ff7e7 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts
@@ -216,7 +216,7 @@ export class Message extends BaseClass { }; @Column({ type: "simple-json", nullable: true }) - components?: MessageComponent[]; + components?: ActionRowComponent[]; @Column({ type: "simple-json", nullable: true }) poll?: Poll; @@ -248,21 +248,100 @@ export class Message extends BaseClass { } export interface MessageComponent { - type: number; - style?: number; + type: MessageComponentType; +} + +export interface ActionRowComponent extends MessageComponent { + type: MessageComponentType.ActionRow; + components: ( + | ButtonComponent + | StringSelectMenuComponent + | SelectMenuComponent + | TextInputComponent + )[]; +} + +export interface ButtonComponent extends MessageComponent { + type: MessageComponentType.Button; + style: ButtonStyle; label?: string; emoji?: PartialEmoji; custom_id?: string; sku_id?: string; url?: string; disabled?: boolean; - components: MessageComponent[]; +} + +export enum ButtonStyle { + Primary = 1, + Secondary = 2, + Success = 3, + Danger = 4, + Link = 5, + Premium = 6, +} + +export interface SelectMenuComponent extends MessageComponent { + type: + | MessageComponentType.StringSelect + | MessageComponentType.UserSelect + | MessageComponentType.RoleSelect + | MessageComponentType.MentionableSelect + | MessageComponentType.ChannelSelect; + custom_id: string; + channel_types?: number[]; + placeholder?: string; + default_values?: SelectMenuDefaultOption[]; // only for non-string selects + min_values?: number; + max_values?: number; + disabled?: boolean; +} + +export interface SelectMenuOption { + label: string; + value: string; + description?: string; + emoji?: PartialEmoji; + default?: boolean; +} + +export interface SelectMenuDefaultOption { + id: string; + type: "user" | "role" | "channel"; +} + +export interface StringSelectMenuComponent extends SelectMenuComponent { + type: MessageComponentType.StringSelect; + options: SelectMenuOption[]; +} + +export interface TextInputComponent extends MessageComponent { + type: MessageComponentType.TextInput; + custom_id: string; + style: TextInputStyle; + label: string; + min_length?: number; + max_length?: number; + required?: boolean; + value?: string; + placeholder?: string; +} + +export enum TextInputStyle { + Short = 1, + Paragraph = 2, } export enum MessageComponentType { Script = 0, // self command script ActionRow = 1, Button = 2, + StringSelect = 3, + TextInput = 4, + UserSelect = 5, + RoleSelect = 6, + MentionableSelect = 7, + ChannelSelect = 8, } export interface Embed { diff --git a/src/util/schemas/MessageCreateSchema.ts b/src/util/schemas/MessageCreateSchema.ts
index 014f6c87d..51263dcee 100644 --- a/src/util/schemas/MessageCreateSchema.ts +++ b/src/util/schemas/MessageCreateSchema.ts
@@ -16,7 +16,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Embed, MessageComponent, PollAnswer, PollMedia } from "@spacebar/util"; +import { + ActionRowComponent, + Embed, + PollAnswer, + PollMedia, +} from "@spacebar/util"; type Attachment = { id: string; @@ -54,7 +59,7 @@ export interface MessageCreateSchema { **/ attachments?: Attachment[]; sticker_ids?: string[]; - components?: MessageComponent[]; + components?: ActionRowComponent[]; // TODO: Fix TypeScript errors in src\api\util\handlers\Message.ts once this is enabled poll?: PollCreationSchema; enforce_nonce?: boolean; // For Discord compatibility, it's the default behavior here diff --git a/src/util/schemas/responses/GuildMessagesSearchResponse.ts b/src/util/schemas/responses/GuildMessagesSearchResponse.ts
index 6121983e0..ec41965b4 100644 --- a/src/util/schemas/responses/GuildMessagesSearchResponse.ts +++ b/src/util/schemas/responses/GuildMessagesSearchResponse.ts
@@ -17,9 +17,9 @@ */ import { + ActionRowComponent, Attachment, Embed, - MessageComponent, MessageType, Poll, PublicUser, @@ -42,7 +42,7 @@ export interface GuildMessagesSearchMessage { timestamp: string; edited_timestamp: string | null; flags: number; - components: MessageComponent[]; + components: ActionRowComponent[]; poll: Poll; hit: true; }