From 59b4d21598fc0d79148340b05b624b0203c1a708 Mon Sep 17 00:00:00 2001 From: Jacob Schlecht Date: Fri, 24 Apr 2026 16:39:19 -0600 Subject: [PATCH] feat: Add the ability to get a user's limits, including current Signed-off-by: Jacob Schlecht --- src/Client.ts | 10 +++++++++- src/classes/User.ts | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 3119525c..7516b37c 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -3,7 +3,7 @@ import { batch, createSignal } from "solid-js"; import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter"; import { API } from "stoat-api"; -import type { DataLogin, RevoltConfig, Role } from "stoat-api"; +import type { DataLogin, RevoltConfig, Role, UserLimits } from "stoat-api"; import type { Channel } from "./classes/Channel.js"; import type { Emoji } from "./classes/Emoji.js"; @@ -578,4 +578,12 @@ export class Client extends AsyncEventEmitter { return data.id; } + + getLimits(): UserLimits | undefined { + if (!this.configured() || !this.user) { + return; + } + + return this.user.getLimits(); + } } diff --git a/src/classes/User.ts b/src/classes/User.ts index 296650f5..cb8334b9 100644 --- a/src/classes/User.ts +++ b/src/classes/User.ts @@ -1,4 +1,9 @@ -import type { User as APIUser, DataEditUser, Presence } from "stoat-api"; +import type { + User as APIUser, + DataEditUser, + Presence, + UserLimits, +} from "stoat-api"; import { decodeTime } from "ulid"; import type { UserCollection } from "../collections/UserCollection.js"; @@ -47,6 +52,13 @@ export class User { return new Date(decodeTime(this.id)); } + /** + * How old this user is in milliseconds + */ + get age() { + return new Date().getTime() - this.createdAt.getTime(); + } + /** * Username */ @@ -325,4 +337,19 @@ export class User { `/users/${this.id as ""}/mutual`, ); } + + getLimits(): UserLimits | undefined { + if (!this.#collection.client.configured()) { + return; + } + if ( + this.age < + (this.#collection.client.configuration?.features.limits.global + .new_user_hours ?? 72) * + 3600_0000 + ) { + return this.#collection.client.configuration?.features.limits.new_user; + } + return this.#collection.client.configuration?.features.limits.default; + } }