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

Function getEndedGiveaways

src/utils/database.js:436–470  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

434}
435
436export async function getEndedGiveaways(client) {
437 try {
438 const wrapper = client?.db;
439 if (!wrapper || typeof wrapper.get !== 'function') {
440 return [];
441 }
442
443 if (isPostgresSqlReady(wrapper)) {
444 const { pgConfig } = await import('../config/postgres.js');
445
446 const result = await wrapper.db.pool.query(
447 `SELECT id, guild_id, message_id, data, ends_at
448 FROM ${pgConfig.tables.giveaways}
449 WHERE ends_at <= NOW()
450 AND COALESCE((data->>'ended')::boolean, false) = false
451 ORDER BY ends_at ASC`,
452 );
453
454 return result.rows || [];
455 }
456
457 if (wrapper.isDegraded?.()) {
458 logger.debug('Postgres SQL unavailable for ended giveaways; scanning key-value store');
459 }
460
461 return await getEndedGiveawaysFromKv(client);
462 } catch (error) {
463 logger.error('Error getting ended giveaways:', error);
464 try {
465 return await getEndedGiveawaysFromKv(client);
466 } catch {
467 return [];
468 }
469 }
470}
471
472export async function markGiveawayEnded(client, giveawayId, endedData) {
473 try {

Callers 1

checkGiveawaysFunction · 0.90

Calls 3

isPostgresSqlReadyFunction · 0.85
getEndedGiveawaysFromKvFunction · 0.85
isDegradedMethod · 0.80

Tested by

no test coverage detected