Skip to content

Commit afdd11f

Browse files
authored
feat: Add the ability to get a user's limits, including current (#153)
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
1 parent 9da2032 commit afdd11f

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/Client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { batch, createSignal } from "solid-js";
44
import { ReactiveMap } from "@solid-primitives/map";
55
import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter";
66
import { API } from "stoat-api";
7-
import type { DataLogin, RevoltConfig, Role } from "stoat-api";
7+
import type { DataLogin, RevoltConfig, Role, UserLimits } from "stoat-api";
88

99
import type { Channel } from "./classes/Channel.js";
1010
import type { Emoji } from "./classes/Emoji.js";
@@ -610,4 +610,12 @@ export class Client extends AsyncEventEmitter<Events> {
610610

611611
this.#slowmodeTimers.set(channelId, timer);
612612
}
613+
614+
getLimits(): UserLimits | undefined {
615+
if (!this.configured() || !this.user) {
616+
return;
617+
}
618+
619+
return this.user.getLimits();
620+
}
613621
}

src/classes/User.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { User as APIUser, DataEditUser, Presence } from "stoat-api";
1+
import type {
2+
User as APIUser,
3+
DataEditUser,
4+
Presence,
5+
UserLimits,
6+
} from "stoat-api";
27
import { decodeTime } from "ulid";
38

49
import type { UserCollection } from "../collections/UserCollection.js";
@@ -48,6 +53,13 @@ export class User {
4853
return new Date(decodeTime(this.id));
4954
}
5055

56+
/**
57+
* How old this user is in milliseconds
58+
*/
59+
get age() {
60+
return new Date().getTime() - this.createdAt.getTime();
61+
}
62+
5163
/**
5264
* Username
5365
*/
@@ -334,4 +346,19 @@ export class User {
334346
`/users/${this.id as ""}/mutual`,
335347
);
336348
}
349+
350+
getLimits(): UserLimits | undefined {
351+
if (!this.#collection.client.configured()) {
352+
return;
353+
}
354+
if (
355+
this.age <
356+
(this.#collection.client.configuration?.features.limits.global
357+
.new_user_hours ?? 72) *
358+
3600_0000
359+
) {
360+
return this.#collection.client.configuration?.features.limits.new_user;
361+
}
362+
return this.#collection.client.configuration?.features.limits.default;
363+
}
337364
}

0 commit comments

Comments
 (0)