MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / getUserLevelData

Function getUserLevelData

src/services/leveling.js:183–221  ·  view source on GitHub ↗
(client, guildId, userId)

Source from the content-addressed store, hash-verified

181}
182
183export async function getUserLevelData(client, guildId, userId) {
184 try {
185 if (!guildId || !userId) {
186 throw new TitanBotError(
187 'Guild ID and User ID are required',
188 ErrorTypes.VALIDATION
189 );
190 }
191
192 const key = `${guildId}:leveling:users:${userId}`;
193 const data = await client.db.get(key);
194
195 if (!data) {
196 return {
197 xp: 0,
198 level: 0,
199 totalXp: 0,
200 lastMessage: 0,
201 rank: 0
202 };
203 }
204
205 return {
206 xp: Math.max(0, data.xp || 0),
207 level: Math.max(0, Math.min(data.level || 0, MAX_LEVEL)),
208 totalXp: Math.max(0, data.totalXp || 0),
209 lastMessage: data.lastMessage || 0,
210 rank: data.rank || 0
211 };
212 } catch (error) {
213 logger.error(`Error getting user level data for ${userId}:`, error);
214 if (error instanceof TitanBotError) throw error;
215 throw new TitanBotError(
216 `Failed to fetch user data: ${error.message}`,
217 ErrorTypes.DATABASE,
218 'Could not fetch level data at this time.'
219 );
220 }
221}
222
223export async function saveUserLevelData(client, guildId, userId, data) {
224 try {

Callers 5

addXpFunction · 0.90
getLeaderboardFunction · 0.70
addLevelsFunction · 0.70
removeLevelsFunction · 0.70
setUserLevelFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected