File size: 888 Bytes
9470e9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import User from '../models/User.js';

export const updateKarma = async (userId, change, reason) => {
  try {
    const user = await User.findById(userId);
    if (!user) return;

    // Calculate new score
    let newScore = user.karma + change;
    
    // Clamp between 0 and 100
    if (newScore > 100) newScore = 100;
    if (newScore < 0) newScore = 0;

    user.karma = newScore;

    // Auto-Ban Logic (Bible Rule: < 30)
    if (newScore < 30) {
      user.flags.isBanned = true;
      console.log(`🚫 BANNED User ${userId} (Karma: ${newScore})`);
    }

    // Log the reason (for future admin tools)
    // In MVP, we just console log, but we could push to a 'karmaHistory' array
    console.log(`Karma Update [${userId}]: ${change} (${reason}) => ${newScore}`);

    await user.save();
    return user;
  } catch (err) {
    console.error("Karma Update Failed", err);
  }
};