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

Method addWarning

src/services/warningService.js:8–51  ·  view source on GitHub ↗
({
    guildId,
    userId,
    moderatorId,
    reason,
    timestamp = Date.now()
  })

Source from the content-addressed store, hash-verified

6export class WarningService {
7
8 static async addWarning({
9 guildId,
10 userId,
11 moderatorId,
12 reason,
13 timestamp = Date.now()
14 }) {
15 try {
16 const key = `moderation:warnings:${guildId}:${userId}`;
17
18 const warnings = await getFromDb(key, []);
19
20 if (!Array.isArray(warnings)) {
21 logger.warn(`Warnings for ${userId} in ${guildId} corrupted, resetting`);
22 await setInDb(key, []);
23 return { success: false, error: 'Corrupted data' };
24 }
25
26 const warning = {
27 id: Date.now(),
28 guildId,
29 userId,
30 moderatorId,
31 reason,
32 timestamp,
33 status: 'active'
34 };
35
36 warnings.push(warning);
37
38 await setInDb(key, warnings);
39
40 logger.info(`Warning added: ${userId} in ${guildId} by ${moderatorId}`);
41
42 return {
43 success: true,
44 id: warning.id,
45 totalCount: warnings.length
46 };
47 } catch (error) {
48 logger.error('Error adding warning:', error);
49 return { success: false, error: error.message };
50 }
51 }
52
53 static async getWarnings(guildId, userId) {
54 try {

Callers 1

executeFunction · 0.80

Calls 2

getFromDbFunction · 0.90
setInDbFunction · 0.90

Tested by

no test coverage detected