MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / getModerationCases

Function getModerationCases

src/utils/moderation.js:138–168  ·  view source on GitHub ↗
(guildId, filters = {})

Source from the content-addressed store, hash-verified

136}
137
138export 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
170export async function logModerationAction({ client, guild, event }) {
171 const caseId = await generateCaseId(client, guild.id);

Callers 1

executeFunction · 0.90

Calls 1

getFromDbFunction · 0.90

Tested by

no test coverage detected