| 136 | } |
| 137 | |
| 138 | export async function getModerationCases(guildId, filters = {}) { |
| 139 | try { |
| 140 | const { userId, moderatorId, action, limit = 50, offset = 0 } = filters; |
| 141 | |
| 142 | const allCases = []; |
| 143 | |
| 144 | const caseListKey = `moderation_cases_list_${guildId}`; |
| 145 | const caseList = await getFromDb(caseListKey, []); |
| 146 | |
| 147 | let filteredCases = caseList; |
| 148 | |
| 149 | if (userId) { |
| 150 | filteredCases = filteredCases.filter(case_ => case_.targetUserId === userId); |
| 151 | } |
| 152 | |
| 153 | if (moderatorId) { |
| 154 | filteredCases = filteredCases.filter(case_ => case_.moderatorId === moderatorId); |
| 155 | } |
| 156 | |
| 157 | if (action) { |
| 158 | filteredCases = filteredCases.filter(case_ => case_.action === action); |
| 159 | } |
| 160 | |
| 161 | filteredCases.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); |
| 162 | |
| 163 | return filteredCases.slice(offset, offset + limit); |
| 164 | } catch (error) { |
| 165 | logger.error("Error getting moderation cases:", error); |
| 166 | return []; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | export async function logModerationAction({ client, guild, event }) { |
| 171 | const caseId = await generateCaseId(client, guild.id); |