Skip to content

Commit

Permalink
Merge branch 'master' into fix/messages-before-param
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake authored Jul 28, 2024
2 parents 81c44a0 + b575564 commit bc3a3ad
Show file tree
Hide file tree
Showing 8 changed files with 104,903 additions and 2,469 deletions.
1,181 changes: 879 additions & 302 deletions assets/openapi.json

Large diffs are not rendered by default.

106,075 changes: 103,918 additions & 2,157 deletions assets/schemas.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/api/routes/guilds/#guild_id/bulk-ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { Config } from "@spacebar/util";

const router: Router = Router();

Expand All @@ -52,7 +53,8 @@ router.post(

const userIds: Array<string> = req.body.user_ids;
if (!userIds) throw new HTTPError("The user_ids array is missing", 400);
if (userIds.length > 200)

if (userIds.length > Config.get().limits.guild.maxBulkBanUsers)
throw new HTTPError(
"The user_ids array must be between 1 and 200 in length",
400,
Expand Down
11 changes: 10 additions & 1 deletion src/api/routes/users/@me/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
});
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export class GuildLimits {
maxEmojis: number = 2000;
maxMembers: number = 25000000;
maxChannels: number = 65535;
maxBulkBanUsers: number = 200;
maxChannelsInCategory: number = 65535;
}
87 changes: 83 additions & 4 deletions src/util/entities/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/util/schemas/MessageCreateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util/schemas/responses/GuildMessagesSearchResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/

import {
ActionRowComponent,
Attachment,
Embed,
MessageComponent,
MessageType,
Poll,
PublicUser,
Expand All @@ -42,7 +42,7 @@ export interface GuildMessagesSearchMessage {
timestamp: string;
edited_timestamp: string | null;
flags: number;
components: MessageComponent[];
components: ActionRowComponent[];
poll: Poll;
hit: true;
}
Expand Down

0 comments on commit bc3a3ad

Please sign in to comment.