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

Function getServerCounters

src/services/serverstatsService.js:193–229  ·  view source on GitHub ↗
(client, guildId)

Source from the content-addressed store, hash-verified

191}
192
193export async function getServerCounters(client, guildId) {
194 try {
195 if (!client || !client.db) {
196 logger.warn('Database not available for getServerCounters');
197 return [];
198 }
199
200 const data = await client.db.get(`counters:${guildId}`);
201
202 let counters = [];
203
204 if (data && typeof data === 'object' && data.ok && Array.isArray(data.value)) {
205 counters = data.value;
206 } else if (Array.isArray(data)) {
207 counters = data;
208 } else if (typeof data === 'string') {
209 try {
210 const parsed = JSON.parse(data);
211 counters = Array.isArray(parsed) ? parsed : [];
212 } catch {
213 counters = [];
214 }
215 } else if (data && typeof data === 'object' && !data.ok && isValidCounterShape(data)) {
216 counters = [data];
217 } else {
218 if (process.env.NODE_ENV !== 'production') {
219 logger.debug('No counter data found, returning empty array');
220 }
221 return [];
222 }
223
224 return sanitizeCounters(counters, guildId);
225 } catch (error) {
226 logger.error("Error getting server counters:", error);
227 return [];
228 }
229}
230
231export async function saveServerCounters(client, guildId, counters) {
232 try {

Callers 9

updateAllCountersMethod · 0.90
handleDeleteFunction · 0.90
handleListFunction · 0.90
handleUpdateFunction · 0.90
handleCreateFunction · 0.90
executeFunction · 0.90
executeFunction · 0.90
executeFunction · 0.90

Calls 3

isValidCounterShapeFunction · 0.85
sanitizeCountersFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected