This commit is contained in:
Aslan 2025-12-28 17:57:58 +01:00
parent 0f6e387f30
commit 05875413f9
2 changed files with 48 additions and 12 deletions

View file

@ -3,6 +3,18 @@ import { state } from "./store/store.js";
import { type IUser, type TRole } from "./store/types.js";
import type { ILevel } from "./types.js";
const fixUserData = (user: IUser) => {
if (!user.experience) {
user.experience = 0;
}
if (!user.money) {
user.money = 0;
}
if (!user.aiCost) {
user.aiCost = 0;
}
};
const getUserById = (userId: string): IUser => {
const user = state.users.find((user) => user.id === userId);
if (!user) {
@ -18,15 +30,7 @@ const getUserById = (userId: string): IUser => {
};
}
if (!user.experience) {
user.experience = 0;
}
if (!user.money) {
user.money = 0;
}
if (!user.aiCost) {
user.aiCost = 0;
}
fixUserData(user);
return user;
};
@ -65,4 +69,28 @@ const getUserName = (user: IUser): string => {
return match.replaceAll("@", "");
};
export { getUserById, checkRoles, getLevel, getUserName };
const getUserFromMention = (mention: string): IUser | undefined => {
const regex = /\[\@\S*:aslan2142.space\]/;
const match = mention
.match(regex)
?.at(0)
?.replaceAll("[", "")
.replaceAll("]", "");
const user = state.users.find((user) => user.id === match);
if (!user) {
return undefined;
}
fixUserData(user);
return user;
};
export {
fixUserData,
getUserById,
checkRoles,
getLevel,
getUserName,
getUserFromMention,
};