Rework AI and add more stats

This commit is contained in:
Aslan 2025-12-28 17:35:36 +01:00
parent 29832dfce3
commit c8de53bfc7
14 changed files with 197 additions and 169 deletions

View file

@ -13,24 +13,31 @@ const registerModuleUser = (
client = matrixClient;
callbackStore.messageCallbacks.push({
startConditions: [`${config.app.triggerPrefix}level`],
callbackFunc: onLevel,
startConditions: [`${config.app.triggerPrefix}me`],
callbackFunc: onMe,
});
callbackStore.messageCallbacks.push({
startConditions: [`${config.app.triggerPrefix}leaderboard`],
callbackFunc: onLeaderboard,
});
callbackStore.messageCallbacks.push({
startConditions: [`${config.app.triggerPrefix}aileaderboard`],
callbackFunc: onAILeaderboard,
});
};
const onLevel = (_text: string, roomId: string, sender: string) => {
const level = getLevel(getUserById(sender).experience);
const onMe = (_text: string, roomId: string, sender: string) => {
const user = getUserById(sender);
const level = getLevel(user.experience);
client.sendHtmlMessage(
roomId,
"",
`<h3>Your Level: ${level.level}</h3>
</br>
<i>Next level progress: ${level.experienceInLevel}/${level.expToNextLevel}xp</i>`,
`<p>Your Role: <b>${user.role}</b></p></br>
<p>Your Money: <b>${user.money}</b></p></br>
<p>Your AI Cost: <b>${user.aiCost}$</b></p></br>
<p>Your Level: <b>${level.level}</b></p></br>
<i>Next level progress: <b>${level.experienceInLevel}/${level.expToNextLevel}xp</b></i>`,
);
};
@ -58,4 +65,28 @@ const onLeaderboard = (_text: string, roomId: string) => {
);
};
const onAILeaderboard = (_text: string, roomId: string) => {
const mapUsersToLeaderboard = (user: IUser): string => {
const cost = user.aiCost;
const userName = getUserName(user);
const userNameMod =
userName.charAt(0).toUpperCase() + userName.slice(1);
return `<li>${userNameMod}: cost <b>${cost}</b></li>`;
};
const users = state.users.sort(
(userA, userB) => userB.aiCost - userA.aiCost,
);
client.sendHtmlMessage(
roomId,
"",
`<h3>AI Cost Leaderboard</h3>
<ul>
${users.map(mapUsersToLeaderboard).join("")}
</ul>`,
);
};
export { registerModuleUser };