From 96c56282d03f02b70b22a66b269f1c9c93e0214a Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 17 Nov 2025 16:48:41 -0600 Subject: [PATCH 1/4] prevent bots from joining guild with config --- .../config/types/subconfigurations/guild/AutoJoin.ts | 1 + src/util/entities/User.ts | 11 ++++++++++- src/util/util/Application.ts | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/config/types/subconfigurations/guild/AutoJoin.ts b/src/util/config/types/subconfigurations/guild/AutoJoin.ts index be1c0d0d8..5acdd74e0 100644 --- a/src/util/config/types/subconfigurations/guild/AutoJoin.ts +++ b/src/util/config/types/subconfigurations/guild/AutoJoin.ts @@ -20,4 +20,5 @@ export class AutoJoinConfiguration { enabled: boolean = true; guilds: string[] = []; canLeave: boolean = true; + bots: boolean = false; } diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index eb42d9f29..5ee633520 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts @@ -157,7 +157,7 @@ export class User extends BaseClass { @OneToOne(() => UserSettings, { cascade: true, orphanedRowAction: "delete", - nullable: true + nullable: true, }) @JoinColumn() settings?: UserSettings; @@ -257,6 +257,7 @@ export class User extends BaseClass { password, id, req, + bot, }: { username: string; password?: string; @@ -264,6 +265,7 @@ export class User extends BaseClass { date_of_birth?: Date; // "2000-04-03" id?: string; req?: Request; + bot?: boolean; }) { // trim special uf8 control characters -> Backspace, Newline, ... username = trimSpecial(username); @@ -306,6 +308,7 @@ export class User extends BaseClass { premium_type: Config.get().defaults.user.premiumType ?? 0, verified: Config.get().defaults.user.verified ?? true, created_at: new Date(), + bot: !!bot, }); user.validate(); @@ -319,6 +322,12 @@ export class User extends BaseClass { } setImmediate(async () => { + if (bot) { + const { guild } = Config.get(); + if (!guild.autoJoin.bots) { + return; + } + } if (Config.get().guild.autoJoin.enabled) { for (const guild of Config.get().guild.autoJoin.guilds || []) { await Member.addToGuild(user.id, guild).catch((e) => console.error("[Autojoin]", e)); diff --git a/src/util/util/Application.ts b/src/util/util/Application.ts index 23019a7ff..35cf6a370 100644 --- a/src/util/util/Application.ts +++ b/src/util/util/Application.ts @@ -7,6 +7,7 @@ export async function createAppBotUser(app: Application, req: Request) { password: undefined, id: app.id, req, + bot: true, }); user.id = app.id; From fbc29a166e59a732b2efaf5a6860ef84decea0f0 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 17 Nov 2025 16:50:43 -0600 Subject: [PATCH 2/4] ignore bun lock file --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 902ed77c0..dc33551ad 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ build tmp/ dump/ result -jwt.key* \ No newline at end of file +jwt.key* +bun.lock From 3ecda540d23ad06ee2c39b9b3735dd3071e0d86a Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 17 Nov 2025 17:02:41 -0600 Subject: [PATCH 3/4] update last message id in more places This update should update the last message id in the greet message endpoint and the Member creation message. --- src/api/routes/channels/#channel_id/greet.ts | 5 ++++- src/util/entities/Member.ts | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api/routes/channels/#channel_id/greet.ts b/src/api/routes/channels/#channel_id/greet.ts index 399e30a22..b6ce1ee51 100644 --- a/src/api/routes/channels/#channel_id/greet.ts +++ b/src/api/routes/channels/#channel_id/greet.ts @@ -20,7 +20,7 @@ import { route } from "@spacebar/api"; import { Channel, emitEvent, Message, MessageCreateEvent, Permissions, Sticker } from "@spacebar/util"; import { Request, Response, Router } from "express"; import { In } from "typeorm"; -import { GreetRequestSchema, MessageType } from "@spacebar/schemas" +import { GreetRequestSchema, MessageType } from "@spacebar/schemas"; const router: Router = Router({ mergeParams: true }); @@ -88,6 +88,8 @@ router.post( sticker_items: randomSticker ? [{ id: randomSticker.id, name: randomSticker.name, format_type: randomSticker.format_type }] : [], }); + channel.last_message_id = message.id; + await Promise.all([ message.save(), emitEvent({ @@ -95,6 +97,7 @@ router.post( data: message, channel_id, } as MessageCreateEvent), + channel.save(), ]); res.send(channel); diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index 98f6e687c..7cfe844b5 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -397,6 +397,9 @@ export class Member extends BaseClassWithoutId { ]); if (guild.system_channel_id) { + const channel = await Channel.findOneOrFail({ + where: { id: guild.system_channel_id }, + }); // Send a welcome message const message = Message.create({ type: 7, @@ -414,6 +417,9 @@ export class Member extends BaseClassWithoutId { mention_roles: [], mention_everyone: false, }); + + channel.last_message_id = message.id; + await Promise.all([ message.save(), emitEvent({ @@ -421,6 +427,7 @@ export class Member extends BaseClassWithoutId { channel_id: message.channel_id, data: message, } as MessageCreateEvent), + channel.save(), ]); } } From e81516a8e6fd287d37866e8edb7ffd631076d263 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 17 Nov 2025 17:21:03 -0600 Subject: [PATCH 4/4] set default notification value This should make it so that people who just joined have the default notification value as set by the guild instead of always defaulting to all messages. --- src/util/entities/Member.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index 98f6e687c..b6b514e08 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -358,7 +358,7 @@ export class Member extends BaseClassWithoutId { hide_muted_channels: false, notify_highlights: 0, channel_overrides: {}, - message_notifications: 0, + message_notifications: guild.default_message_notifications, mobile_push: true, muted: false, suppress_everyone: false,