Fix me
This commit is contained in:
parent
0f6e387f30
commit
05875413f9
2 changed files with 48 additions and 12 deletions
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
import { MatrixClient } from "matrix-js-sdk";
|
||||
import type { ICallbackStore } from "../types.js";
|
||||
import { config } from "../../config.js";
|
||||
import { getLevel, getUserById, getUserName } from "../../helpers.js";
|
||||
import {
|
||||
getLevel,
|
||||
getUserById,
|
||||
getUserFromMention,
|
||||
getUserName,
|
||||
} from "../../helpers.js";
|
||||
import { state } from "../../store/store.js";
|
||||
import type { IUser } from "../../store/types.js";
|
||||
let client: MatrixClient;
|
||||
|
|
@ -29,7 +34,10 @@ const registerModuleUser = (
|
|||
const onMe = (text: string, roomId: string, sender: string) => {
|
||||
const mention = text.split(" ")[1];
|
||||
|
||||
const user = mention ? getUserById(mention) : getUserById(sender);
|
||||
const user = mention ? getUserFromMention(mention) : getUserById(sender);
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
const level = getLevel(user.experience);
|
||||
|
||||
client.sendHtmlMessage(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue