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

Method updateAllCounters

src/app.js:241–276  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

239 }
240
241 async updateAllCounters() {
242 if (!this.db) {
243 logger.warn('Database not available for counter updates');
244 return;
245 }
246
247 for (const [guildId, guild] of this.guilds.cache) {
248 try {
249 const counters = await getServerCounters(this, guildId);
250 const validCounters = [];
251 const orphanedCounters = [];
252
253 for (const counter of counters) {
254 if (counter && counter.type && counter.channelId && counter.enabled !== false) {
255 const channel = guild.channels.cache.get(counter.channelId);
256 if (channel) {
257 validCounters.push(counter);
258 await updateCounter(this, guild, counter);
259 } else {
260 orphanedCounters.push(counter);
261 logger.info(`Removing orphaned counter ${counter.id} (type: ${counter.type}, deleted channel: ${counter.channelId}) from guild ${guildId}`);
262 }
263 }
264 }
265
266 // Save cleaned counters if any were orphaned
267 // Save cleaned counters if any were orphaned
268 if (orphanedCounters.length > 0) {
269 await saveServerCounters(this, guildId, validCounters);
270 logger.info(`Cleaned up ${orphanedCounters.length} orphaned counter(s) from guild ${guildId} during scheduled update`);
271 }
272 } catch (error) {
273 logger.error(`Error updating counters for guild ${guildId}:`, error);
274 }
275 }
276 }
277
278 async loadHandlers() {
279 startupLog('Loading handlers...');

Callers 1

setupCronJobsMethod · 0.95

Calls 4

getServerCountersFunction · 0.90
updateCounterFunction · 0.90
saveServerCountersFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected